Пример #1
0
        static void Main()
        {
            var phoneGuid = "d2d17da2-e6ad-4b6b-bdcd-ffdea39ba78d";
            var parser    = new StoreParser(new PhoneStoreBehavior());

            IStoreApp appData = parser.GetStoreAppDataAsync(phoneGuid).Result;

            Console.WriteLine(appData);
            Console.ReadLine();

            List <string> phoneGuids = new List <string>()
            {
                "d2d17da2-e6ad-4b6b-bdcd-ffdea39ba78d",
                "f4232c0b-24e5-4f01-b8bb-69a892d06e28"
            };


            //this will open a Thread (Task) for each Guid in list
            IEnumerable <IStoreApp> appDataList = parser.GetStoreAppDataCollection(phoneGuids);

            foreach (var app in appDataList)
            {
                Console.WriteLine(app);
                Console.WriteLine("__________________________");
            }

            Console.ReadLine();
        }
Пример #2
0
        static void AddProduct(IStoreApp app)
        {
            string name, input;
            double price;

AddProductInput:
            Console.Clear();
            Console.WriteLine("Enter the name and price of the new product:");
            input = Console.ReadLine();
            try
            {
                if (input.Split(" ").Length != 2)
                {
                    throw new FormatException();
                }
                name  = input.Split(" ")[0];
                price = System.Convert.ToDouble(input.Split(" ")[1]);
            }
            catch (FormatException)
            {
                Console.WriteLine("Invalid input");
                Console.ReadKey();
                goto AddProductInput;
            }
            app.AddProduct(new Product(name, price, 1));
            Console.WriteLine($"new product {name} for ${price:N2} added");
            Console.ReadKey();
        }
Пример #3
0
        static void DisplayOrders(IStoreApp app)
        {
            var orders = app.ShowOrders();

            foreach (var x in orders)
            {
                Console.WriteLine(x.DisplayOrder());
            }
            Console.ReadKey();
        }
Пример #4
0
        // diaplay methods that can be refactored
        static void DisplayCustomers(IStoreApp app)
        {
            var customers = app.ShowCustomers();

            foreach (var x in customers)
            {
                Console.WriteLine($"ID: {x.ID, -3}|{x.FirstName, 7} {x.LastName,-5}");
            }
            Console.ReadKey();
        }
        /// <summary>Get and process app information in public store web page</summary>
        /// <param name="storeApp">Object to complete fields with all information taken from app web page</param>
        /// <param name="dom">C# query object used to explore DOM from Store App web page</param>
        public override void ObjectDOMMapper(IStoreApp storeApp, CQ dom)
        {
            storeApp.Name = dom["h1[itemprop='name']"].Text();
            storeApp.Author = dom["#AppDeveloper"].Text().Trim();
            storeApp.ThumbnailUri = new Uri(dom["img#ScreenshotImage"].Attr("src"));

            //from here working in windows store specific fields
            var winstoreApp = storeApp as WindowsStoreApp;
            if (winstoreApp != null)
            {
                //converting DOM object in string
                string strTargetString = dom.Text();
                //using regular expression to extract PFN
                winstoreApp.PackageFamilyName = InfoExtractor.Match(strTargetString).Groups[1].Value;
            }
        }
        /// <summary>Get and process app information in public store web page</summary>
        /// <param name="storeApp">Object to complete fields with all information taken from app web page</param>
        /// <param name="dom">C# query object used to explore DOM from Store App web page</param>
        public override void ObjectDOMMapper(IStoreApp storeApp, CQ dom)
        {
            storeApp.Name         = dom["h1[itemprop='name']"].Text();
            storeApp.Author       = dom["#AppDeveloper"].Text().Trim();
            storeApp.ThumbnailUri = new Uri(dom["img#ScreenshotImage"].Attr("src"));

            //from here working in windows store specific fields
            var winstoreApp = storeApp as WindowsStoreApp;

            if (winstoreApp != null)
            {
                //converting DOM object in string
                string strTargetString = dom.Text();
                //using regular expression to extract PFN
                winstoreApp.PackageFamilyName = InfoExtractor.Match(strTargetString).Groups[1].Value;
            }
        }
Пример #7
0
 static void AddNewCustomer(IStoreApp app)
 {
     string[] fullname;
     while (true)
     {
         Console.WriteLine("Write the first and last name of the new customer (q to return to main menu)");
         fullname = Console.ReadLine().Split(" ");
         if (fullname.Length == 1 && fullname[0] == "q")
         {
             return;
         }
         if (fullname.Length == 2)
         {
             break;
         }
         Console.WriteLine("Incorrect input");
     }
     app.AddCustomer(new Customer(fullname[0], fullname[1]));
 }
