コード例 #1
0
        // Yuck...
        private int TotalLiters(IEnumerable <ShippingBox> collection)
        {
            ShippingBoxes boxes = new ShippingBoxes();

            foreach (ShippingBox aBox in collection)
            {
                boxes.AddOneBox(aBox);
            }

            return(boxes.TotalVolumeInLiters());
        }
コード例 #2
0
        public void GenerateShippingBoxReport(ShippingBoxes boxes)
        {
            MakeRoom();
            MakeHeader("SHIPPING BOXES");

            Console.Write("MATERIAL".PadRight(20));
            Console.Write("WIDTH x HEIGHT x DEPTH".PadRight(30));
            Console.Write("MAX. WEIGHT".PadRight(30));
            Console.WriteLine();

            foreach (ShippingBox box in boxes.AllBoxes())
            {
                Console.Write($"{box.Material}".PadRight(20));
                Console.Write($"{box.Width} x {box.Height} x {box.Depth}".PadRight(30));
                Console.Write($"(Max. {box.MaxWeight:F3} kgs.)".PadRight(30));
                Console.WriteLine();
            }

            MakeFooter();
            Console.WriteLine($"Summary: a total of {boxes.NumberOfBoxes()} Shipping Boxes are available");
            Console.WriteLine($"         with a total volume of {boxes.TotalVolumeInLiters()} liters");
        }
コード例 #3
0
 public void GenerateShippingBoxReport(ShippingBoxes boxes)
 {
     _shippingBoxGenerator.GenerateReport(_collectionFactory.CreateShippingBoxCollection(boxes), _shippingBoxFormatter);
 }
コード例 #4
0
        public static async Task <string> Run(
            [OrchestrationTrigger] DurableOrchestrationContext shippingContext, TraceWriter log)
        {
            int           minInventory = 100;
            ShippingBoxes input        = shippingContext.GetInput <ShippingBoxes>();

            if (input.Volume > minInventory)
            {
                int procurmentTimeDuration = 1;

                DateTime procurmentTime = shippingContext.CurrentUtcDateTime.AddSeconds(procurmentTimeDuration);

                //Time Monitoring for Procurment
                while (shippingContext.CurrentUtcDateTime < procurmentTime)
                {
                    int requiredBoxes = input.Volume - minInventory;

                    //Chained Func.
                    bool jobStatus = await shippingContext.CallActivityAsync <bool>("PrepareBoxes", requiredBoxes);

                    if (jobStatus)
                    {
                        // Perform action when condition met
                        var tasks = new Task <long> [input.Volume];
                        for (int i = 0; i < input.Volume; i++)
                        {
                            tasks[i] = shippingContext.CallActivityAsync <long>(
                                "FillBoxes",
                                i);
                        }

                        await Task.WhenAll(tasks);

                        long totalWeight = tasks.Sum(t => t.Result);

                        //QC

                        if (totalWeight > 0)
                        {
                            return("---Recipt---|---Your FullFilment ID :" + Guid.NewGuid().ToString() + " ---|---Total Shipping Weight:" + totalWeight);
                        }
                        else
                        {
                            return("Your Order Failed QC");
                        }
                    }
                    // Orchestration will sleep until this time
                    var nextCheck = shippingContext.CurrentUtcDateTime.AddSeconds(procurmentTimeDuration);


                    //Add Monitor : To check Boxes Arrived
                    await shippingContext.CreateTimer(nextCheck, CancellationToken.None);
                }

                return("Time Elapsed but procurment did not arrive due to adhoc conditions");
            }
            else
            {
                //FAN OUT -> to process Candy Full Fillment
                var tasks = new Task <long> [input.Volume];
                for (int i = 0; i < input.Volume; i++)
                {
                    tasks[i] = shippingContext.CallActivityAsync <long>(
                        "FillBoxes",
                        i);
                }

                await Task.WhenAll(tasks);

                long totalWeight = tasks.Sum(t => t.Result);

                //QC : WEight Check

                if (totalWeight > 0)
                {
                    return("---Recipt---|---Your FullFilment ID :" + Guid.NewGuid().ToString() + " ---|---Total Shipping Weight:" + totalWeight);
                }
                else
                {
                    return("Your Order Failed QC");
                }
            }
        }
コード例 #5
0
 public IEnumerable <ShippingBox> CreateShippingBoxCollection(ShippingBoxes boxes)
 {
     return(boxes.AllBoxes());
 }