protected override void OnClosed(EventArgs e)
        {
            if (SecurityUtils.IsAdministrator())
            {
                if (Config.Default.ServerCacheUpdatePeriod != 0 && !Directory.Exists(Config.Default.ServerCacheDir))
                {
                    MessageBox.Show("The cache directory must specify a valid location or the cache update period must be 0.", "Invalid cache directory", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (!ServerScheduler.ScheduleCacheUpdater(Config.Default.ServerCacheDir, Updater.GetSteamCMDPath(), Config.Default.GLOBAL_EnableServerCache ? Config.Default.ServerCacheUpdatePeriod : 0))
                {
                    MessageBox.Show("Failed to update the cache task.  Ensure you have administrative rights and try again.", "Update task failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    if (!Config.Default.GLOBAL_EnableServerCache || (Config.Default.ServerCacheUpdatePeriod == 0))
                    {
                        MessageBox.Show("Server cache updating disabled.", "Updates disabled", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show($"Server cache will update every {Config.Default.ServerCacheUpdatePeriod} minutes.", "Updates enabled", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }

            Config.Default.Save();
            base.OnClosed(e);
        }
Пример #2
0
        protected override void OnStart(string[] args)
        {
            try
            {
                System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog();
                appLog.Source = "Gestão escolar";

                if (args.Length > 0)
                {
                    try
                    {
                        System.Configuration.Configuration config = ConfigurationManager.
                                                                    OpenExeConfiguration(ConfigurationUserLevel.None);

                        if (config == null)
                        {
                            appLog.WriteEntry("config null");
                        }

                        config.AppSettings.Settings.Remove("porta");

                        // Primeiro argumento é a porta.
                        config.AppSettings.Settings.Add("porta", args[0]);

                        config.Save(ConfigurationSaveMode.Modified);
                    }
                    catch (Exception ex)
                    {
                        appLog.WriteEntry("Erro ao alterar o config: " + ex.Message);
                    }
                }

                string porta = ConfigurationManager.AppSettings.Get("porta");

                if (!string.IsNullOrEmpty(porta))
                {
                    appLog.WriteEntry("Iniciando serviço na porta: " + porta);
                    scheduler = new GestaoEscolarScheduler(porta);
                }
                else
                {
                    scheduler = new GestaoEscolarScheduler();
                }

                scheduler.Start();
            }
            catch (Exception ex)
            {
                Util.GravarErro(ex, scheduler.Sis_ID);
            }
        }