Esempio n. 1
0
        public T this[PairItem Index]
        {
            get
            {
                switch (Index)
                {
                case PairItem.First:
                    return(First);

                case PairItem.Second:
                    return(Second);

                default:
                    throw new Exception();
                }
            }
            set
            {
                switch (Index)
                {
                case PairItem.First:
                    First = value;
                    break;

                case PairItem.Second:
                    Second = value;
                    break;

                default:
                    throw new Exception();
                }
            }
        }
 public T this[PairItem index]
 {
     get
     {
         return(index switch
         {
             PairItem.First => First,
             PairItem.Second => Second,
             _ => throw new NotImplementedException(
                 $"The enum {index} has not been implemented"),
         });
Esempio n. 3
0
        /// <summary>
        /// Pair Items
        /// </summary>
        /// <returns></returns>
        private List <string> GetPairItems()
        {
            List <Day> days = _shedule.SheduleGroups.First(q => q.Name == _user.GroupName).Days;

            foreach (var day in days)
            {
                PairItem.AddRange(day.Pairs.Select(q => q.Lesson));
            }
            PairItem = PairItem.Distinct().ToList();

            return(PairItem);
        }
Esempio n. 4
0
            public   T this[PairItem index] {
                get {
                    switch (index)
                    {
                    case PairItem.First:
                        return(First);

                    case PairItem.Second:
                        return(Second);

                    default:
                        throw new NotImplementedException($"The enum {index.ToString()} has not been implemented");
                    }
                }
            }
Esempio n. 5
0
        public static async void Populate(DatabaseContext s)
        {
            var categoryRepo = new IngredientsCategoryRepository(s);
            IEnumerable <IngredientCategory> categories = GetDefaultCategories();

            foreach (var ingredientCategory in categories)
            {
                await categoryRepo.Add(ingredientCategory);
            }
            var fridgeRepos    = new FridgeRepository(s);
            var ingredientRepo = new IngredientsRepository(s, categoryRepo, fridgeRepos);
            var recipeRepo     = new RecipesRepository(s, fridgeRepos, ingredientRepo);

            Ingredient i1   = Ingredient.Create(categories.First().Id, "i1", "cup", 0.9);
            Ingredient i2   = Ingredient.Create(categories.First().Id, "i2", "piece", 1.9);
            Ingredient i3   = Ingredient.Create(categories.First().Id, "i3", "slice", 0.5);
            Ingredient i4   = Ingredient.Create(categories.First().Id, "i3", "cup", 30);
            User       user = User.Create("xx", true, "*****@*****.**", "sh", "sdsbdk", "sureal");

            var userRepo = new UsersRepository(s);
            await userRepo.Add(user);

            await ingredientRepo.Add(i1);

            await ingredientRepo.Add(i2);

            await ingredientRepo.Add(i3);

            await ingredientRepo.Add(i4);

            Recipe recipe1 = Recipe.Create(user.Id, "r1", "reteta", RecipeStatusType.Approved, 10, 1, KitchenType.Asian);
            Recipe recipe2 = Recipe.Create(user.Id, "r2", "reteta2", RecipeStatusType.Approved, 15, 2, KitchenType.Unspecified);
            await recipeRepo.Add(recipe1);

            await recipeRepo.Add(recipe2);

            await recipeRepo.UpdateAllCosts();

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe1.Id, 2));

            await fridgeRepos.Add(PairItem.Create(i2.Id, recipe1.Id, 4));

            await fridgeRepos.Add(PairItem.Create(i3.Id, recipe1.Id, 1));

            await fridgeRepos.Add(PairItem.Create(i1.Id, recipe2.Id, 3));
        }
        public async Task AddIngredientCustom(Guid recipeId, string categoryName, string measureUnit, string name,
                                              double quantity, double cost, double weight)
        {
            Ingredient ingredient;

            if (!await Exists(name, measureUnit))
            {
                Guid categoryId;
                if (!await _ingredientsCategoryRepository.Exists(categoryName))
                {
                    IngredientCategory igCat = IngredientCategory.Create(categoryName);
                    await _ingredientsCategoryRepository.Add(igCat);

                    categoryId = igCat.Id;
                }
                else
                {
                    categoryId = (await _ingredientsCategoryRepository.GetByName(categoryName)).Id;
                }
                double scale = IngredientsRepository.MapMeasurement["undefined"];
                if (IngredientsRepository.MapMeasurement.ContainsKey(measureUnit))
                {
                    scale = IngredientsRepository.MapMeasurement[measureUnit];
                }

                ingredient = Ingredient.Create(categoryId, name, measureUnit, cost * scale * weight / 10000000);
                await Add(ingredient);
                await UpdateIngredientsCategory(name, await GetSpecificCategory(name));
            }
            else
            {
                if (!categoryName.Equals("other-ingredients"))
                {
                    if (!await _ingredientsCategoryRepository.Exists(categoryName))
                    {
                        IngredientCategory igCat = IngredientCategory.Create(categoryName);
                        await _ingredientsCategoryRepository.Add(igCat);
                    }
                    await UpdateIngredientsCategory(name, (await _ingredientsCategoryRepository.GetByName(categoryName)).Id);
                }
                ingredient = await GetByNameAndMeasure(name, measureUnit);
            }
            await _fridgeRepository.Add(PairItem.Create(ingredient.Id, recipeId, quantity));
        }
        }                        // C# 6.0 Getter-Only Autoproperty

        public T this[PairItem index]
        {
            get
            {
                switch (index)
                {
                case PairItem.First:
                    return(First);

                case PairItem.Second:
                    return(Second);

                default:
                    throw new NotImplementedException(
                              string.Format(
                                  "The enum {0} has not been implemented",
                                  index.ToString()));
                }
            }

            /*
             * // In keeping with the principal that structs should
             * // be read-only, the setter is commented out
             *
             * set
             * {
             *  switch(index)
             *  {
             *      case PairItem.First:
             *          First = value;
             *          break;
             *      case PairItem.Second:
             *          Second = value;
             *          break;
             *      default:
             *          throw new NotImplementedException(
             *              string.Format(
             *              "The enum {0} has not been implemented",
             *              index.ToString()));
             *  }
             * }
             */
        }
