Example #1
0
        public void Save()
        {
            using (var context = new Arma3BeClientContext())
            {
                context.Settings.AddOrUpdate(
                    new Settings {
                    Id = AdminNameKey, Value = AdminName
                },
                    new Settings {
                    Id = TimeZoneKey, Value = TimeZoneInfo?.Id
                },
                    new Settings {
                    Id = PlayersUpdateKey, Value = PlayersUpdateSeconds.ToString()
                },
                    new Settings {
                    Id = BansUpdateKey, Value = BansUpdateSeconds.ToString()
                },
                    new Settings {
                    Id = BanMessageTemplateKey, Value = BanMessageTemplate
                },
                    new Settings {
                    Id = KickMessageTemplateKey, Value = KickMessageTemplate
                },
                    new Settings {
                    Id = TopMostKey, Value = TopMost.ToString()
                },
                    new Settings {
                    Id = SteamFolderKey, Value = SteamFolder
                }
                    );

                context.SaveChanges();
                _instance = null;
            }
        }
Example #2
0
        void TopMostChanged()
        {
            if (TopMost == null)
            {
                UpdateTopMost();
                return;
            }

            if (!shiftDown)
            {
                foreach (var item in Items)
                {
                    item.Active = false;
                }
            }
            TopMost.Active = true;

            if (!controlDown)
            {
                TopMost.ItemOrder = ++itemOrder;
            }

            Dispatcher.BeginInvoke((Action)(() =>
            {
                UpdateLayout();
                if (TopMost != null)
                {
                    TopMost.Focus();
                }
            }));

            topMostTimer.Start();
        }
Example #3
0
        bool GetDialogResult(NECommand command, out object dialogResult, bool?multiStatus)
        {
            dialogResult = null;

            var result = true;

            switch (command)
            {
            case NECommand.File_Open_Open: dialogResult = Command_File_Open_Open_Dialog(); break;

            case NECommand.Macro_Open_Open: dialogResult = Command_File_Open_Open_Dialog(Macro.MacroDirectory); break;

            case NECommand.Window_CustomGrid: dialogResult = Command_Window_Type_Dialog(); break;

            default: result = false; break;
            }

            if (result)
            {
                return(dialogResult != null);
            }

            if (TopMost == null)
            {
                return(true);
            }

            return(TopMost.GetDialogResult(command, out dialogResult, multiStatus));
        }
Example #4
0
 void ShowTopMost()
 {
     if (TopMost == null)
     {
         return;
     }
     ShowItem?.Invoke(TopMost);
     TopMost.Focus();
 }
Example #5
0
        public Notifier CreateNotifier(Corner corner, PositionProviderType relation, NotificationLifetimeType lifetime)
        {
            _notifier?.Dispose();
            _notifier = null;

            return(new Notifier(cfg =>
            {
                cfg.PositionProvider = CreatePositionProvider(corner, relation);
                cfg.LifetimeSupervisor = CreateLifetimeSupervisor(lifetime);
                cfg.Dispatcher = Dispatcher.CurrentDispatcher;
                cfg.DisplayOptions.TopMost = TopMost.GetValueOrDefault();
            }));
        }
Example #6
0
 void DoLayout()
 {
     ClearLayout();
     if (Layout == TabsLayout.Full)
     {
         DoFullLayout();
     }
     else
     {
         DoGridLayout();
     }
     TopMost?.Focus();
 }
Example #7
0
        private void botonProbar_Click(object sender, EventArgs e)
        {
            try
            {
                var psi = new ProcessStartInfo(Application.StartupPath + @"\AvisosRep.exe");
                psi.Arguments = "* " + TopMost.ToString() + " " + EnableGlass.ToString() + " " +
                                ((int)styleManager1.ManagerStyle).ToString();

                Process.Start(psi);
            }

            catch (Exception ex)
            {
                MsgBox(ex.Message, "ERROR", MessageBoxIcon.Error);
            }
        }
