Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iJSON"></param>
        /// <returns></returns>
        public static FunctionLimiter FromJSON(String iJSON)
        {
            JObject         pJOtLimiter   = JObject.Parse(iJSON);
            FunctionLimiter pFLrLimiter   = new FunctionLimiter();
            JArray          pJAyFunctions = pJOtLimiter["Functions"].Value <JArray>();

            foreach (JObject curFunction in pJAyFunctions)
            {
                FunctionLimiterFunction pFLFCurFunction = FunctionLimiterFunction.FromJSON(curFunction);
                pFLrLimiter.cLisFunctions.Add(pFLFCurFunction);
                pFLrLimiter.cDicFunctions.Add(pFLFCurFunction.Name, pFLFCurFunction);
            }
            return(pFLrLimiter);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="iJSON"></param>
        /// <returns></returns>
        public static FunctionLimiterFunction FromJSON(JObject iJSON)
        {
            FunctionLimiterFunction pFLFFunction = new FunctionLimiterFunction();

            pFLFFunction.cStrName = iJSON["Name"].Value <String>();
            JArray pJAyLimts = iJSON["Limits"].Value <JArray>();

            foreach (JObject curLimit in pJAyLimts)
            {
                FunctionLimiterLimit pFLLCurLimit = FunctionLimiterLimit.FromJSON(curLimit);
                pFLFFunction.cLisLimits.Add(pFLLCurLimit);
            }
            return(pFLFFunction);
        }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="iStorage"></param>
 /// <param name="iFunctionName"></param>
 /// <param name="iSource"></param>
 /// <returns></returns>
 public Boolean Allowed(Storage iStorage,
                        String iFunctionName,
                        String iSource)
 {
     if (cDicFunctions.ContainsKey(iFunctionName))
     {
         List <FunctionHit> pLisHits = iStorage.GetHits(iFunctionName,
                                                        iSource,
                                                        DateTime.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0)));
         FunctionLimiterFunction pFLFFunction = cDicFunctions[iFunctionName];
         foreach (FunctionLimiterLimit curLimit in pFLFFunction.Limits)
         {
             if (curLimit.Exceeded(pLisHits))
             {
                 return(false);
             }
         }
     }
     return(true);
 }