コード例 #1
0
        public virtual void Identify(IIdentities identities, RdId id)
        {
            Assertion.Require(RdId.IsNil, "Already has RdId: {0}, entity: {1}", RdId, this);
            Assertion.Require(!id.IsNil, "Assigned RdId mustn't be null, entity: {0}", this);

            RdId = id;
            foreach (var pair in BindableChildren)
            {
                pair.Value?.IdentifyPolymorphic(identities, id.Mix("." + pair.Key));
            }
        }
コード例 #2
0
ファイル: HeavySingleContextHandler.cs プロジェクト: yvvan/rd
        protected override void Init(Lifetime lifetime)
        {
            base.Init(lifetime);

            Assertion.Assert(myHandler.IsSendWithoutContexts, "Must bind context handler without sending contexts to prevent reentrancy");

            myInternRoot.RdId       = RdId.Mix("InternRoot");
            myProtocolValueSet.RdId = RdId.Mix("ValueSet");

            myInternRoot.Bind(lifetime, this, "InternRoot");
            myProtocolValueSet.Bind(lifetime, this, "ValueSet");

            myProtocolValueSet.Advise(lifetime, HandleProtocolSetEvent);
        }
コード例 #3
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;
                });
            });
        }
コード例 #4
0
        private T GetOrCreateExtension <T>([NotNull] string name, bool highPriorityExtension, [NotNull] Func <T> create) where T : class
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (create == null)
            {
                throw new ArgumentNullException(nameof(create));
            }

            lock (myExtensions)
            {
                object existing;
                T      res;
                if (myExtensions.TryGetValue(name, out existing))
                {
                    res = existing.NotNull("Found null value for key: '{0}'", name) as T;
                    Assertion.Require(res != null, "Found bad value for key '{0}'. Expected type: '{1}', actual:'{2}", name, typeof(T).FullName, existing.GetType().FullName);
                }
                else
                {
                    res = create().NotNull("'Create' result must not be null");

                    myExtensions[name] = res;
                    if (res is IRdBindable)
                    {
                        var bindable = res as IRdBindable;
                        BindableChildren.Insert(highPriorityExtension ? 0 : BindableChildren.Count, new KeyValuePair <string, object>(name, bindable));
                        if (myBindLifetime != Lifetime.Terminated)
                        {
                            bindable.Identify(Proto.Identities, RdId.Mix("." + name));
                            bindable.Bind(myBindLifetime, this, name);
                        }
                    }
                }

                return(res);
            }
        }