Пример #8
0
        static void DisplayOrdersByCustomer(IStoreApp app)
        {
            var customers = app.ShowCustomers();
            int input     = 0;

            while (input < 1 || input > customers.Count)
            {
DisplayOrdersLocation:
                Console.Clear();
                Console.WriteLine("Enter the number of the customer");

                for (int i = 0; i < customers.Count; i++)
                {
                    Console.WriteLine($"({i + 1}) {customers[i].FirstName} {customers[i].LastName}");
                }
                try
                {
                    input = System.Convert.ToInt32(Console.ReadLine());
                    if (input < 1 || input > customers.Count)
                    {
                        goto DisplayOrdersLocation;
                    }
                }
                catch (FormatException) { goto DisplayOrdersLocation; }

                var orders = app.ShowOrdersByCustomer(customers[input - 1]);
                if (orders.Count == 0)
                {
                    Console.WriteLine("Empty order history");
                    Console.ReadKey();
                }
                else
                {
                    foreach (var x in orders)
                    {
                        Console.WriteLine(x.DisplayOrder());
                    }
                    Console.ReadKey();
                }
            }
        }
 /// <summary>Get and process app information in public store web page</summary>
 /// <param name="storeApp">Object to complete fields with all information taken from app web page</param>
 /// <param name="dom">C# query object used to explore DOM from Store App web page</param>
 public abstract void ObjectDOMMapper(IStoreApp storeApp, CQ dom);
Пример #10
0
 public StoreService(IStoreApp storeApp)
 {
     _storeApp = storeApp;
 }
 /// <summary>Get and process app information in public store web page</summary>
 /// <param name="storeApp">Object to complete fields with all information taken from app web page</param>
 /// <param name="dom">C# query object used to explore DOM from Store App web page</param>
 public override void ObjectDOMMapper(IStoreApp storeApp, CQ dom)
 {
     storeApp.Name = dom["h1[itemprop='name']"].Text();
     storeApp.Author = dom["#publisher a, #publisher span[itemprop='publisher']"].Text();
     storeApp.ThumbnailUri = new Uri(dom["img.appImage"].Attr("src"));
 }
