Ejemplo n.º 1
0
        /// <summary>
        /// <para>初始化与领域对象相关的行为,由于许多行为是第一次使用对象的时候才触发,这样会导致没有使用对象却需要一些额外特性的时候缺少数据</para>
        /// <para>所以我们需要在使用领域驱动的之前执行初始化操作</para>
        /// </summary>
        internal static void Initialize()
        {
            if (_initialized)
            {
                return;
            }
            _initialized = true;

            //以下代码执行顺序不能变
            TypeIndex = GetTypeIndex();

            //指定动态类型的定义
            RemoteType.Initialize();

            //执行远程能力特性的初始化,收集相关数据
            RemotableAttribute.Initialize();


            //触发没有派生类的领域对象的静态构造
            foreach (var objectType in TypeIndex)
            {
                if (DerivedClassAttribute.IsDerived(objectType))
                {
                    continue;                                              //不执行派生类的
                }
                DomainObject.StaticConstructor(objectType);
            }

            //先执行派生类的
            DerivedClassAttribute.Initialize();

            //再执行扩展的
            ExtendedClassAttribute.Initialize();
        }
Ejemplo n.º 2
0
        private object FindObject(RemotableAttribute tip, DTObject arg)
        {
            var idProperty = DomainProperty.GetProperty(tip.ObjectType, EntityObject.IdPropertyName);
            var id         = DataUtil.ToValue(arg.GetValue("id"), idProperty.PropertyType);

            var repository = Repository.Create(tip.ObjectType);

            return(repository.Find(id, QueryLevel.None));
        }
Ejemplo n.º 3
0
        internal static void Cleanup()
        {
            var tips = RemotableAttribute.GetTips();

            foreach (var tip in tips)
            {
                var methodName = RemoteServiceName.GetObject(tip.RemoteType);
                RPCServer.Close(methodName);
            }

            //取消订阅
            CancelEvents();
        }
Ejemplo n.º 4
0
        private string GetSchemaCode(RemotableAttribute tip, DTObject arg)
        {
            var metadataSchemaCode = arg.GetValue("schemaCode", string.Empty);

            if (string.IsNullOrEmpty(metadataSchemaCode))
            {
                return(tip.SchemaCode);                                         //外界没有传递对象代码,那么使用默认的代码
            }
            if (string.IsNullOrEmpty(tip.SchemaCode))
            {
                return(metadataSchemaCode);                                                            //没有设置默认代码,表示不限制外界方面的数据
            }
            return(_isSafe(tip.SchemaCode)(metadataSchemaCode) ? metadataSchemaCode : tip.SchemaCode); //外界的代码超出规定,那么仅用限定的代码
        }
Ejemplo n.º 5
0
        internal static void Initialize()
        {
            //开启获取远程对象的RPC服务
            var tips = RemotableAttribute.GetTips();

            foreach (var tip in tips)
            {
                var methodName = RemoteServiceName.GetObject(tip.RemoteType);
                RPCServer.Open(methodName, GetRemoteObject.Instance);
            }

            //订阅事件
            SubscribeEvents();
        }
Ejemplo n.º 6
0
        static AggregateRoot()
        {
            var objectType = typeof(TObject);

            _remotableTip = RemotableAttribute.GetTip(objectType);
        }
Ejemplo n.º 7
0
        private RemotableAttribute GetTip(DTObject arg)
        {
            var typeName = arg.GetValue <string>("typeName"); //这是远程类型的全称

            return(RemotableAttribute.GetTip(typeName));
        }