Exemplo n.º 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 void Execute()
        {
            var connMgr   = ConnectionManager.Create();
            var sqlHelper = SqlHelper.Create(connMgr[_parameters["SqlConnection"]]);
            var cmd       = sqlHelper.CreateStoredProcCommand(_parameters["StoredProcedure"], false);
            var dataSet   = sqlHelper.PopulateDataSet(cmd);

            StaticResources.ProcessStatusTable0AndReportIfFatal(CallingJob.EventJobId, Context, dataSet.Tables[0], CallingJob.BgWorker);

            //todo: handle params for the sp
        }
        public void Execute()
        {
            var vendorId  = Convert.ToInt32(_parameters["Vendor"]);
            var localFile = CallingJob.PropertyBag[JobPropertyBagKey.Filename].ToString();

            if (!(new[] { SetupJobDirection.Inbound, SetupJobDirection.Outbound }).Contains(CallingJob.JobDirection))
            {
                throw new ProcessRunnerException(Context, "Bad Job Direction");
            }
            CallingJob.PropertyBag[JobPropertyBagKey.ArchivedFilename] =
                StaticResources.ArchiveFile(vendorId, CallingJob.JobDirection, localFile);
        }
        public void Execute()
        {
            var connMgr   = ConnectionManager.Create();
            var sqlHelper = SqlHelper.Create(connMgr[_parameters["SqlConnection"]]);
            var cmd       = sqlHelper.CreateStoredProcCommand(_parameters["StoredProcedure"], false);
            var dataSet   = sqlHelper.PopulateDataSet(cmd);

            if (StaticResources.ProcessStatusTable0AndReportIfFatal(CallingJob.EventJobId, Context, dataSet.Tables[0], CallingJob.BgWorker))
            {
                return;
            }
            FileType fileType;

            if (!Enum.TryParse(_parameters["FileType"], out fileType))
            {
                throw new ProcessRunnerException(Context, string.Format("Unknown file type: {0}", _parameters["FileType"]));
            }
            var tempFileName = Path.GetTempFileName();

            using (TextWriter tw = new StreamWriter(tempFileName))
            {
                switch (fileType)
                {
                case (FileType.PipeDelimitedNoHeader):
                    foreach (DataRow dataRow in dataSet.Tables[1].Rows)
                    {
                        tw.WriteLine(dataRow.ItemArray.Aggregate((a, b) => string.Format("{0}|{1}", a, b)));
                    }
                    break;
                }
            }
            var fileName = _parameters["FileName"] == "TempFile" ? tempFileName : StaticResources.FilenameWithDate(_parameters["FileName"]);

            if (fileName != tempFileName)
            {
                if (string.IsNullOrEmpty(Path.GetDirectoryName(fileName)))
                {
                    fileName = Path.Combine(Path.GetDirectoryName(tempFileName), fileName);
                }
                File.Move(tempFileName, fileName);
            }
            CallingJob.PropertyBag[JobPropertyBagKey.Filename] = fileName;
        }
Exemplo n.º 5
0
        public void Execute()
        {
            var folder    = _parameters.ContainsKey("RemoteFolder") ? _parameters["RemoteFolder"] : "/";
            var localFile = CallingJob.PropertyBag[JobPropertyBagKey.Filename].ToString();

            var remoteFile = Path.Combine(folder, Path.GetFileName(localFile)).Replace("/", @"\");
            int numRetrys  = 3;

            var vendorId         = Convert.ToInt32(_parameters["Vendor"]);
            var transmissionSite = (new ProcessRunnerDcDataContext()).TransmissionSites.Single(ts => ts.VendorId == vendorId);

            var sftpProg = new SshNetSftp();
            ProcessRunnerException pre = null;

            try
            {
                sftpProg.DoWork(
                    SftpOperation.Upload,
                    transmissionSite.Site,
                    0,
                    transmissionSite.LoginName,
                    transmissionSite.Password,
                    null,
                    new[] { remoteFile },
                    new[] { localFile },
                    ref numRetrys
                    );
            } catch (Exception ex)
            {
                if (CallingJob.PropertyBag.ContainsKey(JobPropertyBagKey.ArchivedFilename))
                {
                    var archiveFile = CallingJob.PropertyBag[JobPropertyBagKey.ArchivedFilename].ToString();
                    StaticResources.MarkFileAsFailed(archiveFile);
                }
                pre = new ProcessRunnerException(Context, ex.Message);
            }
            File.Delete(localFile);
            if (pre != null)
            {
                throw pre;
            }
        }
Exemplo n.º 6
0
 public void Start(BackgroundWorker bgWorker)
 {
     if (bgWorker != null)
     {
         _bgWorker = bgWorker;
     }
     _waitMilliseconds = StaticResources.GetPollWaitMilliseconds();
     StaticResources.LogMessage(null, EventMessageSeverity.Documentation, null, "Service Started", _bgWorker);
     while (!StopRequested)
     {
         try
         {
             PerformService();
         } catch (Exception ex)
         {
             var context = (ex is ProcessRunnerException) ? ((ProcessRunnerException)ex).Context : "PerformService failed";
             StaticResources.LogMessage(null, EventMessageSeverity.Fatal, context, ex.Message, _bgWorker);
             break;
         }
     }
     Stopped = true;
     StaticResources.LogMessage(null, EventMessageSeverity.Fatal, null, "Service Stopped", _bgWorker);
 }
Exemplo n.º 7
0
 public FunctionBase(FluentSchedulerJob fluentSchedulerJob, int setupJobFunctionId)
 {
     _parameters = StaticResources.GetParametersForForSetupJobFunction(CallingJob.EventJobId, setupJobFunctionId);
     Context     = string.Format("Event {0}, Job {0}({1}), {2}",
                                 CallingJob.EventJobId, CallingJob.JobName, CallingJob.SetupJobId, GetType().Name);
 }