void StartLocalFileSystemWatcher() { Trace.TraceInformation("Initializing local file watcher..."); _LocalFileSystemWatcher = new LocalFileSystemWatcher(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryArchive); Watchers.FileSystemWatcherEventHandler handler = new Watchers.FileSystemWatcherEventHandler(FileDownloaded); _LocalFileSystemWatcher.FileDownloaded -= handler; _LocalFileSystemWatcher.FileDownloaded += handler; _LocalFileSystemWatcher.Run(); Trace.TraceInformation("Local file watcher initialized with Pull = '{0}' and Archive = '{1}'.", SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryArchive); }
public void Start() { SqlWatchers = new Dictionary <int, SqlWatcher>(); if (!Directory.Exists(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull)) { Directory.CreateDirectory(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull); } WindowsUtility.SetFolderPermission(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull); Trace.TraceInformation("Pullers initialization started."); if (SymplusCoreConfigurationSection.CurrentConfig.TempDirectory.Length > Constants.MaxTempFolderPath) { throw new ConfigurationErrorsException(string.Format("'{0}' can not have more than '{1}' length", SymplusCoreConfigurationSection.CurrentConfig.TempDirectory, Constants.MaxTempFolderPath)); } _Manager = new Manager(); List <int> allDataSourceIds = _Manager.GetAllDataSourceIds(false); foreach (int appId in allDataSourceIds) { string dir = Path.Combine(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, appId.ToString()); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } StartLocalFileSystemWatcher(); List <SreDataSource> dataSources = _Manager.GetDataSources(); foreach (SreDataSource dataSource in dataSources) { List <SreKey> keys = Cache.Instance.Bag[dataSource.Id + ".keys"] as List <SreKey>; if (keys == null) { keys = _Manager.GetApplicationKeys(dataSource.Id, true); Cache.Instance.Bag.Add(dataSource.Id + ".keys", keys); } if ((dataSource.DataFeederType != null) && ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullFtp)) { #region Initializing FtpPullers string ftpRemoteLocation = FindSREKeyUsingType(keys, SreKeyTypes.FtpRemoteLocation); string ftpUserName = FindSREKeyUsingType(keys, SreKeyTypes.FtpUserName); string ftpPassword = FindSREKeyUsingType(keys, SreKeyTypes.FtpPassword); string strinterval = FindSREKeyUsingType(keys, SreKeyTypes.FtpWatchInterval); int ftpWatchIntervalInMinutes = 0; int.TryParse(strinterval, out ftpWatchIntervalInMinutes); if (ftpWatchIntervalInMinutes == 0) { ftpWatchIntervalInMinutes = 1; } string ftpLocalLocation = Path.Combine(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, dataSource.Id.ToString()); string appOutputFolder = Path.Combine(SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryOutput, dataSource.Id.ToString(), DateTime.Now.ToString("yyyyMMdd")); Dictionary <string, object> datasourceParameters = new Dictionary <string, object>(); lock (_lock) { datasourceParameters.Add("DataSourceId", dataSource.Id); datasourceParameters.Add("OutputFolder", appOutputFolder); datasourceParameters.Add("ProcessingBy", dataSource.ProcessingBy); } FtpFileSystemWatcher ftpWatcher = new FtpFileSystemWatcher(datasourceParameters, ftpRemoteLocation, ftpLocalLocation, ftpWatchIntervalInMinutes, ftpUserName, ftpPassword, false, true); Trace.TraceInformation("Initialized 'PullFtp'; '{0}' [ftpRemoteLocation = {1}, ftpLocalLocation = {2}, ftpUserName = {3},ftpPassword = {4}, interval = {5}]", dataSource.Name, ftpRemoteLocation, ftpLocalLocation, ftpUserName, ftpPassword, ftpWatchIntervalInMinutes); Registry.Instance.FtpWatchers.Add(ftpWatcher); #endregion Initializing FtpPullers } else if ((dataSource.DataFeederType != null) && ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullLocalFileSystem)) { if (IsLocalFileSystemFoldersOverriden(keys)) { SreFileSystemWatcher sreFileSystemWatcher = new SreFileSystemWatcher(dataSource.Id, keys); Watchers.FileSystemWatcherEventHandler handler = new Watchers.FileSystemWatcherEventHandler(FileDownloaded); sreFileSystemWatcher.FileDownloaded -= handler; sreFileSystemWatcher.FileDownloaded += handler; sreFileSystemWatcher.StartWatching(); Registry.Instance.DataSourceFileWatcher.Add(dataSource.Id, sreFileSystemWatcher); } //we dont have to do anything if it is generic } else if ((dataSource.DataFeederType != null) && ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullSql)) { #region Initializing SQL Pullers string connectionStringKeyName = FindSREKeyUsingName(keys, SreKeyTypes.PullSqlConnectionString); string returnType = FindSREKeyUsingType(keys, SreKeyTypes.PullSqlReturnType); string selectQuery = FindSREKeyUsingType(keys, SreKeyTypes.SqlQuery); string updateQuery = FindSREKeyUsingType(keys, SreKeyTypes.SqlUpdateQueryProcessing); string interfaceName = FindSREKeyUsingType(keys, SreKeyTypes.PullSqlInterfaceName); string strinterval = FindSREKeyUsingType(keys, SreKeyTypes.SqlWatchInterval); int interval = 0; int.TryParse(strinterval, out interval); if (interval <= 0) { interval = 1; } string appPullFolder = SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull + "\\" + dataSource.Id; string appOutputFolder = SreConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryOutput + "\\" + dataSource.Id + "\\" + DateTime.Now.ToString("yyyyMMdd"); Dictionary <string, object> applicationParameters = new Dictionary <string, object>(); lock (_lock) { applicationParameters.Add("DataSourceId", dataSource.Id); applicationParameters.Add("PullFolder", appPullFolder); applicationParameters.Add("OutputFolder", appOutputFolder); applicationParameters.Add("ProcessingBy", dataSource.ProcessingBy); } SqlWatcher sqlWatcher = new SqlWatcher(applicationParameters, connectionStringKeyName, returnType, selectQuery, updateQuery, interfaceName, interval); sqlWatcher.StartDownloading(); SqlWatchers.Add(dataSource.Id, sqlWatcher); Trace.TraceInformation("Initialized 'PullSql'; '{0}' [Connection String Name = {1}, ReturnType = {2}, Select Query = {3}, Update Query = {4}, InterfaceName = {5}, Interval = {6}]", dataSource.Name, connectionStringKeyName, returnType == "D" ? "Direct" : "Interfaced", selectQuery, updateQuery, interfaceName, interval); #endregion Initializing SQL Pullers } #region Initializing Pushers // if ((!string.IsNullOrEmpty(dataSource.PusherType)) //&& (Type.GetType(dataSource.PusherType) != null)) // { // lock (_lock) // { // Pushers pusher = null; // if (!Registry.Instance.DataSourcePushers.ContainsKey(dataSource.Id)) // { // Trace.TraceInformation("Initializing 'Pusher'; '{0}' = '{1}'.", dataSource.Name, dataSource.PusherType); // object objPusher = Activator.CreateInstance(Type.GetType(dataSource.PusherType)); // pusher = (Pushers)objPusher; // Registry.Instance.DataSourcePushers.Add(dataSource.Id, pusher); // } // else // { // Trace.TraceInformation("Initializing 2 'Pusher'; '{0}' = '{1}'.", dataSource.Name, dataSource.PusherType); // pusher = Registry.Instance.DataSourcePushers[dataSource.Id]; // } // PullersEventHandler pusherHandler = new PullersEventHandler(pusher.FileProcessed); // Registry.Instance.Pullers.FileProcessed -= pusherHandler; // Registry.Instance.Pullers.FileProcessed += pusherHandler; // } // } #endregion Initializing Pushers Trace.Flush(); } Trace.TraceInformation("Pullers initialization finished."); }
public void Start() { SqlWatchers = new Dictionary <int, SqlWatcher>(); try { if (!Directory.Exists(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull)) { Directory.CreateDirectory(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull); } WindowsUtility.SetFolderPermission(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull); } catch (Exception ex) { Trace.TraceInformation(ex.Message); Trace.Flush(); } DateTime stTm = DateTime.Now; if (EyediaCoreConfigurationSection.CurrentConfig.TempDirectory.Length > Constants.MaxTempFolderPath) { throw new ConfigurationErrorsException(string.Format("'{0}' can not have more than '{1}' length", EyediaCoreConfigurationSection.CurrentConfig.TempDirectory, Constants.MaxTempFolderPath)); } _Manager = new Manager(); List <int> allDataSourceIds = _Manager.GetAllDataSourceIds(false); foreach (int dataSourceId in allDataSourceIds) { string dir = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, dataSourceId.ToString()); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } string sysDir = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, "100"); if (!Directory.Exists(sysDir)) { Directory.CreateDirectory(sysDir); } StartLocalFileSystemWatcher(); List <IdpeDataSource> dataSources = _Manager.GetDataSources(); foreach (IdpeDataSource dataSource in dataSources) { List <IdpeKey> keys = Cache.Instance.Bag[dataSource.Id + ".keys"] as List <IdpeKey>; if (keys == null) { keys = DataSource.LoadKeys(dataSource.Id); } if ((dataSource.DataFeederType != null) && ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullFtp)) { #region Initializing FtpPullers string ftpRemoteLocation = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpRemoteLocation); string ftpUserName = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpUserName); string ftpPassword = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpPassword); string strinterval = FindSREKeyUsingType(keys, IdpeKeyTypes.FtpWatchInterval); int ftpWatchIntervalInMinutes = 0; int.TryParse(strinterval, out ftpWatchIntervalInMinutes); if (ftpWatchIntervalInMinutes == 0) { ftpWatchIntervalInMinutes = 1; } string ftpLocalLocation = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryPull, dataSource.Id.ToString()); string appOutputFolder = Path.Combine(IdpeConfigurationSection.CurrentConfig.LocalFileWatcher.DirectoryOutput, dataSource.Id.ToString(), DateTime.Now.ToString("yyyyMMdd")); Dictionary <string, object> datasourceParameters = new Dictionary <string, object>(); lock (_lock) { datasourceParameters.Add("DataSourceId", dataSource.Id); datasourceParameters.Add("OutputFolder", appOutputFolder); datasourceParameters.Add("ProcessingBy", dataSource.ProcessingBy); } FtpFileSystemWatcher ftpWatcher = new FtpFileSystemWatcher(datasourceParameters, ftpRemoteLocation, ftpLocalLocation, ftpWatchIntervalInMinutes, ftpUserName, ftpPassword, false, true); ExtensionMethods.TraceInformation("Pullers - Initialized 'PullFtp'; '{0}' [ftpRemoteLocation = {1}, ftpLocalLocation = {2}, ftpUserName = {3},ftpPassword = {4}, interval = {5}]", dataSource.Name, ftpRemoteLocation, ftpLocalLocation, ftpUserName, ftpPassword, ftpWatchIntervalInMinutes); Registry.Instance.FtpWatchers.Add(ftpWatcher); #endregion Initializing FtpPullers } else if ((dataSource.DataFeederType != null) && ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullLocalFileSystem)) { if (IsLocalFileSystemFoldersOverriden(keys)) { SreFileSystemWatcher sreFileSystemWatcher = new SreFileSystemWatcher(dataSource.Id, keys); Watchers.FileSystemWatcherEventHandler handler = new Watchers.FileSystemWatcherEventHandler(FileDownloaded); sreFileSystemWatcher.FileDownloaded -= handler; sreFileSystemWatcher.FileDownloaded += handler; sreFileSystemWatcher.StartWatching(); Registry.Instance.DataSourceFileWatcher.Add(dataSource.Id, sreFileSystemWatcher); } //we dont have to do anything if it is generic } else if ((dataSource.DataFeederType != null) && ((DataFeederTypes)dataSource.DataFeederType == DataFeederTypes.PullSql)) { #region Initializing SQL Pullers SqlWatcher sqlWatcher = new SqlWatcher(dataSource); sqlWatcher.StartDownloading(); SqlWatchers.Add(dataSource.Id, sqlWatcher); #endregion Initializing SQL Pullers } Trace.Flush(); } ExtensionMethods.TraceInformation("Pullers - Initialization finished.{0}", DateTime.Now - stTm); }