Esempio n. 1
0
        public IList <IDateRangeBlockContext> GetDateRangeBlocks(Func <IFluentDateRangeBlockDescriptor, object> fluentBlockRequest)
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var fluentDescriptor = fluentBlockRequest(new FluentRangeBlockDescriptor());
            var settings         = (IBlockSettings)fluentDescriptor;

            var request = ConvertToDateRangeBlockRequest(settings);

            if (ShouldProtect(request))
            {
                using (var csContext = CreateClientCriticalSection())
                {
                    var csStarted = csContext.TryStart(new TimeSpan(0, 0, 20), 3);
                    if (csStarted)
                    {
                        return(_blockFactory.GenerateDateRangeBlocks(request));
                    }

                    throw new CriticalSectionException("Could not start a critical section in the alloted time");
                }
            }
            else
            {
                return(_blockFactory.GenerateDateRangeBlocks(request));
            }
        }