Example #1
0
        private void calcCost_Click(object sender, RoutedEventArgs e)
        {
            ProductsServiceClient proxy = new ProductsServiceClient();

            try
            {
                int     prodID = Int32.Parse(this.productID.Text);
                int     number = Int32.Parse(this.howMany.Text);
                decimal cost   = proxy.HowMuchWillItCost(prodID, number);
                this.totalCost.Content = String.Format("{0:C}", cost);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error obtaining cost: " +
                                ex.Message, "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
            finally
            {
                if (proxy.State == System.ServiceModel.CommunicationState.Faulted)
                {
                    proxy.Abort();
                }
                else
                {
                    proxy.Close();
                }
            }
        }
Example #2
0
 public OrderController(
     ILogger <OrderController> logger,
     IOrderRepository orderRepository,
     ProductsServiceClient productsServiceClient)
 {
     this.logger                = logger;
     this.orderRepository       = orderRepository;
     this.productsServiceClient = productsServiceClient;
 }
Example #3
0
        static void Main(string[] args)
        {
            // Create a proxy object and connect to the service
            ProductsServiceClient proxy = new ProductsServiceClient("NetTcpBinding_IProductsService");

            // Test the operations in the service

            // Obtain a list of all products
            Console.WriteLine("Test 1: List all products");
            string[] productNumbers = proxy.ListProducts();


            foreach (string productNumber in productNumbers)
            {
                Console.WriteLine("Number: {0}", productNumber);
            }

            Console.WriteLine();

            // Display details of a product
            Console.WriteLine("Test 2: Display the details of a product");
            ProductData product = proxy.GetProduct("WB-H098");
            Console.WriteLine("Number: {0}", product.ProductNumber);
            Console.WriteLine("Name: {0}", product.Name);
            Console.WriteLine("Color: {0}", product.Color);
            Console.WriteLine("Price: {0}", product.ListPrice);
            Console.WriteLine();

            // Query the stock level of this product
            Console.WriteLine("Test 3: Display6 the stock level of a product");
            int numInStock = proxy.CurrentStockLevel("WB-H098");
            Console.WriteLine("Current stock level: {0}", numInStock);
            Console.WriteLine();

            // Modify the stock level of this product
            Console.WriteLine("Test 4: Modify the stock level of a product");

            if (proxy.ChangeStockLevel("WB-H098", 100, "N/A", 0))
            {
                numInStock = proxy.CurrentStockLevel("WB-H098");
                Console.WriteLine("Stock changed. Current stock level: {0}", numInStock);
            }
            else
            {
                Console.WriteLine("Stock level update failed");
            }
            Console.WriteLine();

            // Disconnect from the service
            proxy.Close();
            Console.WriteLine("Press ENTER to finish");
            Console.ReadLine();
        }
Example #4
0
        public async Task <Product> Details(int productID)
        {
            Product product = null;

            try
            {
                product = await ProductsServiceClient.GetProductDetailsAsync(productID);
            }
            catch (Exception exception)
            {
                DisplayAlert(exception);
            }

            return(product);
        }
Example #5
0
        static void Main(string[] args)
        {
            List<Product> products = new List<Product>();

            ProductsServiceClient proxy = new ProductsServiceClient();
            Console.WriteLine("Appel de la méthode distante 'GetData' ...");
            Console.WriteLine(proxy.GetData(99));
            Console.WriteLine("-----------------------");
            Console.WriteLine("Appel de la méthode distante 'GetProducts'... ");
            products = proxy.GetProducts("R");
            foreach (var item in products)
            {
                Console.WriteLine(item.ProductID + " : " + item.Name + " : " + item.Color + " : " + item.ListPrice);
            }
            Console.ReadLine();
        }
Example #6
0
        public AddLicenseKeysForProductResult AddLicenseKeysForLicenseSet(string url, string token,
                                                                          EncryptionInfo encryptionInfo, KeyPair serviceKeys, AddLicenseKeysForProductData data)
        {
            ProductsServiceClient client = ProductClientCreator(url);

            string encryptedToken    = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
            string serializedPayload = _objectSerializationProvider.Serialize(data);
            string encryptedData     = _asymmetricEncryptionProvider.EncryptPrivate(serializedPayload, serviceKeys);


            string encryptedResult = client.AddLicenseKeysForProduct(encryptedToken, encryptedData);
            string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys);

            AddLicenseKeysForProductResult result = _objectSerializationProvider.Deserialize <AddLicenseKeysForProductResult>(decryptedResult);

            return(result);
        }
