Ejemplo n.º 1
0
        public async Task linkShopVareAsync(int shopId, int shopIngredientId)
        {
            Shop shop1 = await ctx.shops.FirstAsync(s => s.shopId == shopId);

            /*foreach (var vare in ctx.shopvares.ToList())
             * {
             *  if (shopId == vare.shopId)
             *  {
             *      shop1.shopVares.Add(vare);
             *  }
             * }*/
            ShopIngredient shopIngredient1 = await ctx.shopIngredients.FirstAsync(s => s.id == shopIngredientId);

            ShopVare sv2 = new ShopVare()
            {
                shop           = shop1,
                shopIngredient = shopIngredient1
            };

            if (shop1.shopVares == null)
            {
                shop1.shopVares = new List <ShopVare>();
            }
            shop1.shopVares.Add(sv2);
            await ctx.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        private void _bindIngredients <TTarget>(IngredientBuilder <TTarget> builder, ShopProduct product,
                                                ShopIngredient ingredient)
            where TTarget : class
        {
            var ingredientBuilder = builder
                                    .Cost(ingredient.Price)
                                    .Tweakable(ingredient.Tweakable)
                                    .DisplayName(ingredient.Name)
                                    .DefaultAmount(ingredient.Amount)
                                    .Id(product.Guid + "_" + ingredient.Name);

            foreach (var effect in ingredient.Effects)
            {
                ingredientBuilder.Effect(ProductShopUtility.ConvertEffectType(effect.Type), effect.Amount);
            }
        }
Ejemplo n.º 3
0
        public async Task <String> linkObjectsAsync(Object o1, Object o2, string toLink)
        {
            switch (toLink)
            {
            case "ShopIngredientToShop":
            {
                ShopIngredient shopIngredient = (ShopIngredient)o1;
                Shop           shop           = (Shop)o2;
                await ShopIngrService.addShopIngredientAsync(shopIngredient, shop);

                return("linked");
            }
            }

            return("Error");
        }
Ejemplo n.º 4
0
        public async Task <string> removeObjectAsync(Object o, string toRemove)
        {
            switch (toRemove)
            {
            case "recipe":
            {
                Recipe recipe = (Recipe)o;
                await RecipeService.removeRecipeAsync(recipe.recipeName);

                return(recipe.recipeName + " removed");
            }

            case "ingredient":
            {
                Ingredient ingredient = (Ingredient)o;
                await IngredientService.removeIngredientAsync(ingredient);

                return(ingredient.ingredientName + " removed");
            }

            case "shopIngredient":
            {
                ShopIngredient shopIngredient = (ShopIngredient)o;
                await ShopIngrService.removeShopIngredientAsync(shopIngredient);

                return(shopIngredient.name + " removed");
            }

            case "shop":
            {
                Shop shop = (Shop)o;
                await ShopService.removeShopAsync(shop.shopName);

                return(shop.shopName + " removed");
            }
            }

            return("Error");
        }
Ejemplo n.º 5
0
        public async Task removeShopIngredientAsync(ShopIngredient ingredient)
        {
            Console.WriteLine("Inside remove");
            if (ctx.shopvares.FirstOrDefaultAsync(s => s.shopIngredientId == ingredient.id) != null)
            {
                Console.WriteLine("ShopVares to remove");
                List <ShopVare> shopVares = await ctx.shopvares.Where(s => s.shopIngredientId == ingredient.id).ToListAsync();

                foreach (var shopVare in shopVares)
                {
                    Shop temp = await ctx.shops.FirstOrDefaultAsync(s => s.shopId == shopVare.shopId);

                    Console.WriteLine(temp);
                    temp.vares.Remove(ingredient);
                    temp.shopVares.Remove(shopVare);
                    ctx.shops.Update(temp);
                    ingredient.ShopVares.Remove(shopVare);
                    ctx.shopvares.Remove(shopVare);
                }
            }
            ctx.shopIngredients.Remove(ingredient);
            await ctx.SaveChangesAsync();
        }
Ejemplo n.º 6
0
        /*public async Task<ShopIngredient> getShopIngredientAsync(int id)
         * {
         *  ShopIngredient temp = await ctx.shopIngredients.FirstOrDefaultAsync(s => s.id == id);
         *  return temp;
         * }*/


        public async Task addShopIngredientAsync(ShopIngredient ingredient, Shop shop)
        {
            bool boolShopIngExists = false;

            foreach (var shopIngExists in ctx.shopIngredients)
            {
                if (shopIngExists.id == ingredient.id)
                {
                    boolShopIngExists = true;
                }
            }

            if (!boolShopIngExists)
            {
                ctx.shopIngredients.Add(ingredient);
            }
            await ctx.SaveChangesAsync();

            ShopIngredient getSI = ctx.shopIngredients.FirstOrDefault(n => n.name.Equals(ingredient.name));
            Shop           getS  = ctx.shops.FirstOrDefault(s => s.shopName.Equals(shop.shopName));

            await linkShopVareAsync(getS.shopId, getSI.id);
        }
        private Object getClientsObject(NetworkStream stream, String toConvert)
        {
            byte[] data1ToClient = Encoding.ASCII.GetBytes("Ready");
            stream.Write(data1ToClient, 0, data1ToClient.Length);
            byte[] objectFromClient = new byte[1024];
            int    objectRead       = stream.Read(objectFromClient, 0, objectFromClient.Length);
            string objectString     = Encoding.ASCII.GetString(objectFromClient, 0, objectRead);

            switch (toConvert)
            {
            case "Shop":
            {
                Shop objectToReturn = JsonSerializer.Deserialize <Shop>(objectString);
                return(objectToReturn);
            }

            case "Recipe":
            {
                Recipe objectToReturn = JsonSerializer.Deserialize <Recipe>(objectString);
                return(objectToReturn);
            }

            case "Ingredient":
            {
                Ingredient objectToReturn = JsonSerializer.Deserialize <Ingredient>(objectString);
                return(objectToReturn);
            }

            case "ShopIngredient":
            {
                ShopIngredient objectToReturn = JsonSerializer.Deserialize <ShopIngredient>(objectString);
                return(objectToReturn);
            }
            }
            return(null);
        }
Ejemplo n.º 8
0
 public async Task updateShopIngredientAsync(ShopIngredient ingredient)
 {
     ctx.shopIngredients.Update(ingredient);
     await ctx.SaveChangesAsync();
 }
        private static async Task Seed(DatabaseContext databaseContext)
        {
            Console.WriteLine("Start of seed");
            Address[] addresses =
            {
                new Address {
                    street  = "Solvgade 1, 3tv",
                    city    = "Horsens",
                    zipCode = 8700,
                },
            };
            foreach (var address in addresses)
            {
                databaseContext.addresses.Add(address);
            }
            Console.WriteLine("2");

            BankInfo[] bankInfos =
            {
                new BankInfo {
                    cardNumber = 1234123412341234,
                    cardHolder = "Pawel Skrzypkowski"
                },
            };
            foreach (var bankInfo in bankInfos)
            {
                databaseContext.bankInfos.Add(bankInfo);
            }
            Console.WriteLine("3");


            Account[] acs =
            {
                new Account {
                    username = "******",
                    password = "******",
                    email    = "*****@*****.**",
                },
            };

            foreach (var account in acs)
            {
                databaseContext.accounts.Add(account);
            }
            Console.WriteLine("4");

            Category[] categories =
            {
                new Category()
                {
                    categoryName = "Italian",
                },
                new Category()
                {
                    categoryName = "Greek",
                },
            };

            foreach (var cat in categories)
            {
                databaseContext.categories.Add(cat);
            }
            Console.WriteLine("5");


            Recipe[] recipes =
            {
                new Recipe()
                {
                    recipeName   = "Arrabbiata",
                    recipeId     = 1,
                    description  = "Arrabbiata sauce, or sugo all'arrabbiata in Italian, is a spicy sauce for pasta made from garlic, tomatoes, and dried red chili peppers cooked in olive oil. The sauce originates from the Lazio region, around Rome. Arrabbiata literally means 'angry' in Italian; the name of the sauce refers to the spiciness of the chili peppers.",
                    instructions = "Sauté the crushed red pepper flakes: Heat the butter (or olive oil) in a large saucepan or deep sauté pan.  Add the crushed red pepper flakes and sauté for about 2 minutes, to help toast and bring out their flavor.\nAdd onion and garlic: Add in the onions and sauté until softened, followed by the garlic.\nAdd tomatoes:  Then add in the cans of whole tomatoes, juices included.  And as they begin to heat up, use a wooden spoon or a potato masher to carefully break up the tomatoes.  (Just wear an apron so that those juices inside of the tomatoes don’t accidentally splatter you!)\nSimmer: Continue heating the sauce until it comes to a simmer.  Then reduce heat to medium (or medium-low) to maintain a low simmer, and let the sauce cook for about 30 minutes, or until it reaches your desired consistency.\nStir in the basil, salt and pepper.  Then taste the sauce, and season with any extra salt, pepper and/or crushed red pepper flakes as needed.\nServe warm.  Or let the sauce cool and then refrigerate it in a sealed container for up to 4 days.",
                    cookingTime  = 40,
                    imageName    = "Arrabiata.jpg"
                },

                new Recipe()
                {
                    recipeName   = "Pizza",
                    recipeId     = 2,
                    description  = "Pizza, dish of Italian origin consisting of a flattened disk of bread dough topped with some combination of olive oil, oregano, tomato, olives, mozzarella or other cheese, and many other ingredients, baked quickly—usually, in a commercial setting, using a wood-fired oven heated to a very high temperature—and served hot.",
                    instructions = "Add warm water to the bowl of a stand mixer with the dough attachment, and sprinkle the yeast on top of the water.  Give the yeast a quick stir to mix it in with the water.  Then let it sit for 5-10 minute until the yeast is foamy.\nTurn the mixer onto low speed, and add gradually flour, honey, olive oil and salt.  Increase speed to medium-low, and continue mixing the dough for 5 minutes.\nRemove dough from the mixing bowl, and use your hands to shape it into a ball.  Grease the mixing bowl (or a separate bowl) with olive oil or cooking spray, then place the dough ball back in the bowl and cover it with a damp towel.  Place in a warm location (I set mine by the window) and let it rise for 30-45 minutes until the dough has nearly doubled in size.\nPreheat oven to 450 degrees F.  Turn the dough onto a floured surface, and roll the dough into a 12- to 14-inch round for a thick-crusted pizza.  (Or cut the dough in half, and roll it into two 12-inch rounds for two thin crust pizzas.)  Sprinkle a baking sheet or pizza stone evenly with the cornmeal, then place the dough on the baking sheet.\nTop the dough with your desired sauce and toppings.  (And for extra-golden crust, brush the crust with an extra few teaspoons of olive oil or butter.)\nFor thick crust, bake for 16-18 minutes, or until the crust is golden brown and the toppings are melted and cooked.  For the (two) thin crusts, bake for 14-16 minutes, or until the crust is golden brown and the toppings are melted and cooked.\nSlice and serve pizza warm.",
                    cookingTime  = 75,
                    imageName    = "Pizza.jpeg"
                },
            };
            foreach (var rec in recipes)
            {
                databaseContext.recipes.Add(rec);
            }
            Console.WriteLine("6");

            Ingredient[] ingredients =
            {
                new Ingredient()
                {
                    ingredientId   = 1,
                    ingredientName = "Garlic",
                    number         = 3,
                    unitType       = "cloves"
                },
                new Ingredient()
                {
                    ingredientId   = 2,
                    ingredientName = "Pasta",
                    number         = 0.5,
                    unitType       = "kg"
                }
            };

            foreach (var ing in ingredients)
            {
                databaseContext.ingredients.Add(ing);
            }
            Console.WriteLine("8");

            databaseContext.SaveChanges();

            Shop[] shops =
            {
                new Shop {
                    shopId      = 1,
                    shopName    = "Lidl",
                    shopAddress = addresses[0]
                },
            };

            foreach (var shop in shops)
            {
                databaseContext.shops.Add(shop);
            }
            Console.WriteLine("9");

            ShopIngredient[] shopIngredients =
            {
                new ShopIngredient()
                {
                    id       = 1,
                    name     = "Garlic",
                    price    = 3,
                    amount   = 3,
                    unitType = "cloves"
                },
                new ShopIngredient()
                {
                    id       = 2,
                    name     = "Pasta",
                    price    = 2,
                    amount   = 0.2,
                    unitType = "kg"
                },
            };

            foreach (var shoping in shopIngredients)
            {
                databaseContext.shopIngredients.Add(shoping);
            }
            Console.WriteLine("10");

            databaseContext.SaveChanges();

            Account steve = await databaseContext.accounts.FirstAsync(s => s.username.Equals("Jannik"));

            Address tek = await databaseContext.addresses.FirstAsync(c => c.street.Equals("Solvgade 1, 3tv"));

            AccountAddress sc = new AccountAddress()
            {
                address = tek,
                account = steve
            };

            steve.AccountAddresses = new List <AccountAddress>();
            steve.AccountAddresses.Add(sc);
            databaseContext.Update(steve);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Account steve2 = await databaseContext.accounts.FirstAsync(s => s.username.Equals("Jannik"));

            BankInfo bankInfo2 = await databaseContext.bankInfos.FirstAsync(c => c.cardNumber == 1234123412341234);

            AccountBankInfo sc2 = new AccountBankInfo()
            {
                account  = steve2,
                bankInfo = bankInfo2
            };

            steve.AccountBankInfos = new List <AccountBankInfo>();
            steve.AccountBankInfos.Add(sc2);
            databaseContext.Update(steve2);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //Connecting ingredients with recipes

            Recipe steve1 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 1);

            Ingredient tek1 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 1);

            IngredientRecipe sc1 = new IngredientRecipe()
            {
                ingredient = tek1,
                recipe     = steve1
            };

            steve1.IngredientRecipes = new List <IngredientRecipe>();
            steve1.IngredientRecipes.Add(sc1);
            databaseContext.Update(steve1);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Recipe steve3 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 1);

            Category bankInfo3 = await databaseContext.categories.FirstAsync(c => c.categoryName.Equals("Italian"));

            RecipeCategory sc3 = new RecipeCategory()
            {
                recipe   = steve3,
                category = bankInfo3
            };

            steve3.RecipeCategories = new List <RecipeCategory>();
            steve3.RecipeCategories.Add(sc3);
            databaseContext.Update(steve3);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();


            //connecting second recipe
            Recipe steve5 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2);

            Ingredient tek5 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 1);

            IngredientRecipe sc5 = new IngredientRecipe()
            {
                ingredient = tek5,
                recipe     = steve5
            };

            steve5.IngredientRecipes = new List <IngredientRecipe>();
            steve5.IngredientRecipes.Add(sc5);
            databaseContext.Update(steve5);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //adding second ingredient
            Recipe steve7 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2);

            Ingredient tek7 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 2);

            IngredientRecipe sc7 = new IngredientRecipe()
            {
                ingredient = tek7,
                recipe     = steve7
            };

            if (steve7.IngredientRecipes == null)
            {
                steve7.IngredientRecipes = new List <IngredientRecipe>();
            }
            steve7.IngredientRecipes.Add(sc7);
            databaseContext.Update(steve7);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Recipe steve6 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2);

            Category bankInfo6 = await databaseContext.categories.FirstAsync(c => c.categoryName.Equals("Greek"));

            RecipeCategory sc6 = new RecipeCategory()
            {
                recipe   = steve6,
                category = bankInfo6
            };

            steve6.RecipeCategories = new List <RecipeCategory>();
            steve6.RecipeCategories.Add(sc6);
            databaseContext.Update(steve6);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //shops


            //adding shopingredients
            Shop shop1 = await databaseContext.shops.FirstAsync(s => s.shopId == 1);

            ShopIngredient shopIngredient1 = await databaseContext.shopIngredients.FirstAsync(c => c.id == 1);

            ShopVare ss1 = new ShopVare()
            {
                shop           = shop1,
                shopIngredient = shopIngredient1
            };

            if (shop1.shopVares == null)
            {
                shop1.shopVares = new List <ShopVare>();
            }
            shop1.shopVares.Add(ss1);
            databaseContext.Update(shop1);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            Shop shop2 = await databaseContext.shops.FirstAsync(s => s.shopId == 1);

            ShopIngredient shopIngredient2 = await databaseContext.shopIngredients.FirstAsync(c => c.id == 2);

            ShopVare ss2 = new ShopVare()
            {
                shop           = shop2,
                shopIngredient = shopIngredient2
            };

            if (shop2.shopVares == null)
            {
                shop2.shopVares = new List <ShopVare>();
            }
            shop2.shopVares.Add(ss2);
            databaseContext.Update(shop2);

            // ctx.Set<StudentCourse>().Add(sc); This is an alternative
            await databaseContext.SaveChangesAsync();

            //update categories in recipes
            Recipe          recipeUp1    = recipes[0];
            Recipe          recipeUp2    = recipes[1];
            List <Category> categoriesUp = await databaseContext.categories.ToListAsync();

            recipeUp1.category = categoriesUp[0];
            recipeUp2.category = categoriesUp[1];
            databaseContext.recipes.Update(recipeUp1);
            databaseContext.recipes.Update(recipeUp2);
            await databaseContext.SaveChangesAsync();

            Console.WriteLine("Finished seeding");
        }
        public async Task <IList <OrderedShopIngredients> > GetShopIngredientsAsync(int id)
        {
            IList <ShopIngredient> allShopIngredients = (List <ShopIngredient>)so.getShopIngredients();

            Console.WriteLine(allShopIngredients[0].name);
            ingredients = (List <Ingredient>)so.getIngredients(id);
            Console.WriteLine(ingredients[0].ingredientName);
            IList <OrderedShopIngredients> orderedShopIngredientses = new List <OrderedShopIngredients>();
            ShopIngredient temporaryIngredient = null;

            foreach (var ingredient in ingredients)
            {
                foreach (var shopIng in allShopIngredients)
                {
                    if (ingredient.ingredientName.Equals(shopIng.name))
                    {
                        if (temporaryIngredient == null)
                        {
                            temporaryIngredient = shopIng;
                        }
                        else
                        {
                            double tempPriceIncrease  = temporaryIngredient.price;
                            double tempAmountIncrease = temporaryIngredient.amount;
                            double tempIngPrice       = temporaryIngredient.price;
                            double tempIngAmount      = temporaryIngredient.amount;
                            while (tempIngAmount < ingredient.number)
                            {
                                tempIngAmount = tempIngAmount + tempPriceIncrease;
                                tempIngPrice  = tempIngPrice + tempAmountIncrease;
                            }

                            double newPriceIncrease  = shopIng.price;
                            double newAmountIncrease = shopIng.amount;
                            double newIngPrice       = shopIng.price;
                            double newIngAmount      = shopIng.amount;
                            while (newIngAmount < ingredient.number)
                            {
                                newIngAmount = newIngAmount + newAmountIncrease;
                                newIngPrice  = newIngPrice + newPriceIncrease;
                            }

                            if (tempIngAmount > newIngAmount)
                            {
                                temporaryIngredient = shopIng;
                            }
                        }
                    }
                }
                double priceIncrease = temporaryIngredient.price;

                double amountIncrease     = temporaryIngredient.amount;
                double temporaryIngPrice  = temporaryIngredient.price;
                double temporaryIngAmount = temporaryIngredient.amount;
                while (temporaryIngAmount < ingredient.number)
                {
                    temporaryIngAmount = temporaryIngAmount + amountIncrease;
                    temporaryIngPrice  = temporaryIngPrice + priceIncrease;
                }
                OrderedShopIngredients newOrd = new OrderedShopIngredients();
                double totalAmount            = temporaryIngAmount;
                totalAmount           = Math.Round(totalAmount, 2);
                newOrd.amount         = (int)Math.Round(totalAmount / amountIncrease);
                newOrd.totalPrice     = temporaryIngPrice;
                newOrd.totalPrice     = Math.Round(newOrd.totalPrice, 2);
                newOrd.shopIngredient = temporaryIngredient;
                newOrd.osId           = 0;
                orderedShopIngredientses.Add(newOrd);
                temporaryIngredient = null;
            }
            Console.WriteLine(orderedShopIngredientses[0].shopIngredient.name);
            return(orderedShopIngredientses);
        }
