public IImmutableQueue<TimeSpan> EnqueueElapsed(IImmutableQueue<TimeSpan> currentTimes)
        {
            if (!this.hasTimingInformation)
                return currentTimes;

            return currentTimes.Enqueue(this.Elapsed);
        }
 public PermissionsProvider(Permissions permissions, ContextType? activeDirectoryContextType = null)
 {
     this.permissions = permissions;
     this.requiredRights = ConsolidateRights(permissions.RequiredRights, permissions.RequiredRoles);
     this.restrictedRights = ConsolidateRights(permissions.RestrictedRights, permissions.RestrictedRoles);
     this.requiredRoles = GetManualRoles(permissions.RequiredRoles);
     this.restrictedRoles = GetManualRoles(permissions.RestrictedRoles);
     this.requiredActiveDirectoryRoles = GetActiveDirectoryRoles(permissions.RequiredRoles);
     this.restrictedActiveDirectoryRoles = GetActiveDirectoryRoles(permissions.RestrictedRoles);
     this.activeDirectoryContextType = activeDirectoryContextType; 
 }
        public ContractBundle(IImmutableQueue<IContractCondition> preconditions = null,
                              IImmutableQueue<IContractCondition> postconditionsOnReturn = null,
                              IImmutableQueue<IContractCondition> postconditionsOnThrow = null,
                              IImmutableQueue<Action> instanceValidations = null,
                              int threadCountRestriction = 0,
                              WaitTimeout? threadCountRestrictionTimeout = null,
                              WaitHandle threadWaitHandleSignalRestriction = null,
                              WaitTimeout? threadWaitHandleSignalRestrictionTimeout = null)
        {
            this.Preconditions = preconditions.DefaultIfNull();
            this.PostconditionsOnReturn = postconditionsOnReturn.DefaultIfNull();
            this.PostconditionsOnThrow = postconditionsOnThrow.DefaultIfNull();
            this.InstanceValidations = instanceValidations.DefaultIfNull();
            this.ThreadCountRestriction = threadCountRestriction;
            this.ThreadCountRestrictionTimeout = threadCountRestrictionTimeout.DefaultIfNull();

            //Not defaulting this because null is checked for and verifying a default handle would be confusing to the caller
            this.ThreadWaitHandleSignalRestriction = threadWaitHandleSignalRestriction; 

            this.ThreadWaitHandleSignalRestrictionTimeout = threadWaitHandleSignalRestrictionTimeout.DefaultIfNull();
        }
 public LockTransactionContractBundle(IImmutableQueue<IContractCondition> preconditions = null,
                                      IImmutableQueue<IContractCondition> postconditionsOnReturn = null,
                                      IImmutableQueue<IContractCondition> postconditionsOnThrow = null,
                                      IImmutableQueue<Action> instanceValidations = null,
                                      int threadCountRestriction = 0,
                                      WaitTimeout? threadCountRestrictionTimeout = null,
                                      WaitHandle threadWaitHandleSignalRestriction = null,
                                      WaitTimeout? threadWaitHandleSignalRestrictionTimeout = null,
                                      ILockTransactionMember[] transactionMembers = null,
                                      LockOrder lockOrder = Runtime.LockOrder.Unknown)
     :base(preconditions,
           postconditionsOnReturn,
           postconditionsOnThrow,
           instanceValidations,
           threadCountRestriction, 
           threadCountRestrictionTimeout,
           threadWaitHandleSignalRestriction,
           threadWaitHandleSignalRestrictionTimeout)
 {
     this.transactionMembers = transactionMembers.DefaultIfNull();
     this.lockOrder = lockOrder;
 }
Example #5
0
 private State(
     int logViewMax,
     IImmutableQueue<ProcessLogItem> log
 )
 {
     LogViewMax = logViewMax;
     Log        = log;
 }
Example #6
0
 public State(int logViewMax)
 {
     LogViewMax = logViewMax;
     Log        = Queue<ProcessLogItem>();
 }
 private IContractBundle Copy(IImmutableQueue<IContractCondition> preconditions = null,
                              IImmutableQueue<IContractCondition> postconditionsOnReturn = null,
                              IImmutableQueue<IContractCondition> postconditionsOnThrow = null,
                              IImmutableQueue<Action> instanceValidations = null,
                              int? threadCountRestriction = null,
                              WaitTimeout? threadCountRestrictionTimeout = null,
                              WaitHandle threadWaitHandleSignalRestriction = null,
                              WaitTimeout? threadWaitHandleSignalRestrictionTimeout = null)
 {
     return new ContractBundle(preconditions ?? this.Preconditions,
                               postconditionsOnReturn ?? this.PostconditionsOnReturn,
                               postconditionsOnThrow ?? this.PostconditionsOnThrow,
                               instanceValidations ?? this.InstanceValidations,
                               threadCountRestriction ?? this.ThreadCountRestriction,
                               threadCountRestrictionTimeout ?? this.ThreadCountRestrictionTimeout,
                               threadWaitHandleSignalRestriction ?? this.ThreadWaitHandleSignalRestriction,
                               threadWaitHandleSignalRestrictionTimeout ?? this.ThreadWaitHandleSignalRestrictionTimeout);
 }
        private bool VerifyActiveDirectoryRoles(IIdentity identity, IImmutableQueue<IRole> roles, Func<bool,bool> isValid)
        {
            if (roles.IsEmpty)
                return true;

            if (this.activeDirectoryContextType == null)
                return true;

            var contextType = this.activeDirectoryContextType.Value;
            var context = new PrincipalContext(contextType);
            var user = UserPrincipal.FindByIdentity(context, identity.Name);

            if (user == null)
                throw new IdentityConfigurationException(String.Format("Identity '{0}' requires Active Directory but could not be found", identity.Name));

            for (var currentRoles = roles; !currentRoles.IsEmpty; currentRoles = currentRoles.Dequeue())
            {
                var role = currentRoles.Peek();
                var isMember = user.IsMemberOf(context, IdentityType.SamAccountName, role.Name);

                if (!isValid(isMember))
                    return false;
            }

            return true;
        }
