Exemplo n.º 1
0
        /// <summary>
        /// Called by the business object's Save() method to
        /// insert, update or delete an object in the database.
        /// </summary>
        /// <param name="obj">A reference to the business object to be updated.</param>
        /// <param name="loc">The loc.</param>
        /// <returns>
        /// A reference to the updated business object.
        /// </returns>
        /// <remarks>
        /// Note that this method returns a reference to the updated business object.
        /// If the server-side DataPortal is running remotely, this will be a new and
        /// different object from the original, and all object references MUST be updated
        /// to use this new object.
        /// </remarks>
        public static object Update(object obj, DataPortalLocation loc = DataPortalLocation.Dynamic)
        {
            try
            {
                RafyEnvironment.ThreadPortalCount++;

                object res = null;

                //只是不要纯客户端,都直接使用本地访问
                if (loc == DataPortalLocation.Local || RafyEnvironment.Location.ConnectDataDirectly)
                {
                    /*********************** 代码块解释 *********************************
                     *
                     * 由于开发人员平时会使用单机版本开发,而正式部署时,又会选用 C/S 架构。
                     * 所以需要保证单机版本和 C/S 架构版本的模式是一样的。也就是说,在单机模式下,
                     * 在通过门户访问时,模拟网络版,clone 出一个新的对象。
                     * 这样,在底层 Update 更改 obj 时,不会影响上层的实体。
                     * 而是以返回值的形式把这个被修改的实体返回给上层。
                     *
                     * 20120828
                     * 但是,当在服务端本地调用时,不需要此模拟功能。
                     * 这是因为在服务端本地调用时(例如服务端本地调用 RF.Save),
                     * 在开发体验上,数据层和上层使用的实体应该是同一个,数据层的修改应该能够带回到上层,不需要克隆。
                     *
                     **********************************************************************/

                    //ThreadPortalCount == 1 表示第一次进入数据门户
                    if (RafyEnvironment.Location.IsWPFUI && RafyEnvironment.Location.ConnectDataDirectly && RafyEnvironment.ThreadPortalCount == 1)
                    {
                        res = ObjectCloner.Clone(obj);
                    }
                    else
                    {
                        res = obj;
                    }

                    FinalDataPortal.Update(res);
                }
                else
                {
                    var proxy = GetDataPortalProxy();

                    var dpContext = CreateDataPortalContext();

                    var result = proxy.Update(obj, dpContext);

                    res = ReadServerResult(result);
                }

                return(res);
            }
            finally
            {
                RafyEnvironment.ThreadPortalCount--;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update a business object.
        /// </summary>
        /// <param name="obj">Business object to update.</param>
        /// <param name="context">
        /// <see cref="DataPortalContext" /> object passed to the server.
        /// </param>
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                var portal = new FinalDataPortal();
                var result = portal.Update(obj, context);

                return(result);
            }
            finally
            {
                ClearContext(context);
            }
        }