Example #1
0
        public IList <INumericRangeBlockContext> GetNumericRangeBlocks(Func <IFluentNumericRangeBlockDescriptor, object> fluentBlockRequest)
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

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

            var request = ConvertToNumericRangeBlockRequest(settings);

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

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