Example #8
0
        private void botonReproducirAvisoVisual_Click(object sender, EventArgs e)
        {
            try
            {
                superTabControl1.SelectedTabIndex = 0;

                var psi = new ProcessStartInfo(Application.StartupPath + @"\AvisosRep.exe");
                psi.Arguments = "*v " + TopMost.ToString() + " " + EnableGlass.ToString() + " " +
                                ((int)styleManager1.ManagerStyle).ToString();;

                Process.Start(psi);
            }

            catch (Exception ex)
            {
                MsgBox(ex.Message, "ERROR", MessageBoxIcon.Error);
            }
        }
Example #9
0
        void Command_Macro_Play_Repeat()
        {
            var result = MacroPlayRepeatDialog.Run(WindowParent, Macro.ChooseMacro);

            if (result == null)
            {
                return;
            }

            var macro      = Macro.Load(result.Macro);
            var expression = new NEExpression(result.Expression);
            var count      = int.MaxValue;

            if (result.RepeatType == MacroPlayRepeatDialog.RepeatTypeEnum.Number)
            {
                count = expression.Evaluate <int>();
            }

            Action startNext = null;

            startNext = () =>
            {
                if ((TopMost == null) || (--count < 0))
                {
                    return;
                }

                if (result.RepeatType == MacroPlayRepeatDialog.RepeatTypeEnum.Condition)
                {
                    if (!expression.Evaluate <bool>(TopMost.GetVariables()))
                    {
                        return;
                    }
                }

                macro.Play(this, playing => MacroPlaying = playing, startNext);
            };
            startNext();
        }
Example #10
0
 private void gunaWinSwitch1_CheckedChanged(object sender, EventArgs e)
 {
     TopMost.ToString();
 }
Example #11
0
        private async void Form4_Load(object sender, EventArgs e)
        {
            TUpdate("Loading");
            Tools.Enabled      = false;
            Scriptbox.Enabled  = false;
            Scriptlist.Enabled = false;

            try
            {
                foreach (string path in Directory.GetFiles("./Scripts"))
                {
                    this.Scriptlist.Items.Add(Path.GetFileName(path));
                }
            }
            catch (Exception)
            {
                Directory.CreateDirectory("./Scripts");
                foreach (string path2 in Directory.GetFiles("./Scripts"))
                {
                    this.Scriptlist.Items.Add(Path.GetFileName(path2));
                }
            }

            try
            {
                a = Convert.ToBoolean(new Settings().SettingsConfig.Read("ScriptsFolder", "Configuration"));

                if (a == false)
                {
                    this.Size = new Size(500, 300);
                }
                else
                {
                    this.Size = new Size(658, 300);
                }
            }
            catch (Exception)
            {
            }

            toolStripMenuItem3.Text = "Scripts Folder = " + a.ToString();

            if (File.Exists("Settings.AJax"))
            {
                string tm = new Settings().SettingsConfig.Read("Topmost", "Configuration");
                TopMost = Convert.ToBoolean(tm);
                toolStripMenuItem4.Text = "Topmost = " + TopMost.ToString();

                string wr = new Settings().SettingsConfig.Read("WordWrap", "Configuration");
                Scriptbox.WordWrap      = Convert.ToBoolean(wr);
                toolStripMenuItem2.Text = "WordWrap = " + Scriptbox.WordWrap.ToString();
                Scriptbox.Text          = File.ReadAllText(@"bin\\AJax.lua");
            }
            else
            {
                toolStripMenuItem4.Text = "Topmost = True";
                toolStripMenuItem2.Text = "WordWrap = False";
            }

            if (File.Exists(@"bin\\AJax.lua"))
            {
                await Task.Delay(500);

                Scriptbox.Text = File.ReadAllText(@"bin\\AJax.lua");
            }

            Synapse              = SxLib.InitializeOffscreen(directory);
            Synapse.LoadEvent   += Loader;
            Synapse.AttachEvent += Attacher;
            Synapse.Load();
        }
Example #12
0
 private void toolStripMenuItem4_Click(object sender, EventArgs e)
 {
     TopMost = !TopMost;
     new Settings().SettingsConfig.Write("Topmost", TopMost.ToString(), "Configuration");
     toolStripMenuItem4.Text = "Topmost = " + TopMost.ToString();
 }
