コード例 #1
0
ファイル: DataPortal.cs プロジェクト: hudsonchoi/Church
        public static void Delete(object criteria)
        {
            Server.DataPortalResult result;

            MethodInfo method = MethodCaller.GetMethod(
                MethodCaller.GetObjectType(criteria), "DataPortal_Delete", criteria);

            DataPortalClient.IDataPortalProxy proxy;
            proxy = GetDataPortalProxy(RunLocal(method));

            Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote);

            OnDataPortalInvoke(new DataPortalEventArgs(dpContext));

            try
            {
                result = proxy.Delete(criteria, dpContext);
            }
            catch (Server.DataPortalException ex)
            {
                result = ex.Result;
                if (proxy.IsServerRemote)
                {
                    ApplicationContext.SetGlobalContext(result.GlobalContext);
                }
                throw new DataPortalException("DataPortal.Delete " + Resources.Failed, ex.InnerException, result.ReturnObject);
            }

            if (proxy.IsServerRemote)
            {
                ApplicationContext.SetGlobalContext(result.GlobalContext);
            }

            OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext));
        }
コード例 #2
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                DataPortalResult result;

                MethodInfo method;
                string     methodName;
                if (obj is CommandBase)
                {
                    methodName = "DataPortal_Execute";
                }
                else if (obj is Core.BusinessBase)
                {
                    Core.BusinessBase tmp = (Core.BusinessBase)obj;
                    if (tmp.IsDeleted)
                    {
                        methodName = "DataPortal_DeleteSelf";
                    }
                    else
                    if (tmp.IsNew)
                    {
                        methodName = "DataPortal_Insert";
                    }
                    else
                    {
                        methodName = "DataPortal_Update";
                    }
                }
                else
                {
                    methodName = "DataPortal_Update";
                }

                method = MethodCaller.GetMethod(obj.GetType(), methodName);

                IDataPortalServer portal;
                switch (TransactionalType(method))
                {
                case TransactionalTypes.EnterpriseServices:
                    portal = new ServicedDataPortal();
                    try
                    {
                        result = portal.Update(obj, context);
                    }
                    finally
                    {
                        ((ServicedDataPortal)portal).Dispose();
                    }
                    break;

                case TransactionalTypes.TransactionScope:
                    portal = new TransactionalDataPortal();
                    result = portal.Update(obj, context);
                    break;

                default:
                    portal = new SimpleDataPortal();
                    result = portal.Update(obj, context);
                    break;
                }
                return(result);
            }
            finally
            {
                ClearContext(context);
            }
        }
コード例 #3
0
ファイル: DataPortal.cs プロジェクト: hudsonchoi/Church
        public static object Update(object obj)
        {
            Server.DataPortalResult result;

            MethodInfo method;
            string     methodName;

            if (obj is CommandBase)
            {
                methodName = "DataPortal_Execute";
            }
            else if (obj is Core.BusinessBase)
            {
                Core.BusinessBase tmp = (Core.BusinessBase)obj;
                if (tmp.IsDeleted)
                {
                    methodName = "DataPortal_DeleteSelf";
                }
                else
                if (tmp.IsNew)
                {
                    methodName = "DataPortal_Insert";
                }
                else
                {
                    methodName = "DataPortal_Update";
                }
            }
            else
            {
                methodName = "DataPortal_Update";
            }

            method = MethodCaller.GetMethod(obj.GetType(), methodName);

            DataPortalClient.IDataPortalProxy proxy;
            proxy = GetDataPortalProxy(RunLocal(method));

            Server.DataPortalContext dpContext =
                new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote);

            OnDataPortalInvoke(new DataPortalEventArgs(dpContext));

            try
            {
                result = proxy.Update(obj, dpContext);
            }
            catch (Server.DataPortalException ex)
            {
                result = ex.Result;
                if (proxy.IsServerRemote)
                {
                    ApplicationContext.SetGlobalContext(result.GlobalContext);
                }
                throw new DataPortalException("DataPortal.Update " +
                                              Resources.Failed, ex.InnerException, result.ReturnObject);
            }

            if (proxy.IsServerRemote)
            {
                ApplicationContext.SetGlobalContext(result.GlobalContext);
            }

            OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext));

            return(result.ReturnObject);
        }
コード例 #4
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                // tell the business object we're about to make a DataPortal_xyz call
                MethodCaller.CallMethodIfImplemented(obj, "DataPortal_OnDataPortalInvoke", new DataPortalEventArgs(context));

                // tell the business object to update itself
                if (obj is Core.BusinessBase)
                {
                    Core.BusinessBase busObj = (Core.BusinessBase)obj;
                    if (busObj.IsDeleted)
                    {
                        if (!busObj.IsNew)
                        {
                            // tell the object to delete itself
                            MethodCaller.CallMethod(busObj, "DataPortal_DeleteSelf");
                        }
                        // mark the object as new
                        MethodCaller.CallMethodIfImplemented(busObj, "MarkNew");
                    }
                    else
                    {
                        if (busObj.IsNew)
                        {
                            // tell the object to insert itself
                            MethodCaller.CallMethod(busObj, "DataPortal_Insert");
                        }
                        else
                        {
                            // tell the object to update itself
                            MethodCaller.CallMethod(
                                busObj, "DataPortal_Update");
                        }
                        // mark the object as old
                        MethodCaller.CallMethodIfImplemented(busObj, "MarkOld");
                    }
                }
                else if (obj is CommandBase)
                {
                    // tell the object to update itself
                    MethodCaller.CallMethod(
                        obj, "DataPortal_Execute");
                }
                else
                {
                    MethodCaller.CallMethod(obj, "DataPortal_Update");
                    // mark the object as old
                    MethodCaller.CallMethodIfImplemented(obj, "MarkOld");
                }


                MethodCaller.CallMethodIfImplemented(obj, "DataPortal_OnDataPortalInvokeComplete", new DataPortalEventArgs(context));

                return(new DataPortalResult(obj));
            }
            catch (Exception ex)
            {
                try
                {
                    MethodCaller.CallMethodIfImplemented(obj, "DataPortal_OnDataPortalException", new DataPortalEventArgs(context), ex);
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new DataPortalException("DataPortal.Update " + Resources.FailedOnServer, ex, new DataPortalResult(obj));
            }
        }
コード例 #5
0
 public DataPortalEventArgs(Server.DataPortalContext dataPortalContext)
 {
     _dataPortalContext = dataPortalContext;
 }
コード例 #6
0
        public DataPortalResult Delete(object criteria, DataPortalContext context)
        {
            SimpleDataPortal portal = new SimpleDataPortal();

            return(portal.Delete(criteria, context));
        }
コード例 #7
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            SimpleDataPortal portal = new SimpleDataPortal();

            return(portal.Update(obj, context));
        }