Ejemplo n.º 1
0
        public IList <IListBlockContext <T> > GetListBlocks <T>(Func <IFluentListBlockDescriptorBase <T>, object> fluentBlockRequest)
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var fluentDescriptor = fluentBlockRequest(new FluentListBlockDescriptorBase <T>());
            var settings         = (IBlockSettings)fluentDescriptor;

            if (settings.BlockType == BlockType.List)
            {
                var request = ConvertToListBlockRequest(settings);
                if (ShouldProtect(request))
                {
                    using (var csContext = CreateClientCriticalSection())
                    {
                        var csStarted = csContext.TryStart(new TimeSpan(0, 0, 20), 3);
                        if (csStarted)
                        {
                            return(_blockFactory.GenerateListBlocks <T>(request));
                        }
                        throw new CriticalSectionException("Could not start a critical section in the alloted time");
                    }
                }
                else
                {
                    return(_blockFactory.GenerateListBlocks <T>(request));
                }
            }

            throw new NotSupportedException("BlockType not supported");
        }