Ejemplo n.º 1
0
 /// <summary>
 /// Called by the client-side DataPortal to update an object.
 /// </summary>
 /// <remarks>
 /// This method delegates to 
 /// <see cref="SimpleDataPortal">SimpleDataPortal</see>
 /// but wraps that call within a
 /// <see cref="TransactionScope">TransactionScope</see>
 /// to provide transactional support via
 /// System.Transactions.
 /// </remarks>
 /// <param name="obj">A reference to the object being updated.</param>
 /// <param name="context">Context data from the client.</param>
 /// <returns>A reference to the newly updated object.</returns>
 public DataPortalResult Update(object obj, DataPortalContext context)
 {
     DataPortalResult result;
     using (TransactionScope tr = new TransactionScope())
     {
         SimpleDataPortal portal = new SimpleDataPortal();
         result = portal.Update(obj, context);
         tr.Complete();
     }
     return result;
 }
Ejemplo n.º 2
0
 public DataPortalResult Update(object obj, DataPortalContext context)
 {
     SimpleDataPortal portal = new SimpleDataPortal();
     return portal.Update(obj, context);
 }
Ejemplo n.º 3
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;
            }
            catch (DataPortalException ex)
            {
                Exception tmp = ex;
                throw;
            }
            catch (Exception ex)
            {
                throw new DataPortalException(
                  "DataPortal.Update " + "Failed on server",
                  ex, new DataPortalResult());
            }
            finally
            {
                ClearContext(context);
            }
        }