Example #1
0
 private void LoadHistoryFilesAsync()
 {
     _ = Task.Run(() =>
     {
         Log.Debug("{class} {method} {message}", "GlobalQueryHistory", "LoadHistoryFilesAsync", "Start Load");
         FileInfo[] fileList = null;
         try
         {
             DirectoryInfo d = new DirectoryInfo(_queryHistoryPath);
             fileList        = d.GetFiles("*-query-history.json", SearchOption.TopDirectoryOnly);
             List <QueryHistoryEvent> tempHist = new List <QueryHistoryEvent>(_globalOptions.QueryHistoryMaxItems);
             foreach (var fileInfo in fileList)
             {
                 using (StreamReader file = File.OpenText(fileInfo.FullName))
                 {
                     JsonSerializer serializer      = new JsonSerializer();
                     QueryHistoryEvent queryHistory = (QueryHistoryEvent)serializer.Deserialize(file, typeof(QueryHistoryEvent));
                     tempHist.Add(queryHistory);
                 }
             }
             QueryHistory.AddRange(tempHist);
         }
         catch (Exception ex)
         {
             Log.Error(ex, "{class} {method} {message}", nameof(GlobalQueryHistory), nameof(LoadHistoryFilesAsync), $"Error loading query history files: {ex.Message}");
         }
         Log.Debug("{class} {method} {message}", "GlobalQueryHistory", "LoadHistoryFilesAsync", "End Load (" + fileList?.Length + " files)");
     });
 }
Example #2
0
 private async Task LoadHistoryFilesAsync()
 {
     await Task.Run(() =>
     {
         Log.Debug("{class} {method} {message}", "GlobalQueryHistory", "LoadHistoryFilesAsync", "Start Load");
         FileInfo[] fileList = null;
         int errorCnt        = 0;
         try
         {
             DirectoryInfo d = new DirectoryInfo(_queryHistoryPath);
             fileList        = d.GetFiles("*-query-history.json", SearchOption.TopDirectoryOnly);
             Log.Debug(Constants.LogMessageTemplate, nameof(GlobalQueryHistory), nameof(LoadHistoryFilesAsync), $"Starting load of {fileList.Length} history files");
             List <QueryHistoryEvent> tempHist = new List <QueryHistoryEvent>(_globalOptions.QueryHistoryMaxItems);
             foreach (var fileInfo in fileList)
             {
                 try
                 {
                     using (StreamReader file = File.OpenText(fileInfo.FullName))
                     {
                         JsonSerializer serializer      = new JsonSerializer();
                         QueryHistoryEvent queryHistory = (QueryHistoryEvent)serializer.Deserialize(file, typeof(QueryHistoryEvent));
                         tempHist.Add(queryHistory);
                     }
                 }
                 catch (Exception ex)
                 {
                     Log.Error(ex, "{class} {method} {message}", nameof(GlobalQueryHistory), nameof(LoadHistoryFilesAsync), $"Error loading History file: {fileInfo.FullName}, Message: {ex.Message}");
                     errorCnt++;
                 }
             }
             QueryHistory.AddRange(tempHist);
         }
         catch (Exception ex)
         {
             Log.Error(ex, "{class} {method} {message}", nameof(GlobalQueryHistory), nameof(LoadHistoryFilesAsync), $"Error loading query history files: {ex.Message}");
         }
         if (errorCnt > 0)
         {
             _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Warning, $"Not all Query History records could be loaded, {errorCnt} error{(errorCnt==1?" has":"s have")} been written to the log file"));
         }
         Log.Debug("{class} {method} {message}", "GlobalQueryHistory", "LoadHistoryFilesAsync", "End Load (" + fileList?.Length + " files)");
     });
 }
Example #3
0
 private void LoadHistoryFilesAsync()
 {
     Task.Run(() =>
     {
         Log.Debug("{class} {method} {message}", "GlobalQueryHistory", "LoadHistoryFilesAsync", "Start Load");
         DirectoryInfo d = new DirectoryInfo(_queryHistoryPath);
         var fileList    = d.GetFiles("*-query-history.json", SearchOption.TopDirectoryOnly);
         List <QueryHistoryEvent> tempHist = new List <QueryHistoryEvent>(_globalOptions.QueryHistoryMaxItems);
         foreach (var fileInfo in fileList)
         {
             using (StreamReader file = File.OpenText(fileInfo.FullName))
             {
                 JsonSerializer serializer      = new JsonSerializer();
                 QueryHistoryEvent queryHistory = (QueryHistoryEvent)serializer.Deserialize(file, typeof(QueryHistoryEvent));
                 tempHist.Add(queryHistory);
             }
         }
         QueryHistory.AddRange(tempHist);
         Log.Debug("{class} {method} {message}", "GlobalQueryHistory", "LoadHistoryFilesAsync", "End Load (" + fileList.Count() + " files)");
     });
 }
Example #4
0
        static MessageBus()
        {
            new Thread(UpdateChecker.CheckUpdate).Start();

            if (File.Exists(LOGIN_TICKET_FILE))
            {
                LoginTicket = File.ReadAllText(LOGIN_TICKET_FILE);
            }

            if (File.Exists(QUERY_HISTORY_FILE))
            {
                try
                {
                    string queryHistory = File.ReadAllText(QUERY_HISTORY_FILE);
                    QueryHistory.AddRange(Regex.Split(queryHistory.Trim(), "\r\n|\r|\n"));
                }
                catch
                {
                    MessageBox.Show("查询历史记录解析失败");
                }
            }
        }