Example #9
0
        public static void ArrayAsRootObject()
        {
            const string ExpectedJson         = @"[1,true,{""City"":""MyCity""},null,""foo""]";
            const string ReversedExpectedJson = @"[""foo"",null,{""City"":""MyCity""},true,1]";

            string[] expectedObjects = { @"""foo""", @"null", @"{""City"":""MyCity""}", @"true", @"1" };

            var address = new Address();

            address.Initialize();

            var    array = new object[] { 1, true, address, null, "foo" };
            string json  = JsonSerializer.ToString(array);

            Assert.Equal(ExpectedJson, json);

            var dictionary = new Dictionary <string, string> {
                { "City", "MyCity" }
            };
            var arrayWithDictionary = new object[] { 1, true, dictionary, null, "foo" };

            json = JsonSerializer.ToString(arrayWithDictionary);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(array);
            Assert.Equal(ExpectedJson, json);

            List <object> list = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(list);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(list);
            Assert.Equal(ExpectedJson, json);

            IEnumerable ienumerable = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(ienumerable);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(ienumerable);
            Assert.Equal(ExpectedJson, json);

            IList ilist = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(ilist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(ilist);
            Assert.Equal(ExpectedJson, json);

            ICollection icollection = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(icollection);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(icollection);
            Assert.Equal(ExpectedJson, json);

            IEnumerable <object> genericIEnumerable = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(genericIEnumerable);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(genericIEnumerable);
            Assert.Equal(ExpectedJson, json);

            IList <object> genericIList = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(genericIList);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(genericIList);
            Assert.Equal(ExpectedJson, json);

            ICollection <object> genericICollection = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(genericICollection);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(genericICollection);
            Assert.Equal(ExpectedJson, json);

            IReadOnlyCollection <object> genericIReadOnlyCollection = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(genericIReadOnlyCollection);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(genericIReadOnlyCollection);
            Assert.Equal(ExpectedJson, json);

            IReadOnlyList <object> genericIReadonlyList = new List <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(genericIReadonlyList);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(genericIReadonlyList);
            Assert.Equal(ExpectedJson, json);

            ISet <object> iset = new HashSet <object> {
                1, true, address, null, "foo"
            };

            json = JsonSerializer.ToString(iset);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(iset);
            Assert.Equal(ExpectedJson, json);

            Stack <object> stack = new Stack <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(stack);
            Assert.Equal(ReversedExpectedJson, json);

            json = JsonSerializer.ToString <object>(stack);
            Assert.Equal(ReversedExpectedJson, json);

            Queue <object> queue = new Queue <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(queue);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(queue);
            Assert.Equal(ExpectedJson, json);

            HashSet <object> hashset = new HashSet <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(hashset);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(hashset);
            Assert.Equal(ExpectedJson, json);

            LinkedList <object> linkedlist = new LinkedList <object>(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(linkedlist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(linkedlist);
            Assert.Equal(ExpectedJson, json);

            IImmutableList <object> iimmutablelist = ImmutableList.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(iimmutablelist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(iimmutablelist);
            Assert.Equal(ExpectedJson, json);

            IImmutableStack <object> iimmutablestack = ImmutableStack.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(iimmutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            json = JsonSerializer.ToString <object>(iimmutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            IImmutableQueue <object> iimmutablequeue = ImmutableQueue.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(iimmutablequeue);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(iimmutablequeue);
            Assert.Equal(ExpectedJson, json);

            IImmutableSet <object> iimmutableset = ImmutableHashSet.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(iimmutableset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            json = JsonSerializer.ToString <object>(iimmutableset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            ImmutableHashSet <object> immutablehashset = ImmutableHashSet.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(immutablehashset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            json = JsonSerializer.ToString <object>(immutablehashset);
            foreach (string obj in expectedObjects)
            {
                Assert.Contains(obj, json);
            }

            ImmutableList <object> immutablelist = ImmutableList.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(immutablelist);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(immutablelist);
            Assert.Equal(ExpectedJson, json);

            ImmutableStack <object> immutablestack = ImmutableStack.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(immutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            json = JsonSerializer.ToString <object>(immutablestack);
            Assert.Equal(ReversedExpectedJson, json);

            ImmutableQueue <object> immutablequeue = ImmutableQueue.CreateRange(new List <object> {
                1, true, address, null, "foo"
            });

            json = JsonSerializer.ToString(immutablequeue);
            Assert.Equal(ExpectedJson, json);

            json = JsonSerializer.ToString <object>(immutablequeue);
            Assert.Equal(ExpectedJson, json);
        }
Example #10
0
 protected QueuedAwaitableStateMachineBase(TState initialState, AwaitableConfiguration <TState, TTrigger> config)
     : base(initialState, config)
 {
     m_actionsQueue = ImmutableQueue.Create <Func <Task> >();
 }