Exemple #1
0
        /// <summary>
        /// This method is used when 'Caller' wants to parse complete file at a time.
        /// </summary>
        /// <param name="dataSourceId">Data source id (either id or name is needed)</param>
        /// <param name="dataSourceName">Data source name (either id or name is needed)</param>
        /// <param name="processingBy">user name who is processing, we could get this from context, but for scenario like 'a126042, Deb'jyoti Das', let caller decide the user name.</param>
        ///<param name="inputData">List of custom objects</param>
        ///<param name="overridenMapping">Comma separated additional mapping override information. For example if "EmpId" from object to be mapped with "EmployeeId" of attribute, then "EmpId=EmployeeId,Ename=EmployeeName"</param>
        /// <returns>Output object. for details, read documentation.</returns>
        public object ProcessObjects(int dataSourceId, string dataSourceName, string processingBy, List <object> inputData, string overridenMapping)
        {
            JobProcessor jobProcessor = new JobProcessor();
            string       jobId        = jobProcessor.InitializeJob(dataSourceId, dataSourceName, processingBy);

            return(new JobProcessor().ProcessJob(jobId, processingBy, inputData, overridenMapping));
        }
Exemple #2
0
        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();
        }
Exemple #3
0
        internal void FileDownloaded(FileSystemWatcherEventArgs e)
        {
            JobProcessorFileHandler jobProcessorFile = new JobProcessorFileHandler(e);

            jobProcessorFile.PrepareInput();

            if (!jobProcessorFile.IsRequestFromWCF)
            {
                ExtensionMethods.TraceInformation("Pullers - Got a new file for {0} - '{1}'", jobProcessorFile.DataSourceId, e.FileName);
            }
            else
            {
                ExtensionMethods.TraceInformation("Pullers - Got a new WCF request for {0}, JobId = '{1}'", jobProcessorFile.DataSourceId, jobProcessorFile.JobId);
            }

            if (DataSourceIsDisabled(jobProcessorFile.DataSourceId, e))
            {
                return;
            }

            StringBuilder result       = new StringBuilder();
            JobProcessor  jobProcessor = new JobProcessor();

            if (jobProcessorFile.IsRequestFromWCF)
            {
                jobProcessor.IsWCFRequest = true;
                result = jobProcessor.ProcessJob(jobProcessorFile.DataSourceId, string.Empty, jobProcessorFile.ProcessingBy,
                                                 jobProcessorFile.InputFileNameOnly, jobProcessorFile.JobId, jobProcessorFile.WithError, jobProcessorFile.WithWarning);
            }
            else if ((jobProcessorFile.InputFileExtension.ToLower() == ".zip") || (jobProcessorFile.InputFileExtension.ToLower() == ".rar") ||
                     (jobProcessorFile.InputFileExtension.ToLower() == ".tar"))
            {
                jobProcessorFile.PrepareInputZip();
                result.AppendLine(jobProcessorFile.ZipUniuqeId);
            }
            else if ((jobProcessorFile.InputFileExtension.ToLower() == ".xls") || (jobProcessorFile.InputFileExtension.ToLower() == ".xlsx"))
            {
                result = jobProcessor.ProcessSpreadSheet(jobProcessorFile.DataSourceId, string.Empty, jobProcessorFile.ProcessingBy, e.FileName);
            }
            else if (jobProcessorFile.InputFileExtension.ToLower() == ".edi")
            {
                new EDIX12FileWatcher(jobProcessorFile.DataSourceId, e.FileName).Process();
                ExtensionMethods.TraceInformation("Pullers - {0} successfully processed. Output file was {1}",
                                                  e.FileName, jobProcessorFile.OutputFileName);
                if (File.Exists(jobProcessorFile.OutputFileName))
                {
                    InvokeFileProcessed(jobProcessorFile.DataSourceId, jobProcessor.JobId,
                                        jobProcessorFile.Keys, jobProcessorFile.OutputFileName,
                                        jobProcessorFile.ActualOutputFolder, jobProcessorFile.ZipUniuqeId);
                }

                jobProcessor.Dispose();
                return;
            }
            else
            {
                result = jobProcessor.ProcessJob(jobProcessorFile.DataSourceId, string.Empty,
                                                 jobProcessorFile.ProcessingBy, e.FileName, string.Empty, jobProcessorFile.WithError, jobProcessorFile.WithWarning);
            }
            #region Commented2

            /*
             * if (File.Exists(jobProcessorFile.OutputFileName))
             * {
             *  string buName = Path.Combine(jobProcessorFile.OutputFolder, string.Format("{0}_{1}", e.RenamedToIdentifier, Path.GetFileName(jobProcessorFile.OutputFileName)));
             *  FileCopy(jobProcessorFile.OutputFileName, buName, true); //backup existing
             * }
             *
             * if (((jobProcessorFile.InputFileExtension.ToLower() == ".zip")
             || (jobProcessorFile.InputFileExtension.ToLower() == ".rar") || (jobProcessorFile.InputFileExtension.ToLower() == ".tar"))
             || && (jobProcessorFile.Keys.GetKeyValue(SreKeyTypes.ZipDoNotCreateAcknoledgementInOutputFolder).ParseBool()))
             ||{
             || ExtensionMethods.TraceInformation("Pullers - The data source '{0}' has been configured as not to copy zip acknoledgement file. File will not be created!",
             ||     jobProcessorFile.DataSourceId);
             || return;
             ||}
             ||
             ||if (result.Length > 0)
             ||{
             || using (StreamWriter tw = new StreamWriter(jobProcessorFile.OutputFileName))
             || {
             ||     tw.Write(result);
             ||     tw.Close();
             || }
             ||
             || ExtensionMethods.TraceInformation("{0} successfully processed. Output file was {1}", e.FileName, outputFileName);
             || InvokeFileProcessed(dataSourceId, jobProcessor.JobId, keys, outputFileName, actualOutputFolder, zipUniuqeId);
             ||}
             ||else
             ||{
             || ExtensionMethods.TraceInformation("Pullers - Failed to process '{0}', empty data came from output writer! Check log for more details.", e.FileName);
             ||}
             */
            #endregion Commented2

            if (jobProcessorFile.PrepareOutput(result))
            {
                InvokeFileProcessed(jobProcessorFile.DataSourceId, jobProcessor.JobId, jobProcessorFile.Keys,
                                    jobProcessorFile.OutputFileName, jobProcessorFile.ActualOutputFolder, jobProcessorFile.ZipUniuqeId);
            }

            jobProcessor.Dispose();
        }