/// <summary> /// Update a business object. /// </summary> /// <param name="obj">Business object to update.</param> /// <param name="context"> /// <see cref="Server.DataPortalContext" /> object passed to the server. /// </param> /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param> public Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { if (DataPortalServer != null) { return(DataPortalServer.Update(obj, context, isSync)); } else { return(DataPortalSelector.Update(obj, context, isSync)); } }
/// <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()) { var portal = new DataPortalSelector(); result = portal.Update(obj, context); tr.Complete(); } return(result); }
/// <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> /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param> /// <returns>A reference to the newly updated object.</returns> public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { DataPortalResult result; using (TransactionScope tr = CreateTransactionScope()) { var portal = new DataPortalSelector(); result = await portal.Update(obj, context, isSync).ConfigureAwait(false); tr.Complete(); } return(result); }
public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { try { SetContext(context); Initialize(new InterceptArgs { Parameter = obj, Operation = DataPortalOperations.Update, IsSync = isSync }); AuthorizeRequest(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); } #if !SILVERLIGHT && !NETFX_CORE context.TransactionalType = method.TransactionalAttribute.TransactionType; #else context.TransactionalType = method.TransactionalType; #endif IDataPortalServer portal; #if !SILVERLIGHT && !NETFX_CORE switch (method.TransactionalAttribute.TransactionType) { #if !MONO case TransactionalTypes.EnterpriseServices: portal = GetServicedComponentPortal(method.TransactionalAttribute); try { result = await portal.Update(obj, context, isSync); } finally { ((System.EnterpriseServices.ServicedComponent)portal).Dispose(); } break; #endif case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(method.TransactionalAttribute); result = await portal.Update(obj, context, isSync); break; default: portal = new DataPortalSelector(); result = await portal.Update(obj, context, isSync); break; } #else portal = new DataPortalSelector(); result = await portal.Update(obj, context, isSync); #endif Complete(new InterceptArgs { Parameter = obj, Result = result, Operation = DataPortalOperations.Update, IsSync = isSync }); return(result); } catch (Csla.Server.DataPortalException ex) { Complete(new InterceptArgs { Parameter = obj, Exception = ex, Operation = DataPortalOperations.Update, IsSync = isSync }); throw; } catch (AggregateException ex) { Exception error = null; if (ex.InnerExceptions.Count > 0) { error = ex.InnerExceptions[0].InnerException; } else { error = ex; } var fex = DataPortal.NewDataPortalException( "DataPortal.Update " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", error), obj); Complete(new InterceptArgs { Parameter = obj, Exception = fex, Operation = DataPortalOperations.Update, IsSync = isSync }); throw fex; } catch (Exception ex) { var fex = DataPortal.NewDataPortalException( "DataPortal.Update " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex), obj); Complete(new InterceptArgs { Parameter = obj, Exception = fex, Operation = DataPortalOperations.Update, IsSync = isSync }); throw fex; } finally { ClearContext(context); } }
public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { var portal = new DataPortalSelector(); return(await portal.Update(obj, context, isSync)); }
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 async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { var portal = new DataPortalSelector(); return await portal.Update(obj, context, isSync).ConfigureAwait(false); }
public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { Type objectType = null; DataPortalOperations operation = DataPortalOperations.Update; try { SetContext(context); objectType = obj.GetType(); if (obj is Core.ICommandObject) operation = DataPortalOperations.Execute; Initialize(new InterceptArgs { ObjectType = objectType, Parameter = obj, Operation = operation, IsSync = isSync }); AuthorizeRequest(new AuthorizeRequest(objectType, obj, operation)); DataPortalResult result; DataPortalMethodInfo method; var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType); 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); } #if !SILVERLIGHT && !NETFX_CORE context.TransactionalType = method.TransactionalAttribute.TransactionType; #else context.TransactionalType = method.TransactionalType; #endif IDataPortalServer portal; #if !SILVERLIGHT && !NETFX_CORE switch (method.TransactionalAttribute.TransactionType) { #if !MONO case TransactionalTypes.EnterpriseServices: portal = GetServicedComponentPortal(method.TransactionalAttribute); try { result = await portal.Update(obj, context, isSync).ConfigureAwait(false); } finally { ((System.EnterpriseServices.ServicedComponent)portal).Dispose(); } break; #endif case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(method.TransactionalAttribute); result = await portal.Update(obj, context, isSync).ConfigureAwait(false); break; default: portal = new DataPortalSelector(); result = await portal.Update(obj, context, isSync).ConfigureAwait(false); break; } #else portal = new DataPortalSelector(); result = await portal.Update(obj, context, isSync).ConfigureAwait(false); #endif Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Result = result, Operation = operation, IsSync = isSync }); return result; } catch (Csla.Server.DataPortalException ex) { Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = ex, Operation = operation, IsSync = isSync }); throw; } catch (AggregateException ex) { Exception error = null; if (ex.InnerExceptions.Count > 0) error = ex.InnerExceptions[0].InnerException; else error = ex; var fex = DataPortal.NewDataPortalException( "DataPortal.Update " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", error), obj); Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = fex, Operation = operation, IsSync = isSync }); throw fex; } catch (Exception ex) { var fex = DataPortal.NewDataPortalException( "DataPortal.Update " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex), obj); Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = fex, Operation = operation, IsSync = isSync }); throw fex; } finally { ClearContext(context); } }
/// <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> /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param> /// <returns>A reference to the newly updated object.</returns> public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { DataPortalResult result; using (TransactionScope tr = CreateTransactionScope()) { var portal = new DataPortalSelector(); result = await portal.Update(obj, context, isSync); tr.Complete(); } return result; }
public DataPortalResult Update(object obj, DataPortalContext context) { var portal = new DataPortalSelector(); return(portal.Update(obj, context)); }