Beispiel #1
0
        public void SetRecord(T job)
        {
            try
            {
                _errorHandler.StartWritingErrors(commandJobHandler);
                var configJob = commandJobHandler.CofigurationJob;
                runningJob.JobId = GetJobIdByJobName();

                if (runningJob.JobId == null)
                {
                    throw new ArgumentNullException("there is no any jobid for " + JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
                }
                runningJob.ID = Guid.Empty;
                InsertRecordJob(job, configJob, runningJob);
                runningJob.Insert  = 1;
                runningJob.Success = 1;
                runningJob.Total   = 1;
                runningJob.Desc    = SerializeToXml(job);

                _errorHandler.FinishWritingErrors(runningJob);
            }
            catch (Exception ex)
            {
                _errorHandler.WriteLog("JobProvider=>SetRecord()", ex.StackTrace, EventLogEntryType.Error);
            }
        }
Beispiel #2
0
        void InsertToSqlAll()
        {
            Console.WriteLine("InsertToSql start ");
            ICommandJob <T> JobHandler = (ICommandJob <T>)commandJobHandler;//.Get(_errorHandler.WriteLog);
            var             jobs       = JobHandler.Get(_errorHandler.WriteLog);

            Console.WriteLine("records " + (jobs == null ? "null" : jobs.Count().ToString()));
            var configJob = commandJobHandler.CofigurationJob;

            if (jobs == null || !jobs.Any())
            {
                runningJob.JobId = GetJobIdByJobName();
                if (runningJob.JobId == null)
                {
                    throw new ArgumentNullException("there is no any jobid for " + JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
                }
            }
            else
            {
                //Insert jobs, and get job id.
                foreach (var job in jobs)
                {
                    Console.WriteLine("Insert record: " + job.CurrentStep.ToString());
                    InsertRecordJob(job, configJob, runningJob);
                }
            }
            Console.WriteLine("InsertToSql end ");
        }
Beispiel #3
0
        void MonitorRunningBegin()
        {
            var configJob = commandJobHandler.CofigurationJob;

            runningJob.JobId = GetJobIdByJobName();
            if (runningJob.JobId == null)
            {
                throw new ArgumentNullException("there is no any jobid for " + JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
            }

            runningJob.BeginRun = DateTime.Now;
            var id = JobUtilHelper.AddHistory(runningJob.JobId, runningJob.BeginRun);

            runningJob.ID = id;
        }
Beispiel #4
0
 public static Guid InsertRecordJob(string xmlObject, string fullname,
                                    CofigurationJob configJob, RunningJob runnerjob)
 {
     using (var connection = GetSqlConnection(GetConectionString()))
     {
         var command = new SqlCommand(@"dbo.GS_InsertRecordJob", connection);
         command.Parameters.AddWithValue("@jobName", JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
         command.Parameters.AddWithValue("@MaxRetries", configJob.MaxRetries);
         command.Parameters.AddWithValue("@ModelXml", xmlObject);
         command.Parameters.AddWithValue("@ModelTypeXml", fullname);
         command.Parameters.AddWithValue("@historyId", runnerjob.ID);
         command.CommandType = System.Data.CommandType.StoredProcedure;
         connection.Open();
         var jobid = (Guid)command.ExecuteScalar();
         return(jobid);
         //if (runningJob.JobId == null)
         //    runningJob.JobId = (Guid)command.ExecuteScalar();
         //else
         //    command.ExecuteNonQuery();
     }
 }
Beispiel #5
0
        void InsertToSqlFetchCrmXml()
        {
            var configJob  = commandJobHandler.CofigurationJob;
            var jobHandler = ((IFetchCrmData <T>)commandJobHandler);
            LargeResultSetsFetchXML largeXml = new LargeResultSetsFetchXML();

            runningJob.JobId = GetJobIdByJobName();
            if (runningJob.JobId == null)
            {
                throw new ArgumentNullException("there is no any jobid for " + JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
            }
            //return;
            foreach (var itemFetchXmlRow in largeXml.Get(Service, jobHandler.FetchXml, jobHandler.Count))
            {
                bool toinsert;
                var  job = jobHandler.ConvertToObject(itemFetchXmlRow, out toinsert);
                if (toinsert)
                {
                    InsertRecordJob(job, configJob, runningJob);
                }
            }
        }
Beispiel #6
0
        void InsertToSqlChunkData(string fetchFilterXmlObject = "")
        {
            var jobHandler = ((IFetchFilterXmlObjects <T>)commandJobHandler);

            Console.WriteLine("InsertToSqlChunkData start ");
            ChunkData chunkdata = new ChunkData();

            chunkdata.Limit    = jobHandler.Limit;
            chunkdata.Page     = jobHandler.Page;
            chunkdata.FromDate = jobHandler.FromDate;
            var maxdate = jobHandler.MaxDate ?? DateTime.Now;

            chunkdata.FetchFilterXmlObject = fetchFilterXmlObject;
            chunkdata.ToDate = jobHandler.Next(chunkdata.FromDate);

            while (chunkdata.FromDate < maxdate)
            {
                bool hasrows = true;
                do
                {
                    var jobs = jobHandler.Get(_errorHandler.WriteLog, chunkdata);
                    Console.WriteLine("records " + (jobs == null ? "null" : jobs.Count().ToString()));
                    var configJob = commandJobHandler.CofigurationJob;
                    if (jobs == null || !jobs.Any())
                    {
                        runningJob.JobId = GetJobIdByJobName();
                        if (runningJob.JobId == null)
                        {
                            throw new ArgumentNullException("there is no any jobid for " + JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
                        }
                        //return;
                        hasrows         = false;
                        chunkdata.JobId = runningJob.JobId.Value;
                    }
                    else
                    {
                        runningJob.JobId = runningJob.JobId.HasValue ? runningJob.JobId.Value : GetJobIdByJobName();
                        if (runningJob.JobId == null)
                        {
                            throw new ArgumentNullException("there is no any jobid!!! for " + JobUtilHelper.GetFullJobNameByCofigurationJob(configJob));
                        }

                        chunkdata.JobId = runningJob.JobId.Value;
                        //Insert jobs, and get job id.
                        hasrows = jobs.Any();
                        foreach (var job in jobs)
                        {
                            Console.WriteLine("Insert record: " + job.CurrentStep.ToString());
                            InsertRecordJob(job, configJob, runningJob);
                        }
                    }
                    if (!hasrows)
                    {
                        chunkdata.Page = 1;
                    }
                    else
                    {
                        chunkdata.Page += 1;
                    }
                } while (hasrows);

                Console.WriteLine("InsertToSqlChunkData end ");
                chunkdata.FromDate = chunkdata.ToDate;
                chunkdata.ToDate   = jobHandler.Next(chunkdata.FromDate);
            }
        }