public static async Task <ServiceOperationResult> RemoveLogFileByPath(string logFilePath, bool saveOnCompletion = false) { var serviceOperationHelper = new ServiceOperationHelper(typeof(LogFile), Plurality.Single, ServiceOperation.Remove, _targetName, logFilePath); await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); var index = GetLogFileIndexByPath(logFilePath); if (index >= 0) { Settings.Default.XmlLogFiles.RemoveAt(index); } serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); if (saveOnCompletion) { serviceOperationHelper.ServiceOperationResult = SaveSettings(); } } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); return(serviceOperationHelper.ServiceOperationResult); }
public static async Task <ServiceOperationResult> LoadDatabasesIntoSourceCache(SourceCache <Database, string> sourceCache) { var serviceOperationHelper = new ServiceOperationHelper(typeof(Database), Plurality.Plural, ServiceOperation.Load, _targetName); await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); sourceCache.Edit(innerCache => { foreach (var xmlDatabase in Settings.Default.XmlDatabases) { innerCache.AddOrUpdate(new Database(xmlDatabase, false)); } }); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); return(serviceOperationHelper.ServiceOperationResult); }
public static async Task <ServiceOperationResult> ReloadLogView(LogView logView) { var serviceOperationHelper = new ServiceOperationHelper(typeof(LogView), Plurality.Single, ServiceOperation.Reload, _targetName, logView.Name); await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); var index = GetLogViewIndexByName(logView.Name); if (index < 0) { throw new ArgumentException($"The {typeof(LogView).Name} \"{logView.Name}\" was not found in the {_targetName}."); } logView.UpdateFromXml(Settings.Default.XmlLogViews[index]); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); return(serviceOperationHelper.ServiceOperationResult); }
public static async Task <ServiceOperationResult> AddOrUpdateLogFile(LogFile logFile, bool saveOnCompletion = false) { var serviceOperationHelper = new ServiceOperationHelper(typeof(LogFile), Plurality.Single, ServiceOperation.Add, _targetName, logFile.NetworkFile.FullName); await Task.Run(() => { try { var index = GetLogFileIndexByPath(logFile.NetworkFile.FullName); if (index < 0) { //If item isn't in settings, add it serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); Settings.Default.XmlLogFiles.Add(logFile.ExportToXml()); } else { //If item is in settings, update it serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); Settings.Default.XmlLogFiles[index] = logFile.ExportToXml(); } serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); if (saveOnCompletion) { serviceOperationHelper.ServiceOperationResult = SaveSettings(); } } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); return(serviceOperationHelper.ServiceOperationResult); }
public static async Task <ServiceOperationResult> LoadLogEntriesIntoSourceCacheAsync(LogFile logFile, SourceCache <LogEntry, string> logEntriesSourceCache) { var serviceOperationHelper = new ServiceOperationHelper(typeof(LogEntry), Plurality.Plural, ServiceOperation.Load, $"{typeof(LogFile).Name} with network path \"{logFile.NetworkFile.FullName}\""); await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); var numberOfOldLogEntries = logEntriesSourceCache.Keys.Where(k => k.Contains(logFile.Identifier)).Count(); var contents = File.ReadAllText(logFile.NetworkFile.FullName); long logEntryIndex = 0; logEntriesSourceCache.Edit(innerCache => { foreach (var line in GetLogEntriesFromLogContents(contents)) { if (++logEntryIndex > numberOfOldLogEntries) { var newLogEntry = ParseLogEntry(line, logFile, LogEntry.GetIdentifier(logFile.Identifier, logEntryIndex)); newLogEntry.IsNew = true; innerCache.AddOrUpdate(newLogEntry); } } }); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); return(serviceOperationHelper.ServiceOperationResult); }
private void AddAvailableComputernameAsync(object obj) { Task.Run(() => { var computername = obj?.ToString(); var operationHelper = new ServiceOperationHelper("Computername", Plurality.Single, ServiceOperation.AddOrUpdate, $"{typeof(FilterOptions).Name} available computernames", computername); try { if (!string.IsNullOrWhiteSpace(computername) && !AvailableComputernamesSourceCache.Keys.Contains(computername)) { operationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); AvailableComputernamesSourceCache.Edit(innerCache => { innerCache.AddOrUpdate(computername); }); operationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } } catch (Exception ex) { operationHelper.LogServiceOperation(ex.Message); } }); }
/*@" * SELECT * [SOADB].[dbo].[Local_SSI_ErrorLogDetail].[OBJECT_NAME], * [SOADB].[dbo].[Local_SSI_ErrorLogDetail].[Error_Section], * [SOADB].[dbo].[Local_SSI_ErrorLogDetail].[ERROR_MESSAGE], * [SOADB].[dbo].[Local_SSI_ErrorLogDetail].[TimeStamp], * [SOADB].[dbo].[Local_SSI_ErrorSeverityLevel].[Severity_Level_Desc] * FROM[SOADB].[dbo].[Local_SSI_ErrorLogDetail] * WITH (NOLOCK) * INNER JOIN [SOADB].[dbo].[Local_SSI_ErrorSeverityLevel] * ON[SOADB].[dbo].[Local_SSI_ErrorSeverityLevel].Severity_Level_Id = [SOADB].[dbo].[Local_SSI_ErrorLogDetail].Error_Severity_Level * ORDER BY [SOADB].[dbo].[Local_SSI_ErrorLogDetail].[TimeStamp]";*/ #endregion #region Public methods public static async Task <ServiceOperationResult> LoadLogEntriesIntoSourceCache(Database database, SourceCache <LogEntry, string> logEntriesSourceCache) { var serviceOperationHelper = new ServiceOperationHelper(typeof(LogEntry), Plurality.Plural, ServiceOperation.Load, $"{typeof(Database).Name} {database.Name}"); await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); var numberOfOldLogEntries = logEntriesSourceCache.Keys.Where(k => k.Contains(database.Identifier)).Count(); var addDatabaseInfo = new AddDatabaseInfo(database.Name); var sqlConnection = new SqlConnection(addDatabaseInfo.ToConnectionString()); sqlConnection.Open(); using (SqlCommand sqlCommand = new SqlCommand(GetSQLCommandText(addDatabaseInfo.DatabaseName), sqlConnection)) { using (var sqlDataReader = sqlCommand.ExecuteReader()) { long logEntryIndex = 0; logEntriesSourceCache.Edit(innerCache => { while (sqlDataReader.Read()) { if (++logEntryIndex > numberOfOldLogEntries) { //If the log entry is new var newLogEntry = ParseDatabaseLogEntry(sqlDataReader, database.Name, database, LogEntry.GetIdentifier(database.Identifier, logEntryIndex)); newLogEntry.IsNew = true; innerCache.AddOrUpdate(newLogEntry); } } }); } } sqlConnection.Close(); sqlConnection.Dispose(); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); return(serviceOperationHelper.ServiceOperationResult); }
public static async Task RemoveDatabaseRoutine(IDialogCoordinator dialogCoordinator, object dialogContext, SourceCache <Database, string> databasesSourceCache, Database database) { var serviceOperationHelper = new ServiceOperationHelper(typeof(Database), Plurality.Single, ServiceOperation.Remove, "databases source cache", database.Name); var dialogSettings = new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Negative, }; var dialogResult = await dialogCoordinator.ShowMessageAsync(dialogContext, "Remove Database", $"Are you sure that you would like to remove database \"{database.Name}\"?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings); if (dialogResult == MessageDialogResult.Affirmative) { serviceOperationHelper.ServiceOperationResult = await SettingsService.RemoveDatabaseByName(database.Name, true); if (serviceOperationHelper.ServiceOperationResult.OperationSuceeded) { await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); databasesSourceCache.Remove(database); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); } } if (serviceOperationHelper.ServiceOperationResult.OperationFailed) { await serviceOperationHelper.ServiceOperationResult.ShowUserErrorMessage(dialogCoordinator, dialogContext); } }
public static async Task DeleteLogViewRoutine(IDialogCoordinator dialogCoordinator, object dialogContext, SourceCache <LogView, string> logViewsSourceCache, LogView logView) { var serviceOperationHelper = new ServiceOperationHelper(typeof(LogView), Plurality.Single, ServiceOperation.Remove, "log views source cache", logView.Name); var dialogSettings = new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Negative, }; var dialogResult = await dialogCoordinator.ShowMessageAsync(dialogContext, "Permanently Delete Log View", $"Are you sure that you would like to permanently delete log view \"{logView.Name}\"?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings); if (dialogResult == MessageDialogResult.Affirmative) { await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); logViewsSourceCache.Remove(logView); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); if (serviceOperationHelper.ServiceOperationResult.OperationSuceeded) { serviceOperationHelper.ServiceOperationResult = await SettingsService.RemoveLogViewByName(logView.Name, true); } } if (serviceOperationHelper.ServiceOperationResult.OperationFailed) { await serviceOperationHelper.ServiceOperationResult.ShowUserErrorMessage(dialogCoordinator, dialogContext); } }
public static async Task AddDatabaseRoutine(IDialogCoordinator dialogCoordinator, object dialogContext, SourceCache <Database, string> databasesSourceCache) { var maxCharLength = 100; var keepPrompting = true; var dialogSettings1 = new MetroDialogSettings() { AffirmativeButtonText = "Add", }; while (keepPrompting) { var newDatabaseName = dialogCoordinator.ShowModalInputExternal(dialogContext, "Add Database", $"Enter the database name in the format {_databaseNameFormat}.{Environment.NewLine + _databaseNameFormatNote}", dialogSettings1); dialogSettings1.DefaultText = newDatabaseName; if (newDatabaseName == null) { keepPrompting = false; } else if (string.IsNullOrWhiteSpace(newDatabaseName)) { await dialogCoordinator.ShowMessageAsync(dialogContext, "Invalid Database Name", "The new database name cannot be empty or whitespace."); } else if (newDatabaseName.Length > maxCharLength) { await dialogCoordinator.ShowMessageAsync(dialogContext, "Invalid Database Name", $"The new database name cannot be greater than {maxCharLength} characters."); dialogSettings1.DefaultText = newDatabaseName.Substring(0, maxCharLength); } else if (!newDatabaseName.Contains(AddDatabaseInfo.DatabaseInfoSplitter) || newDatabaseName.Contains("{") || newDatabaseName.Contains("}")) { await dialogCoordinator.ShowMessageAsync(dialogContext, "Invalid Database Name", $"The new database name must be in the format {_databaseNameFormat}.{Environment.NewLine + _databaseNameFormatNote}" + Environment.NewLine + $"Example: 198.163.22.10\\MSSQLSERVER,1433{AddDatabaseInfo.DatabaseInfoSplitter}CustomerInfo*username*password"); } else { var addDatabaseInfo = new AddDatabaseInfo(newDatabaseName); if (SettingsService.SettingsContainsDatabaseName(addDatabaseInfo.ToFormattedString())) { await dialogCoordinator.ShowMessageAsync(dialogContext, "Database Already Added", $"Database \"{newDatabaseName}\" has already been added."); keepPrompting = false; } else { //Show progress dialog while searching for new database var progressController = await dialogCoordinator.ShowProgressAsync(dialogContext, "Looking for Database", $"Trying to find database \"{newDatabaseName}\"..."); progressController.SetIndeterminate(); var databaseExists = false; await Task.Run(() => { databaseExists = TestDatabaseConnection(addDatabaseInfo.ToConnectionString()); }); await progressController.CloseAsync(); //If database can't be found, ask user if they want to continue adding database var dialogSettings = new MetroDialogSettings() { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative, }; if (!databaseExists && await dialogCoordinator.ShowMessageAsync(dialogContext, "Database Not Found", $"The database \"{newDatabaseName}\" could not be found. Would you still like to add it?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings) != MessageDialogResult.Affirmative) { return; } var newDatabase = new Database(addDatabaseInfo.ToFormattedString()); var serviceOperationHelper = new ServiceOperationHelper(typeof(Database), Plurality.Single, ServiceOperation.Add, "databases source cache", addDatabaseInfo.ToFormattedString()); await Task.Run(() => { try { serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting); databasesSourceCache.AddOrUpdate(newDatabase); serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded); } catch (Exception ex) { serviceOperationHelper.LogServiceOperation(ex.Message); } }); keepPrompting = false; if (serviceOperationHelper.ServiceOperationResult.OperationSuceeded) { serviceOperationHelper.ServiceOperationResult = await SettingsService.AddOrUpdateDatabase(newDatabase, true); } if (serviceOperationHelper.ServiceOperationResult.OperationFailed) { await serviceOperationHelper.ServiceOperationResult.ShowUserErrorMessage(dialogCoordinator, dialogContext); } } } } }