/// <summary> /// Create a new business object. /// </summary> /// <param name="objectType">Type of business object to create.</param> /// <param name="criteria">Criteria object describing business object.</param> /// <param name="context"> /// <see cref="Server.DataPortalContext" /> object passed to the server. /// </param> public DataPortalResult Create( Type objectType, object criteria, DataPortalContext context) { try { SetContext(context); Authorize(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Create)); DataPortalResult result; DataPortalMethodInfo method = DataPortalMethodCache.GetCreateMethod(objectType, criteria); IDataPortalServer portal; switch (method.TransactionalType) { case TransactionalTypes.EnterpriseServices: portal = new ServicedDataPortal(); try { result = portal.Create(objectType, criteria, context); } finally { ((ServicedDataPortal)portal).Dispose(); } break; case TransactionalTypes.TransactionScope: portal = new TransactionalDataPortal(); result = portal.Create(objectType, criteria, context); break; default: portal = new DataPortalSelector(); result = portal.Create(objectType, criteria, context); break; } return(result); } catch (Csla.Server.DataPortalException ex) { Exception tmp = ex; throw; } catch (Exception ex) { throw new DataPortalException( "DataPortal.Create " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Create", ex), new DataPortalResult()); } finally { ClearContext(context); } }
/// <summary> /// Gets a reference to the DataPortal_Create method for /// the specified business object type. /// </summary> /// <param name="objectType">Type of the business object.</param> /// <param name="criteria">Criteria parameter value.</param> /// <remarks> /// If the criteria parameter value is an integer, that is a special /// flag indicating that the parameter should be considered missing /// (not Nothing/null - just not there). /// </remarks> internal static DataPortalMethodInfo GetCreateMethod(Type objectType, object criteria) { // an "Integer" criteria is a special flag indicating // that criteria is empty and should not be used DataPortalMethodInfo method = null; var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType); if (factoryInfo == null) { if (criteria is EmptyCriteria) method = GetMethodInfo(objectType, "DataPortal_Create"); else method = GetMethodInfo(objectType, "DataPortal_Create", criteria); } else { var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName); if (factoryType != null) { if (criteria is EmptyCriteria) method = GetMethodInfo( factoryType, factoryInfo.CreateMethodName); else method = GetMethodInfo( factoryType, factoryInfo.CreateMethodName, criteria); } else method = new DataPortalMethodInfo(); } return method; }
public static DataPortalMethodInfo GetMethodInfo(Type objectType, string methodName, params object[] parameters) { var key = new MethodCacheKey(objectType.FullName, methodName, MethodCaller.GetParameterTypes(parameters)); DataPortalMethodInfo result = null; var found = false; try { found = _cache.TryGetValue(key, out result); } catch { /* failure will drop into !found block */ } if (!found) { lock (_cache) { if (!_cache.TryGetValue(key, out result)) { result = new DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters)); _cache.Add(key, result); } } } return(result); }
public static DataPortalMethodInfo GetMethodInfo(Type objectType, string methodName, params object[] parameters) { var key = new MethodCacheKey(objectType.FullName, methodName, MethodCaller.GetParameterTypes(parameters)); DataPortalMethodInfo result = null; var found = false; #if NET5_0_OR_GREATER try { found = _cache.TryGetValue(key, out var methodInfo); result = methodInfo?.Item2; } catch { /* failure will drop into !found block */ } if (!found) { lock (_cache) { found = _cache.TryGetValue(key, out var methodInfo); result = methodInfo?.Item2; if (!found) { result = new DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters)); var cacheInstance = AssemblyLoadContextManager.CreateCacheInstance(objectType, result, OnAssemblyLoadContextUnload); _cache.Add(key, cacheInstance); } } } #else try { found = _cache.TryGetValue(key, out result); } catch { /* failure will drop into !found block */ } if (!found) { lock (_cache) { if (!_cache.TryGetValue(key, out result)) { result = new DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters)); _cache.Add(key, result); } } } #endif return(result); }
public static DataPortalMethodInfo GetMethodInfo(Type objectType, string methodName, params object[] parameters) { var key = new MethodCacheKey(objectType.Name, methodName, MethodCaller.GetParameterTypes(parameters)); DataPortalMethodInfo result = null; if (!_cache.TryGetValue(key, out result)) { lock (_cache) { if (!_cache.TryGetValue(key, out result)) { result = new DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters)); _cache.Add(key, result); } } } return(result); }
/// <summary> /// Gets a reference to the DataPortal_Create method for /// the specified business object type. /// </summary> /// <param name="objectType">Type of the business object.</param> /// <param name="criteria">Criteria parameter value.</param> /// <remarks> /// If the criteria parameter value is an integer, that is a special /// flag indicating that the parameter should be considered missing /// (not Nothing/null - just not there). /// </remarks> internal static DataPortalMethodInfo GetCreateMethod(Type objectType, object criteria) { // an "Integer" criteria is a special flag indicating // that criteria is empty and should not be used DataPortalMethodInfo method = null; var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType); if (factoryInfo == null) { if (criteria is EmptyCriteria) { method = GetMethodInfo(objectType, "DataPortal_Create"); } else { method = GetMethodInfo(objectType, "DataPortal_Create", criteria); } } else { var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName); if (factoryType != null) { if (criteria is EmptyCriteria) { method = GetMethodInfo( factoryType, factoryInfo.CreateMethodName); } else { method = GetMethodInfo( factoryType, factoryInfo.CreateMethodName, criteria); } } else { method = new DataPortalMethodInfo(); } } return(method); }
public static DataPortalMethodInfo GetMethodInfo(Type objectType, string methodName, params object[] parameters) { var key = new MethodCacheKey(objectType.FullName, methodName, MethodCaller.GetParameterTypes(parameters)); DataPortalMethodInfo result = null; var found = false; try { found = _cache.TryGetValue(key, out result); } catch { /* failure will drop into !found block */ } if (!found) { lock (_cache) { if (!_cache.TryGetValue(key, out result)) { result = new DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters)); _cache.Add(key, result); } } } return result; }
/// <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); } }