/// <summary> /// Called by the client-side DataProtal to retrieve 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="objectType">Type of business object to retrieve.</param> /// <param name="criteria">Object-specific criteria.</param> /// <param name="context">Object containing context data from client.</param> /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param> /// <returns>A populated business object.</returns> public async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync) { DataPortalResult result; using (TransactionScope tr = CreateTransactionScope()) { result = await _portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); tr.Complete(); } return(result); }
public async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync) { var portal = new DataPortalBroker(); return(await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false)); }
/// <summary> /// Get an existing business object. /// </summary> /// <param name="objectType">Type of business object to retrieve.</param> /// <param name="criteria">Criteria object describing business object.</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 async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync) { try { SetContext(context); Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Fetch, IsSync = isSync }); AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Fetch)); DataPortalResult result; DataPortalMethodInfo method = DataPortalMethodCache.GetFetchMethod(objectType, criteria); IDataPortalServer portal; #if !(ANDROID || IOS) && !NETFX_CORE switch (method.TransactionalAttribute.TransactionType) { #if !MONO case TransactionalTypes.EnterpriseServices: portal = GetServicedComponentPortal(method.TransactionalAttribute); try { result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); } finally { ((System.EnterpriseServices.ServicedComponent)portal).Dispose(); } break; #endif case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(method.TransactionalAttribute); result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); break; default: portal = new DataPortalBroker(); result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); break; } #else portal = new DataPortalBroker(); result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); #endif Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Fetch, IsSync = isSync }); return(result); } catch (Csla.Server.DataPortalException ex) { Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Fetch, 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.Fetch " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Fetch", error), null); Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync }); throw fex; } catch (Exception ex) { var fex = DataPortal.NewDataPortalException( "DataPortal.Fetch " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Fetch", ex), null); Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync }); throw fex; } finally { ClearContext(context); } }
/// <summary> /// Get an existing business object. /// </summary> /// <param name="objectType">Type of business object to retrieve.</param> /// <param name="criteria">Criteria object describing business object.</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 async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync) { try { SetContext(context); Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Fetch, IsSync = isSync }); AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Fetch)); DataPortalResult result; DataPortalMethodInfo method; Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo; if (criteria is EmptyCriteria) { serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <FetchAttribute>(objectType, null); } else { serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <FetchAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria)); } serviceProviderMethodInfo.PrepForInvocation(); method = serviceProviderMethodInfo.DataPortalMethodInfo; IDataPortalServer portal; switch (method.TransactionalAttribute.TransactionType) { #if !NETSTANDARD2_0 && !NET5_0 case TransactionalTypes.EnterpriseServices: portal = GetServicedComponentPortal(method.TransactionalAttribute); try { result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); } finally { ((System.EnterpriseServices.ServicedComponent)portal).Dispose(); } break; #endif case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(method.TransactionalAttribute); result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); break; default: portal = new DataPortalBroker(); result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false); break; } Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Fetch, IsSync = isSync }); return(result); } catch (Csla.Server.DataPortalException ex) { Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Fetch, 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.Fetch " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Fetch", error), null); Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync }); throw fex; } catch (Exception ex) { var fex = DataPortal.NewDataPortalException( "DataPortal.Fetch " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Fetch", ex), null); Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync }); throw fex; } finally { ClearContext(context); } }