コード例 #1
0
        static void Main(string[] args)
        {
            BurgerMaster burgerMaster = new BurgerMaster();

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            Task <Patty> pattyTask   = burgerMaster.CookPattyAsync();
            var          friesTask   = burgerMaster.FryFriesAsync();
            var          produceTask = burgerMaster.ChopProduceAsync();
            var          bunTask     = burgerMaster.ToastBunAsync();

            // Cook patty
            Patty patty = pattyTask.Result;

            // Fry some fries
            Fries fries = friesTask.Result;

            // Chop some veggies
            Produce produce = produceTask.Result;

            // Toasted bun
            Bun bun = bunTask.Result;

            // Assemble burger
            Burger burger = burgerMaster.AssembleBurger();

            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            Console.ReadKey();
        }
コード例 #2
0
 public Burger(Bread bread, Patty patty, Sauce sauce, Cheese cheese)
 {
     Bread  = bread;
     Patty  = patty;
     Sauce  = sauce;
     Cheese = cheese;
 }
コード例 #3
0
ファイル: AsyncUI.cs プロジェクト: Spawlak93/AsyncBurgerDemo
        public void Run()
        {
            BurgerMaster burgerMaster = new BurgerMaster();

            Patty patty = burgerMaster.CookPatty();

            Console.WriteLine("Patty Done");
            Fries fries = burgerMaster.FryFries();

            Console.WriteLine("Fries Done");
            Bun bun = burgerMaster.ToastBun();

            Console.WriteLine("Bun Toasted");
            Produce produce = burgerMaster.ChopProduce();

            Console.WriteLine("Produce Chopped");

            burgerMaster.AssembleBurger();
            Console.WriteLine("Enjoy Burger");

            Console.ReadKey();
        }
コード例 #4
0
ファイル: Tests.cs プロジェクト: mariuszcyranowski/Patty
 public Tests()
 {
     patty = new Patty();
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: mariuszcyranowski/Patty
        private static void Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name        = "Patty",
                Description =
                    "Provided with set of samples and regexs called pattern fragments, builds up a list of patterns which matches these samples."
            };

            app.HelpOption("-?|-h|--help");
            var patternsFile = app.Option("-p |--patterns-file <filepath>", "File with pattern fragments to be used",
                                          CommandOptionType.SingleValue);

            var samples = app.Option("-s |--samples <filepath>", "Source of samples", CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                if (!samples.HasValue() || !System.IO.File.Exists(samples.Value()))
                {
                    app.Error.WriteLine("sample file not exist or not provided");

                    return(1);
                }

                var patty = new Patty();

                if (patternsFile.HasValue())
                {
                    if (System.IO.File.Exists(patternsFile.Value()))
                    {
                        using (var reader = new System.IO.StreamReader(patternsFile.Value())) {
                            string pattern;
                            while ((pattern = reader.ReadLine()) != null)
                            {
                                patty.AddPatternFragment(pattern);
                            }
                        }
                    }
                    else
                    {
                        app.Error.WriteLine($"patterns file does not exists - {patternsFile.Value()}");
                    }
                }

                using (var reader = new System.IO.StreamReader(samples.Value())) {
                    string sample;
                    while ((sample = reader.ReadLine()) != null)
                    {
                        patty.AddSample(sample);
                    }
                }

                var result = patty.CompileAll();
                foreach (var item in result)
                {
                    app.Out.WriteLine(item);
                }

                return(0);
            });

            app.Execute(args);
        }