Пример #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;
        }
Пример #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;
        }