Ejemplo n.º 11
0
    public virtual void DeSerialize(Dictionary <string, object> elements)
    {
        if (elements.ContainsKey("Name"))
        {
            Name = (string)elements["Name"];
        }

        if (elements.ContainsKey("Price"))
        {
            Price = Convert.ToSingle(elements["Price"]);
        }

        if (elements.ContainsKey("key"))
        {
            Key = (string)elements["key"];
        }

        if (elements.ContainsKey("ProductType"))
        {
            ProductType = (ProductType)Enum.Parse(typeof(ProductType), (string)elements["ProductType"]);
        }

        if (ProductType == ProductType.ON_GOING || ProductType == ProductType.CONSUMABLE)
        {
            if (elements.ContainsKey("Hand"))
            {
                HandSide = (HandSide)Enum.Parse(typeof(HandSide), (string)elements["Hand"]);
            }
            if (elements.ContainsKey("IsInterestingToLookAt"))
            {
                IsInterestingToLookAt = (bool)elements["IsInterestingToLookAt"];
            }
            if (elements.ContainsKey("IsTwoHanded"))
            {
                IsTwoHanded = (bool)elements["IsTwoHanded"];
            }
        }

        switch (ProductType)
        {
        case ProductType.ON_GOING:
        {
            if (elements.ContainsKey("Duration"))
            {
                Duration = Convert.ToInt32(elements["Duration"]);
            }
            if (elements.ContainsKey("RemoveWhenDepleted"))
            {
                RemoveWhenDepleted = (bool)elements["RemoveWhenDepleted"];
            }
            if (elements.ContainsKey("DestroyWhenDepleted"))
            {
                DestroyWhenDepleted = (bool)elements["DestroyWhenDepleted"];
            }
        }
        break;

        case ProductType.CONSUMABLE:
        {
            if (elements.ContainsKey("ConsumeAnimation"))
            {
                ConsumeAnimation = (ConsumeAnimation)Enum.Parse(typeof(ConsumeAnimation), (string)elements["ConsumeAnimation"]);
            }
            if (elements.ContainsKey("Temprature"))
            {
                Temprature = (Temperature)Enum.Parse(typeof(Temperature), (string)elements["Temprature"]);
            }
            if (elements.ContainsKey("Portions"))
            {
                Portions = Convert.ToInt32(elements["Portion"]);
            }
        }
        break;

        case ProductType.WEARABLE:
        {
            if (elements.ContainsKey("BodyLocation"))
            {
                BodyLocation = (Body)Enum.Parse(typeof(Body), (string)elements["BodyLocation"]);
            }
            if (elements.ContainsKey("SeasonalPrefrence"))
            {
                SeasonalPrefrence = (Seasonal)Enum.Parse(typeof(Seasonal), (string)elements["SeasonalPrefrence"]);
            }
            if (elements.ContainsKey("TempreaturePrefrence"))
            {
                TempreaturePrefrence = (Temperature)Enum.Parse(typeof(Temperature), (string)elements["TempreaturePrefrence"]);
            }
            if (elements.ContainsKey("HideOnRide"))
            {
                HideOnRide = (bool)elements["HideOnRide"];
            }
            if (elements.ContainsKey("HideHair"))
            {
                HideHair = (bool)elements["HideHair"];
            }
        }
        break;
        }

        if (elements.ContainsKey("Ingredients"))
        {
            foreach (var ing in (List <object>)elements["Ingredients"])
            {
                ShopIngredient ingredient = new ShopIngredient();
                ingredient.DeSerialize(ing as Dictionary <string, object>);
                Ingredients.Add(ingredient);
            }
        }
    }