Example #7
0
        public void TestProductsService(int controlNumber)
        {
            // Create a proxy object and connect to the service
            proxy = new ProductsServiceClient(new InstanceContext(this), "WSDualHttpBinding_ProductsService");

            // Test the operations in the service
            try
            {
                proxy.SubscribeToPriceChangedEvent();

                // Obtain a list of products
                if (controlNumber == 1)
                {
                    Console.WriteLine("Control Number 1: List all products");
                    ProductData[] products = proxy.ListProducts();
                    foreach (ProductData product in products)
                    {
                        Console.WriteLine("Name: {0}", product.Name);
                        Console.WriteLine("Price: {0}", product.ListPrice);
                    }
                    Console.WriteLine();
                }


                // Modify the price of all products
                if (controlNumber == 2)
                {
                    Console.WriteLine("Control Number 2: Change product price");
                    ProductData[] products = proxy.ListProducts();
                    foreach (ProductData product in products)
                    {
                        proxy.ChangePrice(product.Name, product.ListPrice + 10);
                    }
                    Console.WriteLine();
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
            }
        }
Example #8
0
        public void TestProductsService()
        {
            // Create a proxy object and connect to the service
            proxy = new ProductsServiceClient(new InstanceContext(this),
                                              "WSDualHttpBinding_IProductsServiceV3");

            // Test the operations in the service
            try
            {
                proxy.SubscribeToPriceChangedEvent();

                // Obtain a list of products
                Console.WriteLine("Test 1: List all products");
                string[] productNumbers = proxy.ListProducts();
                foreach (string productNumber in productNumbers)
                {
                    Console.WriteLine("Number: {0}", productNumber);
                }
                Console.WriteLine();

                // Fetch the details for a specific bicycle frame
                Console.WriteLine("Test 2: Display the details of a bicycle frame");
                ProductData product = proxy.GetProduct("FR-M21S-40");
                Console.WriteLine("Number: {0}", product.ProductNumber);
                Console.WriteLine("Name: {0}", product.Name);
                Console.WriteLine("Color: {0}", product.Color);
                Console.WriteLine("Price: {0:C}", product.ListPrice);
                Console.WriteLine();

                // Modify the price of this bicycle frame
                Console.WriteLine("Test 3: Modify the price of a bicycle frame");
                proxy.ChangePrice("FR-M21S-40", product.ListPrice + 10);
                Console.WriteLine();
            }

            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
            }
        }
Example #9
0
        // TODO This should get paged with an optional pagesize.
        private async Task Read(ProductCategory category, ProductSubcategory subcategory, string namePart)
        {
            ProductsOverviewList productsOverview;

            try
            {
                productsOverview = await ProductsServiceClient.GetProductsOverviewByAsync(
                    category?.Id,
                    subcategory?.Id,
                    namePart);
            }
            catch (Exception exception)
            {
                DisplayAlert(exception);
                return;
            }

            foreach (var product in productsOverview)
            {
                items.Add(product);
            }
        }
