Exemple #1
0
        public void Simple_Create_Cloud_Process()
        {
            var child  = CloudBuilder.Sleep(1000).OnSuccess(() => 42);
            var parent = this.Run(CloudBuilder.CreateProcess(child));

            Assert.AreEqual(42, parent.Result);
        }
Exemple #2
0
        public void Simple_Map_Reduce()
        {
            string[] texts =
                new string[] {
                "Lorem ipsum dolor sit amet, mea ferri alienum efficiantur cu, periculis principes complectitur ius te. Eum te quaerendum delicatissimi, at consul audiam eripuit mel, eu vide cibo facilisis mel. Saepe blandit vix et, dicat facilisis comprehensam ea vis. No vis hinc vivendo fabellas, atqui dicunt vel ad.",
                "Cu quodsi percipit has, unum tincidunt dissentiunt eum ne, at oratio latine vel. Debet consul cum id, nec illum debet eruditi no. His audire reformidans id, reque theophrastus in mea. Usu saepe nostro sensibus te, mel inimicus gubergren no.",
                "Duo id inermis noluisse pericula, no sit solet deserunt definitionem. Summo oporteat te vix, sanctus iudicabit honestatis ad eum. Et tritani corpora albucius eos, et mei utroque graecis fabellas. Ex enim aperiri sea, no quo prodesset referrentur, vel utamur diceret eu. Sed laudem noluisse luptatum in. Legere inermis ullamcorper duo ut.",
                "Id vim vocent urbanitas theophrastus, vim in elit homero civibus. Ut augue mentitum adipisci eam, eum id velit possim. No sea nullam vocibus. Inani aliquam quo ex, sonet vitae detraxit in nec, ut legere indoctum consectetuer his. Ei tale nominati disputationi mei."
            };

            Func <string, Tuple <string, int>[]> mapper =
                text =>
                text.Split(new char[] { ',', ' ', '.' })
                .Select(w => w.ToLower().Trim())
                .GroupBy(w => w)
                .Select(gp => new Tuple <string, int>(gp.Key, gp.Count()))
                .ToArray();

            Func <Tuple <string, int>[], Tuple <string, int>[], Tuple <string, int>[]> reducer =
                (freq, freq2) =>
                freq.Concat(freq2)
                .GroupBy(t => t.Item1)
                .Select(gp => new Tuple <string, int>(gp.Key, gp.Select(t => t.Item2).Sum()))
                .ToArray();

            var workflow = CloudBuilder.MapReduce(texts, mapper, reducer, new Tuple <string, int>[] { });
            var results  = this.Run(workflow);
            var expected = mapper.Invoke(String.Join(",", texts));

            Assert.AreEqual(expected, results);
        }
Exemple #3
0
        public void Simple_Cloud_Workflow()
        {
            var workflow = CloudBuilder
                           .FromValue(21)
                           .OnSuccess(x => x * 2)
                           .OnSuccess(x => Assert.AreEqual(42, x));

            this.Run(workflow);
        }
        public static void DrawCloud(WordsCollectionBuilder wcbuilder, WordNormalizator normalizator, IEnumerable<string> words, CloudBuilder cloudBuilder, WordRenderer renderer, RenderTarget target)
        {
            if (wcbuilder == null)
                throw new ArgumentNullException(nameof(wcbuilder));
            if (normalizator == null)
                throw new ArgumentNullException(nameof(normalizator));

            var wordsSorted = wcbuilder(normalizator, words);
            DrawCloud(wordsSorted, cloudBuilder, renderer, target);
        }
Exemple #5
0
        public void Simple_Local_Choice()
        {
            var child1 = CloudBuilder.Sleep(1000).OnSuccess(() => 1);
            var child2 = CloudBuilder.Sleep(3000).OnSuccess(() => 2);
            var parent = CloudBuilder
                         .LocalChoice(child1, child2)
                         .OnSuccess(result => Assert.AreEqual(1, result));

            this.Run(parent);
        }
