Пример #1
0
            /// <summary>
            /// Checks if the database is OK
            /// </summary>
            public static void CheckDatabaseIntegrity()
            {
                try
                {
                    Logger.LogInfo("CheckDatabaseIntegrity", "Checking database integrity");

                    var _s = new SettingsRepo().Load().Result;
                    var _w = new WatchFolderRepo().Load().Result;
                    var _m = new MusicFileRepo().LoadAll(true).Result;
                    var _p = new PlaylistFileRepo().LoadAll().Result;
                    var _l = new LogsRepo().LoadSpecific("3").Result;

                    Logger.LogInfo("CheckDatabaseIntegrity", "Database integrity check complete - No issues");
                }
                catch (Exception e)
                {
                    if (
                        MessageBox.Show(
                            $"Unfortunately the database integrity check has failed ({e.Message}). YT Music Uploader cannot continue in this state. " +
                            $"If you click 'OK', YT Music Uploader will reset the database to its original state. You'll lose any uploaded file states but the program" +
                            $" should then work. Otherwise click cancel to attempt to rectify the database yourself located in: %localappdata%\\YTMusicUploader",
                            "Database Integrity Check Fail",
                            MessageBoxButton.OKCancel,
                            MessageBoxImage.Error) == MessageBoxResult.OK)
                    {
                        ResetDatabase();
                        Logger.LogInfo("CheckDatabaseIntegrity", "Database has been reset due to integrity check failure. Comfirmed by user.");
                    }
                }
            }
Пример #2
0
        /// <summary>
        /// Log error from exception with error severity
        /// </summary>
        /// <param name="e">Exception to log</param>
        public static void Log(Exception e, LogTypeEnum logType)
        {
            if (IsInIgnoreList(GetExceptionMessage(e)))
            {
                return;
            }

            try
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    var log = new Log
                    {
                        Event      = DateTime.Now,
                        LogTypeId  = logType,
                        Source     = GetExceptionSource(e).Ellipse(200 - 5),
                        Message    = GetExceptionMessage(e).Ellipse(1500 - 5),
                        StackTrace = GetExceptionStackTrace(e).Ellipse(4000 - 5),
                        Machine    = MachineName.Ellipse(210),
                        Version    = VersionHelper.GetVersionFull()
                    };

                    Task.Run(async() => await LogsRepo.Add(log));
                });
            }
            catch { }
        }
Пример #3
0
        public LogsRepoUnitTests()
        {
            // cannot mock LiteCollection<Event>, it is sealed

            _app = new App(null, _dbName);
            _sut = _app.Get <LogsRepo>();
        }
Пример #4
0
        /// <summary>
        /// Log custom error message
        /// </summary>
        /// <param name="source">Where the message originated</param>
        /// <param name="message">The messsage to log</param>
        public static void LogError(string source, string message, string stackTrace = null)
        {
            if (IsInIgnoreList(message))
            {
                return;
            }

            try
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    var log = new Log
                    {
                        Event      = DateTime.Now,
                        LogTypeId  = LogTypeEnum.Error,
                        Source     = source.Ellipse(200 - 5),
                        Message    = message.Ellipse(1500 - 5),
                        StackTrace = stackTrace,
                        Machine    = MachineName.Ellipse(210),
                        Version    = VersionHelper.GetVersionFull()
                    };

                    Task.Run(async() => await LogsRepo.Add(log));
                });
            }
            catch { }
        }
Пример #5
0
        /// <summary>
        /// Log custom info message
        /// </summary>
        /// <param name="source">Where the message originated</param>
        /// <param name="message">The messsage to log</param>
        public static void LogCritial(string source, string message, bool ignoreRemote = false)
        {
            try
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    var log = new Log
                    {
                        Event      = DateTime.Now,
                        LogTypeId  = LogTypeEnum.Critical,
                        Source     = source.Ellipse(200 - 5),
                        Message    = message.Ellipse(1500 - 5),
                        StackTrace = null,
                        Machine    = MachineName.Ellipse(210),
                        Version    = VersionHelper.GetVersionFull()
                    };

                    Task.Run(async() => await LogsRepo.Add(log));
                    if (SendLogToSource & !ignoreRemote)
                    {
                        log.Machine += $"@{ExternalIp}";
                        LogsRepo.RemoteAdd(log);
                    }
                });
            }
            catch { }
        }