Example #10
0
        private void getProduct_Click(object sender, RoutedEventArgs e)
        {
            ProductsServiceClient proxy = new ProductsServiceClient();

            try
            {
                int         prodID  = Int32.Parse(this.productID.Text);
                ProductInfo product = proxy.GetProductInfo(prodID);
                this.productName.Content     = product.ProductName;
                this.supplierID.Content      = product.SupplierID;
                this.categoryID.Content      = product.CategoryID;
                this.quantityPerUnit.Content = product.QuantityPerUnit;
                this.unitPrice.Content       = String.Format("{0:C}", product.UnitPrice);
                this.unitsInStock.Content    = product.UnitsInStock;
                this.unitsOnOrder.Content    = product.UnitsOnOrder;
                this.reorderLevel.Content    = product.ReorderLevel;
                this.discontinued.IsChecked  = product.Discontinued;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error fetching product details: " +
                                ex.Message, "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
            finally
            {
                if (proxy.State == System.ServiceModel.CommunicationState.Faulted)
                {
                    proxy.Abort();
                }
                else
                {
                    proxy.Close();
                }
            }
        }
Example #11
0
        protected override async Task <bool> Read(bool addEmptyElement = true)
        {
            if (await base.Read(addEmptyElement))
            {
                ProductSubcategoryList subcategories;

                try
                {
                    subcategories = await ProductsServiceClient.GetProductSubcategoriesAsync();
                }
                catch (Exception exception)
                {
                    DisplayAlert(exception);
                    return(false);
                }

                foreach (var subcategory in subcategories)
                {
                    items.Add(subcategory);
                }
            }

            return(true);
        }
Example #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press ENTER when the service has started");
            Console.ReadLine();


            // Create a proxy object and connect to the service
            ProductsServiceClient proxy = new ProductsServiceClient("WS2007HttpBinding_IProductsService");

            // Test the operations in the service
            // Obtain a list of all products
            Console.WriteLine("Test 1: List all products");
            List <ProductData> products = proxy.ListMatchingProducts("Prod").ToList();

            foreach (ProductData p in products)
            {
                Console.WriteLine("Name: {0}", p.Name);
                Console.WriteLine("Code: {0}", p.Code);
                Console.WriteLine("Price: {0}", p.Price);
                Console.WriteLine();
            }
            Console.WriteLine();

            // Get details of this product
            Console.WriteLine("Test 2: Display the details of a product");
            ProductData product = proxy.GetProduct("0001");

            if (product != null)
            {
                Console.WriteLine("Name: {0}", product.Name);
                Console.WriteLine("Code: {0}", product.Code);
                Console.WriteLine("Price: {0}", product.Price);
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("No such product.");
                Console.WriteLine();
            }


            // Query the stock of this product
            Console.WriteLine("Test 3: Display stock of a product");
            int quantity = proxy.CurrentStock("0001");

            Console.WriteLine("Current stock: {0}", quantity);
            Console.WriteLine();

            // Add stock of this product
            Console.WriteLine("Test 4: Add stock for a product");
            if (proxy.AddStock("0001", 100))
            {
                quantity = proxy.CurrentStock("0001");
                Console.WriteLine("Stock changed. Current stock: {0}", quantity);
            }
            else
            {
                Console.WriteLine("Stock update failed");
            }

            // Disconnect from the service
            proxy.Close();
            Console.WriteLine("Press ENTER to finish");
            Console.ReadLine();
        }
