コード例 #1
0
        void UpdateRow(RecordJob <T> record, int status, string action = "")
        {
            record.Retry += 1;
            var xmlObject = SerializeToXml(record.JobRecord);

            JobUtilHelper.UpdateRow(record.RecordId, xmlObject, record.Retry, status, commandJobHandler.CofigurationJob, action);
        }
コード例 #2
0
        public JobsProvider(ICommandJobBase <T> commandJob, IProccessErrorHandler <T> errorHandler, string conn, IOrganizationService crmService)
        {
            if (String.IsNullOrEmpty(conn))
            {
                connectionString = ConfigurationManager.AppSettings[JobUtilHelper.JobProviderConnectionString];
            }
            else
            {
                connectionString = conn;
            }

            JobUtilHelper.InitConnectionString(connectionString);

            if (crmService == null)
            {
                LoadCrmService();
            }
            else
            {
                service = crmService;
            }

            commandJobHandler             = commandJob;
            _errorHandler                 = errorHandler;
            commandJobHandler.JobProvider = this;
            runningJob = new RunningJob();
        }
コード例 #3
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);
            }
        }
コード例 #4
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 ");
        }
コード例 #5
0
 void MonitorRunningEnd()
 {
     if (runningJob.ID == Guid.Empty)
     {
         return;
     }
     JobUtilHelper.UpdateJobHistory(runningJob);
     runningJob.EndRun = DateTime.Now;
     Console.WriteLine("runningJob.end= " + runningJob.Insert);
 }
コード例 #6
0
 void MonitorCompleteGetData()
 {
     if (runningJob.ID == Guid.Empty)
     {
         return;
     }
     JobUtilHelper.UpdateJobHistory(runningJob, true);
     runningJob.EndRun = DateTime.Now;
     Console.WriteLine("runningJob.MonitorCompleteGetData= " + runningJob.Insert);
 }
コード例 #7
0
        private void InsertRecordJob(T job, CofigurationJob configJob, RunningJob runnerjob)
        {
            var xmlObject = SerializeToXml(job);
            var fullname  = typeof(T).FullName;
            var jobid     = JobUtilHelper.InsertRecordJob(xmlObject, fullname, commandJobHandler.CofigurationJob, runnerjob);

            if (runningJob.JobId == null)
            {
                runningJob.JobId = jobid;
            }
        }
コード例 #8
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;
        }
コード例 #9
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();
     }
 }
コード例 #10
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);
                }
            }
        }
コード例 #11
0
 void UpdateStatus(RecordJob <T> record, int status)
 {
     JobUtilHelper.UpdateStatus(record.RecordId, status, commandJobHandler.CofigurationJob);
 }
コード例 #12
0
        private void ExcuteRecords()
        {
            Console.WriteLine("ExcuteRecords start ");
            if (this.RunningJob.JobId == null)
            {
                throw new ArgumentException("Running job must contain JobId");
            }
            bool hasmore; int pageNumber = 1;

            do
            {
                //this.connectionString
                var getRecordsById = GetRecordsById(pageNumber, commandJobHandler.CofigurationJob.RowspPage, out hasmore);
                pageNumber += 1;
                //1	מוכן לטעינה
                //2	בתהליך
                //3	הסתיים
                //4	נכשל
                Console.WriteLine("ExcuteRecords before foreach ");
                foreach (var record in getRecordsById)
                {
                    Console.WriteLine("ExcuteRecords foreach : " + runningJob.Total.ToString());
                    int status = 0; string action = "";
                    try
                    {
                        runningJob.Total++;
                        UpdateOnProgressRow(record);
                        Console.WriteLine("ExcuteRecords foreach after UpdateOnProgressRow ");
                        ResultJob returnValues = commandJobHandler.Execute(record.JobRecord, _errorHandler.WriteLog);
                        action = returnValues.ToString();
                        Console.WriteLine("ExcuteRecords foreach after returnValues ");
                        if (returnValues.HasFlag(ResultJob.Insert))
                        {
                            runningJob.Insert++;
                        }
                        if (returnValues.HasFlag(ResultJob.Update))
                        {
                            runningJob.Update++;
                        }
                        if (returnValues.HasFlag(ResultJob.NoUpdate))
                        {
                            runningJob.NoUpdate++;
                        }
                        if (returnValues.HasFlag(ResultJob.Failed) || returnValues.HasFlag(ResultJob.FailedRetry))
                        {
                            runningJob.Failed++;
                        }
                        else
                        {
                            runningJob.Success++;
                        }

                        if (returnValues.HasFlag(ResultJob.FailedRetry))
                        {
                            status = (int)StatusRecord.Failed;
                        }
                        else
                        {
                            status = (int)StatusRecord.Finish;
                        }
                        Console.WriteLine("ExcuteRecords foreach finish");
                    }
                    catch (FaultException <OrganizationServiceFault> fex)
                    {
                        if (_errorHandler != null)
                        {
                            _errorHandler.WriteLog(record.JobRecord, fex.StackTrace + "_" + fex.Message, EventLogEntryType.Error);
                        }
                        runningJob.Failed++;
                        HandleFualtException(fex, ref status);
                        Console.WriteLine("Error: " + fex.Message + Environment.NewLine + fex.InnerException);
                    }
                    catch (Exception e)
                    {
                        if (_errorHandler != null)
                        {
                            _errorHandler.WriteLog(record.JobRecord, e.StackTrace + "_ex_" + e.ToString(), EventLogEntryType.Error);
                        }

                        runningJob.Failed++;
                        HandleUnHandeledExc(e, ref status);
                        Console.WriteLine("Error: " + e.Message + Environment.NewLine + e.InnerException);
                    }
                    finally
                    {
                        UpdateRow(record, status, action);
                    }

                    Console.WriteLine("ResultJob.Insert " + ResultJob.Insert);
                    Console.WriteLine("ResultJob.Update " + ResultJob.Update);
                }
            }while (hasmore == true);
            JobUtilHelper.UpdateBulkUpdate(runningJob.JobId.Value);
            Console.WriteLine("ExcuteRecords end ");
        }
コード例 #13
0
        private int GetMaxRetries(Guid jobId)
        {
            int maxRetrys = JobUtilHelper.GetMaxRetries(jobId);

            return(maxRetrys);
        }
コード例 #14
0
        private Guid?GetJobIdByJobName()
        {
            Guid?jobid = JobUtilHelper.GetJobIdByJobName(commandJobHandler.CofigurationJob);

            return(jobid);
        }
コード例 #15
0
 public DateTime?GetLastJobDate()
 {
     return(JobUtilHelper.GetLastJob(commandJobHandler.CofigurationJob));
 }
コード例 #16
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);
            }
        }