public DataPortalResult Update(object obj, DataPortalContext context) { try { SetContext(context); Authorize(new AuthorizeRequest(obj.GetType(), obj, DataPortalOperations.Update)); DataPortalResult result; DataPortalMethodInfo method; var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType()); if (factoryInfo != null) { string methodName; var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName); var bbase = obj as Core.BusinessBase; if (bbase != null) { if (bbase.IsDeleted) { methodName = factoryInfo.DeleteMethodName; } else { methodName = factoryInfo.UpdateMethodName; } } else if (obj is Core.ICommandObject) { methodName = factoryInfo.ExecuteMethodName; } else { methodName = factoryInfo.UpdateMethodName; } method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, new object[] { obj }); } else { string methodName; var bbase = obj as Core.BusinessBase; if (bbase != null) { if (bbase.IsDeleted) { methodName = "DataPortal_DeleteSelf"; } else if (bbase.IsNew) { methodName = "DataPortal_Insert"; } else { methodName = "DataPortal_Update"; } } else if (obj is Core.ICommandObject) { methodName = "DataPortal_Execute"; } else { methodName = "DataPortal_Update"; } method = DataPortalMethodCache.GetMethodInfo(obj.GetType(), methodName); } context.TransactionalType = method.TransactionalType; IDataPortalServer portal; switch (method.TransactionalType) { 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 DataPortalSelector(); result = portal.Update(obj, context); break; } return(result); } catch (Csla.Server.DataPortalException ex) { Exception tmp = ex; throw; } catch (Exception ex) { throw new DataPortalException( "DataPortal.Update " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex), new DataPortalResult()); } finally { ClearContext(context); } }
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); } }