Esempio n. 8
0
    // parse the cookie name and value
    /// <summary>
    /// 解析Cookie的名字和值
    /// </summary>
    /// <param name="ckNameValueExpr"></param>
    /// <param name="pair"></param>
    /// <returns></returns>
    public static bool ParseCookieNameValue(string ckNameValueExpr, out PairItem pair)
    {
        bool parsedOk = false;

        if (ckNameValueExpr == "")
        {
            pair.Key   = "";
            pair.Value = "";
            parsedOk   = false;
        }
        else
        {
            ckNameValueExpr = ckNameValueExpr.Trim();

            int equalPos = ckNameValueExpr.IndexOf('=');
            if (equalPos > 0) // is valid expression
            {
                pair.Key = ckNameValueExpr.Substring(0, equalPos);
                pair.Key = pair.Key.Trim();
                if (IsValidCookieName(pair.Key))
                {
                    // only process while is valid cookie field
                    pair.Value = ckNameValueExpr.Substring(equalPos + 1);
                    pair.Value = pair.Value.Trim();
                    parsedOk   = true;
                }
                else
                {
                    pair.Key   = "";
                    pair.Value = "";
                    parsedOk   = false;
                }
            }
            else
            {
                pair.Key   = "";
                pair.Value = "";
                parsedOk   = false;
            }
        }
        return(parsedOk);
    }
Esempio n. 9
0
        public T this[PairItem index]
        {
            get
            {
                switch (index)
                {
                case PairItem.First:
                    return(First);

                case PairItem.Second:
                    return(Second);

                default:
                    throw new NotImplementedException(
                              string.Format(
                                  "The enum {0} has not been implemented",
                                  index.ToString()));
                }
            }
            #endregion Indexer
        }
