private static void Main(string[] args) { using (var repo = new az.tweetstore.ftp.Repository()) { var frc = new FlowRuntimeConfiguration() .AddStreamsFrom("az.receiver.application.root.flow", Assembly.GetExecutingAssembly()) .AddAction<string>("dequeue", new IronMQOperations("AppZwitschern", TokenRepository.LoadFrom("ironmq.credentials.txt")).Dequeue) .AddFunc<string, Versandauftrag>("deserialize", new Serialization<Versandauftrag>().Deserialize) .AddAction<Versandauftrag>("speichern", repo.Store); using (var fr = new FlowRuntime(frc)) { fr.Message += Console.WriteLine; fr.UnhandledException += e => { Console.WriteLine(e.InnerException); fr.Process(new Message(".stop") { Priority = 99 }); }; fr.Process(".start"); fr.WaitForResult(); } } }
static void Main3(string[] args) { using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "Find files"); frc.AddStream("Find files", "Count words"); frc.AddStream("Count words", "Total"); frc.AddStream("Total", ".out"); frc.AddFunc <string, IEnumerable <String> >("Find files", Find_files) .AddFunc <IEnumerable <string>, IEnumerable <int> >("Count words", Count_words2) .AddFunc <IEnumerable <int>, Tuple <int, int> >("Total", Total); fr.Configure(frc); var start = DateTime.Now; fr.Process(new Message(".in", "x")); Tuple <int, int> result = null; fr.WaitForResult(5000, _ => result = (Tuple <int, int>)_.Data); var delta = DateTime.Now.Subtract(start); Console.WriteLine("{0} words in {1} files, {2}msec", result.Item2, result.Item1, delta); } }
public void Run_flat() { using (var fr = new FlowRuntime()) { /* * (.in) -> (Split) -> (Map) -> (Build) -> (.out) */ var frc = new FlowRuntimeConfiguration(); frc.AddStream(new Stream(".in", "Split")); frc.AddStream(new Stream("Split", "Map")); frc.AddStream(new Stream("Map", "Build")); frc.AddStream(new Stream("Build", ".out")); frc.AddFunc<string, IEnumerable<string>>("Split", configuration => configuration.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries)); frc.AddAction<IEnumerable<string>, IEnumerable<KeyValuePair<string, string>>>("Map", Map); frc.AddFunc<IEnumerable<KeyValuePair<string, string>>, Dictionary<string, string>>("Build", Build); fr.Configure(frc); Dictionary<string, string> dict = null; var are = new AutoResetEvent(false); fr.Result += _ => { dict = (Dictionary<string, string>) _.Data; are.Set(); }; fr.Process(new Message(".in", "a=1;b=2")); Assert.IsTrue(are.WaitOne(500)); Assert.AreEqual(2, dict.Count); Assert.AreEqual("1", dict["a"]); Assert.AreEqual("2", dict["b"]); } }
private static void Main(string[] args) { _email = ConfigurationManager.AppSettings["GoogleAccount"]; _baseDirPath = String.IsNullOrEmpty(ConfigurationManager.AppSettings["BasePath"]) ? @"c:\temp\" : ConfigurationManager.AppSettings["BasePath"]; _deleteOlderFiles = bool.Parse(String.IsNullOrEmpty(ConfigurationManager.AppSettings["DeleteOlderFiles"]) ? "false" : ConfigurationManager.AppSettings["DeleteOlderFiles"]); _label = "Listen Subscriptions"; _dateFormat = "yyyyMMddTHHmmss"; _getFilesFromTheLastXDays = int.Parse(String.IsNullOrEmpty(ConfigurationManager.AppSettings["GetFilesFromTheLastXDays"]) ? "3" : ConfigurationManager.AppSettings["GetFilesFromTheLastXDays"]); _reader = null; //Console.WriteLine("Enter password"); var password = "******";// Console.ReadLine(); _reader = Reader.CreateReader(_email, password, "scroll") as Reader; using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "Get_Feeds"); frc.AddStream("Get_Feeds", ".out"); frc.AddFunc<Reader, IEnumerable<UrlAndFeed>>("Get_Feeds", getFeedsWithGivenLabel); fr.Configure(frc); fr.Process(new Message(".in", _reader)); fr.WaitForResult(5000, _ => Console.WriteLine(_.Data)); Console.ReadLine(); } }
static void Main(string[] args) { using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "Pushc"); frc.AddStream("Pushc", "Find Files"); frc.AddStream("Pushc.exception", "Handle Exception"); frc.AddStream("Find Files", "Count Words"); frc.AddStream("Count Words", "popc"); frc.AddStream("Popc", "Total"); frc.AddStream("Total", ".out"); frc.AddFunc <IEnumerable <string>, IEnumerable <int> >("Count Words", Count_words3) .AddFunc <string, IEnumerable <String> >("Find Files", Find_files) .AddAction <FlowRuntimeException>("Handle Exception", Handle_exception) .AddPopCausality("Popc") .AddPushCausality("Pushc") .AddFunc <IEnumerable <int>, Tuple <int, int> >("Total", Total); fr.Configure(frc); fr.Process(new Message(".in", "x")); Tuple <int, int> result = null; fr.WaitForResult(5000, _ => result = (Tuple <int, int>)_.Data); if (result != null) { Console.WriteLine("{0} words in {1} files", result.Item2, result.Item1); } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); /* * The dialog/clock is part of the flow. * Since it fires events without prior input it is defined as an [ActiveOperation] */ using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); // Define flow // Feature: close application frc.AddStream("Dialog.closed", ".stop"); // Feature: set alarm frc.AddStream("Dialog.setAlarm", "Join.in0"); frc.AddStream("Dialog.setAlarm", "Alarm switched on"); frc.AddStream("Clock.now", "Join.in1"); frc.AddStream("Join", "Calc time diff"); frc.AddStream("Calc time diff", "Display time diff"); // Feature: stop alarm frc.AddStream("Dialog.stopAlarm", "Join.reset"); frc.AddStream("Dialog.stopAlarm", "Alarm switched off"); frc.AddStream("Dialog.stopAlarm", "Stop alarm"); // Feature: sound alarm frc.AddStream("Calc time diff", "Alarm time reached"); frc.AddStream("Alarm time reached", "Sound alarm"); fr.Configure(frc); // Register operations var dlg = new Dialog(); var clock = new npantarhei.runtime.patterns.operations.Clock(); var player = new Soundplayer(); frc.AddOperation(dlg) .AddOperation(clock) .AddAction("Alarm switched off", dlg.Alarm_switched_off).MakeSync() .AddAction("Alarm switched on", dlg.Alarm_switched_on).MakeSync() .AddAction<TimeSpan>("Alarm time reached", Alarm_time_reached) .AddFunc<Tuple<DateTime,DateTime>,TimeSpan>("Calc time diff", Calc_time_diff) .AddAction<TimeSpan>("Display time diff", dlg.Display_time_diff).MakeSync() .AddManualResetJoin<DateTime, DateTime>("Join") .AddAction("Sound alarm", player.Start_playing) .AddAction("Stop alarm", player.Stop_playing); fr.Configure(frc); fr.Message += Console.WriteLine; fr.UnhandledException += Console.WriteLine; // Execute flow // Feature: start application Application.Run(dlg); // needs to run on this thread; cannot be done on flow runtime thread. } }
public void Run() { var config = new FlowRuntimeConfiguration() .AddStreamsFrom(@" / .in, rechenwerk.teilen rechenwerk.resultat, .result rechenwerk.divisionDurchNull, .fehler ") .AddEventBasedComponent("rechenwerk", new Rechenwerk()); using(var fr = new FlowRuntime(config)) { fr.Process(".in", new Tuple<int,int>(42,7)); IMessage result = null; fr.WaitForResult(_ => result = _); Assert.AreEqual(".result", result.Port.Fullname); Assert.AreEqual(6, (int)result.Data); fr.Process(".in", new Tuple<int, int>(42, 0)); fr.WaitForResult(_ => result = _); Assert.AreEqual(".fehler", result.Port.Fullname); Assert.AreEqual(new Tuple<int,int>(42,0), result.Data); } }
public void Avoid_nested_FlowRuntimeExceptions() { var config = new FlowRuntimeConfiguration() .AddAction("throw", () => { throw new ApplicationException("arg!"); }) .AddAction("continue", () => {}, true) .AddAction("continue2", () => { }, true) .AddStreamsFrom(@" / .in, continue continue, continue2 continue2, throw "); using(var fr = new FlowRuntime(config, new Schedule_for_sync_depthfirst_processing())) { try { fr.Process(".in"); } catch(FlowRuntimeException ex) { Assert.IsInstanceOf<UnhandledFlowRuntimeException>(ex); Assert.IsTrue(ex.InnerException.GetType() != typeof(FlowRuntimeException) && ex.InnerException.GetType() != typeof(UnhandledFlowRuntimeException)); } catch (Exception ex) { Assert.Fail("Unexpected exception type: " + ex); } } }
public void Run() { var awsSecrets = SecretsRepository.LoadFrom("mailfollowup.reminder.app.awssecrets.txt", Assembly.GetExecutingAssembly()); var smtpSecrets = MailAccessRepository.LoadFrom("mailfollowup.reminder.app.mail.smtp.txt", Assembly.GetExecutingAssembly()); var frc = new FlowRuntimeConfiguration(); frc.AddStreamsFrom("mailfollowup.reminder.app.root.flow", Assembly.GetExecutingAssembly()); var store = new MailStore(awsSecrets); var smtp = new Smtp(smtpSecrets); frc.AddFunc("aktuelle_zeit_ermitteln", Now); frc.AddAction<DateTime, Erinnerungsauftrag>("erinnerungsauftrag_holen", store.Load); frc.AddFunc<Erinnerungsauftrag, Erinnerungsauftrag>("erinnerung_versenden", smtp.Send); frc.AddAction<Erinnerungsauftrag>("erinnerungsauftrag_loeschen", store.Delete); using (var fr = new FlowRuntime(frc)) { fr.Message += Console.WriteLine; fr.UnhandledException += e => { Console.WriteLine(e); Environment.Exit(1); }; fr.Process(".start"); fr.WaitForResult(); } }
public void High_prio_exception_message_terminates_runtime() { var config = new FlowRuntimeConfiguration() .AddStreamsFrom(@" / .in, doit .stop, .error doit, .result " ) .AddAction <int, string>("doit", (int d, Action <string> continueWith) => { continueWith(d + "x"); continueWith(d + "y"); throw new ApplicationException("arrrghhh!"); }); using (var fr = new FlowRuntime(config, new Schedule_for_async_breadthfirst_processing())) { IMessage result = null; fr.UnhandledException += ex => { fr.Process(new Message(".stop", ex) { Priority = 99 }); }; fr.Process(".in", 42); Assert.IsTrue(fr.WaitForResult(500, _ => { if (result == null) { result = _; } })); Assert.AreEqual("error", result.Port.Name); } }
public void Avoid_nested_FlowRuntimeExceptions() { var config = new FlowRuntimeConfiguration() .AddAction("throw", () => { throw new ApplicationException("arg!"); }) .AddAction("continue", () => {}, true) .AddAction("continue2", () => { }, true) .AddStreamsFrom(@" / .in, continue continue, continue2 continue2, throw " ); using (var fr = new FlowRuntime(config, new Schedule_for_sync_depthfirst_processing())) { try { fr.Process(".in"); } catch (FlowRuntimeException ex) { Assert.IsInstanceOf <UnhandledFlowRuntimeException>(ex); Assert.IsTrue(ex.InnerException.GetType() != typeof(FlowRuntimeException) && ex.InnerException.GetType() != typeof(UnhandledFlowRuntimeException)); } catch (Exception ex) { Assert.Fail("Unexpected exception type: " + ex); } } }
public void Active_EBC_fires_in_flow() { var ebc = new ActiveEbc(); var config = new FlowRuntimeConfiguration() .AddStreamsFrom(@" / .in, subflow.in subflow.out, .out subflow .in, ebc.Run ebc.Out, .out ") .AddEventBasedComponent("ebc", ebc); using (var fr = new FlowRuntime(config)) { fr.Process(".in", "hello"); var result = ""; Assert.IsTrue(fr.WaitForResult(2000, _ => result = (string)_.Data)); Assert.AreEqual("hellox", result); } }
static void Main(string[] args) { using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "A"); frc.AddStream("A", "B"); frc.AddStream("B", "C"); frc.AddFunc <int, int>("A", i => i + 1) .AddFunc <int, int>("B", i => i * 2) .AddAction <int>("C", (int i) => Console.WriteLine("={0}", i)); fr.Configure(frc); // Trace messages selectively using Rx var tracer = new Subject <IMessage>(); tracer.Where(msg => msg.Port.OperationName == "B") // message filter .Select(msg => (int)msg.Data) .Subscribe(i => Console.WriteLine("{0} -> B", i), // message handler _ => { }); fr.Message += tracer.OnNext; fr.Process(new Message(".in", 1)); fr.Process(new Message(".in", 2)); fr.Process(new Message(".in", 3)); fr.WaitForResult(500); } }
public static void Main() { using (var flowRuntime = new FlowRuntime()) { flowRuntime.AddStream(".in", "Dateien im Pfad ermitteln"); flowRuntime.AddStream(".abort", "Ermittlung abbrechen"); flowRuntime.AddStream("Dateien im Pfad ermitteln", "filtern"); flowRuntime.AddStream("filtern", "map"); var viewModel = new ViewModel(); var mainWindow = new MainWindow(viewModel); var map = new Map(viewModel); var dateien_im_Pfad_ermitteln = new Dateien_im_Pfad_ermitteln(); var flowOperationContainer = new FlowOperationContainer(() => new WpfSynchronize<IMessage>()) .AddFunc<string, IEnumerable<messages.Datei>>("Dateien im Pfad ermitteln", dateien_im_Pfad_ermitteln.Process) .MakeAsync() .AddAction("Ermittlung abbrechen", dateien_im_Pfad_ermitteln.Abbrechen) .AddFunc<IEnumerable<messages.Datei>, IEnumerable<messages.Datei>>("filtern", Filtern_der_20_groessten_Dateien.Process) .AddAction<IEnumerable<messages.Datei>>("map", map.Process) .MakeSync(); flowRuntime.AddOperations(flowOperationContainer.Operations); flowRuntime.UnhandledException += e => MessageBox.Show(e.InnerException.Message); mainWindow.Suchen += flowRuntime.CreateEventProcessor<string>(".in"); mainWindow.Abbrechen += flowRuntime.CreateEventProcessor(".abort"); var app = new Application {MainWindow = mainWindow}; app.Run(app.MainWindow); } }
public void Connect_transceivers_operationhost() { var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt"); var configServer = new FlowRuntimeConfiguration() .AddFunc<string, string>("greeting", s => s + "x") .AddStream(".@greeting", "greeting") .AddStream("greeting", ".@greeting"); using (var server = new FlowRuntime(configServer)) using (var serverhost = new PubnubOperationHost(server, cre, "thehost")) { server.Message += Console.WriteLine; var config = new FlowRuntimeConfiguration() .AddOperation(new PubnubStandInOperation("op", cre, "thehost")) .AddStream(".in", "op#greeting") .AddStream("op#greeting", ".out"); using (var fr = new FlowRuntime(config)) { fr.Message += Console.WriteLine; fr.Process(".in", "hello"); var result = ""; Assert.IsTrue(fr.WaitForResult(5000, _ => result = _.Data as string)); Assert.AreEqual("hellox", result); } } }
static void Main(string[] args) { using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "Pushc"); frc.AddStream("Pushc", "Find Files"); frc.AddStream("Pushc.exception", "Handle Exception"); frc.AddStream("Find Files", "Count Words"); frc.AddStream("Count Words", "popc"); frc.AddStream("Popc", "Total"); frc.AddStream("Total", ".out"); frc.AddFunc<IEnumerable<string>, IEnumerable<int>>("Count Words", Count_words3) .AddFunc<string, IEnumerable<String>>("Find Files", Find_files) .AddAction<FlowRuntimeException>("Handle Exception", Handle_exception) .AddPopCausality("Popc") .AddPushCausality("Pushc") .AddFunc<IEnumerable<int>, Tuple<int, int>>("Total", Total); fr.Configure(frc); fr.Process(new Message(".in", "x")); Tuple<int, int> result = null; fr.WaitForResult(5000, _ => result = (Tuple<int, int>)_.Data); if (result != null) Console.WriteLine("{0} words in {1} files", result.Item2, result.Item1); } }
public void Scatter_gather() { var frc = new FlowRuntimeConfiguration(); frc.AddStream(new Stream(".in", "scatter")); frc.AddStream(new Stream("scatter.stream", "sleep")); frc.AddStream(new Stream("scatter.count", "gather.count")); frc.AddStream(new Stream("sleep", "gather.stream")); frc.AddStream(new Stream("gather", ".out")); frc.AddFunc <int, int>("sleep", _ => { Console.WriteLine("sleep {0} on {1}", _, Thread.CurrentThread.GetHashCode()); Thread.Sleep(_); return(_); }).MakeParallel(); frc.AddOperation(new Scatter <int>("scatter")); frc.AddOperation(new Gather <int>("gather")); using (var fr = new FlowRuntime(frc)) { var list = new[] { 10, 200, 100, 30, 200, 70 }; fr.Process(new Message(".in", list)); IMessage result = null; Assert.IsTrue(fr.WaitForResult(1000, _ => result = _)); Assert.That(list, Is.EquivalentTo(((int[])result.Data))); } }
public void Run_on_separate_thread() { var frc = new FlowRuntimeConfiguration(); frc.AddStream(new Stream(".in", "asyncNop")); frc.AddStream(new Stream("asyncNop", ".out")); var cont = new FlowRuntimeConfiguration(); long asyncThreadId = 0; cont.AddFunc<string, string>("asyncNop", _ => { asyncThreadId = Thread.CurrentThread.GetHashCode(); return _; }).MakeAsync(); frc.AddOperations(cont.Operations); using (var sut = new FlowRuntime(frc)) { IMessage result = null; long runtimeThreadId = 0; var are = new AutoResetEvent(false); sut.Result += _ => { runtimeThreadId = Thread.CurrentThread.GetHashCode(); result = _; are.Set(); }; sut.Process(new Message(".in", "hello")); Assert.IsTrue(are.WaitOne(1000)); Assert.AreEqual("hello", result.Data.ToString()); Assert.AreNotEqual(runtimeThreadId, asyncThreadId); } }
public void Run() { FlowRuntimeConfiguration.SynchronizationFactory = () => new SyncWithWPFDispatcher(); var frc = new FlowRuntimeConfiguration(); frc.AddStreamsFrom("appchatten.application.root.flow", Assembly.GetExecutingAssembly()); var chat = new Chat(new QueueFinder<Message>()); var mainWindow = new MainWindow(); frc.AddAction<string>("anmelden", chat.Anmelden); frc.AddAction<string>("verbinden", chat.Verbinden); frc.AddFunc<string, Message>("absender_hinzufuegen", chat.Absender_hinzufuegen); frc.AddFunc<Message, Message>("versenden", chat.Versenden).MakeAsync(); frc.AddFunc<Message, string>("formatieren", m => string.Format("{0}: {1}", m.Absender, m.Text)); frc.AddAction<string>("anzeigen", mainWindow.MessageHinzufügen).MakeSync(); frc.AddOperation(new Timer("timer", 500)); frc.AddAction<Message>("empfangen", chat.Empfangen).MakeAsync(); frc.AddAction<FlowRuntimeException>("fehler_anzeigen", ex => mainWindow.FehlerAnzeigen(ex.InnerException.Message)).MakeSync(); using (var fr = new FlowRuntime(frc)) { fr.Message += Console.WriteLine; fr.UnhandledException += fr.CreateEventProcessor<FlowRuntimeException>(".exception"); mainWindow.Anmelden += fr.CreateEventProcessor<string>(".anmelden"); mainWindow.Verbinden += fr.CreateEventProcessor<string>(".verbinden"); mainWindow.TextSenden += fr.CreateEventProcessor<string>(".senden"); var app = new Application{MainWindow = mainWindow}; app.Run(mainWindow); } }
static void Main(string[] args) { var textfileadapter = new TextfileAdapter(); var formatter = new Formatter(); var config = new FlowRuntimeConfiguration() .AddStreamsFrom("TelegramProblem.run.flow", Assembly.GetExecutingAssembly()) .AddAction<string>("read", textfileadapter.Read).MakeAsync() .AddAction<string>("write", textfileadapter.Write, true) .AddAction<string, string>("decompose", formatter.Decompose) .AddAction<string, string>("concatenate", formatter.Concatenate) .AddAction<Tuple<string, string>>("textfileadapter_config", textfileadapter.Config) .AddAction<int>("formatter_config", formatter.Config); using(var fr = new FlowRuntime(config)) { fr.UnhandledException += Console.WriteLine; fr.Process(".configFilenames", new Tuple<string,string>("source.txt", "target.txt")); fr.Process(".configLineWidth", 60); fr.Process(".run"); fr.WaitForResult(); Console.WriteLine(File.ReadAllText("target.txt")); } }
public void test_cyclic_flow_with_async_EBC() { Console.WriteLine("test started for {0} flow cycles...", maxCycles); var config = new FlowRuntimeConfiguration() .AddStreamsFrom(@" / .in, cyclic.run cyclic.continue, cyclic.run cyclic.stopOn, .out ") .AddEventBasedComponent("cyclic", new CyclicFlow()); using(var fr = new FlowRuntime(config)) { fr.UnhandledException += Console.WriteLine; fr.Process(".in", 1); IMessage result = null; Assert.IsTrue(fr.WaitForResult(5000, _ => result = _), "result not received within 5 seconds"); Assert.AreEqual(".out", result.Port.Fullname); Assert.AreEqual(maxCycles, (int)result.Data); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var operation = new Operationsschlange(); var akku = new Zwischenergebnis(); var ui = new WinMain(); var config = new FlowRuntimeConfiguration() .AddStreamsFrom("Taschenrechner.root.flow", Assembly.GetExecutingAssembly()) .AddFunc<int, int>("ergebnis_zwischenspeichern", akku.Merken) .AddFunc<Tuple<int, int, Operatoren>, int>("operanden_verknuepfen", Rechenwerk.Operanden_verknüpfen) .AddFunc<Rechenauftrag, int>("operation_speichern", operation.Einstellen) .AddPushCausality("pushc") .AddPopCausality("popc") .AddFunc<Tuple<int, int>, Tuple<int, int, Operatoren>>("vormalige_operation_laden", operation.Herausholen) .AddEventBasedComponent("akku", akku) .AddEventBasedComponent("ui", ui); using (var fr = new FlowRuntime(config)) { fr.Message += Console.WriteLine; fr.UnhandledException += fr.CreateEventProcessor<FlowRuntimeException>(".error"); Application.Run(ui); } }
public void Run() { var config = new FlowRuntimeConfiguration() .AddEventBasedComponent("Op", new Op()) .AddStream(".receive@op", "op.receive") .AddStream("op.send", ".send@op"); using(var fr = new FlowRuntime(config, new Schedule_for_sync_depthfirst_processing())) { fr.Message += Console.WriteLine; var sut = new HostTranslator(); sut.Translated_input += fr.Process; fr.Result += sut.Process_local_output; Tuple<string, HostOutput> result = null; sut.Translated_output += _ => result = _; var input = new HostInput { CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "op.receive", StandInEndpointAddress = "localhost:1234"}; sut.Process_remote_input(input); Assert.AreEqual("localhost:1234", result.Item1); Assert.AreEqual(input.CorrelationId, result.Item2.CorrelationId); Assert.AreEqual("<hello>".Serialize(), result.Item2.Data); Assert.AreEqual("op.send", result.Item2.Portname); } }
static void Main2(string[] args) { using(var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "Find_files"); frc.AddStream("Find_files", "scatter"); frc.AddStream("scatter.stream", "Count_words"); frc.AddStream("scatter.count", "gather.count"); frc.AddStream("Count_words", "gather.stream"); frc.AddStream("gather", "Total"); frc.AddStream("Total", ".out"); frc.AddFunc<string, IEnumerable<String>>("Find_files", Find_files).MakeAsync() .AddFunc<string,int>("Count_words", Count_words).MakeParallel() .AddFunc<IEnumerable<int>, Tuple<int,int>>("Total", Total) .AddOperation(new Scatter<string>("scatter")) .AddOperation(new Gather<int>("gather")); fr.Configure(frc); var start = DateTime.Now; fr.Process(new Message(".in", "x")); Tuple<int,int> result = null; fr.WaitForResult(5000, _ => result = (Tuple<int,int>)_.Data); var delta = DateTime.Now.Subtract(start); Console.WriteLine("{0} words in {1} files, {2}msec", result.Item2, result.Item1, delta); } }
public void Run() { var mailAccess = MailAccessRepository.LoadFrom("mailfollowup.receiver.application.mail.access.txt", Assembly.GetExecutingAssembly()); var awsSecrets = SecretsRepository.LoadFrom("mailfollowup.receiver.application.awssecrets.txt", Assembly.GetExecutingAssembly()); var frc = new FlowRuntimeConfiguration(); frc.AddStreamsFrom("mailfollowup.receiver.application.root.flow", Assembly.GetExecutingAssembly()); var imap = new Imap(mailAccess); var erinnerungsauftraege = new Erinnerungsauftraege(Now, new FollowupParser()); var store = new MailStore(awsSecrets); frc.AddAction<Mail>("mail_abholen", imap.Mail_holen); frc.AddFunc<Mail, Erinnerungsauftrag>("erinnerungsauftrag_erstellen", erinnerungsauftraege.Erinnerungsauftrag_erstellen); frc.AddFunc<Erinnerungsauftrag, string>("erinnerungsauftrag_speichern", store.Save); frc.AddAction<string>("mail_verschieben", imap.Mail_verschieben); using (var fr = new FlowRuntime(frc)) { fr.Message += Console.WriteLine; fr.UnhandledException += e => { Console.WriteLine(e); Environment.Exit(1); }; fr.Process(".start"); fr.WaitForResult(); } }
public void Run() { var mainWindowViewModel = new MainWindowViewModel(); var mainWindow = new MainWindow(); mainWindow.DataContext = mainWindowViewModel; var app = new Application { MainWindow = mainWindow }; var mapper = new Mapper(mainWindowViewModel); FlowRuntimeConfiguration.DispatcherFactory = () => new DispatchForWPF(); var flowRuntimeConfguration = new FlowRuntimeConfiguration() .AddStreamsFrom("fotobrowser.root.flow", Assembly.GetExecutingAssembly()) .AddFunc("arbeitsverzeichnis_ermitteln", () => Environment.GetCommandLineArgs()[1]) .AddFunc<string, IEnumerable<contracts.Directory>>("unterverzeichnisse_ermitteln", Drives.Verzeichnisse_ermitteln) .AddAction<IEnumerable<contracts.Directory>>("verzeichnisse_mappen", mapper.MapDirectories).MakeDispatched() .AddFunc<string, IEnumerable<string>>("bilddateien_ermitteln", Drives.Bilddateien_ermitteln) .AddAction<IEnumerable<string>>("bilddateien_mappen", mapper.MapFilenames).MakeDispatched(); using (var flowRuntime = new FlowRuntime(flowRuntimeConfguration)) { flowRuntime.Message += Console.WriteLine; flowRuntime.UnhandledException += Console.WriteLine; mainWindow.Refresh += flowRuntime.CreateEventProcessor<string>(".refresh"); flowRuntime.Process(".start"); app.Run(mainWindow); } }
public void Run() { var config = new FlowRuntimeConfiguration() .AddOperations(new AssemblyCrawler(this.GetType().Assembly)) .AddStreamsFrom(@" / .in, f f, g g, CrawlerEbc.Process CrawlerEbc.Result, .out "); foreach(var op in config.Operations) Console.WriteLine(op.Name); using(var fr = new FlowRuntime(config, new Schedule_for_sync_depthfirst_processing())) { int result = 0; fr.Result += _ => result = (int)_.Data; fr.Process(".in", 2); Assert.AreEqual(36, result); } }
static void Main(string[] args) { using(var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); var pageBufferContainer = new DataContainer<PageBuffer>(); var frontend = new Frontend(); frc.AddFlow(new Main(new Formatter(), frontend)); frc.AddFlow(new Features(new CommandlineParser(pageBufferContainer), new TextFileAdapter(), new LineBuffer(pageBufferContainer), new Pager(pageBufferContainer))); fr.Configure(frc); frontend.displayFirstPage += fr.CreateEventProcessor(".displayFirstPage"); frontend.displayLastPage += fr.CreateEventProcessor(".displayLastPage"); frontend.displayNextPage += fr.CreateEventProcessor(".displayNextPage"); frontend.displayPrevPage += fr.CreateEventProcessor(".displayPrevPage"); //fr.Message += Console.WriteLine; fr.Process(new Message(".run", new[]{"test1.txt"})); fr.WaitForResult(); } }
public void Run() { var configServer = new FlowRuntimeConfiguration() .AddFunc<string, string>("hello", s => "hello, " + s) .AddStream(".@hello", "hello") .AddStream("hello", ".@hello"); using (var server = new FlowRuntime(configServer)) using (new WcfOperationHost(server, "localhost:8000")) { server.Message += Console.WriteLine; var configClient = new FlowRuntimeConfiguration() .AddOperation(new WcfStandInOperation("standin", "localhost:8100", "localhost:8000")) .AddStream(".in", "standin#hello") .AddStream("standin#hello", ".out"); using (var client = new FlowRuntime(configClient)) { client.Message += Console.WriteLine; client.Process(".in", "peter"); var result = ""; Assert.IsTrue(client.WaitForResult(2000, _ => result = (string)_.Data)); Assert.AreEqual("hello, peter", result); } } }
public void Throttle() { var frc = new FlowRuntimeConfiguration(); frc.AddFunc<int, int>("nop1", _ => { Console.WriteLine("nop1: {0}", _); return _; }); frc.AddFunc<int, int>("nop2", _ => { Console.WriteLine("nop2: {0}", _); return _; }); frc.AddStream(new Stream(".in", "nop1")); frc.AddStream(new Stream("nop1", "nop2")); frc.AddStream(new Stream("nop2", ".out")); using (var fr = new FlowRuntime(frc)) { var are = new AutoResetEvent(false); fr.Result += _ => { if ((int)_.Data == -1) are.Set(); }; fr.Throttle(100); new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1 }.ToList().ForEach(i => fr.Process(new Message(".in", i))); Assert.IsFalse(are.WaitOne(1000)); } }
public void Scatter_gather() { var frc = new FlowRuntimeConfiguration(); frc.AddStream(new Stream(".in", "scatter")); frc.AddStream(new Stream("scatter.stream", "sleep")); frc.AddStream(new Stream("scatter.count", "gather.count")); frc.AddStream(new Stream("sleep", "gather.stream")); frc.AddStream(new Stream("gather", ".out")); frc.AddFunc<int, int>("sleep", _ => { Console.WriteLine("sleep {0} on {1}", _, Thread.CurrentThread.GetHashCode()); Thread.Sleep(_); return _; }).MakeParallel(); frc.AddOperation(new Scatter<int>("scatter")); frc.AddOperation(new Gather<int>("gather")); using(var fr = new FlowRuntime(frc)) { var list = new[] {10, 200, 100, 30, 200, 70}; fr.Process(new Message(".in", list)); IMessage result = null; Assert.IsTrue(fr.WaitForResult(1000, _ => result = _)); Assert.That(list, Is.EquivalentTo(((List<int>)result.Data).ToArray())); } }
public static void Main(string[] args) { var twitterops = new TwitterOperations(); var gui = new MainWindow(); var ironmq = new IronMQOperations("AppZwitschern", TokenRepository.LoadFrom("ironmq.credentials.txt")); var serialisieren = new Serialization<Versandauftrag>(); var urlShortener = new TinyUrlOperations(); var compressor = new TextCompressor(); FlowRuntimeConfiguration.SynchronizationFactory = () => new SyncWithWPFDispatcher(); var config = new FlowRuntimeConfiguration() .AddStreamsFrom("az.application.flows.flow", Assembly.GetExecutingAssembly()) .AddFunc<Versandauftrag, Versandauftrag>("versandauftrag_schnueren", twitterops.Versandauftrag_um_access_token_erweitern) .AddFunc<Versandauftrag, string>("serialisieren", serialisieren.Serialize) .AddAction<string>("enqueue", ironmq.Enqueue, true) .AddFunc<string, string[]>("extract_urls", compressor.Extract_Urls) .AddFunc<Tuple<string, Tuple<string,string>[]>,string>("replace_urls", compressor.Replace_Urls) .AddFunc<IEnumerable<string>, Tuple<String,string>[]>("shorten_urls", urlShortener.ShortenMany) .AddOperation(new AutoResetJoin<string, Tuple<string,string>[]>("join")) .AddOperation(new Throttle("throttle", 1000)) .AddAction<string>("display_shortened_text", gui.ShortenedText).MakeSync() .AddAction("versandstatus_anzeigen", () => gui.Versandstatus("Versendet!")).MakeSync(); using (var fr = new FlowRuntime(config)) { fr.UnhandledException += ex => MessageBox.Show(ex.InnerException.Message); fr.Message += Console.WriteLine; gui.Versenden += fr.CreateEventProcessor<Versandauftrag>(".versenden"); gui.ShortenText += fr.CreateEventProcessor<string>(".shortenText"); var app = new Application { MainWindow = gui }; app.Run(gui); } }
static void Main(string[] args) { using(var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); frc.AddStream(".in", "A"); frc.AddStream("A", "B"); frc.AddStream("B", "C"); frc.AddFunc<int, int>("A", i => i + 1) .AddFunc<int, int>("B", i => i * 2) .AddAction<int>("C", (int i) => Console.WriteLine("={0}", i)); fr.Configure(frc); // Trace messages selectively using Rx var tracer = new Subject<IMessage>(); tracer.Where(msg => msg.Port.OperationName == "B") // message filter .Select(msg => (int)msg.Data) .Subscribe(i => Console.WriteLine("{0} -> B", i), // message handler _ => { }); fr.Message += tracer.OnNext; fr.Process(new Message(".in", 1)); fr.Process(new Message(".in", 2)); fr.Process(new Message(".in", 3)); fr.WaitForResult(500); } }
public void Activation_if_attribute_present() { var op = new ActiveOp(); using (var fr = new FlowRuntime(new FlowRuntimeConfiguration().AddOperation(op))) { Assert.AreEqual(1, op.messages.Count); Assert.IsInstanceOf<ActivationMessage>(op.messages[0]); } }
public void Sync_depthfirst() { using (var fr = new FlowRuntime(_config, new Schedule_for_sync_depthfirst_processing())) { fr.Process(".in", "x"); Assert.AreEqual("/a(x)/b(x1)/d(x11)/d(x12)/b(x2)/d(x21)/d(x22)/c(x3)", _payload_flow); } }
public void No_activation_if_attribute_not_present() { var op = new InactiveOp(); using (var fr = new FlowRuntime(new FlowRuntimeConfiguration().AddOperation(op))) { Assert.AreEqual(0, op.messages.Count); } }
public void Run_on_separate_thread() { var frc = new FlowRuntimeConfiguration() .AddStream(new Stream(".in", "serNop0")) .AddStream(new Stream("serNop0", "serNop1")) .AddStream(new Stream("serNop1", ".out")); var asyncThreadIds0 = new List<long>(); frc.AddFunc<string, string>("serNop0", _ => { lock (asyncThreadIds0) { Console.WriteLine("serNop0: {0} on {1}", _, Thread.CurrentThread.GetHashCode()); asyncThreadIds0.Add(Thread.CurrentThread.GetHashCode()); } return _; }).MakeSerial(); var asyncThreadIds1 = new List<long>(); frc.AddFunc<string, string>("serNop1", _ => { lock (asyncThreadIds1) { Console.WriteLine("serNop1: {0} on {1}", _, Thread.CurrentThread.GetHashCode()); asyncThreadIds1.Add(Thread.CurrentThread.GetHashCode()); } return _; }).MakeSerial(); using (var sut = new FlowRuntime(frc)) { const int N = 5; var results = new List<IMessage>(); long runtimeThreadId = 0; var are = new AutoResetEvent(false); sut.Result += _ => { lock (results) { Console.WriteLine("res {0} on {1}", _.Data, Thread.CurrentThread.GetHashCode()); runtimeThreadId = Thread.CurrentThread.GetHashCode(); results.Add(_); if (results.Count == N) are.Set(); } }; for (var i = 0; i < N; i++ ) sut.Process(new Message(".in", "x" + i)); Assert.IsTrue(are.WaitOne(10000)); Assert.AreEqual(N, results.Count); Assert.That(results.Select(r => r.Data.ToString()).ToArray(), Is.EquivalentTo(new[]{"x0", "x1", "x2", "x3", "x4"})); Assert.IsFalse(asyncThreadIds0.Contains(runtimeThreadId)); Assert.IsFalse(asyncThreadIds1.Contains(runtimeThreadId)); Assert.AreEqual(0, asyncThreadIds0.Intersect(asyncThreadIds1).Count()); } }
/// <summary> /// 驳回 /// 如果NodeRejectStep不为空,优先使用;否则按照NodeRejectType驳回 /// </summary> /// <returns></returns> public bool NodeReject(VerificationReq reqest) { var user = _auth.GetCurrentUser().User; FlowInstance flowInstance = Get(reqest.FlowInstanceId); FlowRuntime wfruntime = new FlowRuntime(flowInstance); string resnode = ""; resnode = string.IsNullOrEmpty(reqest.NodeRejectStep) ? wfruntime.RejectNode(reqest.NodeRejectType) : reqest.NodeRejectStep; var tag = new Tag { Description = reqest.VerificationOpinion, Taged = (int)TagState.Reject, UserId = user.Id, UserName = user.Name }; wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); flowInstance.IsFinish = 4;//4表示驳回(需要申请者重新提交表单) if (resnode != "") { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = resnode; flowInstance.ActivityType = wfruntime.GetNodeType(resnode); flowInstance.ActivityName = wfruntime.Nodes[resnode].name; flowInstance.MakerList = GetNodeMakers(wfruntime.Nodes[resnode]);//当前节点可执行的人信息 AddTransHistory(wfruntime); } UnitWork.Update(flowInstance); UnitWork.Add(new FlowInstanceOperationHistory { InstanceId = reqest.FlowInstanceId , CreateUserId = user.Id , CreateUserName = user.Name , CreateDate = DateTime.Now , Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + reqest.VerificationOpinion }); UnitWork.Save(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); return(true); }
public void No_activation_if_attribute_not_present() { var op = new InactiveOp(); using (var fr = new FlowRuntime(new FlowRuntimeConfiguration().AddOperation(op))) { Assert.AreEqual(0, op.messages.Count); } }
public void Run_on_separate_thread() { var frc = new FlowRuntimeConfiguration(); frc.AddStream(new Stream(".in", "parNop")); frc.AddStream(new Stream("parNop", ".out")); var cont = new FlowRuntimeConfiguration(); var asyncThreadIds = new List <long>(); cont.AddFunc <string, string>("parNop", _ => { lock (asyncThreadIds) { Console.WriteLine("{0} on {1}", _, Thread.CurrentThread.GetHashCode()); asyncThreadIds.Add(Thread.CurrentThread.GetHashCode()); } Thread.Sleep((DateTime.Now.Millisecond % 100 + 1) * 50); return(_); }).MakeParallel(); frc.AddOperations(cont.Operations); using (var sut = new FlowRuntime(frc, new Schedule_for_async_breadthfirst_processing())) { const int N = 5; var results = new List <IMessage>(); long runtimeThreadId = 0; var are = new AutoResetEvent(false); sut.Result += _ => { lock (results) { Console.WriteLine("res {0} on {1}", _.Data, Thread.CurrentThread.GetHashCode()); runtimeThreadId = Thread.CurrentThread.GetHashCode(); results.Add(_); if (results.Count == N) { are.Set(); } } }; for (var i = 0; i < N; i++) { sut.Process(new Message(".in", "x" + i)); } Assert.IsTrue(are.WaitOne(10000)); Assert.AreEqual(N, results.Count); Assert.That(results.Select(r => r.Data.ToString()).ToArray(), Is.EquivalentTo(new[] { "x0", "x1", "x2", "x3", "x4" })); Assert.IsFalse(asyncThreadIds.Contains(runtimeThreadId)); Assert.IsTrue(asyncThreadIds.Distinct().Count() > 1); } }
public void Activation_if_attribute_present() { var op = new ActiveOp(); using (var fr = new FlowRuntime(new FlowRuntimeConfiguration().AddOperation(op))) { Assert.AreEqual(1, op.messages.Count); Assert.IsInstanceOf <ActivationMessage>(op.messages[0]); } }
/// <summary> /// 创建一个实例 /// </summary> /// <returns></returns> public bool CreateInstance(JObject obj) { var flowInstance = obj.ToObject <FlowInstance>(); //获取提交的表单数据 var frmdata = new JObject(); foreach (var property in obj.Properties().Where(U => U.Name.Contains("data_"))) { frmdata[property.Name] = property.Value; } flowInstance.FrmData = JsonHelper.Instance.Serialize(frmdata); //创建运行实例 var wfruntime = new FlowRuntime(flowInstance); var user = _auth.GetCurrentUser(); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.CreateUserId = user.User.Id; flowInstance.CreateUserName = user.User.Account; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); UnitWork.Add(flowInstance); wfruntime.flowInstanceId = flowInstance.Id; #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { InstanceId = flowInstance.Id, CreateUserId = user.User.Id, CreateUserName = user.User.Name, CreateDate = DateTime.Now, Content = "【创建】" + user.User.Name + "创建了一个流程进程【" + flowInstance.Code + "/" + flowInstance.CustomName + "】" }; UnitWork.Add(processOperationHistoryEntity); #endregion 流程操作记录 AddTransHistory(wfruntime); UnitWork.Save(); return(true); }
public void Breadthfirst() { using (var fr = new FlowRuntime(_config, new Schedule_for_async_breadthfirst_processing())) { fr.Process(".in", "x"); fr.WaitForResult(1000); Assert.AreEqual("/a(x)/b(x1)/b(x2)/c(x3)/d(x11)/d(x12)/d(x21)/d(x22)", _payload_flow); } }
public void Setup() { var frc = new FlowRuntimeConfiguration(); frc.AddPushCausality("push"); frc.AddPopCausality("pop"); frc.AddFunc <int, int>("exOn0", i => { if (i == 0) { throw new ApplicationException("on0"); } return(i); }); frc.AddFunc <int, int>("exOn1", i => { if (i == 1) { throw new ApplicationException("on1"); } return(i); }); frc.AddAction <int>("exOn2", i => { if (i == 2) { throw new ApplicationException("on2"); } }); _exCausality = null; _are = new AutoResetEvent(false); frc.AddAction <FlowRuntimeException>("handleEx", _ => { _exCausality = _; _are.Set(); }); frc.AddStream(new Stream(".in", "push")); frc.AddStream(new Stream("push", "exOn0")); frc.AddStream(new Stream("push.exception", "handleEx")); frc.AddStream(new Stream("exOn0", "exOn1")); frc.AddStream(new Stream("exOn1", "pop")); frc.AddStream(new Stream("pop", "exOn2")); _fr = new FlowRuntime(frc); _exUnhandled = null; _fr.UnhandledException += _ => { _exUnhandled = _; _are.Set(); }; }
public void Register_instance_operations() { var iop = new MethodOperations(); var config = new FlowRuntimeConfiguration() .AddInstanceOperations(iop) .AddStreamsFrom(@" / .inProcedure, Procedure .inProcedureV, ProcedureV .inProcedureC, ProcedureC ProcedureC, .outProcedureC .inProcedureVC, ProcedureVC ProcedureVC, .outProcedureVC .inProcedureVCC, ProcedureVCC ProcedureVCC.continueWith0, .outProcedureVCC0 ProcedureVCC.continueWith1, .outProcedureVCC1 .inFunction, Function Function, .outFunction .inFunctionV, FunctionV FunctionV, .outFunctionV " ); using (var fr = new FlowRuntime(config, new Schedule_for_sync_depthfirst_processing())) { var results = new List <IMessage>(); fr.Result += results.Add; fr.Process(".inProcedure"); Assert.AreEqual(99, iop.Result); fr.Process(".inProcedureV", 42); Assert.AreEqual(42, iop.Result); fr.Process(".inProcedureC"); Assert.AreEqual(99, results[0].Data); results.Clear(); fr.Process(".inProcedureVC", 99); Assert.AreEqual(100, results[0].Data); results.Clear(); fr.Process(".inProcedureVCC", 99); Assert.That(results.Select(r => r.Data).ToArray(), Is.EquivalentTo(new object[] { 100, "101" })); results.Clear(); fr.Process(".inFunction"); Assert.AreEqual(99, results[0].Data); results.Clear(); fr.Process(".inFunctionV", 99); Assert.AreEqual(100, results[0].Data); } }
public void Setup() { _sut = new FlowRuntime(); _are = new AutoResetEvent(false); _result = null; _sut.Result += _ => { _result = _; _are.Set(); }; }
/// <summary> /// 返回用于处理流程节点 /// </summary> /// <param name="id"></param> /// <returns></returns> public FlowVerificationResp GetForVerification(string id) { var flowinstance = Get(id); var resp = flowinstance.MapTo <FlowVerificationResp>(); var runtime = new FlowRuntime(flowinstance); if (runtime.nextNode != null && runtime.nextNode.setInfo != null && runtime.nextNodeType != 4) { resp.NextNodeDesignateType = runtime.nextNode.setInfo.NodeDesignate; } return(resp); }
public static void Main(string[] args) { var config = new FlowRuntimeConfiguration() .AddStreamsFrom("bankueberweisung.console.root.flow", Assembly.GetExecutingAssembly()) .AddOperations(new AssemblyCrawler(Assembly.GetExecutingAssembly())); using (var fr = new FlowRuntime(config)) { //fr.Message += Console.WriteLine; fr.Process(".run"); fr.WaitForResult(); } }
/// <summary> /// 重发一个实例 /// </summary> /// <param name="flowInstanceRepostDto"></param> /// <returns></returns> public virtual async Task RepostInstance(FlowInstanceRepostDto flowInstanceRepostDto) { var manager = Manager as FlowInstanceManager; var user = await GetCurrentUserAsync(); var flowInstance = await manager.GetByIdAsync(flowInstanceRepostDto.Id); flowInstance.FormData = flowInstanceRepostDto.FormData;//读取表单数据 //创建运行实例 var wfruntime = new FlowRuntime(flowInstance); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.InstanceStatus = (wfruntime.GetNextNodeType() == 4 ? InstanceStatus.Finish : InstanceStatus.Processing); await manager.UpdateAsync(flowInstance); await CurrentUnitOfWork.SaveChangesAsync(); if (flowInstance.InstanceStatus == InstanceStatus.Finish) { await manager.FinishInstance(flowInstance);//调用流程结束事件 } wfruntime.flowInstanceId = flowInstance.Id; #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { FlowInstanceId = flowInstance.Id, Content = "【重发】" + user.Name + "重发了一个流程进程【" + flowInstance.Code + "/" + flowInstance.InstanceName + "】" }; await FlowInstanceOperationHistoryRepository.InsertAsync(processOperationHistoryEntity); #endregion 流程操作记录 await AddTransHistory(wfruntime); }
static void Main(string[] args) { var config = new FlowRuntimeConfiguration() .AddFunc <string, string>("greet", Greet) .AddStream(".@greet", "greet") .AddStream("greet", ".@greet"); using (var fr = new FlowRuntime(config)) using (new WcfOperationHost(fr, "localhost:8000")) { Console.WriteLine("Waiting for names..."); Console.ReadLine(); } }
/// <summary> /// 添加扭转记录 /// </summary> private async Task AddTransHistory(FlowRuntime wfruntime) { await FlowInstanceTransitionHistoryRepository.InsertAsync(new FlowInstanceTransitionHistory { FlowInstanceId = wfruntime.flowInstanceId, FromNodeId = wfruntime.currentNodeId, FromNodeName = wfruntime.currentNode.name, FromNodeType = wfruntime.currentNodeType, ToNodeId = wfruntime.nextNodeId, ToNodeName = wfruntime.nextNode.name, ToNodeType = wfruntime.nextNodeType, InstanceStatus = wfruntime.nextNodeType == 4 ? InstanceStatus.Finish : InstanceStatus.Processing, TransitionSate = 0 }); }
private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var win = new WinDesigner(); var nav = new Navigator(); var frc = new FlowRuntimeConfiguration() .AddStreamsFrom("npantarhei.interviz.root.flow", Assembly.GetExecutingAssembly()) .AddFunc <Tuple <string, string>[], Tuple <string, string> >("combine_sources", AssemblyResourceAdapter.Combine_sources) .AddFunc <string, Tuple <Image, NodeMap> >("compile_dot_source", GraphVizAdapter.Compile_graph) .AddFunc <string[], string>("compile_flow_to_dot_source", FlowCompiler.Compile_to_dot_source) .AddAction <Tuple <string, string> >("display_flow", win.Display_flow).MakeSync() .AddAction <Tuple <string[], int> >("display_flownames", win.Display_flownames).MakeSync() .AddAction <Tuple <Image, NodeMap> >("display_graph", win.Display_graph).MakeSync() .AddFunc <string[], string>("extract_filename_from_commandline", _ => _[0]) .AddFunc <Tuple <string[], int>, Tuple <string[], Tuple <string[], int> > >("extract_flownames", FlowCompiler.Extract_flownames) .AddAction <Tuple <string[], string> >("extend_history", nav.Extend_history) .AddFunc <Tuple <string[], string>, int>("find_flow_headline", FlowCompiler.Find_flow_headline) .AddFunc <string, Tuple <Assembly, string[]> >("find_flow_resources", AssemblyResourceAdapter.Find_flow_resources) .AddFunc <string, Tuple <string, string> >("load_flow_from_file", filename => new Tuple <string, string>(filename, File.ReadAllText(filename))) .AddFunc <Tuple <Assembly, string[]>, Tuple <string, string>[]>("load_sources_from_resources", AssemblyResourceAdapter.Load_soures_from_resources) .AddAction <int>("move_cursor_to_flow_header", win.Move_cursor_to_flow_header).MakeSync() .AddAction <string[], Tuple <string[], string> >("navigate_backward_in_flow", nav.Navigate_backward) .AddAction <string[], Tuple <string[], string> >("navigate_forward_in_flow", nav.Navigate_forward) .AddAction <Tuple <string, string> >("save_flow", _ => File.WriteAllText(_.Item1, _.Item2)) .AddFunc <Tuple <string[], int>, string[]>("select_current_flow", FlowCompiler.Select_flow_by_line) .AddFunc <Tuple <string[], Tuple <string[], int> >, Tuple <string[], int> >("select_flowname", FlowCompiler.Select_flowname) .AddOperation(new Throttle("throttle_redrawings")); using (var fr = new FlowRuntime(frc)) { fr.Message += Console.WriteLine; fr.UnhandledException += ex => MessageBox.Show(ex.ToString()); win.Redraw += fr.CreateEventProcessor <Tuple <string[], int> >(".redraw"); win.Load_flow_from_textfile += fr.CreateEventProcessor <string>(".loadFromTextfile"); win.Load_flow_from_assembly += fr.CreateEventProcessor <string>(".loadFromAssembly"); win.Save_flow += fr.CreateEventProcessor <Tuple <string, string> >(".save"); win.Jump_to_flow += fr.CreateEventProcessor <Tuple <string[], string> >(".jump_to_flow"); win.Navigate_backward += fr.CreateEventProcessor <string[]>(".navigate_backward"); win.Navigate_forward += fr.CreateEventProcessor <string[]>(".navigate_forward"); fr.Process(".run", args); Application.Run(win); } }
/// <summary> /// 驳回 /// </summary> /// <returns></returns> public virtual async Task NodeReject(FlowVerifySubmitDto reqest) { var user = await GetCurrentUserAsync(); FlowInstance flowInstance = await Manager.GetByIdAsync(reqest.FlowInstanceId); FlowRuntime wfruntime = new FlowRuntime(flowInstance); string resnode = ""; resnode = string.IsNullOrEmpty(reqest.NodeRejectStep) ? wfruntime.RejectNode() : reqest.NodeRejectStep; var tag = new Tag { Description = reqest.VerificationOpinion, Taged = TagState.Reject, UserId = user.Id, UserName = user.Name }; wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); flowInstance.InstanceStatus = InstanceStatus.Reject;//4表示驳回(需要申请者重新提交表单) if (resnode != "") { var currentNode = wfruntime.Nodes[resnode]; flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = resnode; flowInstance.ActivityType = wfruntime.GetNodeType(resnode); flowInstance.ActivityName = currentNode.name; //如果是开始节点,则取流程实例的创建者 flowInstance.MakerList = flowInstance.ActivityType == 3?$",{flowInstance.CreatorUserId},": GetNodeMakers(currentNode);//当前节点可执行的人信息 await AddTransHistory(wfruntime); } flowInstance.SchemeContent = Newtonsoft.Json.JsonConvert.SerializeObject(wfruntime.ToSchemeObj()); await Manager.UpdateAsync(flowInstance); await FlowInstanceOperationHistoryRepository.InsertAsync(new FlowInstanceOperationHistory { FlowInstanceId = reqest.FlowInstanceId, Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:" + reqest.VerificationOpinion }); }
static void Main_use_manual_wrapper(string[] args) { var config = new FlowRuntimeConfiguration() .AddStreamsFrom(@" / .in, toupper toupper, .out ") .AddOperation(new ToUpperOp("toupper")); using (var fr = new FlowRuntime(config)) { fr.Process(".in", "hello"); fr.WaitForResult(_ => Console.WriteLine(_.Data)); } }
static void Main(string[] args) { var portnumber = 8100 + DateTime.Now.Second; var config = new FlowRuntimeConfiguration() .AddEventBasedComponent("ui", new UI()) .AddOperation(new WcfStandInOperation("proxy", "localhost:" + portnumber, "localhost:8000")) .AddStreamsFrom("DistributedHelloWorld.Client.root.flow", Assembly.GetExecutingAssembly()); using (var fr = new FlowRuntime(config)) { Console.WriteLine("Enter names: "); fr.Process(".run"); fr.WaitForResult(); } }
/// <summary> /// 获取会签开始节点的所有可执行者 /// </summary> /// <param name="forkNodeId">会签开始节点</param> /// <returns></returns> private string GetForkNodeMakers(FlowRuntime wfruntime, string forkNodeId) { string makerList = ""; foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[forkNodeId].Select(u => u.to)) { var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 if (makerList != "") { makerList += ","; } makerList += GetOneForkLineMakers(fromForkStartNode, wfruntime); } return(makerList); }
static void Main(string[] args) { var config = new FlowRuntimeConfiguration() .AddStreamsFrom(@" / .in, toupper.process toupper.result, .out ") .AddEventBasedComponent("toupper", new ToUpperEBC()); using (var fr = new FlowRuntime(config)) { fr.Process(".in", "hello"); fr.WaitForResult(_ => Console.WriteLine(_.Data)); } }
/// <summary> /// 添加扭转记录 /// </summary> private void AddTransHistory(FlowRuntime wfruntime) { var tag = _auth.GetCurrentUser().User; UnitWork.Add(new FlowInstanceTransitionHistory { InstanceId = wfruntime.flowInstanceId, CreateUserId = tag.Id, CreateUserName = tag.Name, FromNodeId = wfruntime.currentNodeId, FromNodeName = wfruntime.currentNode.name, FromNodeType = wfruntime.currentNodeType, ToNodeId = wfruntime.nextNodeId, ToNodeName = wfruntime.nextNode.name, ToNodeType = wfruntime.nextNodeType, IsFinish = wfruntime.nextNodeType == 4 ? 1 : 0, TransitionSate = 0 }); }
public void Run() { using (var fr = new FlowRuntime(_config)) { fr.Message += Console.WriteLine; fr.UnhandledException += e => { Console.WriteLine(e.InnerException); fr.Process(new Message(".stop") { Priority = 99 }); }; fr.Process(".start"); fr.WaitForResult(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); /* * The dialog/clock are outside the flow; they are viewed as part of the environment. * They are bound to the flow as event source using CreateEventProcessor(). */ using (var fr = new FlowRuntime()) { var frc = new FlowRuntimeConfiguration(); // Register streams frc.AddStreamsFrom("Alarm_clock.Flow2.flow", typeof(Program2).Assembly); // Register operations var dlg = new Dialog2(); var clock = new Clock2(); var player = new Soundplayer(); frc.AddAction("Alarm switched off", dlg.Alarm_switched_off).MakeSync() .AddAction("Alarm switched on", dlg.Alarm_switched_on).MakeSync() .AddAction <TimeSpan>("Alarm time reached", Alarm_time_reached) .AddFunc <Tuple <DateTime, DateTime>, TimeSpan>("Calc time diff", Calc_time_diff) .AddAction <TimeSpan>("Display time diff", dlg.Display_time_diff).MakeSync() .AddManualResetJoin <DateTime, DateTime>("Join") .AddAction("Sound alarm", player.Start_playing) .AddAction("Stop alarm", player.Stop_playing); fr.Configure(frc); // Wire-up event sources dlg.SetAlarm += fr.CreateEventProcessor <DateTime>(".setAlarm"); dlg.ResetAlarm += fr.CreateEventProcessor(".resetAlarm"); clock.CurrentTime += fr.CreateEventProcessor <DateTime>(".now"); fr.Message += Console.WriteLine; fr.UnhandledException += Console.WriteLine; // Execute flow // Feature: start application Application.Run(dlg); // needs to run on this thread; cannot be done on flow runtime thread. } }