From 6943b4f42d86389faa25899b91bc598c24a7b0ca Mon Sep 17 00:00:00 2001 From: 1kamma Date: Mon, 15 May 2023 00:08:17 +0300 Subject: [PATCH] modify visuality --- NetWork/Program.cs | 59 ++++++----- NetWork/Properties/Resources.Designer.cs | 73 +++++++++++++ NetWork/Properties/Resources.resx | 124 +++++++++++++++++++++++ desktop.ini | Bin 244 -> 0 bytes 4 files changed, 230 insertions(+), 26 deletions(-) create mode 100644 NetWork/Properties/Resources.Designer.cs create mode 100644 NetWork/Properties/Resources.resx delete mode 100644 desktop.ini diff --git a/NetWork/Program.cs b/NetWork/Program.cs index 6e26b22..18af48b 100644 --- a/NetWork/Program.cs +++ b/NetWork/Program.cs @@ -3,7 +3,7 @@ using DotRas; using Microsoft.Win32.TaskScheduler; using NAudio.CoreAudioApi; using Newtonsoft.Json.Linq; -using NLog; +using Serilog; using System; using System.Collections.Generic; using System.Diagnostics; @@ -12,9 +12,14 @@ using System.Net.NetworkInformation; using System.ServiceProcess; using System.Text.RegularExpressions; using System.Threading; +using Serilog.Core; +using Serilog.Sinks.File; +using Serilog.Events; -namespace NetWork { - class Program { +namespace NetWork +{ + class Program + { /// /// this function gets an array of service names, and start or stop command, and it runs on the array and /// @@ -45,7 +50,8 @@ namespace NetWork { foreach (var ser in Services) { try { ser.Stop(); - } catch { + } + catch { } } } else { @@ -53,7 +59,8 @@ namespace NetWork { try { ser.Start(); - } catch { + } + catch { } @@ -68,7 +75,7 @@ namespace NetWork { var device = new MMDeviceEnumerator(); var Devices = device.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active); foreach (var Device in Devices) { - foreach (string ob in array) { + foreach (string ob in array!) { if (Device.FriendlyName.Contains(ob)) { return true; } @@ -77,15 +84,7 @@ namespace NetWork { } return false; } - public static Logger StartLogger() { - var config = new NLog.Config.LoggingConfiguration(); - var logfile = new NLog.Targets.FileTarget("lgfle") { FileName = "logme.txt" }; - config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); - NLog.LogManager.Configuration = config; - NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); - return logger; - } - public static Logger logger = StartLogger(); + /// /// String of paths /// @@ -102,7 +101,10 @@ namespace NetWork { if (stop) { Process[] ids = Process.GetProcessesByName("mstsc"); foreach (var id in ids) { - logger.Debug(id.MainWindowTitle); + //using (ILogger log=Logger) + //{ + // log.Debug(id.MainWindowTitle); + //} Regex rdp = new("(משרדוש.rdp|161.2)"); if (rdp.IsMatch(id.MainWindowTitle) || id.MainWindowTitle.Equals("חיבור לשולחן עבודה מרוחק")) { id.Kill(); @@ -117,7 +119,7 @@ namespace NetWork { bool started = false; foreach (var id in ids) { Regex rdp = new("(משרדוש.rdp|161.2)"); - logger.Debug(id.MainWindowTitle); + if (rdp.IsMatch(id.MainWindowTitle) || id.MainWindowTitle.Equals("חיבור לשולחן עבודה מרוחק")) { started = true; } @@ -193,7 +195,8 @@ namespace NetWork { StopRDP(); } } - } catch { + } + catch { continue; } } @@ -228,7 +231,8 @@ namespace NetWork { try { wifiname = wlan.Interfaces[0].CurrentConnection.profileName; - } catch { + } + catch { wifiname = ""; } return wifiname; @@ -253,7 +257,7 @@ namespace NetWork { } return false; } - static string GetLan(System.Net.NetworkInformation.NetworkInterface networkAdapter) { + static string? GetLan(System.Net.NetworkInformation.NetworkInterface networkAdapter) { if (LanEthernet(networkAdapter) && IgnoreLan(networkAdapter)) { return networkAdapter.GetPhysicalAddress().ToString(); } @@ -288,7 +292,7 @@ namespace NetWork { } } - net_dict.Add("Wi-Fi", IsItGoodWifi(getwifi)); + net_dict.Add("Wi-Fi", IsItGoodWifi(getwifi)!); net_dict["good_lan"] = getgoodland; if (getlan.Length > 0) { net_dict["lan"] = true; @@ -310,10 +314,10 @@ namespace NetWork { return "Wi-Fi"; } - public static bool AllowedMac(string mac, string[] those_are_the_AllowedMacs = null) { + public static bool AllowedMac(string mac, string?[] those_are_the_AllowedMacs = null) { string[] AllowedMac_adresses; if (!(those_are_the_AllowedMacs is null)) { - AllowedMac_adresses = those_are_the_AllowedMacs; + AllowedMac_adresses = those_are_the_AllowedMacs!; } else { AllowedMac_adresses = new string[] { "00E04C6813E4" }; } @@ -325,7 +329,7 @@ namespace NetWork { return false; } - public static bool AllowedMac(string[] mac, string[] those_are_the_AllowedMacs = null) { + public static bool AllowedMac(string[] mac, string?[] those_are_the_AllowedMacs = null) { foreach (var single_mac in mac) { if (AllowedMac(single_mac, those_are_the_AllowedMacs)) { return true; @@ -335,7 +339,7 @@ namespace NetWork { } public static void StartProgram(string process_name) { if (process_name.Contains("rdp") || process_name.Contains("mstsc")) { - Process.Start("mstsc.exe", @"D:\Drive\מסמכים\vms\משרדוש.rdp"); + Process.Start("mstsc.exe", $"{Environment.ExpandEnvironmentVariables("%USERPROFILE%")}/Documents/משרדוש.rdp"); } else if (Process.GetProcessesByName(process_name).Length < 1) { string process; if (progs.ContainsKey(process_name)) { @@ -441,7 +445,10 @@ namespace NetWork { return System.IO.File.ReadAllText("Other\\Data.ini").Equals("RunNetwork"); } static void Main(string[] args) { - logger.Debug("me"); + Log.Logger = new LoggerConfiguration().WriteTo.File("Logs/NetworkLog.log", LogEventLevel.Debug, + "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}[{Level: u3}] {Message:lj}{NewLine}", + rollingInterval: RollingInterval.Minute).CreateLogger(); + //IgnoreFile.M(); DoTheSchtik(IniData()); diff --git a/NetWork/Properties/Resources.Designer.cs b/NetWork/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e05f63a --- /dev/null +++ b/NetWork/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NetWork.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NetWork.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] ek { + get { + object obj = ResourceManager.GetObject("ek", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/NetWork/Properties/Resources.resx b/NetWork/Properties/Resources.resx new file mode 100644 index 0000000..4801d1e --- /dev/null +++ b/NetWork/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Other\ek.pbk;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/desktop.ini b/desktop.ini deleted file mode 100644 index 757d3e706e9f113cbae3a2b8da57fbd8f186fc05..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 244 zcmY+8u?oUK5JX=s_z(F22~n|7NTozlDO!3KA)Mwwjd&`4zLPBsvh3aL?#wU;QuZ`> zE~=%vBC1MmoM<^RWT1U(bKt?1f*_t}!=0SW7$voFcG^dwmzcG1F6{!xR&&c)ZzYH1 x=Mi;V>(bpiPsd7}z+1RyCCd2J-kaJnW31endT#%}NAFNbmrC_fkC-sEtY3M8DPI5p