Exemple #6
0
        public void Simple_Create_Task()
        {
            var child  = CloudBuilder.Sleep(1000).OnSuccess(() => 42);
            var parent = CloudBuilder
                         .StartAsTask(child)
                         .OnSuccess(task => task.Result)
                         .OnSuccess(result => Assert.AreEqual(42, result));

            this.Run(parent);
        }
Exemple #7
0
        public void Simple_Exception_Handling()
        {
            var workflow = CloudBuilder
                           .FromFunc(() => 0)
                           .OnSuccess(i => 25 / i)
                           .OnFailure <int, System.DivideByZeroException>(exn => - 1)
                           .OnSuccess(x => Assert.AreEqual(-1, x));

            this.Run(workflow);
        }
Exemple #8
0
        public void Simple_Choice_Workflow()
        {
            var workflow = Enumerable
                           .Range(1, 10)
                           .Select(x => CloudBuilder.Sleep(10000 * x).OnSuccess(() => x))
                           .Choice()
                           .OnSuccess(x => Assert.AreEqual(1, x));

            this.Run(workflow);
        }
Exemple #9
0
        public void Simple_Local_Parallel()
        {
            var child1 = CloudBuilder.Sleep(1000).OnSuccess(() => 15);
            var child2 = CloudBuilder.Sleep(1000).OnSuccess(() => 27);
            var parent = CloudBuilder
                         .LocalParallel(child1, child2)
                         .OnSuccess(results => results.Sum())
                         .OnSuccess(sum => Assert.AreEqual(42, sum));

            this.Run(parent);
        }
Exemple #10
0
        public void Simple_Cloud_Composition()
        {
            var workflowA = CloudBuilder.FromFunc(() => 25);
            var workflowB = CloudBuilder.FromFunc(() => 17);
            var combined  = CloudBuilder
                            .Combine(workflowA, workflowB)
                            .OnSuccess((x, y) => x + y)
                            .OnSuccess(x => Assert.AreEqual(42, x));

            this.Run(combined);
        }
Exemple #11
0
        public void Simple_Parallel_Workflow()
        {
            var expected = Enumerable.Range(1, 100).Select(x => x * x).Sum();
            var workflow = Enumerable
                           .Range(1, 100)
                           .Select(x => CloudBuilder.FromFunc(() => x * x))
                           .Parallel()
                           .OnSuccess(results => results.Sum());

            this.Run(workflow);
        }
Exemple #12
0
        private Cloud <int> Fibonacci(int n)
        {
            if (n <= 1)
            {
                return(CloudBuilder.FromValue(n));
            }

            return(CloudBuilder
                   .Parallel(Fibonacci(n - 2), Fibonacci(n - 1))
                   .OnSuccess(fs => fs.Sum()));
        }
Exemple #13
0
        public void Simple_Parallel_ForEach()
        {
            var N        = 1000;
            var workflow = Enumerable
                           .Range(1, N)
                           .ParallelForEach(x => CloudBuilder.Log("I'm log entry #{0}", x))
                           .Bind(() => CloudBuilder.Sleep(5000));

            var logs = this.RunWithLogs(workflow);

            Assert.AreEqual(N, logs.Length);
        }
        public static void DrawCloud(WordsCollection words, CloudBuilder cloudBuilder, WordRenderer renderer, RenderTarget target)
        {
            if (words == null)
                throw new ArgumentNullException(nameof(words));
            if (cloudBuilder == null)
                throw new ArgumentNullException(nameof(cloudBuilder));
            if (renderer == null)
                throw new ArgumentNullException(nameof(renderer));

            target.Render(g =>
                renderer.Render(cloudBuilder(words, renderer, g), g)
                );
        }
 public CloudBuilder Configure()
 {
     return(CloudBuilder.Create()
            .WithAzure(AppSettingsConst.AzureAadAppRegistration));
 }