Ejemplo n.º 1
0
 private void RefreshLogFilesSourceCacheAsync(LogView oldLogView, LogView newLogView)
 {
     Task.Run(() =>
     {
         var logFilesToRefresh = new List <LogFile>();
         if (oldLogView != null)
         {
             foreach (var identifier in oldLogView.AllLogFilePathsAndDatabaseNames)
             {
                 var logFile = LogFilesSourceCache.Lookup(identifier);
                 if (logFile.HasValue)
                 {
                     logFilesToRefresh.Add(logFile.Value);
                 }
             }
         }
         if (newLogView != null)
         {
             foreach (var identifier in newLogView.AllLogFilePathsAndDatabaseNames)
             {
                 var logFile = LogFilesSourceCache.Lookup(identifier);
                 if (logFile.HasValue)
                 {
                     logFilesToRefresh.Add(logFile.Value);
                 }
             }
         }
         LogFilesSourceCache.Refresh(logFilesToRefresh);
         RaisePropertyChangedEvent("LogFiles");
     });
 }
Ejemplo n.º 2
0
        private async void OpenLogView(LogView logView)
        {
            logView.Open();
            AdjustOpenLogViewCount(1);
            RequestSetSelectedLogView(logView);
            logView.IsLoading = true;
            RequestToggleLaunchViewIsOpen();

            await Task.Delay(500);

            if (!logView.IsNew && LogViewToOpenDocumentIn == null)
            {
                OpenableObjectService.SaveOpenableObject(logView);
            }

            var tasks = new List <Task <ServiceOperationResult> >();

            foreach (var logFilePath in logView.LogFilePaths)
            {
                var logFile = LogFilesSourceCache.Lookup(logFilePath);
                if (logFile.HasValue)
                {
                    logFile.Value.Open();
                    OpenableObjectService.SaveOpenableObject(logFile.Value);
                    tasks.Add(LogFileService.LoadLogEntriesIntoSourceCacheAsync(logFile.Value, LogEntriesSourceCache));
                }
            }

            foreach (var databaseName in logView.DatabaseNames)
            {
                var database = DatabasesSourceCache.Lookup(databaseName);
                if (database.HasValue)
                {
                    database.Value.Open();
                    OpenableObjectService.SaveOpenableObject(database.Value);
                    tasks.Add(DatabaseService.LoadLogEntriesIntoSourceCache(database.Value, LogEntriesSourceCache));
                }
            }

            var results = await Task.WhenAll(tasks);

            var failedLogFilesString  = string.Empty;
            var failedDatabasesString = string.Empty;
            var errorMessage          = string.Empty;
            await Task.Run(() =>
            {
                for (int i = 0; i < results.Length - logView.DatabaseNames.Count; i++)
                {
                    var result = results[i];
                    if (result.OperationFailed && logView.LogFilePaths.Count > i)
                    {
                        failedLogFilesString += logView.LogFilePaths[i] + "," + Environment.NewLine;
                    }
                }
                if (failedLogFilesString.Length > 2)
                {
                    failedLogFilesString = failedLogFilesString.Substring(0, failedLogFilesString.Length - 3);
                }

                for (int i = logView.LogFilePaths.Count; i < results.Length; i++)
                {
                    var result = results[i];
                    if (result.OperationFailed)
                    {
                        failedDatabasesString += logView.DatabaseNames[i - logView.LogFilePaths.Count] + "," + Environment.NewLine;
                    }
                }
                if (failedDatabasesString.Length > 2)
                {
                    failedDatabasesString = failedDatabasesString.Substring(0, failedDatabasesString.Length - 3);
                }

                if (!string.IsNullOrWhiteSpace(failedLogFilesString))
                {
                    errorMessage += $"Failed to load log entries for the following log files:{Environment.NewLine + failedLogFilesString}";
                    if (!string.IsNullOrWhiteSpace(failedDatabasesString))
                    {
                        errorMessage += $"{Environment.NewLine + Environment.NewLine}Failed to load log entries for the following databases:{Environment.NewLine + failedDatabasesString}";
                    }
                }
                else if (!string.IsNullOrWhiteSpace(failedDatabasesString))
                {
                    errorMessage += $"Failed to load log entries for the following databases:{Environment.NewLine + failedDatabasesString}";
                }
            });

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                //TODO: I'm getting this summary error message and individual error messages. Have to disable the error message for each individual log source.
                await DialogCoordinator.ShowMessageAsync(this, "Failed to Load Log Entries", errorMessage);
            }

            //Notify the LogViewManagementViewModel that the AutoRefreshSetting changed so that it can tell databases and log files
            Mediator.NotifyColleagues(MediatorMessages.AutoRefreshSettingChanged, logView.Settings.AutoRefresh);

            logView.IsLoading = false;
        }