示例#1
0
        public IList <IObjectBlockContext <T> > GetObjectBlocks <T>(Func <IFluentObjectBlockDescriptorBase <T>, object> fluentBlockRequest)
        {
            if (!IsExecutionContextActive)
            {
                throw new ExecutionException(NotActiveMessage);
            }

            var fluentDescriptor = fluentBlockRequest(new FluentObjectBlockDescriptorBase <T>());
            var settings         = (IObjectBlockSettings <T>)fluentDescriptor;

            var request = ConvertToObjectBlockRequest(settings);

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