Exemple #1
0
 protected override void Init(Lifetime lifetime)
 {
     base.Init(lifetime);
     Proto.ClientIdSet.View(lifetime, (clientIdLt, clientId) =>
     {
         var value = myValueFactory(IsMaster).WithId(RdId.Mix(clientId.Value));
         value.Bind(clientIdLt, this, $"[{clientId.Value}]");
         myMap.Add(clientId, value);
         clientIdLt.OnTermination(() => myMap.Remove(clientId));
     });
 }
Exemple #2
0
        protected override void Init(Lifetime lifetime)
        {
            base.Init(lifetime);
            var protocolValueSet = Proto.Contexts.GetValueSet(Context);

            myMap.Keys.Where(it => !protocolValueSet.Contains(it)).ToList().ForEach(it => myMap.Remove(it));
            protocolValueSet.View(lifetime, (contextValueLifetime, contextValue) =>
            {
                myMap.TryGetValue(contextValue, out var oldValue);
                var value = (oldValue ?? myValueFactory(IsMaster)).WithId(RdId.Mix(contextValue.ToString()));
                value.Bind(contextValueLifetime, this, $"[{contextValue.ToString()}]");
                if (oldValue == null)
                {
                    myMap.Add(contextValue, value);
                }
                contextValueLifetime.OnTermination(() =>
                {
                    value.RdId = RdId.Nil;
                });
            });
        }