Esempio n. 10
0
        public static IEnumerable <PairItem> GetPairItems(int count = 1)
        {
            List <PairItem> items = new List <PairItem>
            {
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 1.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 5.3f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 8.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 9.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 3.4f),
                PairItem.Create(Guid.NewGuid(), Guid.NewGuid(), 2.1f)
            };

            if (0 >= count)
            {
                throw new IndexOutOfRangeException("Null or negative count [in BaseIntegrationTest class]");
            }
            if (items.Count < count)
            {
                throw new IndexOutOfRangeException("Not enough users in Pair Item List [in BaseIntegrationTest class]");
            }
            return(items.Take(count));
        }
 public T this[PairItem index]
 {
     get
     {
         PairItem pairItem  = index;
         PairItem pairItem2 = pairItem;
         T        result;
         if (pairItem2 != PairItem.First)
         {
             if (pairItem2 != PairItem.Second)
             {
                 throw new NotImplementedException(string.Format("The enum {0} has not been implemented", index.ToString()));
             }
             result = Second;
         }
         else
         {
             result = First;
         }
         return(result);
     }
 }
Esempio n. 12
0
    //add recognized cookie field: expires/domain/path/secure/httponly/version, into cookie
    /// <summary>
    /// 添加字段到Cookie.
    /// </summary>
    /// <param name="ck">Cookie对象</param>
    /// <param name="pairInfo"></param>
    /// <returns></returns>
    public static bool AddFieldToCookie(ref Cookie ck, PairItem pairInfo)
    {
        bool added = false;

        if (pairInfo.Key != "")
        {
            string lowerKey = pairInfo.Key.ToLower();
            switch (lowerKey)
            {
            case "expires":
                DateTime expireDatetime;
                bool     parseDatetimeOk = false;
                parseDatetimeOk = DateTime.TryParse(pairInfo.Value, out expireDatetime);
                if (parseDatetimeOk)
                {
                    // note: here coverted to local time: GMT +8
                    ck.Expires = expireDatetime;

                    //update expired filed
                    if (DateTime.Now.Ticks > ck.Expires.Ticks)
                    {
                        ck.Expired = true;
                    }

                    added = true;
                }
                break;

            case "domain":
                ck.Domain = pairInfo.Value;
                added     = true;
                break;

            case "secure":
                ck.Secure = true;
                added     = true;
                break;

            case "path":
                ck.Path = pairInfo.Value;
                added   = true;
                break;

            case "httponly":
                ck.HttpOnly = true;
                added       = true;
                break;

            case "version":
                int versionValue;
                if (int.TryParse(pairInfo.Value, out versionValue))
                {
                    ck.Version = versionValue;
                    added      = true;
                }
                break;

            default:
                break;
            }
        }

        return(added);
    } //addFieldToCookie
Esempio n. 13
0
    // parse cookie field expression

    /// <summary>
    /// 解析Cookie的项和域值
    /// </summary>
    /// <param name="ckFieldExpr"></param>
    /// <param name="pair"></param>
    /// <returns></returns>
    public bool ParseCookieField(string ckFieldExpr, out PairItem pair)
    {
        bool parsedOk = false;

        if (ckFieldExpr == "")
        {
            pair.Key   = "";
            pair.Value = "";
            parsedOk   = false;
        }
        else
        {
            ckFieldExpr = ckFieldExpr.Trim();

            //some specials: secure/httponly
            if (ckFieldExpr.ToLower() == "httponly")
            {
                pair.Key = "httponly";
                //pair.value = "";
                pair.Value = "true";
                parsedOk   = true;
            }
            else if (ckFieldExpr.ToLower() == "secure")
            {
                pair.Key = "secure";
                //pair.value = "";
                pair.Value = "true";
                parsedOk   = true;
            }
            else // normal cookie field
            {
                int equalPos = ckFieldExpr.IndexOf('=');
                if (equalPos > 0) // is valid expression
                {
                    pair.Key = ckFieldExpr.Substring(0, equalPos);
                    pair.Key = pair.Key.Trim();
                    if (IsValidCookieField(pair.Key))
                    {
                        // only process while is valid cookie field
                        pair.Value = ckFieldExpr.Substring(equalPos + 1);
                        pair.Value = pair.Value.Trim();
                        parsedOk   = true;
                    }
                    else
                    {
                        pair.Key   = "";
                        pair.Value = "";
                        parsedOk   = false;
                    }
                }
                else
                {
                    pair.Key   = "";
                    pair.Value = "";
                    parsedOk   = false;
                }
            }
        }

        return(parsedOk);
    } //parseCookieField