Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (id_ != null)
            {
                hash ^= Id.GetHashCode();
            }
            if (Status != 0)
            {
                hash ^= Status.GetHashCode();
            }
            if (paymentsAccount_ != null)
            {
                hash ^= PaymentsAccount.GetHashCode();
            }
            if (paymentsAccountInfo_ != null)
            {
                hash ^= PaymentsAccountInfo.GetHashCode();
            }
            if (startTimeCase_ == StartTimeOneofCase.StartDateTime)
            {
                hash ^= StartDateTime.GetHashCode();
            }
            if (startTimeCase_ == StartTimeOneofCase.StartTimeType)
            {
                hash ^= StartTimeType.GetHashCode();
            }
            if (endTimeCase_ == EndTimeOneofCase.EndDateTime)
            {
                hash ^= EndDateTime.GetHashCode();
            }
            if (endTimeCase_ == EndTimeOneofCase.EndTimeType)
            {
                hash ^= EndTimeType.GetHashCode();
            }
            hash ^= (int)startTimeCase_;
            hash ^= (int)endTimeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ResourceName.Length != 0)
            {
                hash ^= ResourceName.GetHashCode();
            }
            if (id_ != null)
            {
                hash ^= Id.GetHashCode();
            }
            if (Status != global::Google.Ads.GoogleAds.V2.Enums.BillingSetupStatusEnum.Types.BillingSetupStatus.Unspecified)
            {
                hash ^= Status.GetHashCode();
            }
            if (paymentsAccount_ != null)
            {
                hash ^= PaymentsAccount.GetHashCode();
            }
            if (paymentsAccountInfo_ != null)
            {
                hash ^= PaymentsAccountInfo.GetHashCode();
            }
            if (startTimeCase_ == StartTimeOneofCase.StartDateTime)
            {
                hash ^= StartDateTime.GetHashCode();
            }
            if (startTimeCase_ == StartTimeOneofCase.StartTimeType)
            {
                hash ^= StartTimeType.GetHashCode();
            }
            if (endTimeCase_ == EndTimeOneofCase.EndDateTime)
            {
                hash ^= EndDateTime.GetHashCode();
            }
            if (endTimeCase_ == EndTimeOneofCase.EndTimeType)
            {
                hash ^= EndTimeType.GetHashCode();
            }
            hash ^= (int)startTimeCase_;
            hash ^= (int)endTimeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 3
0
        private IAlgorithm GetAlgorithm(string storageType, TimeSpan statWindow, StartTimeType startTimeType, int limitNumber, int lockSeconds)
        {
            var fixedWindowRules = new FixedWindowRule[]
            {
                new FixedWindowRule()
                {
                    Id            = Guid.NewGuid().ToString(),
                    StatWindow    = statWindow,
                    StartTimeType = startTimeType,
                    LimitNumber   = limitNumber,
                    LockSeconds   = lockSeconds,
                    ExtractTarget = (request) =>
                    {
                        return((request as SimulationRequest).RequestResource);
                    },
                    CheckRuleMatching = (request) =>
                    {
                        return(true);
                    },
                    ExtractTargetAsync = (request) =>
                    {
                        return(Task.FromResult((request as SimulationRequest).RequestResource));
                    },
                    CheckRuleMatchingAsync = (request) =>
                    {
                        return(Task.FromResult(true));
                    },
                }
            };

            if (storageType == "redis")
            {
                var redisClient = StackExchange.Redis.ConnectionMultiplexer.Connect("127.0.0.1");
                return(new RedisFixedWindowAlgorithm(fixedWindowRules, redisClient));
            }
            else
            {
                return(new InProcessFixedWindowAlgorithm(fixedWindowRules));
            }
        }
Exemplo n.º 4
0
        private IAlgorithm GetAlgorithm(string storageType, int capacity, int outflowQuantity, TimeSpan outflowUnit, int lockSeconds, StartTimeType startTimeType = StartTimeType.FromCurrent)
        {
            var leakyBucketRules = new LeakyBucketRule[]
            {
                new LeakyBucketRule(capacity, outflowQuantity, outflowUnit)
                {
                    Id            = Guid.NewGuid().ToString(),
                    LockSeconds   = lockSeconds,
                    StartTimeType = startTimeType,
                    ExtractTarget = (request) =>
                    {
                        return((request as SimulationRequest).RequestResource);
                    },
                    CheckRuleMatching = (request) =>
                    {
                        return(true);
                    },
                }
            };

            if (storageType == "redis")
            {
                var redisClient = StackExchange.Redis.ConnectionMultiplexer.Connect("127.0.0.1");
                return(new RedisLeakyBucketAlgorithm(leakyBucketRules, redisClient));
            }
            else
            {
                return(new InProcessLeakyBucketAlgorithm(leakyBucketRules));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Convert to the time of specified type
        /// </summary>
        /// <param name="startTimeMilliseonds"></param>
        /// <param name="statWindow"></param>
        /// <param name="startTimeType"></param>
        /// <returns></returns>
        public static long ToSpecifiedTypeTime(long startTimeMilliseonds, TimeSpan statWindow, StartTimeType startTimeType)
        {
            if (startTimeType == StartTimeType.FromNaturalPeriodBeign)
            {
                DateTimeOffset startTimeUtc = DateTimeOffset.FromUnixTimeMilliseconds(startTimeMilliseonds);
                DateTimeOffset startTime    = AlgorithmStartTime.ToNaturalPeriodBeignTime(startTimeUtc, statWindow);
                return(startTime.ToUnixTimeMilliseconds());
            }

            return(startTimeMilliseonds);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Convert to the time of specified type
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="statWindow"></param>
        /// <param name="startTimeType"></param>
        /// <returns></returns>
        public static DateTimeOffset ToSpecifiedTypeTime(DateTimeOffset startTime, TimeSpan statWindow, StartTimeType startTimeType)
        {
            if (startTimeType == StartTimeType.FromNaturalPeriodBeign)
            {
                startTime = AlgorithmStartTime.ToNaturalPeriodBeignTime(startTime, statWindow);
            }

            return(startTime);
        }