public bool PrepareInput() { //int dataSourceId = 0; //int.TryParse(e.ApplicationParameters["DataSourceId"].ToString(), out dataSourceId); //if (dataSourceId == 0) // return; InputFileNameOnly = Path.GetFileNameWithoutExtension(InputFileName); //string InputFileExtension = Path.GetExtension(InputFileName); Keys = Cache.Instance.Bag[DataSourceId + ".keys"] as List <IdpeKey>; if (Keys == null) { Keys = DataSource.LoadKeys(DataSourceId); } OutputFolder = DataSource.GetOutputFolder(DataSourceId, Keys); ActualOutputFolder = OutputFolder; OutputFileName = DataSource.GetOutputFileName(DataSourceId, Keys, OutputFolder, InputFileNameOnly); string appWatchFilter = Keys.GetKeyValue(IdpeKeyTypes.WatchFilter); ZipInterfaceName = Keys.GetKeyValue(IdpeKeyTypes.ZipInterfaceName); if ((InputFileExtension.ToLower() == ".zip") || (InputFileExtension.ToLower() == ".rar") || (InputFileExtension.ToLower() == ".tar")) { OutputFolder = Path.Combine(EyediaCoreConfigurationSection.CurrentConfig.TempDirectory, Constants.IdpeBaseFolderName); OutputFolder = Path.Combine(OutputFolder, "RedirectedOutput"); OutputFolder = Path.Combine(OutputFolder, DateTime.Now.ToDBDateFormat()); OutputFolder = Path.Combine(OutputFolder, DataSourceId.ToString()); } if ((!string.IsNullOrEmpty(appWatchFilter)) && (appWatchFilter != Pullers.FileExtensionSupportAll)) { List <string> filters = new List <string>(); if (appWatchFilter.Contains("|")) { filters.AddRange(appWatchFilter.ToLower().Split("|".ToCharArray())); } else { filters.Add(appWatchFilter.ToLower()); } var filterOrNot = (from f in filters where f == InputFileExtension.ToLower() select f).SingleOrDefault(); if (filterOrNot == null) { if (!InputFileNameOnly.StartsWith(Constants.UnzippedFilePrefix)) { IdpeMessage warn = new IdpeMessage(IdpeMessageCodes.IDPE_FILE_TYPE_NOT_SUPPORTED); DataSource dataSource = new DataSource(DataSourceId, string.Empty); WithWarning = string.Format(warn.Message, dataSource.Name, appWatchFilter, Path.GetFileName(InputFileName)); ExtensionMethods.TraceInformation(WithWarning); new PostMan(dataSource).Send(PostMan.__warningStartTag + WithWarning + PostMan.__warningEndTag, "File Ignored"); return(false); } } } if (InputFileNameOnly.StartsWith(Constants.WCFFilePrefix)) { IsRequestFromWCF = true; JobId = InputFileNameOnly.Replace(Constants.WCFFilePrefix, ""); JobId = JobId.Replace(InputFileExtension, ""); } else if (InputFileNameOnly.StartsWith(Constants.UnzippedFilePrefix)) { ZipUniuqeId = ZipFileWatcher.ExtractUniqueId(InputFileNameOnly); OutputFolder = Path.Combine(OutputFolder, ZipUniuqeId); if (!Directory.Exists(OutputFolder)) { Directory.CreateDirectory(OutputFolder); } OutputFileName = Path.Combine(OutputFolder, InputFileNameOnly + Path.GetExtension(OutputFileName)); OutputFileName = ZipFileWatcher.ExtractActualFileName(OutputFileName); } return(true); }
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); }