public static ITrapForThrottling CreateSimpleWait(string name, int requestQuota, RequestQuoteTimePeriodType requestQuoteTimePeriodType)
        {
            WriteToLog(string.Format("TrapForThrottling::CreateSimpleWait ({0})", name), WriteLogType.Info);
            var item = new TrapForThrottlingSimpleWait(name, requestQuota, requestQuoteTimePeriodType);

            return(AddItemToStorage(item));
        }
        public void TrapForThrottlingRunInterval()
        {
            var t1 = new TrapForThrottlingSimpleWait("test", 1, RequestQuoteTimePeriodType.PerSecond);

            Assert.AreEqual(1, t1.RunWithIntervalInSeconds.TotalSeconds);
            var t2 = new TrapForThrottlingSimpleWait("test", 6, RequestQuoteTimePeriodType.PerMinute);

            Assert.AreEqual(10, t2.RunWithIntervalInSeconds.TotalSeconds);

            var t3 = new TrapForThrottlingSimpleWait("test", 10, RequestQuoteTimePeriodType.PerSecond);

            Assert.AreEqual(100, t3.RunWithIntervalInSeconds.TotalMilliseconds);
            var t4 = new TrapForThrottlingSimpleWait("test", 60, RequestQuoteTimePeriodType.PerMinute);

            Assert.AreEqual(1, t4.RunWithIntervalInSeconds.TotalSeconds);
        }
        public void TrapForThrottlingSimple()
        {
            var t = new TrapForThrottlingSimpleWait("test", 6, RequestQuoteTimePeriodType.PerSecond);
            //var t = new TrapForThrottlingSimpleWait( "test", 6, CommonLib.TrapForThrottlingSimpleWait.RequestQuoteTimePeriodType.PerMinute );

            var tasks = new List <Task>();

            Debug.WriteLine(string.Format("[{0}] Start", DateTime.Now));

            for (int i = 0; i < 10; i++)
            {
                var name = string.Format("Action #{0}", i + 1);

                tasks.Add(Task.Factory.StartNew(() => t.Execute(new ActionInfo(name)
                {
                    Action = () => { },
                    Access = ActionAccessType.Full,
                })));
            }

            Task.WaitAll(tasks.ToArray());
            Debug.WriteLine(string.Format("[{0}] Finish", DateTime.Now));
        }