//----------------------------------------------------------------------- // // Copyright © 2012 Nils Hammar. All rights reserved. // //----------------------------------------------------------------------- /* * Software to access vehicle information via the OBD-II connector. * * Copyright © 2012 Nils Hammar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Alternative licensing is possible, see the licensing document. * * The above text may not be removed or modified. */ namespace DataSource { using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; using global::DataSource.FileAccess; using global::SharedObjects; using global::SharedObjects.DataMgmt; using global::SharedObjects.Misc; /// /// Implementation of data source interface. /// public class DataSourceImplementation : IDataSource { /// /// Communication speeds file. /// public const string COMMSPEED_FILE = "commspeeds.xml"; /// /// Preferences file. /// public const string PREFERENCES_FILE = "preferences.xml"; /// /// Parameters file. /// public const string PARAMETERS_FILE = "parameters.xml"; /// /// Modes file. /// public const string MODES_FILE = "modes.xml"; /// /// Pidgroups file. /// public const string PIDGROUP_FILE = "pidgroups.xml"; /// /// Units file. /// public const string UNITS_FILE = "units.xml"; /// /// Vehicles file. /// public const string VEHICLES_FILE = "vehicles.xml"; /// /// Icons file. /// public const string ICONS_FILE = "icons.xml"; /// /// Filters file. /// public const string FILTER_FILE = "filters.xml"; /// /// Gauges config file. /// public const string GAUGES_FILE = "gauges.xml"; /// /// Gauges config file. /// public const string TELLTALES_FILE = "telltales.xml"; /// /// General OBD codes file. /// public const string OBDCODES_FILE = "obdcodes.txt"; /// /// Event logging instance. /// private ILogging iLogging; /// /// Current preferences implementation instance. /// private IPreferences iPreferences; /// /// Communication speeds file access instance. /// private CommspeedFileAccess commspeedFileAccess; /// /// Vehicles file access instance. /// private VehiclesFileAccess vehiclesFileAccess; /// /// Access instance for mode file. /// private ModeFileAccess modeFileAccess; /// /// Access instance for pidgroup file. /// private PidGroupFileAccess pidGroupFileAccess; /// /// Access instance for units file. /// private UnitsFileAccess unitsFileAccess; /// /// Parameters file access instance. /// private ParametersFileAccess parametersFileAccess; /// /// Icon registry file access. /// private IconFileAccess iconFileAccess; /// /// Filter file access. /// private FilterFileAccess filterFileAccess; /// /// Access class for gauges file. /// private GaugeFileAccess gaugeFileAccess; /// /// Access class for telltales file. /// private TelltaleFileAccess telltaleFileAccess; /// /// Gets commspeed list instance. /// public IList commspeeds { get { return this.commspeedFileAccess.commspeeds; } } /// /// Gets vehicles list instance. /// public IList vehicles { get { return this.vehiclesFileAccess.vehicles; } } /// /// Gets pidgroups list instance. /// public IList modes { get { return this.modeFileAccess.modegroups; } } /// /// Gets pidgroups list instance. /// public IList pidgroups { get { return this.pidGroupFileAccess.pidgrouplist; } } /// /// Gets pidgroups list instance. /// public IList restrictedPidgroups { get { return this.pidGroupFileAccess.restrictedPidgrouplist; } } /// /// Gets units list instance. /// public IList units { get { return this.unitsFileAccess.unitslist; } } /// /// Gets parameter list instance. /// public IList parameters { get { return this.parametersFileAccess.paramlist; } } /// /// Gets List of supported icons. /// public IList icons { get { return this.iconFileAccess.icons; } } /// /// Gets List of supported filters. /// public IList filters { get { return this.filterFileAccess.filters; } } /// /// Gets List of supported gauges. /// public IList gauges { get { return this.gaugeFileAccess.gaugeitems; } } /// /// Gets List of supported telltales. /// public IList telltales { get { return this.telltaleFileAccess.telltaleitems; } } /// /// Gets data file directory. /// public string dataFileDir { get; private set; } /// /// Initializes a new instance of the class. /// /// Event logging instance. /// Preferences interface instance. /// Data file directory path. public DataSourceImplementation(ILogging iLogging, IPreferences iPreferences, string dataFileDir) { this.iLogging = iLogging; this.iPreferences = iPreferences; this.dataFileDir = dataFileDir; this.commspeedFileAccess = new CommspeedFileAccess(this.iLogging, DataSourceImplementation.COMMSPEED_FILE, this.dataFileDir); this.vehiclesFileAccess = new VehiclesFileAccess(this.iLogging, DataSourceImplementation.VEHICLES_FILE, this.dataFileDir); this.unitsFileAccess = new UnitsFileAccess(this.iLogging, DataSourceImplementation.UNITS_FILE, this.dataFileDir); this.parametersFileAccess = new ParametersFileAccess(iLogging, DataSourceImplementation.PARAMETERS_FILE, this.dataFileDir); this.modeFileAccess = new ModeFileAccess(this.iLogging, DataSourceImplementation.MODES_FILE, this.dataFileDir); this.pidGroupFileAccess = new PidGroupFileAccess(this.iPreferences, this.iLogging, this, DataSourceImplementation.PIDGROUP_FILE, this.dataFileDir); this.iconFileAccess = new IconFileAccess(this.iLogging, DataSourceImplementation.ICONS_FILE, this.dataFileDir); this.filterFileAccess = new FilterFileAccess(iLogging, DataSourceImplementation.FILTER_FILE, this.dataFileDir); this.gaugeFileAccess = new GaugeFileAccess(iLogging, DataSourceImplementation.GAUGES_FILE, this.dataFileDir); this.telltaleFileAccess = new TelltaleFileAccess(iLogging, DataSourceImplementation.TELLTALES_FILE, this.dataFileDir); } /// /// Locate data files directory. /// /// Path to data files. public static string locateDataFiles() { string dataFileDir = null; foreach (string pathStr in Utils.DEFAULT_DATA_FILE_DIR) { string expPath = Environment.ExpandEnvironmentVariables(pathStr); if (File.Exists(expPath + DataSourceImplementation.PARAMETERS_FILE)) { dataFileDir = expPath; break; } } if (dataFileDir == null) { string currDir = Directory.GetCurrentDirectory(); MessageBox.Show( "Data files not found in expected location '" + dataFileDir + "',\r\n" + "trying current directory '" + currDir + "' instead.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); dataFileDir = currDir + "\\"; } return dataFileDir; } /// /// Load data from files. /// public void load() { //// Notice that the order below is important. this.commspeedFileAccess.load(); this.unitsFileAccess.load(); this.parametersFileAccess.load(); this.vehiclesFileAccess.load(); this.modeFileAccess.load(); this.pidGroupFileAccess.load(); this.iconFileAccess.load(); this.filterFileAccess.load(); this.gaugeFileAccess.load(); this.telltaleFileAccess.load(); } /// /// Reload the pid group data. /// public void loadPidgroups() { this.pidGroupFileAccess.load(); } /// /// Save the vehicle data to file. /// public void saveCommspeeds() { this.commspeedFileAccess.save(); } /// /// Save the vehicle data to file. /// public void saveVehicles() { this.vehiclesFileAccess.save(); } /// /// Save the unit data to file. /// public void saveUnits() { this.unitsFileAccess.save(); } /// /// Save parameter data. /// public void saveParameters() { this.parametersFileAccess.save(); } /// /// Save the Modes data to file. /// public void saveModes() { this.modeFileAccess.save(); } /// /// Save the PID group data to file. /// public void savePidgroups() { this.pidGroupFileAccess.save(); } /// /// Save the PID group data to file. /// public void saveIcons() { this.iconFileAccess.save(); } /// /// Save the Filters data to file. /// public void saveFilters() { this.filterFileAccess.save(); } /// /// Save the gauge data to file. /// public void saveGauges() { this.gaugeFileAccess.save(); } /// /// Save the telltale data to file. /// public void saveTelltales() { this.telltaleFileAccess.save(); } } }