Exemplo n.º 1
0
        public JSONResponseMapper<object, BlenderInput> getProducts(JSONRequestMapper<object, BlenderInput> Request)
        {
            JSONResponseMapper<object, BlenderInput> jsonResp = new JSONResponseMapper<object, BlenderInput>();

            BlenderInput obj = new BlenderInput();
            List<BlenderInputProduct> lstBInputProduct = new List<BlenderInputProduct>();
            foreach (BlenderInputProduct item in Request.data.Products)
            {
                BlenderInputProduct product = new BlenderInputProduct();
                product.Id = item.Id;
                product.MaxDemand = item.MaxDemand;
                product.Price = item.Price;
                List<BlenderInputProperty> lstBInputProperty = new List<BlenderInputProperty>();
                foreach (BlenderInputProperty p1 in item.Properties)
                {
                    BlenderInputProperty objProp = new BlenderInputProperty();
                    objProp.MinSpec = p1.MinSpec;
                    objProp.MaxSpec = p1.MaxSpec;

                    lstBInputProperty.Add(p1);
                }
                product.Properties = lstBInputProperty;
                lstBInputProduct.Add(product);
            }

            obj.Products = lstBInputProduct;

            List<BlenderInputComponent> lstBInputComponent = new List<BlenderInputComponent>();

            foreach (BlenderInputComponent item in Request.data.Components)
            {
                BlenderInputComponent component = new BlenderInputComponent();
                component.Name = item.Name;
                component.MaxAvail = item.MaxAvail;
                component.Cost = item.Cost;
                Dictionary<string, double> lstD = new Dictionary<string, double>();
                lstD = (Dictionary<string, double>)item.BlendValues;
                component.BlendValues = lstD;
                lstBInputComponent.Add(component);
            }
            obj.Components = lstBInputComponent;

            jsonResp.header = Request.header;
            jsonResp.data = Request.data;
            return jsonResp;
        }
Exemplo n.º 2
0
        public JSONResponseMapper<object, BlenderInputOutput> getSolveResults(JSONRequestMapper<object, BlenderInputOutput> Request)
        {
            JSONResponseMapper<object, BlenderInputOutput> jsonResp = new JSONResponseMapper<object, BlenderInputOutput>();

            BlenderInputOutput obj = new BlenderInputOutput();
            obj.Output.Objective = Request.data.Output.Objective;
            obj.Output.Shortage = Request.data.Output.Shortage;

            List<BlenderIOProduct> lstBInputProduct = new List<BlenderIOProduct>();
            foreach (BlenderInputProduct item in Request.data.Input.Products)
            {
                BlenderIOProduct product = new BlenderIOProduct();
                product.Id = item.Id;
                product.MaxDemand = item.MaxDemand;
                product.Price = item.Price;
                List<BlenderIOProperty> lstBInputProperty = new List<BlenderIOProperty>();
                foreach (BlenderInputProperty p1 in item.Properties)
                {
                    BlenderIOProperty objProp = new BlenderIOProperty();
                    objProp.InputProperty.Name = p1.Name;
                    objProp.InputProperty.MinSpec = p1.MinSpec;
                    objProp.InputProperty.MaxSpec = p1.MaxSpec;

                    var outputProduct = Request.data.Output.Products.Where(u => u.Id == product.Id).Select(u => u.Properties.Where(p => p.Name == p1.Name));
                    if (outputProduct != null)
                    {
                        objProp.OutputProperty.OptimalValue = outputProduct.Select(p2 => p2.Select(u => u.OptimalValue).FirstOrDefault()).FirstOrDefault();
                        objProp.OutputProperty.Name = outputProduct.Select(p2 => p2.Select(u => u.Name).FirstOrDefault()).FirstOrDefault();
                    }
                    else
                    {
                        objProp.OutputProperty.OptimalValue = 0;
                        objProp.OutputProperty.Name = string.Empty;
                    }

                    lstBInputProperty.Add(objProp);
                }

                product.Properties = lstBInputProperty;
                lstBInputProduct.Add(product);
            }
            obj.Products = lstBInputProduct;

            List<BlenderInputComponent> lstBInputComponent = new List<BlenderInputComponent>();

            foreach (BlenderInputComponent item in Request.data.Input.Components)
            {
                BlenderInputComponent component = new BlenderInputComponent();
                component.Name = item.Name;
                component.MaxAvail = item.MaxAvail;
                component.Cost = item.Cost;
                Dictionary<string, double> lstD = new Dictionary<string, double>();
                lstD = (Dictionary<string, double>)item.BlendValues;
                component.BlendValues = lstD;
                lstBInputComponent.Add(component);
            }
            obj.Input.Components = lstBInputComponent;

            jsonResp.header = Request.header;
            jsonResp.data = obj;
            return jsonResp;
        }
Exemplo n.º 3
0
        public JSONResponseMapper<object, Message> saveProducts(JSONRequestMapper<object, BlenderInput> Request)
        {
            Message objMsg = new Message();
            JSONResponseMapper<object, Message> jsonResp = new JSONResponseMapper<object, Message>();

            var js = new JavaScriptSerializer();
            string strJson;
            strJson = js.Serialize(Request);

            File.WriteAllText(Server.MapPath("..//BTK_Input_1.json"),"{\"Request\"" + ":" + strJson + "}");

            objMsg.JsonResponse = ResponseMessage.strSuccess;

            jsonResp.header = new object();
            jsonResp.data = objMsg;

            return jsonResp;
        }