Esempio n. 1
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                Options = new INIFile("settings.ini");
                Options.Write("timerSettings", TimerSetting.ToString());
                Options.Write("areaLatitude", AreaLatitude.ToString());
                Options.Write("areaLongitude", AreaLongitude.ToString());
                Options.Write("pressure", Pressure.ToString());
                Options.Write("temperature", Temperature.ToString());
                Options.Write("seaLevelRise", SeaLevelRise.ToString());
                Options.Write("timeZone", TimeZone.ToString());
                Options.Write("portName", PortName);
                Options.Write("driverName", DriverName);
                Options.Write("errorEmailAddress", String.Join(";", ErrorEmailAddress));

                if (!string.IsNullOrEmpty(Program.ConsoleForm.ConsoleBoxValue))
                {
                    if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\log\"))
                    {
                        Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\log\");
                    }
                    using (
                        StreamWriter outputFile =
                            new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\log\" +
                                             $"{LogDateTimeStart.ToString("yy.MM.dd HH-mm-ss")} - {DateTime.Now.ToString("yy.MM.dd HH-mm-ss")}" +
                                             ".txt"))
                    {
                        string[] consoleboxvalue = Program.ConsoleForm.ConsoleBoxValue.Split('\n');

                        foreach (string line in consoleboxvalue)
                        {
                            outputFile.WriteLine(line);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // ignored
            }
            Environment.Exit(0);
        }
Esempio n. 2
0
        public MainForm()
        {
            InitializeComponent();

            SPort.BaudRate      = 9800;
            SPort.Parity        = Parity.None;
            SPort.DataBits      = 8;
            SPort.StopBits      = StopBits.One;
            SPort.Handshake     = Handshake.XOnXOff;
            SPort.DataReceived += SPortRead;
            SPort.ReadTimeout   = 1000;
            SPort.WriteTimeout  = 1000;
            SPort.DtrEnable     = true;
            SPort.RtsEnable     = true;

            _SPAData = new SPACalculator.SPAData();

            if (!File.Exists("settings.ini"))
            {
                File.Create("settings.ini");
            }
            Options = new INIFile("settings.ini");

            try
            {
                TimerSetting      = int.Parse(Options.Read("timerSettings"));
                AreaLatitude      = Double.Parse(Options.Read("areaLatitude"));
                AreaLongitude     = Double.Parse(Options.Read("areaLongitude"));
                Pressure          = Double.Parse(Options.Read("pressure"));
                Temperature       = Double.Parse(Options.Read("temperature"));
                SeaLevelRise      = Double.Parse(Options.Read("seaLevelRise"));
                TimeZone          = Double.Parse(Options.Read("timeZone"));
                PortName          = Options.Read("portName");
                DriverName        = Options.Read("driverName");
                ErrorEmailAddress = new List <string>(Options.Read("errorEmailAddress").Split(';'));
                DriverPath        = Assembly.GetExecutingAssembly().Location.Replace(@"\SOAutomatic.exe", "") + @"\drivers\" + DriverName;
                DriverMethod      = Program.SettingsForm.CreateFunction(File.ReadAllText(DriverPath));
            }
            catch
            {
                MessageBox.Show("Не удалось загрузить настройки из файла settings.ini.");
            }
        }