Пример #12
0
        static void PlaceOrder(IStoreApp app)
        {
            var customers = app.ShowCustomers();
            int input     = 0;

            while (input < 1 || input > customers.Count)
            {
PlaceOrderChooseCustomer:
                Console.Clear();
                Console.WriteLine("Enter the number of the customer");

                for (int i = 0; i < customers.Count; i++)
                {
                    Console.WriteLine($"({i + 1}) {customers[i].FirstName} {customers[i].LastName}");
                }
                try
                {
                    input = System.Convert.ToInt32(Console.ReadLine());
                    if (input < 1 || input > customers.Count)
                    {
                        goto PlaceOrderChooseCustomer;
                    }
                }
                catch (FormatException) { goto PlaceOrderChooseCustomer; }
            }
            var customer = customers[input - 1];

            var locations = app.ShowLocations();

            input = 0;

            while (input < 1 || input > locations.Count)
            {
PlaceOrderChooseLocation:
                Console.Clear();
                Console.WriteLine("Enter the number of the location");

                for (int i = 0; i < locations.Count; i++)
                {
                    Console.WriteLine($"({i + 1}) {locations[i].Name}");
                }
                try
                {
                    input = System.Convert.ToInt32(Console.ReadLine());
                    if (input < 1 || input > locations.Count)
                    {
                        goto PlaceOrderChooseLocation;
                    }
                }
                catch (FormatException) { goto PlaceOrderChooseLocation; }
            }
            var location = locations[input - 1];

            var inventory = app.ShowLocationInventory(location);

            var cart = new List <Product>();

            string Scart_input = "";

            int[] Icart_input = { 0, 0 };

            while (Icart_input[0] != inventory.Count + 1)
            {
PlaceOrderBuildCart:
                Console.Clear();
                Console.WriteLine($"{location.Name} inventory");
                for (int i = 0; i < inventory.Count; i++)
                {
                    Console.WriteLine($"({i+1}) {inventory[i].DisplayProduct()}");
                }
                Console.WriteLine($"({inventory.Count+1}) to finish");
                if (cart.Count > 0)
                {
                    Console.WriteLine("Cart items");
                    foreach (var x in cart)
                    {
                        Console.WriteLine(x.DisplayProduct());
                    }
                }
                else
                {
                    Console.WriteLine("Cart is empty");
                }
                Console.WriteLine("Enter the product number and quantity desired:");
                try
                {
                    Scart_input    = Console.ReadLine();
                    Icart_input[0] = System.Convert.ToInt32(Scart_input.Split(" ")[0]);
                    if (Icart_input[0] == inventory.Count + 1)
                    {
                        break;
                    }

                    if (Scart_input.Split(" ").Length != 2)
                    {
                        Console.WriteLine("Invalid input");
                        Console.ReadKey();
                        goto PlaceOrderBuildCart;
                    }
                    Icart_input[1] = System.Convert.ToInt32(Scart_input.Split(" ")[1]);

                    if (Icart_input[0] < 1 || Icart_input[0] > inventory.Count + 1)
                    {
                        goto PlaceOrderBuildCart;
                    }
                }
                catch (FormatException) {
                    Console.WriteLine("Invalid input");
                    Console.ReadKey();
                    goto PlaceOrderBuildCart;
                }
                if (inventory[Icart_input[0] - 1].Amount < Icart_input[1])
                {
                    Console.WriteLine("Can't order more of an item than exists in inventory");
                    goto PlaceOrderBuildCart;
                }
                else
                {
                    inventory[Icart_input[0] - 1].Amount -= Icart_input[1];
                    cart.Add(new Product(inventory[Icart_input[0] - 1].Name, inventory[Icart_input[0] - 1].Price, Icart_input[1]));
                }
            }
            Console.Clear();
            Console.WriteLine("Order to be placed:\n");
            Console.WriteLine($"Customer: {customer.FirstName} {customer.LastName}");
            Console.WriteLine($"Location: {location.Name}");
            foreach (var x in cart)
            {
                Console.WriteLine(x.DisplayProduct());
            }
            Console.ReadKey();
            try
            {
                app.AddOrder(new Order(location, customer, cart));
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Order placed successfully");
            Console.ReadKey();
        }
Пример #13
0
        // business logic that can be refactored into domain classes
        static void AddInventoryToLocation(IStoreApp app)
        {
            var products  = app.ShowProducts();
            var locations = app.ShowLocations();
            int input     = 0;

            while (input < 1 || input > locations.Count)
            {
AddInventoryChooseLocation:
                Console.Clear();
                Console.WriteLine("Enter the number of the location");

                for (int i = 0; i < locations.Count; i++)
                {
                    Console.WriteLine($"{i + 1} {locations[i].Name}");
                }
                try
                {
                    input = System.Convert.ToInt32(Console.ReadLine());
                    if (input < 1 || input > locations.Count)
                    {
                        goto AddInventoryChooseLocation;
                    }
                }
                catch (FormatException) { goto AddInventoryChooseLocation; }
            }
            var location = locations[input - 1];

            var inventory = app.ShowLocationInventory(location);

            string Scart_input = "";

            int[] Icart_input = { 0, 0 };

            while (Icart_input[0] != inventory.Count + 1)
            {
AddInventoryBuildCart:
                Console.Clear();
                Console.WriteLine("Available Products:");
                for (int i = 0; i < products.Count; i++)
                {
                    Console.WriteLine($"({i+1}) {products[i].Name} ${products[i].Price:N2}");
                }
                Console.WriteLine($"({products.Count + 1}) to finish\n");
                Console.WriteLine($"{location.Name} inventory");
                for (int i = 0; i < inventory.Count; i++)
                {
                    Console.WriteLine($"{inventory[i].DisplayProduct()}");
                }
                Console.WriteLine("Enter the product number and quantity desired:");
                try
                {
                    Scart_input    = Console.ReadLine();
                    Icart_input[0] = System.Convert.ToInt32(Scart_input.Split(" ")[0]);
                    if (Icart_input[0] == products.Count + 1)
                    {
                        break;
                    }

                    if (Scart_input.Split(" ").Length != 2)
                    {
                        Console.WriteLine("Invalid input");
                        Console.ReadKey();
                        goto AddInventoryBuildCart;
                    }
                    Icart_input[1] = System.Convert.ToInt32(Scart_input.Split(" ")[1]);
                    if (Icart_input[1] < 1)
                    {
                        Console.WriteLine("Invalid amount of items to add");
                        Console.ReadKey();
                        goto AddInventoryBuildCart;
                    }

                    if (Icart_input[0] < 1 || Icart_input[0] > products.Count + 1)
                    {
                        goto AddInventoryBuildCart;
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid input");
                    Console.ReadKey();
                    goto AddInventoryBuildCart;
                }
                app.AddInventoryToLocation(location, new List <Product> {
                    new Product(products[Icart_input[0] - 1].Name,
                                products[Icart_input[0] - 1].Price, Icart_input[1])
                });
                inventory = app.ShowLocationInventory(location);
            }
        }
Пример #14
0
 /// <summary>Get and process app information in public store web page</summary>
 /// <param name="storeApp">Object to complete fields with all information taken from app web page</param>
 /// <param name="dom">C# query object used to explore DOM from Store App web page</param>
 public override void ObjectDOMMapper(IStoreApp storeApp, CQ dom)
 {
     storeApp.Name         = dom["h1[itemprop='name']"].Text();
     storeApp.Author       = dom["#publisher a, #publisher span[itemprop='publisher']"].Text();
     storeApp.ThumbnailUri = new Uri(dom["img.appImage"].Attr("src"));
 }
Пример #15
0
 /// <summary>Get and process app information in public store web page</summary>
 /// <param name="storeApp">Object to complete fields with all information taken from app web page</param>
 /// <param name="dom">C# query object used to explore DOM from Store App web page</param>
 public abstract void ObjectDOMMapper(IStoreApp storeApp, CQ dom);