コード例 #1
0
        /// <summary>
        /// Logs information about the system the application is running on.
        /// </summary>
        /// <param name="app">The application object.</param>
        public static void LogSystemInfo(this IDeckAdvisorApp app)
        {
            ManagementObjectSearcher videoController = new ManagementObjectSearcher("select * from Win32_VideoController");

            foreach (ManagementObject obj in videoController.Get())
            {
                app.Logger.Debug("Video Controller Info:\nName:{Name}\nStatus:{Status}\nCaption:{Caption}\nDeviceID:{DeviceID}\nAdapterRAM:{AdapterRAM}\nAdapterDACType:{AdapterDACType}\nMonochrome:{Monochrome}\n" +
                                 "InstalledDisplayDrivers:{InstalledDisplayDrivers}\nDriverVersion:{DriverVersion}\nVideoProcessor:{VideoProcessor}\nVideoArchitecture:{VideoArchitecture}\nVideoMemoryType:{VideoMemoryType}",
                                 obj.TryGetProperty("Name"), obj.TryGetProperty("Status"), obj.TryGetProperty("Caption"), obj.TryGetProperty("DeviceID"), SizeSuffix((long)Convert.ToDouble(obj.TryGetProperty("AdapterRAM"))), obj.TryGetProperty("AdapterDACType"), obj.TryGetProperty("Monochrome"),
                                 obj.TryGetProperty("InstalledDisplayDrivers"), obj.TryGetProperty("DriverVersion"), obj.TryGetProperty("VideoProcessor"), obj.TryGetProperty("VideoArchitecture"), obj.TryGetProperty("VideoMemoryType"));
            }

            ManagementObjectSearcher processor = new ManagementObjectSearcher("select * from Win32_Processor");

            foreach (ManagementObject obj in processor.Get())
            {
                app.Logger.Debug("Processor Info:\nName:{Name}\nDeviceID:{DeviceID}\nManufacturer:{Manufacturer}\nCurrentClockSpeed:{CurrentClockSpeed}\nCaption:{Caption}\nNumberOfCores:{NumberOfCores}\nNumberOfEnabledCore:{NumberOfEnabledCore}\n" +
                                 "NumberOfLogicalProcessors:{NumberOfLogicalProcessors}\nArchitecture:{Architecture}\nFamily:{Family}\nProcessorType:{ProcessorType}\nCharacteristics:{Characteristics}\nAddressWidth:{AddressWidth}",
                                 obj.TryGetProperty("Name"), obj.TryGetProperty("DeviceID"), obj.TryGetProperty("Manufacturer"), obj.TryGetProperty("CurrentClockSpeed"), obj.TryGetProperty("Caption"), obj.TryGetProperty("NumberOfCores"), obj.TryGetProperty("NumberOfEnabledCore"),
                                 obj.TryGetProperty("NumberOfLogicalProcessors"), obj.TryGetProperty("Architecture"), obj.TryGetProperty("Family"), obj.TryGetProperty("ProcessorType"), obj.TryGetProperty("Characteristics"), obj.TryGetProperty("AddressWidth"));
            }

            ManagementObjectSearcher operatingSystem = new ManagementObjectSearcher("select * from Win32_OperatingSystem");

            foreach (ManagementObject obj in operatingSystem.Get())
            {
                app.Logger.Debug("Operating System Info:\nCaption:{Caption}\nWindowsDirectory:{WindowsDirectory}\nProductType:{ProductType}\nSerialNumber:{SerialNumber}\nSystemDirectory:{SystemDirectory}\nCountryCode:{CountryCode}\nCurrentTimeZone:{CurrentTimeZone}\n" +
                                 "EncryptionLevel:{EncryptionLevel}\nOSType:{OSType}\nVersion:{Version}",
                                 obj.TryGetProperty("Caption"), obj.TryGetProperty("WindowsDirectory"), obj.TryGetProperty("ProductType"), obj.TryGetProperty("SerialNumber"), obj.TryGetProperty("SystemDirectory"), obj.TryGetProperty("CountryCode"), obj.TryGetProperty("CurrentTimeZone"),
                                 obj.TryGetProperty("EncryptionLevel"), obj.TryGetProperty("OSType"), obj.TryGetProperty("Version"));
            }
        }
