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 Core.Services.ServiceOutcome DoPipelineWork() { string serviceName = this.Configuration.Parameters.Get <string>("ServiceToRun"); DateTime fromDate = this.Configuration.TimePeriod.Value.Start.ToDateTime(); DateTime toDate = this.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 this.Configuration.Parameters) { configuration.Parameters[param.Key] = param.Value; } this.Environment.ScheduleServiceByName(serviceName, this.Configuration.Profile.ProfileID, configuration); fromDate = fromDate.AddDays(1); } return(Core.Services.ServiceOutcome.Success); }
protected override Core.Services.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; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); StreamReader 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"]; PipelineServiceConfiguration config = new PipelineServiceConfiguration(); config.Parameters[Const.DeliveryServiceConfigurationOptions.SourceUrl] = SourceUrl; config.Parameters["FileSize"] = fileInfo["Size"]; config.Parameters["DeliveryFileName"] = fileInfo["Name"]; config.Parameters["FileModifyDate"] = fileInfo["ModifyDate"]; Environment.ScheduleServiceByName( this.Configuration.Parameters.Get <string>("FtpService"), this.Configuration.Profile.ProfileID, config ); } } fileInfoAsString = reader.ReadLine(); filesCounter++; } reader.Close(); response.Close(); if (filesCounter == 0) { Core.Utilities.Log.Write("No files in FTP directory for account id " + this.Configuration.Profile.Parameters["AccountID"].ToString(), LogMessageType.Information); } } catch (Exception e) { Core.Utilities.Log.Write( string.Format("Cannot connect FTP server for account ID:{0} Exception: {1}", this.Configuration.Profile.Parameters["AccountID"].ToString(), e.Message), LogMessageType.Information); return(Edge.Core.Services.ServiceOutcome.Failure); } return(Core.Services.ServiceOutcome.Success); }