Exemple #1
0
        public static HTTPRequest_RetailerToClientGateway AttemptToViewProducts(HTTPRequest_ClientToGateway request)
        {
            Cookie userCookie = request.Cookie;

            Console.WriteLine("Checkin if user string is valid, info received - USERACCOUNTSTRING: " + userCookie.CurrentCookieString);
            //Todo: remember to verify password and not just username.
            HTTPRequest_RetailerToClientGateway response = new HTTPRequest_RetailerToClientGateway();

            response.Cookie = userCookie;
            if (_RequiresLogin == false || Cookie.ServerCheckIsValidUserString(userCookie.CurrentCookieString)) //If doesn't require login or login is verifiable.
            {
                Console.WriteLine("Valid user account string, responding with product list.");
                #region Construct response with list of products.
                //Get product list from warehouse
                HTTPRequest_RetailToWarehouse requestToForward = new HTTPRequest_RetailToWarehouse();
                requestToForward.WarehouseCmd = HTTPRequest_RetailToWarehouse.WarehouseCommand.ViewProducts;
                RetailToWarehouseCtrl_TopicBased rtwhctrl        = new RetailToWarehouseCtrl_TopicBased();
                HTTPRequest_WarehouseToRetail    wrhouseResponse = rtwhctrl.PublishToWarehouse(request.Location, requestToForward, RetailToWarehouseCtrl_TopicBased.WhichWarehouses.All);
                //rtwhctrl.SubscribeToWarehouse(request.Location, requestToForward, RetailToWarehouseCtrl_TopicBased.WhichWarehouses.All);
                response.Products = wrhouseResponse.Products;
                //response.Products = getTestProductList();
                #endregion
                return(response);
            }
            else
            {
                Console.WriteLine("User account string could not be verified.");
                return(response);
            }
        }
        public static HTTPRequest_RetailerToClientGateway AttemptLogin(HTTPRequest_ClientToGateway request)
        {
            User user = request.User;

            Console.WriteLine("Checkin if user is valid, info received - USERNAME: "******" PASSWORD: "******"Valid user, sending verification cookie.");
                Cookie cookie = new Cookie();
                cookie.CurrentCookieString = GetUserAccountString(user.userName);
                #region Create HTTP response

                response.Cookie = cookie;
                //response.Basket = BasketManager.Singleton().GetUserBasket(request.Cookie.CurrentCookieString);
                //if (response.Basket == null)
                //{
                //    response.Basket = new Baskets();
                //}
                response.Products = RetailRequestResponse_ViewProducts.getTestProductList();
                #endregion
            }
            else
            {
                Cookie cookie = new Cookie();
                cookie.CurrentCookieString = "NotLoggedIn";
                response.Cookie            = cookie;
                Console.WriteLine("User could not be verified.");
            }
            return(response);
        }
        private void ViewProducts()
        {
            //Display a list of products for the user. Inform them they must log in to access the shop.
            HTTPRequest_ClientToGateway requestViewProducts = new HTTPRequest_ClientToGateway();

            #region Request setup
            requestViewProducts.RetailCmd = HTTPRequest_ClientToGateway.RetailCommand.ViewAllProducts;
            requestViewProducts.Cookie    = ClientSession.ClientCookie;
            #endregion
            ClientRequestResponse.SendRequest(requestViewProducts);
        }
        private void Login()
        {
            string userName = "";
            string password = "";

            Console.WriteLine("Username: "******"Password: ");
            password = Console.ReadLine();
            HTTPRequest_ClientToGateway requestLogin = new HTTPRequest_ClientToGateway();

            #region Request setup
            requestLogin.RetailCmd = HTTPRequest_ClientToGateway.RetailCommand.Login;
            requestLogin.User      = new User(userName, password);
            #endregion
            ClientRequestResponse.SendRequest(requestLogin);
        }
        private void AddProduct()
        {
            if (!ClientRequestResponse_Login.IsLoggedIn())
            {
                Console.WriteLine("ERROR - Not logged in.");
                return;
            }

            int productIDAsInt = -1;

            Console.WriteLine("Product ID: ");
            string productID = Console.ReadLine();

            if (!int.TryParse(productID, out productIDAsInt))
            {
                Console.WriteLine("ERROR - not a number.");
            }
            Console.WriteLine("Quantity: ");
            string quantity      = Console.ReadLine();
            int    quantityAsInt = -1;

            if (!int.TryParse(quantity, out quantityAsInt))
            {
                Console.WriteLine("ERROR - not a number.");
            }
            Product p = ClientSession.CurrentProductListDisplayed.FirstOrDefault(x => x.ID == productIDAsInt);

            if (p == null)
            {
                Console.WriteLine("Invalid product ID. Please update products list by typing 'see products' in the main menu.");
                return;
            }
            p.Quantity = quantityAsInt;
            //Request
            HTTPRequest_ClientToGateway requestAddProduct = new HTTPRequest_ClientToGateway();

            #region Request setup
            requestAddProduct.Product   = p;
            requestAddProduct.Cookie    = ClientSession.ClientCookie;
            requestAddProduct.RetailCmd = HTTPRequest_ClientToGateway.RetailCommand.AddProduct;
            #endregion
            ClientRequestResponse.SendRequest(requestAddProduct);
        }
        public static HTTPRequest_RetailerToClientGateway AttemptToAddProduct(HTTPRequest_ClientToGateway request)
        {
            Cookie userCookie = request.Cookie;

            Console.WriteLine("Checkin if user string is valid, info received - USERACCOUNTSTRING: " + userCookie.CurrentCookieString);
            //Todo: remember to verify password and not just username.
            if (Cookie.ServerCheckIsValidUserString(userCookie.CurrentCookieString))
            {
                if (request.Product == null)
                {
                    Console.WriteLine("Product is null before adding");
                }
                Console.WriteLine("Valid user account string, adding product to basket.");
                HTTPRequest_RetailerToClientGateway response = new HTTPRequest_RetailerToClientGateway();
                #region Add product to basket + construct response with new basket.
                //Add to basket
                response.Basket = BasketManager.Singleton().AddObjectToUserBasket(userCookie.CurrentCookieString, request.Product);
                //Response
                response.Cookie = userCookie;
                foreach (var product in response.Basket.ShowContent)
                {
                    if (product == null)
                    {
                        Console.WriteLine("Product is null");
                    }
                    else
                    {
                        Console.WriteLine("Product: " + product.Name);
                    }
                }
                #endregion
                return(response);
            }
            else
            {
                Console.WriteLine("User account string could not be verified.");
                return(null);
            }
        }
Exemple #7
0
        public static void SendRequest(HTTPRequest_ClientToGateway request)
        {
            using (var bus = RabbitHutch.CreateBus("host=localhost;timeout=5"))
            {
                try
                {
                    MonitorObject = new MonitorObject();
                    MonitorObject.StartMonitoring();
                    request.Cookie = ClientSession.ClientCookie;
                    #region HTTP command setup

                    #endregion
                    var task = bus.RequestAsync <HTTPRequest_ClientToGateway, HTTPRequest_RetailerToClientGateway>(request);

                    // Each response is handled by a separate task.
                    // the requester can have multiple outstanding requests.
                    task.ContinueWith(response => HandleResponse(response)).Wait();
                }
                catch (AggregateException ex)
                {
                    Console.WriteLine("Request to server failed.");
                }
            }
        }