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 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)));
            }
        }
Beispiel #3
0
        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.
            }
        }
Beispiel #4
0
        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);
            }
        }     
Beispiel #5
0
        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.
            }
        }
Beispiel #6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var config = new FlowRuntimeConfiguration();

            config.AddStreamsFrom("WinScratchpad.flows.flow", Assembly.GetExecutingAssembly());

            config.AddFunc<string, string>("toUpper", Program.ToUpper).MakeParallel();
            config.AddFunc<string, string>("reverse", Program.Reverse);

            var dlg = new Dialog();
            config.AddAction<Correlation>("display", dlg.Display).MakeSync();
            config.AddOperation(new Correlator());

            using (var fr = new FlowRuntime(config))
            {
                dlg.Transform_text += fr.CreateEventProcessor<Correlation>(".transform_text");

                Application.Run(dlg);
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var config = new FlowRuntimeConfiguration();

            // aus embeddded resource laden
            config.AddStreamsFrom("Scratchpad.flows.flow", Assembly.GetExecutingAssembly());

            //            // im 3GL Quelltext
            //            config.AddStreamsFrom(@"/
            //                                    .in, Transform.in
            //                                    Transform.out, .out
            //
            //                                    Transform
            //                                    .in, toUpper
            //                                    toUpper, reverse
            //                                    reverse, .out");

            //            // als Liste von Streams
            //            config.AddStream(".in", "Transform.in")
            //                    .AddStream("Transform.out", ".out")

            //                    .AddStream("Transform/.in", "Transform/toUpper")
            //                    .AddStream("Transform/toUpper", "Transform/reverse")
            //                    .AddStream("Transform/reverse", "Transform/.out");

            config.AddFunc<string, string>("toUpper", Program.ToUpper);
            //config.AddOperation(new ToUpperOperation());
            config.AddFunc<string, string>("reverse", Program.Reverse);

            config.AddOperation(new Get_text());
            config.AddAction<string>("display_text", (string text) => Console.WriteLine("-> {0}\n", text), true);

            using(var fr = new FlowRuntime(config))
            {
                //fr.Message += Console.WriteLine;
                //fr.Throttle(1000);

                //fr.Process(".in", string.Join(" ", args));
                //fr.WaitForResult(_ => Console.WriteLine(_.Data));
                fr.Process(".run");
                fr.WaitForResult();
            }

            var f = new F(new A(), new S(), new T());
            var g = new G(new A(), new O(), new P());
        }
        public void TestMethod1()
        {
            string email = "*****@*****.**";
            string password = "";
            reader = new FeedRepository(Reader.CreateReader(email, password, "scroll") as Reader);
            //reader = new FeedRepositoryForTests();

            var frc = new FlowRuntimeConfiguration();
            frc.AddStreamsFrom(@"
                                .in, getFeeds
                                getFeeds.out0, getLinks
                                getFeeds.out1, join.in0
                                getLinks, getAddress
                                getAddress, scatter
                                scatter.count, gather.count
                                scatter.stream, downloadFile
                                downloadFile, gather.stream
                                gather, join.in1
                                join, .out
                                ");

            frc.AddAction<string, UrlAndFeed, int>("getFeeds", getFeeds);
            frc.AddFunc<int, bool>("feedCount", i => { return true; });
            frc.AddFunc<UrlAndFeed, IEnumerable<PodcastLinkInformation>>("getLinks", urlAndFeed => reader.GetItemsForFeed(urlAndFeed.Url, DateTime.Now.AddDays(-1)));
            frc.AddFunc<IEnumerable<PodcastLinkInformation>, IEnumerable<RemoteAndLocalAddress>>("getAddress", getAddress);
            frc.AddFunc<RemoteAndLocalAddress, RemoteAndLocalAddress>("downloadFile", downloadFile).MakeParallel();
            frc.AddOperation(new Scatter<RemoteAndLocalAddress>("scatter"));
            frc.AddOperation(new Gather<RemoteAndLocalAddress>("gather"));
            frc.AddOperation(new MySimpleJoin());

            using (var fr = new FlowRuntime(frc))
            {
                fr.Process(".in", "Listen Subscriptions");

                object erg;
                fr.WaitForResult(message => erg = message.Data);
                //Thread.Sleep(60000);
            }
        }