protected void AndThenShouldBeAbleToRepeatProcessingFromConfiguration() { var config = FlowConfiguration.Load($@"{_flowConfig.BasePath}\flow-config.yaml"); var controller = _container.Resolve <FlowController>(); // clear prior results Directory.Delete(_flowConfig.BasePath, true); // re-create csv AndGivenAGeneratedDataSourceCsvFile(); // start controller.Start(config); // wait for jobs to finish processing var sw = new Stopwatch(); sw.Start(); // spin wait while (controller.Processed <= 2 && sw.Elapsed.TotalSeconds < 15) { Thread.Sleep(TimeSpan.FromSeconds(1)); } // resave _flowConfig.Save(); }
public bool Save(FlowConfiguration flowConfiguration) { string serializedConfiguration = JsonConvert.SerializeObject(flowConfiguration, Formatting.Indented); flowConfigurations.Add(flowConfiguration); return(true); }
protected void GivenAnInitializedFlowConfig() { var baseDirectoryName = "Flow2"; var baseDirectory = $@"{Environment.CurrentDirectory}\{baseDirectoryName}"; if (Directory.Exists(baseDirectory)) { Directory.Delete(baseDirectory, true); } _flow = new FlowId("ConfigureFlow"); var flowConfig = new FlowConfiguration(_flow) { BasePath = baseDirectory }; var def1 = flowConfig.AddController <TestCsvFlowController>("ProcessorA"); def1.FieldValidationRules.Add(new ValidationRule { FieldName = "Value", ErrorMessage = "Value must be numeric", RegEx = "^[0-9]*$" }); // configuration path def1.ConfigurationDetails.Add("ValueToConfigure", "http://helplnk.etc"); flowConfig.AddController <TestProcessResultFlowFileController>("ProcessorB"); _flowConfig = flowConfig; }
/// <summary> /// Initializes a new instance of the <see cref="ParallelTaskBuilder"/> class. /// </summary> /// <param name="config">The configuration.</param> /// <param name="name">The name.</param> /// <param name="taskType">Type of the task.</param> /// <param name="logType">Type of the log.</param> internal ParallelTaskBuilder(FlowConfiguration config, string name, Type taskType, LogType logType = LogType.All) : base(config, name, taskType, logType) { _min = 1; _weekdays = Weekdays.All; _timeZone = TimeZoneInfo.Local; _from = Time.DayMinTime; _to = Time.DayMaxTime; }
private string CheckProvidedAgainstRequired() { var result = new StringBuilder(); AppendIfNotEmpty(result, FlowConfiguration.Check()); AppendIfNotEmpty(result, BookingTypes.Check()); AppendIfNotEmpty(result, StatusDefinition.Check()); AppendIfNotEmpty(result, Dependency.Check()); AppendIfNotEmpty(result, LogicComponent.Check()); return(result.ToString()); }
public BaseResponse Post(string actionName, [FromBody] JToken jsonBody) { FlowConfiguration flowConfiguration = flowConfigurationProvider.GetConfiguration(actionName); if (flowConfiguration == null) { throw new JMException("FlowConfigurationEmpty"); } BaseRequest request = jsonBody.ToObject(Type.GetType(flowConfiguration.RequestIdentifier)) as BaseRequest; return(jmAppClientProvider.CallAction <BaseResponse>(actionName, request)); }
public static void ExecuteValidations(FlowConfiguration flowConfiguration, object request) { if (flowConfiguration != null && flowConfiguration.Validations != null && flowConfiguration.Validations.Length != 0) { foreach (Validation validation in flowConfiguration.Validations) { if (!GetValidation(validation)?.IsValid(GetValues(validation, request)) == true) { throw new JMException(validation.ErrorResource); } } } }
void IService.OnStart() { Console.WriteLine("Service starting"); FlowConfiguration config = new FlowConfiguration(); config.ScheduledTask <MyTask>("scheduled") .RunByDaysOfTheMonths(Months.All) .OnDays(1, 3, 5, 32) .RunsAt(TimeSpan.Parse("12:00")) .OfLocalTimeZone() .Add(); TaskManager.Start(new TaskManagerConfig()); }
public void Initialize() { flowConfigurations = new Dictionary <string, FlowConfiguration>(); string flowConfigsPath = pathProvider.GetCurrentPath() + configuration.ConfigurationFilesPath + "Flows/"; if (Directory.Exists(flowConfigsPath)) { foreach (string flowConfigPath in Directory.GetFiles(flowConfigsPath, "*.json")) { FlowConfiguration flowConfiguration = File.ReadAllText(flowConfigPath).FromJsonObject <FlowConfiguration>(); flowConfigurations.Add(flowConfiguration.Name, flowConfiguration); } } }
private static FlowConfiguration ReadBooking(dynamic process, bool incrementVersion) { var bookingGroup = (string)process.bookingGroup ?? ""; var configuration = (string)process.configuration ?? ""; var resource = (string)process.resource ?? ""; var version = (string)process.version ?? "?"; if (incrementVersion && version != "?") { process.version = VersionIncrement.Increment(Version.Parse(version)).ToString(); } var dependency = Dependency.ParsePackage(resource.Replace("/", "."), ""); var flow = new FlowConfiguration("*" + dependency.GroupId, dependency.ArtifactId, version, bookingGroup, configuration); return(flow); }
public BaseResponse ExecuteFlow(IServiceProvider serviceProvider, string actionName, object request) { FlowConfiguration flowConfiguration = flowConfigurationProvider.GetConfiguration(actionName); contextProvider.GetContext().ActiveFlowConfiguration = flowConfiguration; Type responseType = Type.GetType(flowConfiguration.ResponseIdentifier); BaseResponse response = Activator.CreateInstance(responseType) as BaseResponse; foreach (FlowItemDefinition flowItem in flowExecutionConfigurationProvider.GetActiveConfiguration().FlowItems) { Type flowItemType = Type.GetType(flowItem.TypeIdentifier); BaseFlowItem flowItemInstance = Activator.CreateInstance(flowItemType) as BaseFlowItem; flowItemInstance.ExecuteFlow(serviceProvider, ref request, ref response); } return(response); }
public bool Save(FlowConfiguration flowConfiguration) { return(sqlService.OpenConnection((conn) => { var affectedRows = conn.Execute($"Insert Into {FlowConfigurationTableName} " + $" (Id, Configuration, Name, IsActive, MachineName, ServiceName) On Existing Update Values " + $" (:id, :configuration, :name, :isActive, :machineName, :serviceName);", new { id = flowConfiguration.Id, name = flowConfiguration.Name, configuration = ConvertFromJson(flowConfiguration), isActive = flowConfiguration.IsActive, machineName = flowConfiguration.MachineName, serviceName = flowConfiguration.ServiceName }); return affectedRows > 0; })); }
public string Post([FromBody] RequestPayload requestMessage) { try { contextProvider.SetContext(requestMessage.Context); FlowConfiguration configuration = flowConfigurationProvider.GetConfiguration(requestMessage.Action); ValidationHelper.ExecuteValidations(configuration, requestMessage.Request); BaseResponse response = flowProvider.ExecuteFlow(serviceProvider, requestMessage.Action, requestMessage.Request); ResponsePayload responseMessage = new ResponsePayload { Context = contextProvider.GetContext(), Response = response }; return(responseMessage.ToJson()); } catch (Exception e) { try { JMResult result = serviceProvider.GetRequiredService <IExceptionHandler>().HandleException(e); Context context = contextProvider.GetContext(); context.ActiveResult = result; return(new ResponsePayload { Context = context, Response = null }.ToJson()); } catch (Exception innerException) { DefaultLogger.Error(innerException); return(new ResponsePayload().ToJson()); } } }
internal void ProvideFlow(string source, FlowConfiguration flow) { FlowConfiguration.Provide(source, new Dependency(flow.GroupId, flow.ArtifactId, flow.Version)); }
private byte[] ConvertFromJson(FlowConfiguration flowInstance) { return(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(flowInstance))); }
// // Initialize the generator. // protected override void Initialize( ) { this.GUID = Guid.NewGuid( ).ToString( ); this.Directory = Path.Combine(Settings.TemporaryRetrivalFilesDirectory, this.GUID); // // Unpack // try { System.IO.Directory.CreateDirectory(this.Directory); Zip.Unpack(this.Flow.FilenameFullPath, this.Directory); // // Verify Bin and Config directories. // if (!System.IO.Directory.Exists(Path.Combine(this.Directory, "Bin"))) { string msg = string.Format("The flow file {0} does not contain a Bin directory.", this.Flow.FilenameFullPath); throw new RetrivalException(msg); } if (!System.IO.Directory.Exists(Path.Combine(this.Directory, "Config"))) { string msg = string.Format("The flow file {0} does not contain a Config directory.", this.Flow.FilenameFullPath); throw new RetrivalException(msg); } /* Do not check for data directory, it does not have to bee there. data directory argument in interface then becomes null. * if ( !System.IO.Directory.Exists( Path.Combine( this.Directory, "Data" ) ) ) { * string msg = string.Format( "The flow file {0} does not contain a Data directory.", this.Flow.FilenameFullPath ); * throw new GeneratorException( msg ); * } * */ /* Do not check for config.xml file, it does not have to be there. * if ( !File.Exists( Path.Combine( Path.Combine( this.Directory, "Config" ), "Config.xml" ) ) ) { * string msg = string.Format("The flow file {0} does not contain the required Config\\Config.xml file.", this.Flow.FilenameFullPath); * throw new RetrivalException( msg ); * } */ if (!File.Exists(Path.Combine(Path.Combine(this.Directory, "Config"), "Binding.xml"))) { string msg = string.Format("The flow file {0} does not contain the required Config\\Binding.xml file.", this.Flow.FilenameFullPath); throw new RetrivalException(msg); } } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { RetrivalException ge = new RetrivalException("Catastophics failure. Error while unpacking flow.", x); throw ge; } // // Copy needed assemblies. // try { string[] files = new string[] { "ItSoftware.CompuFlow.Retrival.HostRuntime.dll", "ItSoftware.ExceptionHandler.dll", "ItSoftware.CompuFlow.Manifest.dll", "ItSoftware.CompuFlow.Retrival.Interfaces.dll", "ItSoftware.CompuFlow.Util.dll", "ItSoftware.CompuFlow.Common.dll" }; foreach (string file in files) { string fromFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file); string toFile = Path.Combine(this.Directory, string.Format("Bin\\{0}", file)); File.Copy(fromFile, toFile, true); } } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { RetrivalException ae = new RetrivalException("Catastrophic failure. Could not copy required host assemblies because one or more files was not found.", x); throw ae; } // // Fix Flow.config // try { string sourceFlowConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Flow.config"); string outputFlowConfigFilename = Path.Combine(this.Directory, "Flow.config"); if (File.Exists(outputFlowConfigFilename)) { // // Modify existing Flow.config file. // XmlDocument xdSource = new XmlDocument( ); xdSource.Load(sourceFlowConfigFilename); XmlDocument xdOutput = new XmlDocument( ); xdOutput.Load(outputFlowConfigFilename); XmlDocument xdResult = FlowConfiguration.Merge(xdSource, xdOutput); xdResult.Save(outputFlowConfigFilename); } else { // // Create new Flow.config file. // File.Copy(sourceFlowConfigFilename, outputFlowConfigFilename); } } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { RetrivalException ae = new RetrivalException("Catastrophic failure. Could not configure Flow.config.", x); throw ae; } // // Create app domain // try { AppDomainSetup ads = new AppDomainSetup( ); ads.ApplicationBase = this.Directory; ads.ConfigurationFile = "Flow.config"; ads.PrivateBinPath = "Bin"; ads.PrivateBinPathProbe = "*"; this.AppDomain = AppDomain.CreateDomain(this.Flow.FilenameFullPath, null, ads); } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { RetrivalException ae = new RetrivalException("Catastrophic failure. Could not create application domain.", x); throw ae; } // // Create type // try { this.RealFlow = (RealRetrival)this.AppDomain.CreateInstanceAndUnwrap("ItSoftware.CompuFlow.Retrival.HostRuntime", "ItSoftware.CompuFlow.Retrival.HostRuntime.RealRetrival"); } catch (StackOverflowException) { throw; } catch (OutOfMemoryException) { throw; } catch (ThreadAbortException) { throw; } catch (Exception x) { AppDomain.Unload(this.AppDomain); this.AppDomain = null; RetrivalException ae = new RetrivalException("Could not create RealRetrival type in appdomain.", x); throw ae; } // // Mark initialization complete. // this.Initialized = true; }
public bool Save(FlowConfiguration flowConfiguration) { return(flowConfigurationRepository.Save(flowConfiguration)); }
public Flow(FlowConfiguration config) { this.config = config; }
/// <summary> /// Initializes a new instance of the <see cref="ScheduledTaskBuilder"/> class. /// </summary> /// <param name="config">The configuration.</param> /// <param name="name">The name.</param> /// <param name="taskType">Type of the task.</param> /// <param name="logType">Type of the log.</param> internal ScheduledTaskBuilder(FlowConfiguration config, string name, Type taskType, LogType logType) : base(config, name, taskType, logType) { }
static void Main(string[] args) { Log.WarningSink = Console.WriteLine; Log.InformationSink = Console.WriteLine; Log.ErrorSink = Console.WriteLine; FlowConfiguration config = new FlowConfiguration(); //task to run on ThankGiving config.ScheduledAsyncTask <TestAsyncTask>("ThanksGiving task", LogType.All) .RunByWeeksOfTheMonths(Months.November) .OnWeeks(Weeks.Last) .OnWeekdays(Weekdays.Thursday) .RunsAt(TimeSpan.Parse("02:00")) .OfLocalTimeZone() .AddParameter("count", 10) .Add(); ////task to run on Christmas //config.ScheduledTask<TestAsyncTask>("Christmas Email blaster", LogType.All) // .RunByDaysOfTheMonths(Months.December) // .OnDays(25) // .RunsAt(TimeSpan.Parse("02:00")) // .OfLocalTimeZone() // .AddParameter("count", 10) // .Add(); ////task to run every other day starting from Jan 01, 2016 //config.ScheduledTask<TestAsyncTask>("task name", LogType.All) // .RunDaily() // .RepeatEvery(2) // every other day // .StartsFrom(DateTime.Parse("01/01/2016")) //reference point to skip every other day // .RunsAt(TimeSpan.Parse("06:00")) // .OfLocalTimeZone() // .AddParameter("count", 10) // .Add(); //// task to run every other Monday starting from Jan 01, 2016 //config.ScheduledTask<TestAsyncTask>("Monday task", LogType.All) // .RunWeekly() // .OnWeekdays(Weekdays.Monday) // .RepeatEvery(2) // every other day // .StartsFrom(DateTime.Parse("01/01/2016")) //reference point to skip every other day // .RunsAt(TimeSpan.Parse("06:00")) // .OfLocalTimeZone() // .AddParameter("count", 10) // .Add(); //config.TimerTask<TestAsyncTask>("Every 15 mins", LogType.Error) // .RunEvery(900000) // .RepeatFor(-1) //for continue, you can limit number of time the task should run // .OnWeekdays(Weekdays.Monday | Weekdays.Friday) // Run on Mondays and Fridays // .DuringPeriod(DateTime.Parse("01/01/2016"), DateTime.Parse("12/31/2016")) // life time of the task // .DuringTimeOfDay(TimeSpan.Parse("00:00"), TimeSpan.Parse("06:00")) // valid time during the day. Here it from mid-night thru 6 AM // .OfLocalTimeZone() // .AddParameter("task", 50) // .AddParameter("other", "other parameter") // .Add(); ////Run parallele task to process requests/transactions etc. //config.ParallelTask<TestAsyncTask>("Parallel instances", LogType.Information) // .RunWithMinimumInstancesOf(1) // .AndMaximumInstancesOf(50) // .WithIdlePeriod(2000) // poll every 2 seconds when there is nothing to process // .OnWeekdays(Weekdays.Monday | Weekdays.Tuesday | Weekdays.Wednesday | Weekdays.Thursday | Weekdays.Friday) // weekdays // .DuringTimeOfDay(TimeSpan.Parse("08:00"), TimeSpan.Parse("17:00")) // during work hours // .OfUtcTimeZone() // UTC timezone // .AddParameter("task", 50) // .AddParameter("other", "other parameter") // .Add(); //TaskManager.Bootstrap = c => c.Verify(); TaskManager.Start(config); var obj = new Program(); EventManager.AddPublisher("Event", obj, "Fire"); for (int i = 0; i < 50; i++) { obj.Fire(obj, new EventArgs <int>(i)); } TaskManager.WaitTasksToComplete(); Console.ReadKey(); }
private static void CreateConfiguration() { return; IFlowConfigurationRepository repo = new FlowConfigurationMemoryRepository(); var service = new FlowConfigurationService(repo); var flowConfiguration = new FlowConfiguration { Id = Guid.NewGuid(), Name = "Document scan and process2" }; var onDocumentScannedNode = new NodeConfiguration { Id = Guid.NewGuid(), NodeType = "EventNode", ClassName = "OnDocumentScannedNode", IsStartEvent = true }; flowConfiguration.Nodes.Add(onDocumentScannedNode); var sequenceNode = new NodeConfiguration { Id = Guid.NewGuid(), NodeType = "ActionNode", ClassName = "SequenceNode" }; flowConfiguration.Nodes.Add(sequenceNode); var consoleWriteLineNode = new NodeConfiguration { Id = Guid.NewGuid(), NodeType = "ActionNode", ClassName = "ConsoleWriteLineNode" }; flowConfiguration.Nodes.Add(consoleWriteLineNode); var consoleWriteLineNode2 = new NodeConfiguration { Id = Guid.NewGuid(), NodeType = "ActionNode", ClassName = "ConsoleWriteLineNode" }; flowConfiguration.Nodes.Add(consoleWriteLineNode2); var onDocumentScannedNode2 = new NodeConfiguration { Id = Guid.NewGuid(), NodeType = "EventNode", ClassName = "OnDocumentScannedNode", IsStartEvent = false }; flowConfiguration.Nodes.Add(onDocumentScannedNode2); var consoleWriteLineNode3 = new NodeConfiguration { Id = Guid.NewGuid(), NodeType = "ActionNode", ClassName = "ConsoleWriteLineNode" }; flowConfiguration.Nodes.Add(consoleWriteLineNode3); flowConfiguration.Links = new System.Collections.Generic.List <LinkConfiguration> { new LinkConfiguration { From = new Link { NodeId = onDocumentScannedNode.Id, PinName = "FlowOut" }, To = new Link { NodeId = sequenceNode.Id } }, new LinkConfiguration { From = new Link { NodeId = sequenceNode.Id, PinName = "FlowOutNodes" }, To = new Link { NodeId = consoleWriteLineNode.Id } }, new LinkConfiguration { From = new Link { NodeId = sequenceNode.Id, PinName = "FlowOutNodes" }, To = new Link { NodeId = consoleWriteLineNode2.Id } }, new LinkConfiguration { From = new Link { NodeId = consoleWriteLineNode2.Id, PinName = "FlowOut" }, To = new Link { NodeId = onDocumentScannedNode2.Id } }, new LinkConfiguration { From = new Link { NodeId = onDocumentScannedNode2.Id, PinName = "FlowOut" }, To = new Link { NodeId = consoleWriteLineNode3.Id } } }; flowConfiguration.Pins = new System.Collections.Generic.List <PinConfiguration> { new PinConfiguration { From = new Link { NodeId = onDocumentScannedNode.Id, PinName = "DocumentOut" }, To = new Link { NodeId = consoleWriteLineNode.Id, PinName = "ToPrint" } }, new PinConfiguration { From = new Link { NodeId = onDocumentScannedNode.Id, PinName = "DocumentOut" }, To = new Link { NodeId = consoleWriteLineNode2.Id, PinName = "ToPrint" } }, new PinConfiguration { From = new Link { NodeId = onDocumentScannedNode2.Id, PinName = "DocumentOut" } , To = new Link { NodeId = consoleWriteLineNode3.Id, PinName = "ToPrint" } } }; var jsonStr = service.Save(flowConfiguration); }
/// <summary> /// Initializes a new instance of the <see cref="RunOnceTaskBuilder"/> class. /// </summary> /// <param name="config">The configuration.</param> /// <param name="name">The name.</param> /// <param name="taskType">Type of the task.</param> /// <param name="logType">Type of the log.</param> internal RunOnceTaskBuilder(FlowConfiguration config, string name, Type taskType, LogType logType = LogType.All) : base(config, name, taskType, logType) { }