Пример #6
0
        /// <summary>
        /// Log error from exception with error severity
        /// </summary>
        /// <param name="e">Exception to log</param>
        public static void Log(Exception e, string additionalMessage, LogTypeEnum logType, bool ignoreRemote = false)
        {
            try
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    var log = new Log
                    {
                        Event      = DateTime.Now,
                        LogTypeId  = logType,
                        Source     = GetExceptionSource(e).Ellipse(200 - 5),
                        Message    = (additionalMessage + ": " + GetExceptionMessage(e)).Ellipse(1500 - 5),
                        StackTrace = GetExceptionStackTrace(e).Ellipse(4000 - 5),
                        Machine    = MachineName.Ellipse(210),
                        Version    = VersionHelper.GetVersionFull()
                    };

                    Task.Run(async() => await LogsRepo.Add(log));
                    if (SendLogToSource && !ignoreRemote)
                    {
                        log.Machine += $"@{ExternalIp}";
                        LogsRepo.RemoteAdd(log);
                    }
                });
            }
            catch { }
        }
 /// <summary>
 /// Form to display upload issues. Data fetched from the local database.
 /// </summary>
 public ApplicationLog() : base(formResizable: true)
 {
     LogsRepo = new LogsRepo();
     Font     = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont);
     InitializeComponent();
     InitialiseTooltips();
     SuspendDrawing(this);
 }
Пример #8
0
 /// <summary>
 /// Clears historic logs early than the amount of days as defined in the App.config (default 30 days).
 /// </summary>
 public static void ClearHistoricLogs()
 {
     try
     {
         Task.Run(async() => await LogsRepo.DeleteOlderThan(DateTime.Now.AddDays(Global.ClearLogsAfterDays * -1)));
     }
     catch { }
 }
Пример #9
0
        private Response LoadLogs()
        {
            JsonSettings.MaxJsonLength = int.MaxValue;
            var allLogs = LogsRepo.GetAll().OrderByDescending(x => x.Id).Take(200);
            var model   = new DatatablesModel <LogEntity> {
                Data = new List <LogEntity>()
            };

            foreach (var l in allLogs)
            {
                l.DateString = l.Date.ToString("G");
                model.Data.Add(l);
            }
            return(Response.AsJson(model));
        }
Пример #10
0
        /// <summary>
        /// Log custom info message
        /// </summary>
        /// <param name="source">Where the message originated</param>
        /// <param name="message">The messsage to log</param>
        public static void LogCritial(string source, string message)
        {
            try
            {
                ThreadPool.QueueUserWorkItem(delegate
                {
                    var log = new Log
                    {
                        Event      = DateTime.Now,
                        LogTypeId  = LogTypeEnum.Critical,
                        Source     = source.Ellipse(200 - 5),
                        Message    = message.Ellipse(1500 - 5),
                        StackTrace = null,
                        Machine    = MachineName.Ellipse(210),
                        Version    = VersionHelper.GetVersionFull()
                    };

                    Task.Run(async() => await LogsRepo.Add(log));
                });
            }
            catch { }
        }
Пример #11
0
        private async Task <Response> ClearLogs()
        {
            try
            {
                Analytics.TrackEventAsync(Category.Admin, Action.Delete, "Clear Logs", Username, CookieHelper.GetAnalyticClientId(Cookies));
                var allLogs = await LogsRepo.GetAllAsync();

                foreach (var logEntity in allLogs)
                {
                    await LogsRepo.DeleteAsync(logEntity);
                }
                return(Response.AsJson(new JsonResponseModel {
                    Result = true, Message = "Logs cleared successfully."
                }));
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = e.Message
                }));
            }
        }
Пример #12
0
 /// <summary>
 /// Form to display upload issues. Data fetched from the local database.
 /// </summary>
 public ApplicationLog() : base(formResizable: true)
 {
     LogsRepo = new LogsRepo();
     InitializeComponent();
     SuspendDrawing(this);
 }