コード例 #1
0
        public void TestWorkflowProgressParallel()
        {
            //IWorkContext context = new WorkContext(null, TestEnvironment.Client);
            // defines and executes a distributed workflow
            var w = new ParallelStep();

            w.Initialise(_workContext);
            var p1 = new P1 {
                @from = 0, to = 2000, slice = 100
            };

            // 20 parallel slices
            // start and monitor
            _workContext.Logger.LogDebug("Starting...");
            _workContext.Logger.LogDebug("[{0}] {1}", "I", w.Progress);
            //P9 p9 = w.Execute(p1, TimeSpan.FromSeconds(10));
            AsyncResult <WorkflowOutput <P9> > ar = w.BeginExecute(p1, null);
            int loop = 0;

            while (!ar.IsCompleted)
            {
                Thread.Sleep(100);
                _workContext.Logger.LogDebug("[{0}] {1}", loop, w.Progress);
                loop++;
            }
            P9 p9 = ar.EndInvoke().Result;

            _workContext.Logger.LogDebug("[{0}] {1}", "Z", w.Progress);
            Assert.AreEqual(2001000, p9.total);
            _workContext.Logger.LogDebug("Complete.");
        }
コード例 #2
0
        public void TestWorkstepParallelDelegate()
        {
            // defines and executes a distributed workflow
            var w = new WorkstepBasePar <P1, P2, P8, P9>(
                // splitter-method
                delegate(P1 input)
            {
                var result = new List <P2>();
                int lower  = input.from;
                int upper  = input.from + input.slice - 1;
                while (upper < input.to)
                {
                    var p2 = new P2 {
                        p = lower, q = upper
                    };
                    result.Add(p2);
                    lower  = upper + 1;
                    upper += input.slice;
                }
                var pLast = new P2 {
                    p = lower, q = input.to
                };
                result.Add(pLast);
                return(result.ToArray());
            },
                // parallel-worker-method
                delegate(P2 input)
            {
                P8 result;
                result.subtotal = 0;
                for (int i = input.p; i <= input.q; i++)
                {
                    result.subtotal += i;
                }
                Thread.Sleep(500);
                return(result);
            },
                // combiner-method
                delegate(P8[] outputs)
            {
                var result = new P9 {
                    total = 0
                };
                foreach (var subOutput in outputs)
                {
                    result.total += subOutput.subtotal;
                }
                return(result);
            });

            w.Initialise(_workContext);
            var p1 = new P1 {
                @from = 0, to = 2000, slice = 100
            };
            // 20 parallel slices
            P9 p9 = w.Execute(p1).Result;

            Assert.AreEqual(2001000, p9.total);
        }
コード例 #3
0
        public void TestWorkstepParallelOverride()
        {
            // defines and executes a distributed workflow
            var w = new ParallelStep();

            w.Initialise(_workContext);
            var p1 = new P1 {
                @from = 0, to = 2000, slice = 100
            };
            // 20 parallel slices
            P9 p9 = w.Execute(p1).Result;

            Assert.AreEqual(2001000, p9.total);
        }