Example #13
0
            private static void TestProductsService()
            {
                List <Product> products = new List <Product>
                {
                    new Product()
                    {
                        Articulus    = null,
                        Name         = "M-16",
                        Color        = "Black",
                        Manufacturer = "USANavi",
                        Price        = 123.56m,
                        Quantity     = 45,
                        Sale         = null,
                        Type         = "rifle",
                        Description  = null
                    }
                };

                using (ProductsServiceClient productsclient = new ProductsServiceClient())
                {
                    //Insert
                    Console.WriteLine("1. Insert data:");
                    var cres = productsclient.Create(products[0]);
                    products[0].Articulus = (int)cres.Item2;
                    Console.WriteLine("Insert data\n");

                    //GetAll
                    Console.WriteLine("2. Viewing data:");
                    var gres = productsclient.GetAll();
                    foreach (var product in gres)
                    {
                        Console.WriteLine(product.Articulus + " " + product.Name + " " + product.Color);
                    }

                    //Update
                    Console.WriteLine("\n3. Update data:");
                    products[0].Sale     = 80;
                    products[0].Quantity = 12;
                    products[0].Color    = "Brown";
                    var ures = productsclient.Update(products);
                    Console.WriteLine(ures.Item2 + "\n");

                    //GetAll
                    Console.WriteLine("4. Viewing updated data:");
                    var gres2 = productsclient.GetAll();
                    foreach (var product in gres2)
                    {
                        Console.WriteLine(product.Articulus + " " + product.Name + " " + product.Color);
                    }

                    //Delete
                    Console.WriteLine("\n5. Deleting data:");
                    var dres = productsclient.Delete(products);
                    Console.WriteLine(dres.Item2 + "\n");

                    //GetAll
                    Console.WriteLine("6. Viewing data after delete:");
                    var gres3 = productsclient.GetAll();
                    foreach (var product in gres3)
                    {
                        Console.WriteLine(product.Articulus + " " + product.Name + " " + product.Color);
                    }
                }
            }
        static void Main(string[] args)
        {
            Console.WriteLine("Press ENTER when the service has started");
            Console.ReadLine();

            //Create a proxy object and connect to the service
            PermissiveCertificatePolicy.Enact("CN=rafapri");
            ProductsServiceClient proxy = new ProductsServiceClient("WS2007HttpBinding_IProductsService_Chapter5EndPoint");

            /*
            proxy.ClientCredentials.Windows.ClientCredential.Domain = "mss-rj-210";
            proxy.ClientCredentials.Windows.ClientCredential.UserName = "******";
            proxy.ClientCredentials.Windows.ClientCredential.Password = "******";
            */

            proxy.ClientCredentials.UserName.UserName = "******";//WindowsIdentity.GetCurrent().Name;//"mss\\rafael.paiva";
            proxy.ClientCredentials.UserName.Password = @"Pa$$w0rd";//"1709Raf@prielscill@";
            //ProductsServiceClient proxy = new ProductsServiceClient();

            // Test the operations in the service
            try
            {
                // Obtain a list of all products
                Console.WriteLine("Test 1: List all products");
                string[] productNumbers = proxy.ListProducts();
                foreach (string productNumber in productNumbers)
                {
                    Console.WriteLine("Number: {0}", productNumber);
                }
                Console.WriteLine();

                Console.WriteLine("Test 2: Display the details of a product");
                ProductData product = proxy.GetProduct("WB-H098");
                Console.WriteLine("Number: {0}", product.ProductNumber);
                Console.WriteLine("Name: {0}", product.Name);
                Console.WriteLine("Color: {0}", product.Color);
                Console.WriteLine("Price: {0}", product.ListPrice);
                Console.WriteLine();

                // Query the stock level of this product
                Console.WriteLine("Test 3: Display the stock level of a product");
                int numInStock = proxy.CurrentStockLevel("WB-H098");
                Console.WriteLine("Current stock level: {0}", numInStock);
                Console.WriteLine();

                // Modify the stock level of this product
                Console.WriteLine("Test 4: Modify the stock level of a product");
                if (proxy.ChangeStockLevel("WB-H098", 100, "N/A", 0))
                {
                    numInStock = proxy.CurrentStockLevel("WB-H098");
                    Console.WriteLine("Stock changed. Current stock level: {0}", numInStock);
                }
                else
                {
                    Console.WriteLine("Stock level update failed");
                }
                Console.WriteLine();
            }
            catch (FaultException<SystemFault> sf)
            {
                Console.WriteLine("SystemFault {0}: {1}\n{2}",
                sf.Detail.SystemOperation, sf.Detail.SystemMessage,
                sf.Detail.SystemReason);
            }
            catch (FaultException<DatabaseFault> dbf)
            {
                Console.WriteLine("DatabaseFault {0}: {1}\n{2}",
                dbf.Detail.DbOperation, dbf.Detail.DbMessage,
                dbf.Detail.DbReason);
            }
            catch (FaultException e)
            {
                Console.WriteLine("{0}: {1}", e.Code.Name, e.Reason);
            }
            catch (Exception ex)
            {
                Console.WriteLine("General exception: {0}", ex.Message);
            }

            proxy.Close();
            Console.WriteLine("Press ENTER to finish");

            Console.ReadKey();
        }
        public Product GetProductByProductID(int id)
        {
            ProductsServiceClient productsServiceClient = new ProductsServiceClient();

            return(productsServiceClient.GetProductByProductID(id));
        }