Ejemplo n.º 12
0
    private void DrawIngredients()
    {
        Event e = Event.current;

        EditorGUILayout.LabelField("Ingredients:", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal(GUILayout.Height(300));
        EditorGUILayout.BeginVertical("ShurikenEffectBg", GUILayout.Width(150));
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Height(300));

        for (int i = 0; i < Ingredients.Count; i++)
        {
            Color gui = GUI.color;
            if (Ingredients[i] == selected)
            {
                GUI.color = Color.red;
            }

            if (GUILayout.Button(Ingredients[i].Name + "    $" + Ingredients[i].Price + ".00", "ShurikenModuleTitle"))
            {
                GUI.FocusControl("");
                if (e.button == 1)
                {
                    Ingredients.RemoveAt(i);
                    return;
                }

                if (selected == Ingredients[i])
                {
                    selected = null;
                    return;
                }

                selected = Ingredients[i];
            }

            GUI.color = gui;
        }

        EditorGUILayout.EndScrollView();

        if (GUILayout.Button("Add Ingredients"))
        {
            Ingredients.Add(new ShopIngredient());
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical();
        if (selected != null)
        {
            if (!Ingredients.Contains(selected))
            {
                selected = null;
                return;
            }

            selected.Name      = EditorGUILayout.TextField("Ingridient Name ", selected.Name);
            selected.Price     = EditorGUILayout.FloatField("Price ", selected.Price);
            selected.Amount    = EditorGUILayout.FloatField("Amount ", selected.Amount);
            selected.Tweakable = EditorGUILayout.Toggle("Tweakable ", selected.Tweakable);

            for (int i = 0; i < selected.Effects.Count; i++)
            {
                Color gui = GUI.color;

                if (GUILayout.Button("Effector " + selected.Effects[i].Type, "ShurikenModuleTitle"))
                {
                    GUI.FocusControl("");
                    if (e.button == 1)
                    {
                        selected.Effects.RemoveAt(i);
                        return;
                    }
                }

                selected.Effects[i].Type   = (EffectTypes)EditorGUILayout.EnumPopup("Type ", selected.Effects[i].Type);
                selected.Effects[i].Amount = EditorGUILayout.Slider("Amount", selected.Effects[i].Amount, 1f, -1f);
                GUI.color = gui;
            }

            if (GUILayout.Button("Add Effect"))
            {
                selected.Effects.Add(new Effect());
            }
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.EndVertical();
    }
        public async void start()
        {
            Console.WriteLine("Starting server...");

            IPAddress ip = IPAddress.Parse("127.0.0.1");

            TcpListener listener = new TcpListener(ip, 2921);

            listener.Start();

            ReaderWriterDb readerWriterDb = ReaderWriterDb.getInstance();

            Console.WriteLine("Server started...");
            while (true)
            {
                TcpClient client = listener.AcceptTcpClient();
                Console.WriteLine("Client connected");
                NetworkStream stream = client.GetStream();

                byte[] rcvBytes = new byte[1024];
                stream.Read(rcvBytes);
                String rcv = System.Text.Encoding.ASCII.GetString(rcvBytes);

                //Get methods
                if (rcv.Contains("get"))
                {
                    if (rcv.Contains("Accounts"))
                    {
                        content = await readerWriterDb.getAccountsAsync();
                    }
                    else if (rcv.Contains("ShopIngredients"))
                    {
                        content = await readerWriterDb.getShopIngredientsAsync();
                    }
                    else if (rcv.Contains("Shops"))
                    {
                        content = await readerWriterDb.getShopsAsync();
                    }
                    else if (rcv.Contains("Ingredients"))
                    {
                        content = await readerWriterDb.getIngredientsAsync();
                    }
                    else if (rcv.Contains("Recipes"))
                    {
                        content = await readerWriterDb.getRecipesAsync();
                    }
                    else if (rcv.Contains("Orders"))
                    {
                        content = await readerWriterDb.getOrdersAsync();
                    }
                    else if (rcv.Contains("Categories"))
                    {
                        content = await readerWriterDb.getCategoriesAsync();
                    }
                    //Add methods
                }
                else if (rcv.Contains("add"))
                {
                    string subString = rcv.Substring(3);
                    if (rcv.Contains("ShopIngredient"))
                    {
                        content = await readerWriterDb.addObjectAsync(getClientsObject(stream, "ShopIngredient"), "shopIngredient");
                    }
                    else if (rcv.Contains("Ingredient"))
                    {
                        content = await readerWriterDb.addObjectAsync(getClientsObject(stream, "Ingredient"), "ingredient");
                    }
                    else if (rcv.Contains("Shop"))
                    {
                        content = await readerWriterDb.addObjectAsync(getClientsObject(stream, "Shop"), "shop");
                    }
                    else if (rcv.Contains("Recipe"))
                    {
                        String categoryName = "";
                        int    stringEnd    = rcv.IndexOf(":");
                        int    stringStart  = 9;
                        int    length       = stringEnd - 9;
                        categoryName = rcv.Substring(stringStart, length);
                        readerWriterDb.sendCategory(categoryName);
                        content = await readerWriterDb.addObjectAsync(getClientsObject(stream, "Recipe"),
                                                                      "recipe");
                    }
                    //Remove methods
                }
                else if (rcv.Contains("remove"))
                {
                    if (rcv.Contains("ShopIngredient"))
                    {
                        content = await readerWriterDb.removeObjectAsync(getClientsObject(stream, "ShopIngredient"), "shopIngredient");
                    }
                    else if (rcv.Contains("Ingredient"))
                    {
                        content = await readerWriterDb.removeObjectAsync(getClientsObject(stream, "Ingredient"), "ingredient");
                    }
                    else if (rcv.Contains("Shop"))
                    {
                        content = await readerWriterDb.removeObjectAsync(getClientsObject(stream, "Shop"), "shop");
                    }
                    //Update methods
                }
                else if (rcv.Contains("update"))
                {
                    if (rcv.Contains("Shop"))
                    {
                        content = await readerWriterDb.updateObjectAsync(getClientsObject(stream, "Shop"), "shop");
                    }
                    else if (rcv.Contains("Ingredient"))
                    {
                        content = await readerWriterDb.updateObjectAsync(getClientsObject(stream, "Ingredient"), "ingredient");
                    }
                }
                else if (rcv.Contains("link"))
                {
                    if (rcv.Contains("ShopIngredientToShop1"))
                    {
                        shopToLink = (Shop)getClientsObject(stream, "Shop");
                        content    = "received";
                    }
                    else if (rcv.Contains("ShopIngredientToShop2"))
                    {
                        ShopIngredient shopIngredientToLink = (ShopIngredient)getClientsObject(stream, "ShopIngredient");
                        if (shopToLink != null && shopIngredientToLink != null)
                        {
                            content = await readerWriterDb.linkObjectsAsync(shopIngredientToLink, shopToLink, "ShopIngredientToShop");
                        }
                        else
                        {
                            content = "null error";
                        }
                    }
                }
                // Sending
                byte[] toSendBytes = System.Text.Encoding.ASCII.GetBytes(content);
                stream.Write(toSendBytes);

                client.Close();
            }
        }