Exemple #1
0
        static void Main()
        {
            using (Mutex mutex = new Mutex(true, appGuid))
            {
                if (mutex.WaitOne(TimeSpan.Zero, true))
                {
                    try
                    {
                        //If it is first run chek for setup
                        AuxilaryProc.CreateAutoStartLink();


                        if (Environment.OSVersion.Version.Major >= 6)
                        {
                            SetProcessDPIAware();
                        }
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);
                        Application.Run(new MainForm());
                    }
                    catch (Exception ex)
                    {
                        Logging.AddLog("Unhandled exception: " + ex.Message, LogLevel.Important, Highlight.Error);
                        Logging.AddLog("Exception details: " + ex.ToString(), LogLevel.Debug, Highlight.Debug);
                        MessageBox.Show("Unhandled exception: " + ex.ToString());
                    }
                    mutex.ReleaseMutex();
                }
                else
                {
                    //if already run - set window to foreground
                    Utils.SetCurrentWindowToForeground();
                }

                Logging.DumpToFile();
            }
        }
Exemple #2
0
        /// <summary>
        /// Main form load event - startup actions take place here
        /// </summary>
        private void Form1_Load(object sender, EventArgs e)
        {
            //DefBackColor
            DefBackColor          = chkMaxim.BackColor;
            DefBackColorTextBoxes = txtShortAlt.BackColor;

            //Load config
            ConfigManagement.Load();

            //Load parameters
            LoadParams();
            //Update interface for current Settings values
            //IQP_UpdateSettingsDialogFields();


            //Init programs objects using loaded settings
            ObsControl.InitProgramsObj();

            //Load parameters after all objects was initialized
            LoadOtherParamsFromXML();


            //Dump log, because interface may hang wating for connection
            Logging.DumpToFile();


            //Connect Devices, which are general adapters (no need to power or control something)
            try
            {
                ObsControl.ASCOMSwitch.Connect = true;
                ObsControl.ASCOMSwitch.CheckPowerDeviceStatus_async();
            }
            catch (Exception ex)
            {
                Logging.AddLog("Error connecting Switch on startup [" + ex.Message + "]", LogLevel.Important, Highlight.Error);
                Logging.AddLog("Exception details: " + ex.ToString(), LogLevel.Debug, Highlight.Error);
            }

            try
            {
                ObsControl.ASCOMDome.Connect = true;
            }
            catch (Exception ex)
            {
                Logging.AddLog("Error connecting Dome on startup [" + ex.Message + "]", LogLevel.Important, Highlight.Error);
                Logging.AddLog("Exception details: " + ex.ToString(), LogLevel.Debug, Highlight.Error);
            }

            //Update visual interface statuses
            UpdateStatusbarASCOMStatus();
            UpdatePowerButtonsStatus();

            //init graphic elements
            ROOF_startPos = rectRoof.Location;
            //Update visual Roof Status
            UpdateRoofStatus();

            //Start tcp server
            SocketServer = new SocketServerClass(this);
            toolStripStatus_Connection.Text = "CONNECTIONS: 0";
            if (true)
            {
                backgroundWorker_SocketServer.RunWorkerAsync();
                toolStripStatus_Connection.ForeColor = Color.Black;
            }
            else
            {
                toolStripStatus_Connection.ForeColor = Color.Gray;
            }

            //init vars
            //DrawTelescopeV(panelTelescope);

            //Init versiondata static class
            //Display about information
            VersionData.initVersionData();
            LoadAboutData();

            //Init Log DropDown box
            foreach (LogLevel C in Enum.GetValues(typeof(LogLevel)))
            {
                toolStripDropDownLogLevel.DropDownItems.Add(Enum.GetName(typeof(LogLevel), C));
            }
            toolStripDropDownLogLevel.Text = Enum.GetName(typeof(LogLevel), LogLevel.Activity);

            //Fill in Combobox Boltwood
            comboBoxRainFlag.DataSource = Enum.GetNames(typeof(Enum_RainFlag));
            comboBoxWetFlag.DataSource  = Enum.GetNames(typeof(Enum_WetFlag));

            comboBoxCloudCond.DataSource    = Enum.GetNames(typeof(Enum_CloudCond));
            comboBoxWindCond.DataSource     = Enum.GetNames(typeof(Enum_WindCond));
            comboBoxRainCond.DataSource     = Enum.GetNames(typeof(Enum_RainCond));
            comboBoxDaylightCond.DataSource = Enum.GetNames(typeof(Enum_DayCond));

            comboBoxRoofCloseFlag.DataSource = Enum.GetNames(typeof(Enum_RoofFlag));
            comboBoxAlertFlag.DataSource     = Enum.GetNames(typeof(Enum_AlertFlag));

            //Run all timers at the end
            mainTimer_Short.Enabled    = true;
            mainTimer_Long.Enabled     = true;
            mainTimer_VeryLong.Enabled = true;
            logRefreshTimer.Enabled    = true;


            weatherSmallChart.Series[0].XValueType = ChartValueType.DateTime;
            weatherSmallChart.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "HH:mm";

            foreach (Series Sr in chartWT.Series)
            {
                Sr.XValueType = ChartValueType.DateTime;
            }
            foreach (ChartArea CA in chartWT.ChartAreas)
            {
                CA.AxisX.LabelStyle.Format = "HH:mm";
            }


            //FORM APPEARENCE
            Form_Normal_Width = this.Width;
            borderWidth       = (this.Width - this.ClientSize.Width) / 2;
            titleBarHeight    = this.Height - this.ClientSize.Height - 2 * borderWidth;
            statusBarHeight   = statusBar.Height;
            prevX             = this.Location.X;
            prevY             = this.Location.Y;
            Form_SwitchTo_Maximum_Mode();


            // TEST COMMAND LINE PARAMETERS
            bool   autostart    = false;
            string comport_over = string.Empty;

            AuxilaryProc.CheckStartParams(out autostart, out comport_over);


            if (autostart)
            {
                this.btnStartAll.PerformClick();
            }
        }