Example #13
0
        public void Add(TextEditor item, int?index = null)
        {
            var replace = (!index.HasValue) && (!item.Empty()) && (TopMost != null) && (TopMost.Empty()) ? TopMost : default(TextEditor);

            if (replace != null)
            {
                replace.Closed();
                Items[Items.IndexOf(replace)] = item;
            }
            else
            {
                Items.Insert(index ?? Items.Count, item);
            }
            TopMost = item;
        }
Example #14
0
        public MainWindow(bool ohwsensors)
        {
            OHWSensors = ohwsensors;

            Text            = "System Monitor";
            WindowState     = FormWindowState.Normal;
            FormBorderStyle = FormBorderStyle.SizableToolWindow;             // no min/max buttons as wanted
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.OptimizedDoubleBuffer, true);
            MinimizeBox = false;
            MaximizeBox = false;
            // monitors = 6
            MinimumSize  = new Size(650, 136);
            AutoSizeMode = AutoSizeMode.GrowOnly;
            AutoSize     = true;
            Size         = new System.Drawing.Size(650, 136);
            Padding      = new Padding(3);

            BackColor = Settings.Current.BackColor;

            Console.WriteLine("Analyzing system...");
            try
            {
                using (var memsearch = new ManagementObjectSearcher(@"root\CIMV2", "SELECT TotalPhysicalMemory FROM Win32_ComputerSystem"))
                {
                    foreach (ManagementObject queryObj in memsearch.Get())
                    {
                        TotalMemory   = (ulong)(queryObj["TotalPhysicalMemory"] ?? 0);
                        TotalMemoryMB = TotalMemory / 1024000;
                        break;
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                MessageBox.Show("A COM error occurred while querying for WMI data: " + e.Message);
                return;
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
                return;
            }

            // READ CONFIGURATION

            Console.WriteLine("Configuration start.");

            Console.WriteLine($"+ Free mem threshold: {Settings.Current.FreeMemoryThreshold:N2}");
            Console.WriteLine($"+ Memory pressure:    {Settings.Current.MemoryPressureThreshold:N2}");

            /*
             * string positionkey = "Position";
             * //if (settings[positionkey] == null) settings.Add(positionkey, Location.X + "," + Location.Y);
             * var coords = settings.Get(positionkey)?.Split(',');
             * if (coords != null)
             * {
             *      var x = Convert.ToInt32(coords?[0]);
             *      var y = Convert.ToInt32(coords?[1]);
             *      PointToScreen(new Point(x, y));
             *      Console.WriteLine("+ Position:           {0},{1}", x, y);
             * }
             */
            Console.WriteLine("Configuration end.");

            /*
             * FormClosing += (sender, e) => {
             *      try
             *      {
             *              if (settings[positionkey] == null) settings.Add(positionkey, Location.X + "," + Location.Y);
             *              Console.WriteLine("+ Position: {0},{1}", Location.X, Location.Y);
             *      }
             *      catch
             *      {
             *              Console.WriteLine("Failed to write settings.");
             *      }
             * };
             */

            // INITIALIZE
            InitCounters();

            var tooltip = new ToolTip();

            // https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx

            var layout = new TableLayoutPanel
            {
                Parent = this,
                //ColumnCount = 8,
                RowCount  = 1,
                Dock      = DockStyle.Left,
                GrowStyle = TableLayoutPanelGrowStyle.AddColumns,
                AutoSize  = true,
            };

            // Fill in with whatever resource is getting getting run out of


            //var bottlenecklabel = new SensorHeader { Text = "Bottleneck" };
            //bottleneckvalue = new SensorValue();

            Sensor_Bottleneck = new SensorChunk("Bottleneck");
            tooltip.SetToolTip(Sensor_Bottleneck, "The values are arbitrary but usually 6+ is moderate load while 10+ should mean heavy load.");

            Sensor_CPU = new SensorChunk("CPU", chart: true);
            Sensor_CPU.Chart.MaxValue    = 100.0d;          // 100%
            Sensor_CPU.Chart.StaticRange = true;
            tooltip.SetToolTip(Sensor_CPU.Value, "Queued command counter is clearest indicator of underscaled CPU.\nInterrupt percentage shows load from peripherals, NICs, extension cards, and such.");

            Sensor_Memory = new SensorChunk("Memory", chart: true, horizontal: true);
            tooltip.SetToolTip(Sensor_Memory.Value, "Physical memory usage.\nCommit is swap file usage.\nPressure is private memory load.");
            Sensor_Memory.Chart.MaxValue = TotalMemoryMB;

            if (OHWSensors)
            {
                Sensor_GPU_MEM = new SensorChunk("GPU MEM", chart: true, horizontal: true);
                Sensor_GPU_MEM.Chart.MaxValue    = 100.0d;
                Sensor_GPU_MEM.Chart.StaticRange = true;

                Sensor_GPU_Load = new SensorChunk("GPU Load", chart: true);
                Sensor_GPU_Load.Chart.MaxValue    = 100.0d;
                Sensor_GPU_Load.Chart.StaticRange = true;
            }

            if (Settings.Current.PageFaultsEnabled)
            {
                Sensor_PageFault = new SensorChunk("Page Faults", chart: true);
                tooltip.SetToolTip(Sensor_PageFault.Value, "Page file performance degradation.\nPage faults themselves are not to worry.\nHard page faults can be source of poor performance.");
            }

            Sensor_NVMIO = new SensorChunk("NVM", chart: true);
            tooltip.SetToolTip(Sensor_NVMIO.Header, "Non-volatile memory: HDD, SSD, etc.\nThese are not clear indicators of bottlenecks if multiple NVMs are involved.");
            tooltip.SetToolTip(Sensor_NVMIO.Value, "Split indicates fragmentation performance loss.\nQueue&delay indicates slow NVM.");

            Sensor_NetIO = new SensorChunk("Network", chart: true);
            tooltip.SetToolTip(Sensor_NetIO.Value, "Queue length is indicator of too slow or bad outbound connection.");

            layout.Controls.Add(Sensor_Bottleneck);
            layout.Controls.Add(Sensor_CPU);
            layout.Controls.Add(Sensor_Memory);
            if (OHWSensors)
            {
                layout.Controls.Add(Sensor_GPU_Load);
                layout.Controls.Add(Sensor_GPU_MEM);
            }
            if (Settings.Current.PageFaultsEnabled)
            {
                layout.Controls.Add(Sensor_PageFault);
            }
            layout.Controls.Add(Sensor_NVMIO);
            layout.Controls.Add(Sensor_NetIO);

            ContextMenu = new ContextMenu();
            togglewarn  = ContextMenu.MenuItems.Add("Warnings", (sender, e) =>
            {
                FlashWarnings      = !FlashWarnings;
                togglewarn.Checked = FlashWarnings;

                Console.WriteLine("~ Warning flashes enabled: {0}", FlashWarnings);
            });
            togglewarn.Checked = true;

            ContextMenu.MenuItems.Add("-");
            highpriocmo = ContextMenu.MenuItems.Add("High priority", (sender, e) =>
            {
                try
                {
                    Process.GetCurrentProcess().PriorityClass = Settings.Current.SelfPriority = ProcessPriorityClass.High;
                    normpriocmo.Checked = false;
                    highpriocmo.Checked = true;
                    lowpriocmo.Checked  = false;
                }
                catch { /* NOP */ }
                Console.WriteLine("~ Self-priority set to High.");
            });
            normpriocmo = ContextMenu.MenuItems.Add("Normal priority", (sender, e) =>
            {
                try
                {
                    Process.GetCurrentProcess().PriorityClass = Settings.Current.SelfPriority = ProcessPriorityClass.Normal;
                    normpriocmo.Checked = true;
                    highpriocmo.Checked = false;
                    lowpriocmo.Checked  = false;
                }
                catch { /* NOP */ }
                Console.WriteLine("~ Self-priority set to Normal.");
            });
            lowpriocmo = ContextMenu.MenuItems.Add("Low priority", (sender, e) =>
            {
                try
                {
                    Process.GetCurrentProcess().PriorityClass = Settings.Current.SelfPriority = ProcessPriorityClass.BelowNormal;
                    normpriocmo.Checked = false;
                    highpriocmo.Checked = false;
                    lowpriocmo.Checked  = true;
                }
                catch { /* NOP */ }
                Console.WriteLine("~ Self-priority set to Low.");
            });

            ContextMenu.MenuItems.Add("-");
            UITimer = new System.Windows.Forms.Timer {
                Interval = 2000
            };

            updateFreq05 = ContextMenu.MenuItems.Add("Update 0.5/s", (sender, e) =>
            {
                UITimer.Interval                 = 500;
                updateFreq05.Checked             = true;
                updateFreq15.Checked             = false;
                updateFreq25.Checked             = false;
                Settings.Current.UpdateFrequency = UITimer.Interval;
            });
            updateFreq15 = ContextMenu.MenuItems.Add("Update 1.5/s", (sender, e) =>
            {
                UITimer.Interval                 = 1500;
                updateFreq05.Checked             = false;
                updateFreq15.Checked             = true;
                updateFreq25.Checked             = false;
                Settings.Current.UpdateFrequency = UITimer.Interval;
            });
            updateFreq25 = ContextMenu.MenuItems.Add("Update 2.5/s", (sender, e) =>
            {
                UITimer.Interval                 = 2500;
                updateFreq05.Checked             = false;
                updateFreq15.Checked             = false;
                updateFreq25.Checked             = true;
                Settings.Current.UpdateFrequency = UITimer.Interval;
            });

            ContextMenu.MenuItems.Add("-");

            var  nicDevice     = ContextMenu.MenuItems.Add("Network device");
            var  nicDevices    = new PerformanceCounterCategory("Network Interface").GetInstanceNames();         // 0 = loopback
            var  currentDevice = Settings.Current.NICDevice;
            bool foundNIC      = false;

            for (int i = 1; i < nicDevices.Length; i++)
            {
                var nnic = nicDevice.MenuItems.Add(i + ": " + nicDevices[i]);
                if (currentDevice == nicDevices[i])
                {
                    nnic.Checked = true;
                    nnic.Enabled = false;
                    foundNIC     = true;
                }

                nnic.Click += (_, _ea) =>
                {
                    var rv = MessageBox.Show("Changing network device requires restart", "Restart required", MessageBoxButtons.OKCancel);
                    if (rv == DialogResult.OK)
                    {
                        Settings.Current.NICDevice = nicDevices[i];
                        Console.WriteLine("Restarting");
                        Settings.Current.Save();
                        Application.Restart();
                    }
                };
            }

            if (!foundNIC)             // default
            {
                var dnic = nicDevice.MenuItems[0];
                dnic.Checked = true;
                dnic.Enabled = false;
                Settings.Current.NICDevice = nicDevices[0];
            }

            var pageFaults = ContextMenu.MenuItems.Add("Page faults");

            pageFaults.Click += (_, _ea) =>
            {
                var rv = MessageBox.Show("Toggling page faults requires restarting.", "Restart required", MessageBoxButtons.OKCancel);
                if (rv == DialogResult.OK)
                {
                    UITimer.Stop();
                    Settings.Current.PageFaultsEnabled = pageFaults.Checked = !pageFaults.Checked;
                    Console.WriteLine("Show Page Faults toggled to: " + pageFaults.Checked);
                    Console.WriteLine("Restarting");
                    Settings.Current.Save();
                    Application.Restart();
                }
            };
            pageFaults.Checked = Settings.Current.PageFaultsEnabled;

            ContextMenu.MenuItems.Add("-");

            var alwaysOnTop = ContextMenu.MenuItems.Add("Always on top");

            alwaysOnTop.Click += (_, _ea) =>
            {
                Settings.Current.AlwaysOnTop = TopMost = alwaysOnTop.Checked = !TopMost;
                Console.WriteLine("Topmost toggled to: " + TopMost);
            };

            MenuItem runatstart = ContextMenu.MenuItems.Add("Run at Windows startup");

            runatstart.Click += (sender, e) =>
            {
                runatstart.Checked = RunAtStart(!runatstart.Checked);
            };
            runatstart.Checked = RunAtStart(true, true);

            ContextMenu.MenuItems.Add("-");

            ContextMenu.MenuItems.Add("About", (_, _ea) =>
            {
                MessageBox.Show("System Monitor\nCreated by M.A., 2017–2019\n\nAt Github: " + GithubURL + "\n\nFree system monitor app.\n\nAvailable under MIT license.", "About System Monitor", MessageBoxButtons.OK, MessageBoxIcon.Information);
            });

            ContextMenu.MenuItems.Add("Github", (_, _ea) => { Process.Start(GithubURL); });

            ContextMenu.MenuItems.Add("-");

            var adminRestart = ContextMenu.MenuItems.Add("Restart as admin");

            if (!MKAh.Execution.IsAdministrator)
            {
                adminRestart.Click += (_, _ea) =>
                {
                    UITimer.Stop();
                    var pi = new ProcessStartInfo(Application.ExecutablePath);
                    pi.UseShellExecute = true;
                    pi.Verb            = "runas";
                    Process.Start(pi);
                    Settings.Current.Save();
                    Close();
                };
            }
            else
            {
                adminRestart.Enabled = false;
            }

            ContextMenu.MenuItems.Add("Exit", (_, _ea) =>
            {
                Settings.Current.Save();
                Close();
            });

            //Console.WriteLine("Total physical memory: {0:N2} GiB", TotalMemoryMB/1000);

            UITimer.Tick += (sender, e) => UpdateSensors();

            UpdateSensors();
            UITimer.Enabled = true;
            Console.WriteLine("Timer started.");

            //CenterToScreen();

            StartPosition = FormStartPosition.CenterScreen;

            Point startLocation = Settings.Current.StartLocation;

            if (!startLocation.IsEmpty)
            {
                Location      = startLocation;
                StartPosition = FormStartPosition.Manual;
            }

            alwaysOnTop.Checked = TopMost = Settings.Current.AlwaysOnTop;
            Console.WriteLine("Topmost: " + TopMost.ToString());

            FormClosing += (sender, e) =>
            {
                if (Settings.Current.StartLocation != Location)
                {
                    Settings.Current.StartLocation = Location;
                }

                if (Settings.Current.AlwaysOnTop != TopMost)
                {
                    Settings.Current.AlwaysOnTop = TopMost;
                }

                if (Settings.Current.Save())
                {
                    Console.WriteLine("Start Location saved: " + Settings.Current.StartLocation.ToString());
                    Console.WriteLine("Always on top saved:  " + Settings.Current.AlwaysOnTop.ToString());
                    Console.WriteLine("Self priority saved:  " + Settings.Current.SelfPriority.ToString());
                    Console.WriteLine();
                    Console.WriteLine("Background color: " + Settings.Current.BackColor.ToString());
                    Console.WriteLine("Warning color:    " + Settings.Current.WarnColor.ToString());
                    Console.WriteLine("Text color:       " + Settings.Current.TextColor.ToString());
                    Console.WriteLine("Graph color:      " + Settings.Current.GraphColor.ToString());
                }
            };

            Activated += (_, _ea) =>
            {
                // Refresh topmost as it is known to be finicky.
                if (TopMost)
                {
                    TopMost = false;
                    TopMost = true;
                }
            };

            Console.WriteLine("Start location: " + Location);
            Show();

            Console.WriteLine("Self-priority: " + Settings.Current.SelfPriority.ToSimpleInt() + " = " + Settings.Current.SelfPriority.ToString());
            switch (Settings.Current.SelfPriority)
            {
            case ProcessPriorityClass.High:
                highpriocmo.PerformClick();
                break;

            case ProcessPriorityClass.Normal:
                normpriocmo.PerformClick();
                break;

            default:
                lowpriocmo.PerformClick();
                break;
            }

            Console.WriteLine("Update Frequency: " + Settings.Current.UpdateFrequency);
            switch (Settings.Current.UpdateFrequency)
            {
            case 500:
                updateFreq05.PerformClick();
                break;

            case 1500:
                updateFreq15.PerformClick();
                break;

            default:
            case 2500:
                updateFreq25.PerformClick();
                break;
            }

            Console.WriteLine("Ready.");
        }