Esempio n. 1
0
        public void StartDownloading()
        {
            timer           = new Timer(this.Interval * 60 * 1000);
            timer.AutoReset = true;
            timer.Enabled   = false;
            timer.Elapsed  += new ElapsedEventHandler(JobProcessor_Elapsed);
            timer.Start();

            DataSource.TraceInformation("Initialized 'PullSql'; '{0}' [ReturnType = {1}, Select Query = {2}, Update Query = {3}, InterfaceName = {4}, Interval = {5}]",
                                        DataSource.Name, ReturnType == "D" ? "Direct" : "Interfaced", SelectQuery, UpdateQuery, InterfaceName, Interval);
        }
Esempio n. 2
0
        private bool DataSourceIsDisabled()
        {
            int dataSourceId = 0;

            int.TryParse(DataSourceParameters["DataSourceId"].ToString(), out dataSourceId);
            if (dataSourceId == 0)
            {
                return(true);
            }

            DataSource dataSource = new DataSource(dataSourceId, string.Empty);

            if (dataSource.IsActive == false)
            {
                dataSource.TraceInformation(" - ignored as disabled");
                return(true);
            }
            return(false);
        }
Esempio n. 3
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();
        }