private RootElement settings = new RootElement(); // Конфигурация

        /// <inheritdoc />
        /// <summary>Initializes a new instance of the <see cref="T:MemsourceHelper.MainWindow" /> class.</summary>
        public MainWindow()
        {
            this.InitializeComponent();
            this.logger.Info("Запуск программы Memsource Helper.");

            this.Title = $"Memsource Helper v{Assembly.GetExecutingAssembly().GetName().Version}";

            // Вычитывание параметров из XML
            // Инициализация модели настроек
            var settingsXml = new SettingsXml <RootElement>(SettingsPath);

            this.settings.Api = new Api();

            if (!File.Exists(SettingsPath))
            {
                this.settings = this.SetDefaultValue(this.settings); // Значения по умолчанию
                settingsXml.WriteXml(this.settings);
            }
            else
            {
                this.settings = settingsXml.ReadXml(this.settings);
            }

            this.parcer = new XmlParser(this.logger, this.settings);
        }
Example #2
0
        /// <summary>Основной метод.</summary>
        /// <param name="args">Аргументы.</param>
        public static void Main(string[] args)
        {
            // удаление процесса
            var localProcs = Process.GetProcesses();

            try
            {
                // Вычитывание параметров из XML
                // Инициализация модели настроек
                settingsXml         = new SettingsXml <SettingsShell.RootElement>(SettingsPath);
                settings.SoftUpdate = new SettingsShell.SoftUpdate();

                if (!File.Exists(SettingsPath))
                {
                    settings = SetDefaultValue(settings); // Значения по умолчанию
                    settingsXml.WriteXml(settings);
                }
                else
                {
                    settings = settingsXml.ReadXml(settings);
                }

                // Вычитывание параметров из удаленного xml
                // Инициализация модели настроек
                var remoteSettingsXml = new SettingsXml <RemoteSettingsShell.RootElementRemoteSettings>(settings.SoftUpdate.RemoteSettingsPath);
                remoteSettings.Phonebook    = new RemoteSettingsShell.Phonebook();
                remoteSettings.PhonebookUpd = new RemoteSettingsShell.PhonebookUpd();

                if (!string.IsNullOrEmpty(settings.SoftUpdate.RemoteSettingsPath))
                {
                    remoteSettings = remoteSettingsXml.ReadXml(remoteSettings);
                }

                var targetProc = localProcs.First(p => p.ProcessName == TargetName);
                targetProc.Kill();

                logger.Info("Программа P3.exe выключена");

                if (!string.IsNullOrEmpty(settings.SoftUpdate.RemoteSettingsPath))
                {
                    UpdateSoft();
                }
                else
                {
                    Console.WriteLine($"Неверный путь к файлу конфигурации {settings.SoftUpdate.RemoteSettingsPath}");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
Example #3
0
        /// <summary>Initializes a new instance of the <see cref="MainViewModel" /> class.</summary>
        public MainViewModel()
        {
            this.logger.Info("Запуск приложения Alisa");

            try
            {
                this.FilteredTEPCmd = new Command(arg => this.ApplyFilter());

                // Сервисные
                this.WriteTEPCmd      = new Command(arg => this.WriteTEP());
                this.DBCreateCmd      = new Command(arg => this.DBCreate());
                this.LogMailCmd       = new Command(arg => this.LogMail());
                this.FilterAndSaveCmd = new Command(arg => this.FilterAndSave());

                this.TEP  = new TEPModel {
                };
                this.Misc = new Misc {
                };

                // Вычитывание параметров из XML
                // Инициализация модели настроек
                var settingsXml = new SettingsXml <RootElement>(SettingsPath);
                this.settings.MSSQL  = new MSSQL();
                this.settings.SQLite = new SQLite();
                this.settings.Mail   = new Mail
                {
                    To = new List <string>()
                };

                this.settings.Reserv = new Reserv();

                if (File.Exists(SettingsPath))
                {
                    this.settings = settingsXml.ReadXml(this.settings);
                }
                else
                {
                    this.settings = this.SetDefaultValue(this.settings); // Значения по умолчанию
                    settingsXml.WriteXml(this.settings);
                }

                this.rDB = new RuntimeDb(this.settings.MSSQL);

                Misc.Master = this.settings.Reserv.Master ? "Master" : "Slave";

                // Вычитывание списка тегов из файла
                this.tags = this.rf.ReadFile(TagPath);

                // Коэффициенты
                this.CoeffModels = new ObservableCollection <CoeffModel> {
                };
                this.CoeffModels = this.rf.ReadCoeff(CoeffPath);

                this.sqliteDb = new SqLiteDb(this.settings.SQLite);
                if (!File.Exists(DataBaseName))
                {
                    this.sqliteDb.CreateBase();
                    this.sqliteDb.TEPCreateTable();
                }

                // Таймер вычитывания значений из БД
                this.readTEPTimer.Interval = new TimeSpan(0, 0, 2);
                this.readTEPTimer.Tick    += this.ReadTEP;
                this.readTEPTimer.Start();

                // Расчет ТЭП
                this.calculateTEPTimer.Interval = new TimeSpan(0, 0, 6);
                this.calculateTEPTimer.Tick    += this.CalculateTEP;
                this.calculateTEPTimer.Start();

                // Таймер на вызов метода записи 2-х часовок
                this.write2HourTEPTimer.Interval = new TimeSpan(0, 1, 0);
                this.write2HourTEPTimer.Tick    += new EventHandler(this.Write2HourTEP);
                this.write2HourTEPTimer.Start();

                // Таймер на отправку писем
                this.sendMailTimer.Interval = new TimeSpan(0, 1, 0);
                this.sendMailTimer.Tick    += this.SendMail;
                this.sendMailTimer.Start();

                // Таймер проверки связи с БД MSSQL
                this.checkConnectionTimer.Interval = new TimeSpan(0, 0, 10);
                this.checkConnectionTimer.Tick    += this.CheckConnection;
                this.checkConnectionTimer.Start();

                // Таймер на доступ к записи отчета
                this.accessReportTimer.Interval = new TimeSpan(0, 2, 0);
                this.accessReportTimer.Tick    += this.AccessReport;
                this.accessReportTimer.Start();

                this.LiveTEP   = new LiveTEP {
                };
                this.TEPtoBase = new LiveTEP {
                };
                this.Filters   = new Filters {
                };

                this.Filters.StartDate = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
                this.Filters.EndDate   = DateTime.Now;

                this.HistTEP = new ObservableCollection <HistTEP> {
                };

                this.Filters.OnCount += this.Filter;
                this.Filters.Day      = true;
                this.ApplyFilter();
            }
            catch (Exception ex)
            {
                this.logger.Error(ex.Message);
            }
        }
Example #4
0
        /// <summary>Обновить.</summary>
        public void UpdateSoft()
        {
            this.remotePropPath = this.settings.SoftUpdate.RemoteSettingsPath;

            // Вычитывание параметров из удаленного xml
            // Инициализация модели настроек
            var settingsXml = new SettingsXml <RootElementRemoteSettings>(this.settings.SoftUpdate.RemoteSettingsPath);

            this.remoteSettings.Phonebook    = new Phonebook();
            this.remoteSettings.PhonebookUpd = new PhonebookUpd();

            try
            {
                if (!string.IsNullOrEmpty(this.settings.SoftUpdate.RemoteSettingsPath))
                {
                    this.remoteSettings = settingsXml.ReadXml(this.remoteSettings);
                }

                // Обновление Phonebook Updater
                if (Directory.Exists(this.updFolderPath))
                {
                    this.updPropPath = Path.Combine(this.updFolderPath, UpdaterPropName);

                    // Вычитывание параметров из xml updatera
                    // Инициализация модели настроек
                    var updSettingsXml = new SettingsXml <RootElementUpdaterSettings>(this.updPropPath);
                    this.updaterSettings.Updater = new UpdaterSettingsShell.Updater();

                    this.updaterSettings = updSettingsXml.ReadXml(this.updaterSettings);

                    if (this.remoteSettings.PhonebookUpd.Version != this.updaterSettings.Updater.Version && Directory.Exists(this.remoteSettings.PhonebookUpd.Path))
                    {
                        if (Directory.Exists(this.tempFolderPath))
                        {
                            this.DelDir(this.tempFolderPath);
                        }

                        Directory.CreateDirectory(this.tempFolderPath);
                        this.CopyDir(this.remoteSettings.PhonebookUpd.Path, this.tempFolderPath);
                        this.DelDir(this.updFolderPath);
                        this.CopyDir(this.tempFolderPath, this.updFolderPath);
                        this.DelDir(this.tempFolderPath);

                        this.logger.Info("Обновление Phonebook Updater завершено");
                    }
                }
                else
                {
                    if (Directory.Exists(this.remoteSettings.PhonebookUpd.Path))
                    {
                        this.CopyDir(this.remoteSettings.PhonebookUpd.Path, this.updFolderPath);
                        this.logger.Info("Обновление Phonebook Updater завершено");
                    }
                    else
                    {
                        this.logger.Warn($"Отсутствует папка {this.remoteSettings.PhonebookUpd.Path}");
                    }
                }

                // Обновление Phonebook
                if (this.remoteSettings.Phonebook.Version != Application.ProductVersion && Directory.Exists(this.remoteSettings.Phonebook.Path))
                {
                    if (MessageBox.Show("Появилась новая версия Phonebook! Обновить?", "Внимание", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        Process.Start(Path.Combine(this.updFolderPath, "PhonebookUpdater.exe"));
                    }
                }
            }
            catch (Exception ex)
            {
                this.logger.Error(ex.Message);
            }
        }