コード例 #1
0
        private void ResultBtn_Click(object sender, EventArgs e)
        {
            try
            {
                switch ((sender as Button)?.Name)
                {
                case "ResultYes":
                    PropertiesExtension.Set("ShowUpdatePromptOnStart", "Yes");
                    DoUpdate();
                    _mgr.Dispose();
                    UpdateDialog.IsOpen = false;
                    break;

                case "ResultNo":
                    UpdateDialog.IsOpen = false;
                    _mgr.Dispose();
                    break;

                case "ResultDontRemind":
                    PropertiesExtension.Set("ShowUpdatePromptOnStart", "Disabled");
                    Log.Information("Update check on start was disabled by the user.");
                    _mgr.Dispose();
                    UpdateDialog.IsOpen = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected Error");
            }
        }
コード例 #2
0
        private async void DoUpdate()
        {
            try
            {
                PropertiesExtension.Set("ShowUpdatePromptOnStart", "");

                Log.Information("Update accepted by the user.");

                try
                {
                    Log.Information("Downloading updates.");
                    await _mgr.DownloadReleases(_updates.ReleasesToApply);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error downloading the release");
                    // Notify user of the error
                }

                try
                {
                    Log.Information("Applying updates.");
                    await _mgr.ApplyReleases(_updates);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while applying updates");
                    // Notify user of the error
                }

                try
                {
                    await _mgr.CreateUninstallerRegistryEntry();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while trying to create uninstaller registry entry");
                    // Notify user of the error
                }


                var latestExe = Path.Combine(_mgr.RootAppDirectory, string.Concat("app-", _latestVersion.Version.Version.Major, ".", _latestVersion.Version.Version.Minor, ".", _latestVersion.Version.Version.Build), "GiroZilla.exe");
                Log.Information("Updates applied successfully.");

                Log.Information($"New exe path: {latestExe}");

                UpdateManager.RestartApp(latestExe);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Unexpected Error");
            }
        }
コード例 #3
0
        private void OnApplicationStartup(object sender, StartupEventArgs e)
        {
            switch (string.IsNullOrWhiteSpace(PropertiesExtension.Get <string>("LogsPath")))
            {
            case true:
            {
                PropertiesExtension.Set("LogsPath", $@"{DefaultDirectories.AppData}\GiroZilla\Logs");
                break;
            }
            }

            //Log formats
            const string outputTemplate = "{Timestamp:HH:mm:ss zzz}{NewLine}{Level} | Thread: {ThreadId} | Source: {SourceContext} | Message: {Message}{NewLine}{Exception}{NewLine}";

            //const string summaryFormat = "{Timestamp:dd/MM/yyyy} [{Level}] {Message}";
            //const string descriptionFormat = "{Timestamp:HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";

            //var file = File.CreateText($@"{DefaultDirectories.CurrentUserDesktop}\Serilog.log");                                  // Create a new file for SeriLoggers 'SelfLog'
            //Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));                                                      // Debug serilog and create a new log file for information.

            Log.Logger = new LoggerConfiguration()                                                                                  // Logging configuration for serilog.
                         .MinimumLevel.Debug()                                                                                      // Serilog implements the common concept of a 'minimum level' for log event processing.
                         .Enrich.WithThreadId()                                                                                     // Adds a ThreadID to the log events
                         .Enrich.FromLogContext()                                                                                   // Adds properties from "LogContext" to the event log.
                         .Enrich.WithProperty("Customer", CompanyName())

                         //.WriteTo.Console(                                                                                                 // Sink configured to the console.
                                                                                                         //   LogEventLevel.Information,                                                                                     // The minimum level for events passed through the sink.
                                                                                                         //   outputTemplate)                                                                                                // A message template describing the format used to write to the sink.

                         .WriteTo.File($@"{PropertiesExtension.Get<string>("LogsPath")}\GiroZilla_.log", // Sink configured for physical files.
                                       LogEventLevel.Information,                                        // The minimum level for events passed through the sink.
                                       outputTemplate,                                                   // A message template describing the format used to write to the sink.
                                       rollingInterval: RollingInterval.Day)                             // The interval which logging will roll over to a new file.

                         .WriteTo.MySQL(PropertiesExtension.Get <string>("LicenseConnString"),           // Sink configured for database entries.
                                        restrictedToMinimumLevel: LogEventLevel.Warning)                 // The minimum level for events passed through the sink.


                         .CreateLogger();                                                                                           // Create the logger using the configured minimum level, enrichers & sinks.
        }
コード例 #4
0
        /// <summary>  Verifies the license to check if the license has expired or don't exist.</summary>
        private void CheckLicense()
        {
            try
            {
                Log.Information("Checking License");

                const string getList  = "SELECT * FROM licenses";
                var          licenses = AsyncMySqlHelper.ReturnStringList(getList, "LicenseConnString").Result.ToList();

#if DEBUG
                var localLicense = PropertiesExtension.Get <string>("License");
#else
                var localLicense = RegHelper.Readvalue(@"Software\", "GiroZilla", "License");
#endif

                switch (!string.IsNullOrWhiteSpace(localLicense))
                {
                case true:
                {
                    Log.Information("Local license found");

                    var count = 1;

                    foreach (var s in licenses)
                    {
                        switch (!IsLicenseVerified)
                        {
                        case true:
                        {
                            _isCorrect = Hashing.Confirm(s, localLicense);

                            switch (_isCorrect)
                            {
                            case true:
                            {
                                var searchLicenseId = $"SELECT `License_VALUE` FROM `licenses` WHERE `License_ID`='{count}'";

                                var license    = AsyncMySqlHelper.GetString(searchLicenseId, "LicenseConnString").Result;
                                var query      = $"SELECT * FROM `licenses` WHERE `License_VALUE`='{license}' AND `License_USED` > 0";
                                var canConnect = AsyncMySqlHelper.CheckDataFromDatabase(query, "LicenseConnString").Result;

                                switch (canConnect)
                                {
                                case true:
                                {
                                    _connectionStatus = 1;
                                    break;
                                }

                                case false:
                                {
                                    _connectionStatus = 0;
                                    break;
                                }
                                }

                                switch (_connectionStatus)
                                {
                                case 1:
                                {
                                    LicenseDialog.IsOpen = false;
                                    IsLicenseVerified    = true;
                                    Log.Information(@"GiroZilla v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion + " loaded");
                                    break;
                                }

                                case 0:
                                {
                                    LicenseDialog.IsOpen = true;
                                    IsLicenseVerified    = false;

                                    switch (!string.IsNullOrWhiteSpace(localLicense))
                                    {
                                    case true:
                                    {
                                        Log.Warning("This license is invalid and wil be reset");

                                        ErrorText.Text = "Din nuværende licens er ugyldig & vil blive nulstillet";

#if DEBUG
                                        PropertiesExtension.Set("License", "");
#else
                                        RegHelper.SetRegValue(@"Software\GiroZilla", "License", "", RegistryValueKind.String);
#endif
                                        break;
                                    }
                                    }

                                    break;
                                }

                                default:
                                {
                                    LicenseDialog.IsOpen = true;
                                    IsLicenseVerified    = false;

                                    switch (!string.IsNullOrWhiteSpace(localLicense))
                                    {
                                    case true:
                                    {
                                        Log.Warning("Something went wrong validating this license");

                                        ErrorText.Text = "Kunne ikke validere din licens prøv igen senere";
                                        break;
                                    }

                                    default:
                                    {
                                        Log.Warning("Something went wrong validating this license (String empty or null)");

                                        ErrorText.Text = "Kunne ikke validere din licens";
                                        break;
                                    }
                                    }
                                    break;
                                }
                                }
                                break;
                            }

                            case false:
                            {
                                count++;
                                break;
                            }
                            }
                            break;
                        }
                        }
                    }
                    break;
                }

                default:
                {
                    LicenseDialog.IsOpen = true;
                    IsLicenseVerified    = false;

                    Log.Warning("The license was not found");

                    ErrorText.Text = "Licensen blev ikke fundet";
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                _connectionStatus = 2;

                Log.Error(ex, "Unexpected Error");
            }
        }