/// <summary> /// To check the existance of recovery folder, invalid xml folder, etc... /// </summary> /// <param name="recoverySettings">DataRecoveryServiceSettings in the configuration file</param> /// <returns></returns> private static bool IsAllRecoveryFolderExist(DataRecoveryServiceSettings recoverySettings) { Logger.Log.Info("Inside Methosd"); foreach (FileReaderSetting setting in recoverySettings.FileReaderSettings) { if (!setting.IsActive) { continue; } if (Directory.Exists(setting.RecoveryFolder)) { string subDir = string.Format("{0}\\{1}", setting.RecoveryFolder, StaticInfo.SecondCycleFolder); if (!Directory.Exists(subDir)) { Directory.CreateDirectory(subDir); } subDir = string.Format("{0}\\{1}", setting.RecoveryFolder, StaticInfo.UnRecoverableFolder); if (!Directory.Exists(subDir)) { Directory.CreateDirectory(subDir); } } else { Logger.Log.ErrorFormat("Recovery folder does not exist. Folder Path is {0}", setting.RecoveryFolder); return(false); } if (!Directory.Exists(setting.InvalidXmlFolder)) { Logger.Log.ErrorFormat("Invalid Xml folder does not exist. Folder Path is {0}", setting.InvalidXmlFolder); return(false); } if (!Directory.Exists(setting.InvalidDBRequestFolder)) { Logger.Log.ErrorFormat("Invalid DB Request folder does not exist. Folder Path is {0}", setting.InvalidDBRequestFolder); return(false); } } return(true); }
/// <summary> /// To validate the FileReaderSettings /// </summary> /// <param name="serviceSettings">DataRecoveryServiceSettings in the configuration file</param> /// <returns></returns> private static bool HasValidFileReaderSettings(DataRecoveryServiceSettings serviceSettings) { Logger.Log.Info("Inside Method"); foreach (FileReaderSetting setting in serviceSettings.FileReaderSettings) { if (!setting.IsActive) { continue; } if (string.IsNullOrEmpty(setting.RecoveryFolder)) { Logger.Log.Error("Recovery folder missing in congfiguration"); return(false); } if (string.IsNullOrEmpty(setting.InvalidDBRequestFolder)) { Logger.Log.Error("Invalid DB Request folder missing in congfiguration"); return(false); } if (string.IsNullOrEmpty(setting.InvalidXmlFolder)) { Logger.Log.Error("Invalid Xml folder missing in congfiguration"); return(false); } if (string.IsNullOrEmpty(setting.ConnectionStringName)) { Logger.Log.Error("Connectin string name missing in congfiguration"); return(false); } if (!TryGettingConnectionStringSetting(setting.ConnectionStringName)) { Logger.Log.Error("Connectin string name is not available in connectionStrings section"); return(false); } if (string.IsNullOrEmpty(setting.LoggerName)) { Logger.Log.Error("Logger name missing in congfiguration"); return(false); } } return(true); }
/// <summary> /// To span the threads to start the recovery process /// </summary> private void StartSimultaneousRecoveryProcess() { Logger.Log.Info("Inside Methosd"); int threadCount = 0; DataRecoveryServiceSettings recoverySettings = ConfigurationManager.GetSection("DataRecoveryServiceSettings") as DataRecoveryServiceSettings; foreach (FileReaderSetting readerSetting in recoverySettings.FileReaderSettings) { if (readerSetting.IsActive) { threadCount++; FileReader recoverFileReader = new FileReader(); ParameterizedThreadStart paramThread = new ParameterizedThreadStart(recoverFileReader.StartRecovery); Thread threadInstance = new Thread(paramThread); threadInstance.Name = readerSetting.Name; threadInstance.Start(readerSetting); Interlocked.Increment(ref StaticInfo.ThreadCount); } } Logger.Log.InfoFormat("Total No of Thread Started for Data Recovery : {0}", threadCount); }
/// <summary> /// To check whether the recovery directories reside within one another /// </summary> /// <param name="recoverySettings">RecoverySettings in the configuration</param> /// <returns></returns> private static bool IsRecoveryDirectoryOverlap(DataRecoveryServiceSettings recoverySettings) { Logger.Log.Info("Inside Methosd"); List <string> folders = null; try { folders = new List <string>(); foreach (FileReaderSetting setting in recoverySettings.FileReaderSettings) { folders.Add(setting.RecoveryFolder.ToLower()); } int count = folders.Count; for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (folders[i].StartsWith(folders[j])) { return(true); } } } return(false); } finally { if (folders != null) { folders.Clear(); } folders = null; } }
/// <summary> /// To check the active file reader settings /// </summary> /// <param name="serviceSettings">DataRecoveryServiceSettings in the configuration file</param> /// <returns></returns> private static bool HasActiveFileReaderSettings(DataRecoveryServiceSettings serviceSettings) { Logger.Log.Info("Inside Method"); return(serviceSettings.FileReaderSettings.OfType <FileReaderSetting>().Where(eachSetting => eachSetting.IsActive).Count() > 0); }
/// <summary> /// To validate the application configuration /// </summary> /// <returns></returns> public static bool ValidateConfiguration() { try { Logger.Log.Info("Inside Method"); if (!HasValidAppSettings()) { Logger.Log.Error("Invalid appSettings in congfiguration file"); return(false); } DataRecoveryServiceSettings serviceSettings = ConfigurationManager.GetSection("DataRecoveryServiceSettings") as DataRecoveryServiceSettings; if (serviceSettings == null) { Logger.Log.Error("DataRecoveryServiceSettings missing in congfiguration file"); return(false); } if (serviceSettings.FileReaderSettings.Count == 0) { Logger.Log.Error("There is no FileReaderSettings configured in congfiguration file"); return(false); } if (!HasActiveFileReaderSettings(serviceSettings)) { Logger.Log.Error("There is no active FileReaderSettings in congfiguration file"); return(false); } if (!HasValidFileReaderSettings(serviceSettings)) { Logger.Log.Error("Invalid FileReaderSettings in congfiguration file"); return(false); } if (!IsAllRecoveryFolderExist(serviceSettings)) { Logger.Log.Error("Recovery folder is not available"); return(false); } if (IsRecoveryDirectoryOverlap(serviceSettings)) { Logger.Log.Error("Recovery folders are overlapped with one another"); return(false); } if (!HasValidAppImportSettings()) { Logger.Log.Error("Invalid AppDataImportSettings in congfiguration file"); return(false); } return(true); } catch (Exception ex) { Logger.Log.Error("Error occured while valiation congfiguration settings", ex); return(false); } }