/// <summary> /// This method will get called for each file found within the zip file. /// </summary> /// <param name="unzippedFileName">Un zipped full file name</param> /// <param name="onlyFileName">Un zipped file name</param> /// <param name="extension">file extension</param> /// <param name="fileStatus">file status</param> public virtual void Handle(string unzippedFileName, string onlyFileName, string extension, FileStatus fileStatus) { string destFileName = string.Empty; string zipId = string.Empty; unzippedFileName = ExtractActualFileName(unzippedFileName); zipId = ExtractUniqueId(onlyFileName); ExtensionMethods.TraceInformation("Actual name = '{0}', zip id = '{1}', extension = '{2}', and status = '{3}'", Path.GetFileName(unzippedFileName), zipId, extension, fileStatus); switch (fileStatus) { case FileStatus.Process: destFileName = Path.Combine(DataSource.GetArchiveFolder(DataSourceId, DataSourceKeys), onlyFileName); Registry.Instance.Pullers._LocalFileSystemWatcher.Process(unzippedFileName, onlyFileName, this.DataSourceId); break; case FileStatus.IgnoreMoveToOutput: AddIgnoredFileCountToZipFileInfo(zipId); //moving to output string myOutputFolder = Path.Combine(DataSource.GetOutputFolder(DataSourceId, DataSourceKeys), zipId); if (!Directory.Exists(myOutputFolder)) { Directory.CreateDirectory(myOutputFolder); } destFileName = string.Format("{0}\\{1}", myOutputFolder, onlyFileName); destFileName = ExtractActualFileName(destFileName); if (File.Exists(destFileName)) { string buName = Path.Combine(OutputFolder, string.Format("{0}_{1}", RenamedToIdentifier, onlyFileName)); new FileUtility().FileCopy(destFileName, buName, true); //backup existing } new FileUtility().FileCopy(unzippedFileName, destFileName, false); //ignored and copied to output folder List <IdpeKey> appKeys = _datasourceKeys; if (appKeys == null) { appKeys = Cache.Instance.Bag[DataSourceId + ".keys"] as List <IdpeKey>; } Registry.Instance.Pullers.InvokeFileProcessed(this.DataSourceId, string.Empty, appKeys, destFileName, DataSource.GetOutputFolder(DataSourceId, DataSourceKeys), this.ZipUniqueId); break; case FileStatus.Ignore: AddIgnoredFileCountToZipFileInfo(zipId); break; default: throw new Exception("'fileStatus' can be set either to 'Ignore' or 'IgnoreMoveToOutput'!"); } }
public void PrepareInputZip() { ZipUniuqeId = new ZipFileWatcher(InputFileName, DataSourceId, ZipInterfaceName, ProcessingBy, OutputFolder, RenamedToIdentifier).Handle(); OutputFolder = Path.Combine(DataSource.GetOutputFolder(DataSourceId, Keys), ZipUniuqeId); if (!Directory.Exists(OutputFolder)) { Directory.CreateDirectory(OutputFolder); } OutputFileName = Path.Combine(OutputFolder, InputFileNameOnly + InputFileExtension); }
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); }
void JobProcessor_Elapsed(object sender, ElapsedEventArgs e) { try { if (DataSourceIsDisabled()) { return; } if (DataSourceIsTemporarilyStopped()) { return; } if (!this.IsRunning) { this.IsRunning = true; DataSource.TraceInformation(" - Starting"); Job = JobProcessor.Instantiate(DataSource.Id, DataSource.Name, ProcessingBy); Job.IsTriggeredBySqlPuller = true; this.DataSource.BusinessRules.Execute(Job, null, RuleSetTypes.SqlPullInit); DataTable table = ExecuteQuery(); InvokeAfterExecutingSelect(new SqlWatcherEventArgs(table)); if (table.Rows.Count == 0) { Job.TraceInformation(" - No records found."); lock (_lock) { if (Registry.Instance.Entries.ContainsKey(Job.JobIdentifier)) { Job job = Registry.Instance.Entries[Job.JobIdentifier] as Job; Registry.Instance.Entries.Remove(Job.JobIdentifier); job.Dispose(); job = null; } } } else { if (this.ReturnType == "I") { DataSource.TraceInformation("{0} - found {1} records. Processing with interface {2}", DataSource.Name, table.Rows.Count, InterfaceName); string fileName = GenerateFile(table); InvokeFileDownloaded(new FileSystemWatcherEventArgs(DataSourceParameters, fileName)); DataSource.TraceInformation("{0} - records processed with interface.", DataSource.Name); } else { DataSource.TraceInformation("{0} - found {1} records. Processing...", DataSource.Name, table.Rows.Count); Job.Feed(table); JobProcessor jobProcessor = new JobProcessor(); StringBuilder result = jobProcessor.ProcessJob(Job); if (Job.IsErrored) { new SqlWatcherHelper(Job).ExecuteRecoveryScript(); } string outputFolder = DataSource.GetOutputFolder(DataSource.Id, DataSource.Keys); string actualOutputFolder = outputFolder; string outputFileName = DataSource.GetOutputFileName(DataSource.Id, DataSource.Keys, outputFolder, DataSource.Id.ToString()); if (File.Exists(outputFileName)) { string buName = Path.Combine(outputFolder, string.Format("{0}{1}_{2}", DataSource.Name, Guid.NewGuid().ToString(), Path.GetFileName(outputFileName))); new FileUtility().FileCopy(outputFileName, buName, true); } if (result.Length > 0) { using (StreamWriter tw = new StreamWriter(outputFileName)) { tw.Write(result); tw.Close(); } DataSource.TraceInformation("{0} - A data set from {1} was successfully processed. Output file was {2}", DataSource.Name, DataSource.Name, outputFileName); Registry.Instance.Pullers.InvokeFileProcessed(DataSource.Id, jobProcessor.JobId, DataSource.Keys, outputFileName, outputFolder, string.Empty); } else { DataSource.TraceInformation("{0} - Failed to process the SQL data set from '{1}', empty data came from output writer! Check log for more details.", DataSource.Name, DataSource.Name); } jobProcessor.Dispose(); } } this.IsRunning = false; timer.Enabled = true; } } catch (Exception exp) { this.IsRunning = false; DataSource.TraceError(exp.ToString()); timer.Enabled = true; } Trace.Flush(); }