示例#1
0
 private void StartStop_Click(object sender, EventArgs e)
 {
     if (ThreadStatus)
     {
         DialogResult a;
         a = MessageBox.Show("Вы действительно хотите остановить монитор?", "Стоп", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (a == DialogResult.Yes)
         {
             trd.Suspend();
             ThreadStatus = !ThreadStatus;
             InitializeFields();
             StartStop.Text  = "Пуск";
             this.ControlBox = true;
             TabControl.TabPages.Insert(0, SettingsTab);
             SettingsTab.Select();
         }
     }
     else
     {
         StartStop.Text  = "Стоп";
         this.ControlBox = false;
         MonitorTab.Select();
         TabControl.TabPages.Remove(SettingsTab);
         ThreadStatus = !ThreadStatus;
         if (Thread1stStart)
         {
             Thread1stStart = false;
             trd.Start();
         }
         else
         {
             trd.Resume();
         }
     }
 }
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            List <GroupSetting> loaded = new List <GroupSetting>();

            loaded = XMLHandler.load("config.xml");
            foreach (GroupSetting gs in loaded)
            {
                MonitorTab monitor = new MonitorTab();
                configScreensSaverControl.getGroupSettings().Add(gs);
                monitor.Width      = 383;
                monitor.Height     = 30;
                monitor.MinWidth   = MonitorMenu.MinWidth;
                monitor.MaxWidth   = MonitorMenu.MaxWidth;
                monitor.MouseDown += Monitor_clicked;
                monitor.order      = configScreensSaverControl.getGroupSettings().Count - 1;
                currentScreen      = configScreensSaverControl.getTotalNumberofGroups() - 1;
                monitor.passtitleRef(ref gs.groupName);
                MonitorMenu.Children.Add(monitor);

                configScreensSaverControl.getOwnedMonitors().Add(new List <string>());
                foreach (MonitorSetting ms in gs.monitors)
                {
                    configScreensSaverControl.getOwnedMonitors()[configScreensSaverControl.getOwnedMonitors().Count - 1].Add(ms.monitorId);
                }
            }
        }
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            configScreensSaverControl.deleteGroup(currentScreen);

            for (int i = currentScreen + 1; i <= MonitorMenu.Children.Count - 1; i++)
            {
                MonitorTab tab = (MonitorTab)MonitorMenu.Children[i];
                tab.order = i - 1;
            }

            MonitorMenu.Children.RemoveAt(currentScreen);
            firstAppear = true;
        }
        private void Create_Button_Clicked(object sender, RoutedEventArgs e)
        {
            MonitorTab monitor = new MonitorTab();

            monitor.Width      = 383;
            monitor.Height     = 40;
            monitor.MinWidth   = MonitorMenu.MinWidth;
            monitor.MaxWidth   = MonitorMenu.MaxWidth;
            monitor.MouseDown += Monitor_clicked;
            monitor.order      = configScreensSaverControl.createnewGroup();
            currentScreen      = configScreensSaverControl.getTotalNumberofGroups() - 1;
            monitor.passtitleRef(ref configScreensSaverControl.getGroupSettings(monitor.order).groupName);
            MonitorMenu.Children.Add(monitor);
        }
        private void Monitor_clicked(object sender, EventArgs e)
        {
            MonitorTab tab = (MonitorTab)sender;

            //resetting the color
            foreach (MonitorTab mt in MonitorMenu.Children)
            {
                mt.Background = null;
            }
            currentScreen  = tab.order;
            tab.Background = Brushes.DarkTurquoise;
            if (!firstAppear)
            {
                configScreensSaverControl.saveGroupSettings();
            }
            else
            {
                firstAppear = false;
            }
            configScreensSaverControl.displayGroupControl(currentScreen);
        }
示例#6
0
        public static void Main()
        {
            //Initialize logger
            LogTab Tab = new LogTab("General");

            Log = Tab.GetLogger();
            RequestWorker.RequestLoggerTab = new LogTab("Workers");
            Log.Info("Server is starting!");

            //Create default config
            Log.Info("Loading configuration files...");
            Config.AddConfig(new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Webserver.DefaultConfig.json")));
            Config.SaveDefaultConfig();

            //Load the configuration file
            Dictionary <string, List <string> > Missing = Config.LoadConfig();

            //Display all missing and/or invalid config settings, if any.
            if (Missing == null)
            {
                Log.Fatal("The config file could not be read. Ensure that it is a valid JSON file. Press any key to exit.");
                Console.ReadKey();
                return;
            }
            else if (Missing.Count > 0)
            {
                Log.Fatal("Found one or more invalid or missing configuration settings;");
                foreach (string Key in Missing.Keys)
                {
                    if (Missing[Key].Count == 0)
                    {
                        Console.Write(Key);
                    }
                    foreach (string Key2 in Missing[Key])
                    {
                        Log.Fatal(Key + "." + Key2);
                    }
                }
                Log.Fatal("Please check the configuration file. Press any key to exit.");
                Console.ReadKey();
                return;
            }

            //Check CORS addresses
            CORSAddresses = Utils.ParseAddresses(Config.GetValue("ConnectionSettings.AccessControl").ToObject <List <string> >());
            List <string> Addresses = Utils.ParseAddresses(Configurator.Config.GetValue("ConnectionSettings.ServerAddresses").ToObject <List <string> >());

            CORSAddresses = CORSAddresses.Concat(Addresses).ToList();

            //Run inits
            SQLiteConnection Connection = Database.Init();

            WebFiles.Init();
            Redirect.Init();

            //Find all API endpoints
            DiscoverEndpoints();

            //Create Queue and launch listener
            Thread ListenerThread = new Thread(() => Listener.Run());

            ListenerThread.Start();

            //Create performance tab + watchers
            MonitorTab pTab = new MonitorTab("PerfMon");

            RequestWorker.RequestTimeWatcher = pTab.CreateNumWatcher("Request time", ShowMin: true, ShowAverage: true, ShowMax: true);
            Listener.QueueSizeWatcher        = pTab.CreateNumWatcher("Queue size", ShowMax: true);

            //Launch worker threads
            List <Thread> WorkerThreads = new List <Thread>();

            for (int i = 0; i < (int)Config.GetValue("PerformanceSettings.WorkerThreadCount"); i++)
            {
                RequestWorker Worker       = new RequestWorker((SQLiteConnection)Connection.Clone());
                Thread        WorkerThread = new Thread(new ThreadStart(Worker.Run))
                {
                    Name = "RequestWorker" + i
                };
                WorkerThread.Start();
                WorkerThreads.Add(WorkerThread);
            }

            //Launch maintenance thread
            Timer Maintenance = new Timer(new MaintenanceThread {
                Log = Log
            }.Run, null, 0, 3600 * 1000);

            //Wait for an exit command, then exit.
            foreach (Thread Worker in WorkerThreads)
            {
                Worker.Join();
            }
        }