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); }
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); } }
public static void ReceiveAndHandleRequests() { using (var bus = RabbitHutch.CreateBus("host=localhost;timeout=4")) { bus.RespondAsync <HTTPRequest_ClientToGateway, HTTPRequest_RetailerToClientGateway>(request => Task.Factory.StartNew(() => { Console.WriteLine("Command type received: " + request.RetailCmd); HTTPRequest_RetailerToClientGateway response = new HTTPRequest_RetailerToClientGateway(); response.Cookie = request.Cookie; switch (request.RetailCmd) { case HTTPRequest_ClientToGateway.RetailCommand.Login: response = RetailRequestResponse_Login.AttemptLogin(request); break; case HTTPRequest_ClientToGateway.RetailCommand.AddProduct: response = RetailRequestResponse_Basket.AttemptToAddProduct(request); break; case HTTPRequest_ClientToGateway.RetailCommand.RemoveProduct: break; case HTTPRequest_ClientToGateway.RetailCommand.ViewAllProducts: response = RetailRequestResponse_ViewProducts.AttemptToViewProducts(request); break; default: break; } response.RetailCmd = request.RetailCmd; return(response); } )); Console.WriteLine("Listening for client commands. Hit >ENTER< to quit."); Console.ReadLine(); } }