示例#1
0
        //=========================================
        // AttributesAgent (core)
        //=========================================
        #region AttributesAgent (core)

        public void Add <T>(string attributeSetName, string attributeName, T value)
        {
            var set = _repository.AttributeSetOf(attributeSetName);

            if (set.IsNone)
            {
                var newSet = AttributeSet.Named(attributeSetName);
                newSet.AddIfAbsent(Attribute <T> .From(attributeName, value));
                _repository.Add(newSet);
                _client.SyncWith(newSet);
                _confirmingDistributor.DistributeCreate(newSet);
            }
            else
            {
                var newlyTracked = set.AddIfAbsent(Attribute <T> .From(attributeName, value));
                if (!newlyTracked.IsDistributed)
                {
                    _confirmingDistributor.Distribute(set, newlyTracked, ApplicationMessageType.AddAttribute);
                }
            }
        }
示例#2
0
        internal void DistributeTo(
            AttributeSet set,
            TrackedAttribute tracked,
            ApplicationMessageType type,
            IEnumerable <Node> nodes)
        {
            switch (type)
            {
            case ApplicationMessageType.AddAttribute:
                var add            = AddAttribute.From(_node, set, tracked);
                var addConfirmable = _confirmables.UnconfirmedFor(add, nodes);
                _outbound.Application(ApplicationSays.From(_node.Id, _node.Name, add.ToPayload()), addConfirmable.UnconfirmedNodes);
                _application.InformAttributeAdded(set.Name !, tracked.Attribute?.Name);
                break;

            case ApplicationMessageType.RemoveAttribute:
                var remove            = RemoveAttribute.From(_node, set, tracked);
                var removeConfirmable = _confirmables.UnconfirmedFor(remove, nodes);
                _outbound.Application(ApplicationSays.From(_node.Id, _node.Name, remove.ToPayload()), removeConfirmable.UnconfirmedNodes);
                _application.InformAttributeRemoved(set.Name !, tracked.Attribute?.Name);
                break;

            case ApplicationMessageType.RemoveAttributeSet:
                var removeSet            = RemoveAttributeSet.From(_node, set);
                var removeSetConfirmable = _confirmables.UnconfirmedFor(removeSet, nodes);
                _outbound.Application(ApplicationSays.From(_node.Id, _node.Name, removeSet.ToPayload()), removeSetConfirmable.UnconfirmedNodes);
                _application.InformAttributeSetRemoved(set.Name);
                break;

            case ApplicationMessageType.ReplaceAttribute:
                var replace            = ReplaceAttribute.From(_node, set, tracked);
                var replaceConfirmable = _confirmables.UnconfirmedFor(replace, nodes);
                _outbound.Application(ApplicationSays.From(_node.Id, _node.Name, replace.ToPayload()), replaceConfirmable.UnconfirmedNodes);
                _application.InformAttributeReplaced(set.Name !, tracked.Attribute?.Name);
                break;

            default:
                throw new InvalidOperationException("Cannot distribute unknown ApplicationMessageType.");
            }
        }
 internal void SyncWithout(AttributeSet set)
 {
     _repository.Remove(set.Name);
 }
 internal void SyncWith(AttributeSet set)
 {
     _repository.SyncWith(set.Copy(set));
 }
示例#5
0
 internal void Distribute(AttributeSet set, TrackedAttribute tracked, ApplicationMessageType type) =>
 DistributeTo(set, tracked, type, _allOtherNodes);
示例#6
0
 internal void DistributeCreate(AttributeSet set) => DistributeTo(set, _allOtherNodes);
示例#7
0
 public void DistributeRemove(AttributeSet set) => DistributeRemoveTo(set, _allOtherNodes);
 internal void SyncWith(AttributeSet set) => _all.AddOrUpdate(set.Name, set, (s, attributeSet) => set);
示例#9
0
 internal void Add(AttributeSet set) => _all.AddOrUpdate(set.Name !, set, (s, attributeSet) => set);