static void Main() { var appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (!String.IsNullOrEmpty(appPath)) { Directory.SetCurrentDirectory(appPath); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (var context = new ProgramContext()) { context.Start(); Application.Run(context); } }
public MainForm(ProgramContext appContext) { if (null == appContext) { throw new ArgumentNullException(); } AppContext = appContext; InitializeComponent(); timerWU = new System.Timers.Timer(); timerWU.Interval = 5000; //pov2500 timerWU.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEventWU); timerWU.Enabled = false; timerWU.Start(); _advancedSensorValues = new AdvancedSensorValues[10]; _advancedSensorValues[0] = new AdvancedSensorValues(); _advancedSensorValues[1] = new AdvancedSensorValues(); _advancedSensorValues[2] = new AdvancedSensorValues(); _advancedSensorValues[3] = new AdvancedSensorValues(); _advancedSensorValues[4] = new AdvancedSensorValues(); _advancedSensorValues[5] = new AdvancedSensorValues(); _advancedSensorValues[6] = new AdvancedSensorValues(); _advancedSensorValues[7] = new AdvancedSensorValues(); _advancedSensorValues[8] = new AdvancedSensorValues(); _advancedSensorValues[9] = new AdvancedSensorValues(); Text = ProgramContext.ProgramFriendlyName; ConverterCache = ReadingValuesConverterCache<IReadingValues, ReadingValues>.Default; ConverterCacheReadingValues = ReadingValuesConverterCache<ReadingValues>.Default; ConverterCacheReadingAggregate = ReadingValuesConverterCache<ReadingAggregate>.Default; liveAtmosphericGraph.ConverterCacheReadingValues = ConverterCacheReadingValues; _deviceConnection = new UsbDaqConnection(); // new Demo.DemoDaqConnection(); // create the DB file using the application privilages instead of using the installer if (!File.Exists(DatabaseFileName)) { using(var dbTemplateDataStream = typeof (DbDataStore).Assembly.GetManifestResourceStream("Atmo." + DatabaseFileName)) using(var outDbTemplate = File.Create(DatabaseFileName)) { var buffer = new byte[1024]; int totalRead; while(0 < (totalRead = dbTemplateDataStream.Read(buffer, 0, buffer.Length))) outDbTemplate.Write(buffer,0, totalRead); } Thread.Sleep(250); // just to be safe Log.InfoFormat("Core DB file created at: {0}", Path.GetFullPath(DatabaseFileName)); } try { _dbConnection = new System.Data.SQLite.SQLiteConnection( @"data source=" + DatabaseFileName + @";page size=4096;cache size=4000;journal mode=Off"); _dbConnection.Open(); } catch(Exception ex) { Log.Error("Database connection failure.", ex); throw; } _dbStore = new DbDataStore(_dbConnection); _memoryDataStore = new MemoryDataStore(); _sensorViewPanelControler = new SensorViewPanelController(groupControlSensors) { DefaultSelected = true }; _historicSensorViewPanelController = new HistoricSensorViewPanelController(groupControlDbList) { DefaultSelected = true, }; _historicSensorViewPanelController.OnDeleteRequested += OnDeleteRequested; _historicSensorViewPanelController.OnRenameRequested += OnRenameRequested; historicalTimeSelectHeader.CheckEdit.CheckedChanged += histNowChk_CheckedChanged; historicalTimeSelectHeader.TimeRange.SelectedIndex = historicalTimeSelectHeader.TimeRange.FindNearestIndex(AppContext.PersistentState.HistoricalTimeScale); liveAtmosphericHeader.TimeRange.SelectedIndex = liveAtmosphericHeader.TimeRange.FindNearestIndex(AppContext.PersistentState.LiveTimeScale); historicalTimeSelectHeader.TimeRange.ValueChanged += historicalTimeSelectHeader_TimeRangeValueChanged; liveAtmosphericHeader.TimeRange.ValueChanged += liveTimeSelectHeader_TimeRangeValueChanged; foreach(var view in _historicSensorViewPanelController.Views.Where(v => null != v)) { bool selected = false; if( null != view.SensorInfo && AppContext.PersistentState.SelectedDatabases.Contains(view.SensorInfo.Name) ) { selected = true; } view.IsSelected = selected; } //HandleRapidFireSetup(); HandleDaqTemperatureSourceSet(_deviceConnection.UsingDaqTemp); //rp HandleWFSetup(); //rp HandleAWSetup(); //rp HandleWeatherSetup(); //rp _internetStreamingStatistics = new InternetStreamingStatistics(); ReloadHistoric(); _historicSensorViewPanelController.OnSelectionChanged += RequestHistoricalUpdate; historicalGraphBreakdown.OnSelectedPropertyChanged += RequestHistoricalUpdate; historicalTimeSelectHeader.OnTimeRangeChanged += RequestHistoricalUpdate; windResourceGraph.OnWeibullParamChanged += RequestHistoricalUpdate; #if DEBUG barSubItemDebug.Visibility = DevExpress.XtraBars.BarItemVisibility.Always; #endif }