コード例 #2
0
        /// <summary>
        /// Load the Cached State from a file, or create a new one.
        /// </summary>
        /// <param name="app">The application object.</param>
        public static void LoadState(this IDeckAdvisorApp app)
        {
            if (File.Exists("state.json"))
            {
                string stateJson = File.ReadAllText("state.json");
                app.State = JsonConvert.DeserializeObject <CachedState>(stateJson);

                bool saveState = false;
                if (app.State.Fingerprint == Guid.Empty)
                {
                    app.State.Fingerprint = Guid.NewGuid();
                    saveState             = true;
                }
                if (app.State.Filters == null)
                {
                    app.State.Filters = new DeckFilters();
                    saveState         = true;
                }
                if (saveState)
                {
                    app.SaveState();
                }
            }
            else
            {
                app.State = new CachedState();
            }
        }
コード例 #3
0
 /// <summary>
 /// Clear the Cached State and delete the corresponding file if it exists.
 /// </summary>
 /// <param name="app">The application object.</param>
 public static void ClearState(this IDeckAdvisorApp app)
 {
     app.State = new CachedState();
     if (File.Exists("state.json"))
     {
         File.Delete("state.json");
     }
 }
コード例 #4
0
        /// <summary>
        /// Initialization extension for IDeckAdvisorApp.
        /// </summary>
        /// <param name="app">The app.</param>
        /// <param name="postfix">The postfix for log files.</param>
        /// <param name="logSystemInfo">Whether to log system info (don't do this in the .NET Core application)</param>
        public static void InitializeApp(this IDeckAdvisorApp app, string postfix = "", bool logSystemInfo = true)
        {
            ApplicationUtilities.CurrentApp = app;

            var dataFolder = string.Format("{0}Low{1}DailyArena{1}DailyArenaDeckAdvisor", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Path.DirectorySeparatorChar);

            if (!Directory.Exists(dataFolder))
            {
                Directory.CreateDirectory(dataFolder);
            }
            var logFolder = string.Format($"{dataFolder}{Path.DirectorySeparatorChar}logs");

            if (!Directory.Exists(logFolder))
            {
                Directory.CreateDirectory(logFolder);
            }
            Directory.SetCurrentDirectory(dataFolder);

            SelfLog.Enable(msg => Debug.WriteLine(msg));
            SelfLog.Enable(Console.Error);
            app.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.
                         File(new CompactJsonFormatter(), $"{dataFolder}{Path.DirectorySeparatorChar}logs{Path.DirectorySeparatorChar}log{postfix}.txt",
                              rollingInterval: RollingInterval.Hour,
                              retainedFileCountLimit: 5,
                              fileSizeLimitBytes: 10485760,
                              rollOnFileSizeLimit: true,
                              shared: true).
                         CreateLogger();
            app.FirstChanceLogger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.
                                    File(new CompactJsonFormatter(), $"{dataFolder}{Path.DirectorySeparatorChar}logs{Path.DirectorySeparatorChar}firstChanceExceptions{postfix}.txt",
                                         rollingInterval: RollingInterval.Hour,
                                         retainedFileCountLimit: 2,
                                         fileSizeLimitBytes: 10485760,
                                         rollOnFileSizeLimit: true,
                                         shared: true).
                                    CreateLogger();

            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                app.Logger.Error((Exception)e.ExceptionObject, "UnhandledException");
            };

            AppDomain.CurrentDomain.FirstChanceException += (source, e) =>
            {
                app.FirstChanceLogger.Debug(e.Exception, "FirstChanceException");
            };

            if (logSystemInfo)
            {
                // only log system info when running on Windows
                app.LogSystemInfo();
            }
            app.LoadState();
        }
コード例 #5
0
        /// <summary>
        /// Handle clicks of the Apply Button.
        /// </summary>
        /// <param name="sender">The button that was clicked.</param>
        /// <param name="e">The routed event arguments.</param>
        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            IDeckAdvisorApp application = (IDeckAdvisorApp)Application.Current;

            if (application.State.Filters != Filters)
            {
                application.State.Filters.SetAllFields(Filters);
                application.SaveState();
                ((MainWindow)Owner).ApplyFilters(Filters);
            }
            Close();
        }
コード例 #6
0
        /// <summary>
        /// Save the Cached State out to a file.
        /// </summary>
        /// <param name="app">The application object.</param>
        public static void SaveState(this IDeckAdvisorApp app)
        {
            string stateJson = JsonConvert.SerializeObject(app.State);

            File.WriteAllText("state.json", stateJson);
        }