예제 #1
0
        public void Execute()
        {
            var dc     = new ProcessRunnerDcDataContext();
            var status = EventJobStatus.Working;

            StaticResources.UpdateEventJobStatusAndRunWhen(EventJobId, status);
            foreach (var sjf in dc.Setup_JobFunctions.Where(sjf => sjf.Setup_JobId == SetupJobId && sjf.IsDisabled != true).OrderBy(sjf => sjf.Sequence))
            {
                var funcName = string.Format("Function_{0}", dc.Kind_Functions.Single(kf => kf.Id == sjf.Kind_FunctionId).Name);
                var func     = (IFunction)Activator.CreateInstance(Assembly.GetExecutingAssembly().GetName().Name, funcName, new[] { (object)this, sjf.Id });
                try
                {
                    func.Execute();
                } catch (Exception ex)
                {
                    StaticResources.UpdateEventJobStatusAndRunWhen(EventJobId, EventJobStatus.Failed);
                    if (ex is ProcessRunnerException)
                    {
                        throw ex;
                    }
                    throw new ProcessRunnerException(func.Context, string.Format("Unhandled exception: {0}", ex.Message));
                }
                if (FatalErrorWasReported())
                {
                    status = EventJobStatus.Failed;
                    break;
                }
            }
            status = status == EventJobStatus.Working ? EventJobStatus.Completed : status;
            StaticResources.UpdateEventJobStatusAndRunWhen(EventJobId, status);
        }
 public static void UpdateEventJobStatusAndRunWhen(int eventJobId, EventJobStatus status)
 {
     var dc = new ProcessRunnerDcDataContext();
     var eventJob = dc.Event_Jobs.Single(ej => ej.Id == eventJobId);
     eventJob.Status = (int)status;
     dc.SubmitChanges();
     if (status == EventJobStatus.Working)
         dc.UpdateEventJobRunWhen(eventJobId);
 }
예제 #3
0
        public FluentSchedulerJob(int eventJobId, BackgroundWorker bgWorker)
        {
            EventJobId = eventJobId;
            var dc       = new ProcessRunnerDcDataContext();
            var eventJob = dc.Event_Jobs.Single(ej => ej.Id == eventJobId);

            SetupJobId = eventJob.Setup_JobId;
            JobName    = dc.Setup_Jobs.Single(sj => sj.Id == SetupJobId).Name;

            BgWorker    = bgWorker;
            PropertyBag = new Dictionary <JobPropertyBagKey, object>();
        }
예제 #4
0
        private void PerformService()
        {
            if (_serverBg.CancellationPending)
            {
                return;
            }
            Thread.Sleep(_waitMilliseconds);
            var dc = new ProcessRunnerDcDataContext();

            foreach (var eventJob in dc.Event_Jobs.Where(ej => ej.Status == null))
            {
                var fluentSchedulerJob = new FluentSchedulerJob(eventJob.Id, _serverBg);
                JobManager.AddJob(fluentSchedulerJob, s => s.ToRunNow());
            }
        }
 public static void LogMessage(int? eventJobId, EventMessageSeverity severity, string context, string message, BackgroundWorker bgWorker)
 {
     var dc = new ProcessRunnerDcDataContext();
     var eventMessage = new Event_Message();
     if (eventJobId.HasValue)
         eventMessage.Event_JobId = eventJobId.Value;
     eventMessage.Severity = (int)severity;
     if (!string.IsNullOrEmpty(context))
         eventMessage.Context = context;
     if (!string.IsNullOrEmpty(message))
         eventMessage.Message = message;
     dc.Event_Messages.InsertOnSubmit(eventMessage);
     dc.SubmitChanges();
     if (bgWorker != null)
         bgWorker.ReportProgress(0, message);
 }
 public static string ArchiveFile(int vendorId, SetupJobDirection direction, string localFile)
 {
     var dc = new ProcessRunnerDcDataContext();
     var vendor = dc.Vendors.Single(v => v.Id == vendorId);
     var archivePath = dc.NameValuePairs.Single(nv => nv.Name.Equals("TransmissionArchive")).Value;
     var path = Path.Combine(archivePath, direction.ToString(), vendor.ArchiveLocation);
     if (!Directory.Exists(path))
         Directory.CreateDirectory(path);
     path = Path.Combine(path, DateTime.Now.Year.ToString());
     if (!Directory.Exists(path))
         Directory.CreateDirectory(path);
     var archiveFilename = Path.Combine(path, Path.GetFileName(localFile));
     if (File.Exists(archiveFilename))
         UiLibrary.AppendGuidToFilename(archiveFilename);
     File.Copy(localFile, archiveFilename);
     return archiveFilename;
 }
 public static Dictionary<string, string> GetParametersForForSetupJobFunction(int setupJobId, int setupJobFunctionId)
 {
     //select
     //	 kp.Name ParmName
     //	,sp.Value ParmValue
     //from
     //	Setup_JobFunctionParameter sjfp
     //	inner join Setup_Parameter sp on sjfp.Setup_ParameterId = sp.Id
     //	inner join Kind_Parameter kp on sp.Kind_ParameterId = kp.Id
     //where
     //	sjfp.Setup_JobId = @setupJobId
     //	and sjfp.Setup_JobFunctionId = @setupJobFunctionId
     var dc = new ProcessRunnerDcDataContext();
     var q = from sjfp in dc.Setup_JobFunctionParameters
             join sp in dc.Setup_Parameters on sjfp.Setup_ParameterId equals sp.Id
             join kp in dc.Kind_Parameters on sp.Kind_ParameterId equals kp.Id
             where (sjfp.Setup_JobId == setupJobId) && (sjfp.Setup_JobFunctionId == setupJobFunctionId)
             select new { key = kp.Name, value = sp.Value };
     return q.ToDictionary(a => a.key, a => a.value);
 }
 private void Refresh()
 {
     Dc     = new ProcessRunnerDcDataContext();
     Status = string.Empty;
 }