public bool PerformOperation(DirectoryAction action)
        {
            ImmutableHashSet <string> hashset;

            switch (action.Element)
            {
            case DirectoryElement.User: hashset = _users; break;

            case DirectoryElement.Connection: hashset = _connections; break;

            case DirectoryElement.Group: hashset = _groups; break;

            default:
                throw new NotImplementedException();     //TODO proper exception
            }

            ImmutableHashSet <string> newHashSet = hashset;

            if (action.Action == DirectoryElementAction.Add)
            {
                newHashSet = hashset.Add(action.Item);
            }
            else
            {
                newHashSet = hashset.Remove(action.Item);
            }

            if (newHashSet != hashset)
            {
                switch (action.Element)
                {
                case DirectoryElement.User: Interlocked.Exchange(ref _users, newHashSet); break;

                case DirectoryElement.Connection: Interlocked.Exchange(ref _connections, newHashSet); break;

                case DirectoryElement.Group: Interlocked.Exchange(ref _groups, newHashSet); break;
                }

                return(true);
            }

            return(false);
        }
示例#2
0
        public Task PerformAction(DirectoryAction action)
        {
            var _hub = _hubs.GetOrAdd(action.Hub, _ => new ClusterNodeHubDirectory());


            lock (_syncObject)
            {
                var operationSequence = this.Sequence;

                if (_hub.PerformOperation(action))
                {
                    var remoteOperation = new RemoteDirectoryOperation(_membershipProvider.GetOwnUniqueId(), Sequence, action);

                    this.Sequence = this.Sequence == Int32.MaxValue ? 0 : this.Sequence++;

                    _actionHistory.Add(action);

                    return(_clusterClient.BroadcastDirectoryOperation(new[] { remoteOperation }));
                }
            }

            return(Task.CompletedTask);
        }
示例#3
0
 public RemoteDirectoryOperation(string node, int sequence, DirectoryAction action)
 {
     Node     = node;
     Sequence = sequence;
     Action   = action;
 }