Exemplo n.º 1
0
        private string CompanyName()
        {
            var address = PropertiesExtension.Get <string>("AddressLine");

            var temp = address.Split('+')[0];

            if (string.IsNullOrWhiteSpace(temp))
            {
                temp = "No Company";
            }

            return(temp);
        }
Exemplo n.º 2
0
        private async void CheckForUpdates(bool manualUpdate = false)
        {
            try
            {
                var result = PropertiesExtension.Get <string>("ShowUpdatePromptOnStart");

                switch (result)
                {
                case "Yes":
                {
                    DoCheck(manualUpdate);
                    break;
                }

                case "Disabled":
                {
                    switch (manualUpdate)
                    {
                    case true:
                    {
                        DoCheck(manualUpdate);
                        break;
                    }

                    default:
                    {
                        Log.Information("Update check is disabled.");
                        UpdateDialog.IsOpen = false;
                        break;
                    }
                    }
                    break;
                }
                }
                await Task.FromResult(true);
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Something went wrong while checking for updates");
                UpdateDialog.IsOpen = false;
            }
        }
Exemplo n.º 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.
        }
Exemplo n.º 4
0
        /// <summary>Verifies if the logs folder exists.</summary>
        private static void VerifyLogsFolder()
        {
            try
            {
                var folderPath = PropertiesExtension.Get <string>("LogsPath");

                switch (Directory.Exists(folderPath))
                {
                case true:
                    return;

                case false:
                    Directory.CreateDirectory(folderPath);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "The path could not be made or found");
            }
        }
Exemplo n.º 5
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");
            }
        }