protected override ServiceOutcome DoPipelineWork() { //var serviceName = Configuration.Parameters.Get<string>("ServiceToRun"); if (Configuration.TimePeriod != null) { DateTime fromDate = Configuration.TimePeriod.Value.Start.ToDateTime(); DateTime toDate = Configuration.TimePeriod.Value.End.ToDateTime(); while (fromDate <= toDate) { // {start: {base : '2009-01-01', h:0}, end: {base: '2009-01-01', h:'*'}} var subRange = new DateTimeRange { Start = new DateTimeSpecification { BaseDateTime = fromDate, Hour = new DateTimeTransformation { Type = DateTimeTransformationType.Exact, Value = 0 }, Alignment = DateTimeSpecificationAlignment.Start }, End = new DateTimeSpecification { BaseDateTime = fromDate, Hour = new DateTimeTransformation { Type = DateTimeTransformationType.Max }, Alignment = DateTimeSpecificationAlignment.End } }; var configuration = new PipelineServiceConfiguration { TimePeriod = subRange.ToAbsolute(), ConflictBehavior = DeliveryConflictBehavior.Ignore }; foreach (var param in Configuration.Parameters) { configuration.Parameters[param.Key] = param.Value; } // add to scheduler var serviceInstance = Environment.NewServiceInstance(Configuration); Environment.AddToSchedule(serviceInstance); fromDate = fromDate.AddDays(1); } } return(ServiceOutcome.Success); }
protected override ServiceOutcome DoWork() { // FTP configuration string fileConflictBehavior = this.Configuration.Parameters.Get <string>("FileConflictBehavior", emptyIsError: false, defaultValue: "Abort"); string FtpServer = this.Configuration.Parameters.Get <string>("FtpServer"); string[] AllowedExtensions = this.Configuration.Parameters.Get <string>("AllowedExtensions").Split('|'); bool UsePassive = this.Configuration.Parameters.Get <bool>("UsePassive"); bool UseBinary = this.Configuration.Parameters.Get <bool>("UseBinary"); string UserId = this.Configuration.Parameters.Get <string>("UserID"); string Password = Encryptor.Dec(this.Configuration.Parameters.Get <string>("Password")); FtpWebRequest request; int filesCounter = 0; try { request = (FtpWebRequest)FtpWebRequest.Create(new Uri(FtpServer + "/")); request.UseBinary = UseBinary; request.UsePassive = UsePassive; request.Credentials = new NetworkCredential(UserId, Password); request.Method = WebRequestMethods.Ftp.ListDirectoryDetails; var response = (FtpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); string fileInfoAsString = reader.ReadLine(); while (fileInfoAsString != null) { //Checking AllowedExtensions Dictionary <string, string> fileInfo = GetFileInfo(fileInfoAsString); if (fileConflictBehavior == "Ignore" || !CheckFileConflict(fileInfo)) { //Get files with allowed extensions only. if (AllowedExtensions.Contains(Path.GetExtension(fileInfo["Name"]), StringComparer.OrdinalIgnoreCase)) { string sourceUrl = FtpServer + "/" + fileInfo["Name"]; var config = new PipelineServiceConfiguration(); config.Parameters[Const.DeliveryServiceConfigurationOptions.SourceUrl] = sourceUrl; config.Parameters["FileSize"] = fileInfo["Size"]; config.Parameters["DeliveryFileName"] = fileInfo["Name"]; config.Parameters["FileModifyDate"] = fileInfo["ModifyDate"]; // TODO shriat add to scheduler //Environment.ScheduleServiceByName(this.Configuration.Parameters.Get<string>("FtpService"),Configuration.Profile.ProfileID,config); var serviceInstance = Environment.NewServiceInstance(Configuration); Environment.AddToSchedule(serviceInstance); } } fileInfoAsString = reader.ReadLine(); filesCounter++; } reader.Close(); response.Close(); if (filesCounter == 0) { Log("No files in FTP directory for account id " + Configuration.Profile.Parameters["AccountID"], LogMessageType.Information); } } catch (Exception e) { Log(string.Format("Cannot connect FTP server for account ID:{0} Exception: {1}", Configuration.Profile.Parameters["AccountID"], e.Message), LogMessageType.Information); return(ServiceOutcome.Failure); } return(ServiceOutcome.Success); }
bool ProcessWorkflow(WorkflowNodeInstance nodeInstance, WorkflowNodeFailureBehavior failureBehavior, List <bool> completedSteps) { bool complete; if (nodeInstance.Node is WorkflowNodeGroup) { var group = (WorkflowNodeGroup)nodeInstance.Node; complete = true; foreach (WorkflowNodeInstance child in nodeInstance.Children) { var stepComplete = ProcessWorkflow(child, group.FailureBehavior, completedSteps); complete &= stepComplete; if (!stepComplete && group.Mode == WorkflowNodeGroupMode.Linear) { break; } } } else if (nodeInstance.Node is WorkflowStep) { var step = (WorkflowStep)nodeInstance.Node; if (nodeInstance.Instance == null) { ServiceConfiguration config; if (String.IsNullOrEmpty(step.Name)) { config = step.ServiceConfiguration; } else { config = step.ServiceConfiguration.Derive(); config.ServiceName = step.Name; } nodeInstance.Instance = this.NewChildService(config); nodeInstance.Instance.StateChanged += new EventHandler(Instance_StateChanged); nodeInstance.Instance.Connect(); try { Environment.AddToSchedule(nodeInstance.Instance); } catch (Exception ex) { throw new WorkflowException(String.Format("Error trying to run the step '{0}'.", nodeInstance.Node.Name), ex); } } if (failureBehavior == WorkflowNodeFailureBehavior.Terminate && nodeInstance.Instance.State == ServiceState.Ended && nodeInstance.Instance.Outcome != ServiceOutcome.Success) { throw new WorkflowException(String.Format("Workflow step '{0}' failed, terminating.", nodeInstance.Instance.Configuration.ServiceName)); } complete = nodeInstance.Instance.State == ServiceState.Ended; completedSteps.Add(complete); } else { throw new NotSupportedException(String.Format("Workflow node type '{0}' not supported.", nodeInstance.Node.GetType())); } return(complete); }