BusynessNotification

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fc7be6aa5659ab5613e18a7cface710b9295a75c
parent 30ab0596481e2c3b81fa712fae1bf17296e6adfa
Author: Minerva_juppiter <ryouturn@gmail.com>
Date:   Sun, 31 Mar 2024 22:02:26 +0900


Diffstat:
MApp.config | 60------------------------------------------------------------
MApp.xaml.cs | 2+-
MBN_installer/BN_installer.vdproj | 8++++----
ABN_installer/BN_installer.zip | 0
ABN_installer/BN_installer/BN_installer.msi | 0
ABN_installer/BN_installer/setup.exe | 0
MMainWindow.xaml | 4++--
MMainWindow.xaml.cs | 36++++++++++++++++++------------------
MObserveUseage.cs | 36++++++++++++++++++------------------
9 files changed, 43 insertions(+), 103 deletions(-)

diff --git a/App.config b/App.config @@ -6,64 +6,4 @@ <section name="BusynessNotification.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> </sectionGroup> </configSections> - <userSettings> - <BusynessNotification.Properties.Settings> - <setting name="CheckCPU" serializeAs="String"> - <value>True</value> - </setting> - <setting name="CheckMemory" serializeAs="String"> - <value>True</value> - </setting> - <setting name="CheckDisk" serializeAs="String"> - <value>True</value> - </setting> - <setting name="SliderCPU" serializeAs="String"> - <value>50</value> - </setting> - <setting name="SliderMemory" serializeAs="String"> - <value>90</value> - </setting> - <setting name="SliderDisk" serializeAs="String"> - <value>50</value> - </setting> - <setting name="SecCPU" serializeAs="String"> - <value>10</value> - </setting> - <setting name="SecMemory" serializeAs="String"> - <value>10</value> - </setting> - <setting name="SecDisk" serializeAs="String"> - <value>10</value> - </setting> - </BusynessNotification.Properties.Settings> - <BusynessNotification.Settings1> - <setting name="CheckCPU" serializeAs="String"> - <value>False</value> - </setting> - <setting name="CheckMemory" serializeAs="String"> - <value>False</value> - </setting> - <setting name="CheckDisk" serializeAs="String"> - <value>False</value> - </setting> - <setting name="SliderCPU" serializeAs="String"> - <value>0</value> - </setting> - <setting name="SliderMemory" serializeAs="String"> - <value>0</value> - </setting> - <setting name="SliderDisk" serializeAs="String"> - <value>0</value> - </setting> - <setting name="SecCPU" serializeAs="String"> - <value>0</value> - </setting> - <setting name="SecMemory" serializeAs="String"> - <value>0</value> - </setting> - <setting name="SecDisk" serializeAs="String"> - <value>0</value> - </setting> - </BusynessNotification.Settings1> - </userSettings> </configuration> \ No newline at end of file diff --git a/App.xaml.cs b/App.xaml.cs @@ -28,7 +28,7 @@ namespace BusynessNotification }; notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_Click); - ObserveUseage observeUseage = new ObserveUseage(); + ObserveUseage observeUseage = new(); observeUseage.Controller(); } diff --git a/BN_installer/BN_installer.vdproj b/BN_installer/BN_installer.vdproj @@ -209,15 +209,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:BusynessNotification" - "ProductCode" = "8:{25439495-DFFA-4324-916C-7908E16B2B0A}" - "PackageCode" = "8:{DEF95E01-5F9A-4A08-B26F-69C12BE3AE58}" + "ProductCode" = "8:{E9C68E5A-2A81-44BE-A9D4-360354BB7B30}" + "PackageCode" = "8:{9440545B-BFFC-442F-9DF3-DFA273DCAE5D}" "UpgradeCode" = "8:{40D85B84-04C0-4CE8-ADD7-FBCE950EBFE7}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" - "RemovePreviousVersions" = "11:FALSE" + "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.0.0" + "ProductVersion" = "8:1.1.0" "Manufacturer" = "8:Minerva_juppiter" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:https://github.com/minerva-jupiter/BusynessNotification" diff --git a/BN_installer/BN_installer.zip b/BN_installer/BN_installer.zip Binary files differ. diff --git a/BN_installer/BN_installer/BN_installer.msi b/BN_installer/BN_installer/BN_installer.msi Binary files differ. diff --git a/BN_installer/BN_installer/setup.exe b/BN_installer/BN_installer/setup.exe Binary files differ. diff --git a/MainWindow.xaml b/MainWindow.xaml @@ -1,4 +1,4 @@ -<Window x:Class="BusynessNotification.MainWindow" +<Window x:Name="MainWindow" x:Class="BusynessNotification.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" @@ -7,7 +7,7 @@ ui:WindowHelper.UseModernWindowStyle="True" xmlns:local="clr-namespace:BusynessNotification" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="900"> + Title="SettingWindow" Height="450" Width="900"> <Grid ShowGridLines="True"> <Grid.RowDefinitions> <RowDefinition/> diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs @@ -64,7 +64,7 @@ namespace BusynessNotification MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxResult result; - result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); + System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); } ///取得した値をUIに適応 @@ -147,25 +147,26 @@ namespace BusynessNotification { try { - SettingJson data = new SettingJson(); - - data.CheckCPU = Convert.ToBoolean(CPUcheck.IsChecked); - data.CheckMemory = Convert.ToBoolean(Memorycheck.IsChecked); - data.CheckDisk = Convert.ToBoolean(Diskcheck.IsChecked); - data.SliderCPU = SliderCPU; - data.SliderMemory = SliderMemory; - data.SliderDisk = SliderDisk; - data.SecCPU = SecCPU; - data.SecMemory = SecMemory; - data.SecDisk = SecDisk; + SettingJson data = new() + { + CheckCPU = Convert.ToBoolean(CPUcheck.IsChecked), + CheckMemory = Convert.ToBoolean(Memorycheck.IsChecked), + CheckDisk = Convert.ToBoolean(Diskcheck.IsChecked), + SliderCPU = SliderCPU, + SliderMemory = SliderMemory, + SliderDisk = SliderDisk, + SecCPU = SecCPU, + SecMemory = SecMemory, + SecDisk = SecDisk + }; string jsonStr = JsonSerializer.Serialize(data); File.WriteAllText(@"SettingJson.json", jsonStr); Debug.WriteLine(jsonStr); } - catch (Exception) + catch (Exception ex) { - string messageBoxText = "Please try to set this app expect on secur app"; + string messageBoxText = "Please try to set this app expect on secur app.(Exception number: " + ex + ")"; string caption = "Failed to save setting"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Warning; @@ -187,9 +188,8 @@ namespace BusynessNotification static double InputNormalizerToDouble(string input,double oldValue) { - double value; - bool NormalizationCan = double.TryParse(input, out value); - if(NormalizationCan == false || value < 0 || value > 100) + bool NormalizationCan = double.TryParse(input, out double value); + if (NormalizationCan == false || value < 0 || value > 100) { string messageBoxText = "Please enter up to 100"; string caption = "unexpected input"; @@ -197,7 +197,7 @@ namespace BusynessNotification MessageBoxImage icon = MessageBoxImage.Warning; MessageBoxResult result; - result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); + System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); value = oldValue; return value; } diff --git a/ObserveUseage.cs b/ObserveUseage.cs @@ -46,20 +46,24 @@ namespace BusynessNotification Debug.WriteLine("SecCPU=" + SecCPU + " SecMemory=" + SecMemory + " SecDisk=" + SecDisk); ///インスタンス - System.Diagnostics.PerformanceCounter cpuCounter = new System.Diagnostics.PerformanceCounter("Processor Information", "% Processor Utility", "_Total"); + System.Diagnostics.PerformanceCounter cpuCounter = new("Processor Information", "% Processor Utility", "_Total"); - PerformanceCounter performanceCounterRAM = new PerformanceCounter(); - performanceCounterRAM.CounterName = "% Committed Bytes In Use"; - performanceCounterRAM.CategoryName = "Memory"; + PerformanceCounter performanceCounterRAM = new() + { + CounterName = "% Committed Bytes In Use", + CategoryName = "Memory" + }; - PerformanceCounter Disc1 = new PerformanceCounter(); - Disc1.CategoryName = "LogicalDisk"; - Disc1.CounterName = "Disk Transfers/sec"; - Disc1.InstanceName = "C:"; + PerformanceCounter Disc1 = new() + { + CategoryName = "LogicalDisk", + CounterName = "Disk Transfers/sec", + InstanceName = "C:" + }; System.Threading.Timer timer = null; - - TimerCallback timer_delegate = async state => + + async void timer_delegate(object? state) { Debug.WriteLine("timer is still waiking"); @@ -117,7 +121,7 @@ namespace BusynessNotification } - if(flagCPU >= SecCPU && flagMemory >= SecMemory && flagDisk >= SecDisk) + if (flagCPU >= SecCPU && flagMemory >= SecMemory && flagDisk >= SecDisk) { Debug.WriteLine("All clear"); @@ -128,25 +132,21 @@ namespace BusynessNotification .AddText("This PC is now available") .Show(); - int processid; [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); - [DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)] - static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); - [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId); - GetWindowThreadProcessId(GetForegroundWindow(), out processid); + _ = GetWindowThreadProcessId(GetForegroundWindow(), out int processid); Process p = Process.GetProcessById(processid); if (p.MainModule.FileVersionInfo.ProductName != "BusynessNotification") { Environment.Exit(0); } } - }; - timer = new System.Threading.Timer(timer_delegate,null,1000,1000); + } + timer = new System.Threading.Timer(timer_delegate, null, 1000, 1000); } } }