Пример #1
0
        private LiteDataTable DataPortalFetchTable(IEQC ieqc)
        {
            ieqc.FetchType = FetchType.Table;

            this.OnFetching(ieqc);

            return(DataPortalApi.Fetch(this.GetType(), ieqc, this.DataPortalLocation) as LiteDataTable);
        }
Пример #2
0
        private EntityList DataPortalFetchList(IEQC ieqc)
        {
            this.OnFetching(ieqc);

            var list = DataPortalApi.Fetch(this.GetType(), ieqc, this.DataPortalLocation) as EntityList;

            this.NotifyLoaded(list);

            return(list);
        }
Пример #3
0
        /// <summary>
        /// 调用服务并把返回值转换为指定的类型。
        /// </summary>
        /// <returns></returns>
        public void Invoke()
        {
            this.OnInvoking();

            if (this.DataPortalLocation == DataPortalLocation.Local)
            {
                //由于在本地,所以没有必须调用 ExecuteByDataPortal 来清除不用的属性。
                this.Execute();
            }
            else
            {
                var res = DataPortalApi.Update(this) as IService;

                this.ReadOutput(res);
            }

            this.OnInvoked();
        }
Пример #4
0
        public void Intercept(IInvocation invocation)
        {
            #region 预处理,根据返回值的类型来判断 FetchType。

            //if (Attribute.IsDefined(invocation.TargetType, typeof(IgnoreProxyAttribute))
            //    || Attribute.IsDefined(invocation.Method, typeof(IgnoreProxyAttribute)))
            //{
            //    invocation.Proceed();
            //    return;
            //}

            var fetchType  = RepositoryQueryType.List;
            var returnType = invocation.Method.ReturnType;
            if (returnType.IsClass)
            {
                if (typeof(EntityList).IsAssignableFrom(returnType))
                {
                    fetchType = RepositoryQueryType.List;
                }
                else if (typeof(Entity).IsAssignableFrom(returnType))
                {
                    fetchType = RepositoryQueryType.First;
                }
                else if (returnType == typeof(LiteDataTable))
                {
                    fetchType = RepositoryQueryType.Table;
                }
                else
                {
                    throw new NotSupportedException("仓库查询不支持返回 {0} 类型。".FormatArgs(returnType));
                }
            }
            else
            {
                fetchType = RepositoryQueryType.Count;
            }

            #endregion

            var ieqc = new IEQC
            {
                MethodName = invocation.Method.Name,
                Parameters = invocation.Arguments,
                QueryType  = fetchType
            };

            var repoExt = invocation.InvocationTarget as IRepositoryExt;
            var repo    = invocation.InvocationTarget as EntityRepository ?? repoExt.Repository as EntityRepository;

            //只是不要纯客户端,都直接使用本地访问
            if (repo.DataPortalLocation == DataPortalLocation.Local || RafyEnvironment.Location.ConnectDataDirectly)
            {
                using (FinalDataPortal.CurrentQueryCriteriaItem.UseScopeValue(ieqc))
                {
                    try
                    {
                        RafyEnvironment.ThreadPortalCount++;

                        if (repoExt != null)
                        {
                            //invoke repositoryExt
                            invocation.Proceed();
                        }
                        else
                        {
                            //先尝试在 DataProvider 中调用指定的方法,如果没有找到,才会调用 Repository 中的方法。
                            //这样可以使得 DataProvider 中定义同名方法即可直接重写仓库中的方法。
                            object result = null;
                            if (MethodCaller.CallMethodIfImplemented(
                                    repo.DataProvider, invocation.Method.Name, invocation.Arguments, out result
                                    ))
                            {
                                invocation.ReturnValue = result;
                            }
                            else
                            {
                                //invoke repository
                                invocation.Proceed();
                            }
                        }
                    }
                    finally
                    {
                        RafyEnvironment.ThreadPortalCount--;
                    }
                }
            }
            else
            {
                //调用数据门户,使得在服务端才执行真正的数据层方法。
                invocation.ReturnValue = DataPortalApi.Fetch(invocation.TargetType, ieqc, repo.DataPortalLocation);
            }

            #region Repository.NotifyLoaded

            switch (fetchType)
            {
            case RepositoryQueryType.List:
                var list = invocation.ReturnValue as EntityList;
                repo.NotifyLoaded(list);
                break;

            case RepositoryQueryType.First:
                var entity = invocation.ReturnValue as Entity;
                repo.NotifyLoaded(entity);
                break;

            case RepositoryQueryType.Count:
            case RepositoryQueryType.Table:
            default:
                break;
            }

            #endregion
        }
Пример #5
0
 /// <summary>
 /// 通过门户来保存指定的实体类/列表。
 ///
 /// 所有使用 Save 方法保存的实体,都会通过这个方法来选择是分布式保存、还是直接保存。
 /// 此方法是仓库接口门户层的最后一个方法,之后将会在服务端(如果是分布式)发布 Submit 数据提交操作。
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 private IDomainComponent SaveToPortal(IDomainComponent component)
 {
     return(DataPortalApi.Update(component, this.DataPortalLocation) as IDomainComponent);
 }
Пример #6
0
        protected IEnumerable <TEntity> FetchList(object criteria, string methodName)
        {
            var list = DataPortalApi.Action(this.GetType(), methodName, criteria, this.DataPortalLocation) as IEnumerable <TEntity>;

            return(list);
        }