Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
        /// <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);

                DataPortalResult result;

                MethodInfo method = MethodCaller.GetMethod(
                    objectType, "DataPortal_Create", criteria);

                IDataPortalServer portal;
                switch (TransactionalType(method))
                {
                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 SimpleDataPortal();
                    result = portal.Create(objectType, criteria, context);
                    break;
                }
                return(result);
            }
            finally
            {
                ClearContext(context);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete a 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>
        /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
        public async Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
        {
            try
            {
                SetContext(context);

                Initialize(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Delete, IsSync = isSync
                });

                AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Delete));
                DataPortalResult     result;
                DataPortalMethodInfo method;
                var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
                if (factoryInfo != null)
                {
                    var    factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
                    string methodName  = factoryInfo.DeleteMethodName;
                    method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, criteria);
                }
                else
                {
                    method = DataPortalMethodCache.GetMethodInfo(objectType, "DataPortal_Delete", 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.Delete(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.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);

                    break;

                default:
                    portal = new DataPortalBroker();
                    result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);

                    break;
                }
#else
                portal = new DataPortalBroker();
                result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
#endif
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Delete, IsSync = isSync
                });
                return(result);
            }
            catch (Csla.Server.DataPortalException ex)
            {
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Delete, 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.Delete " + Resources.FailedOnServer,
                    new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", error),
                    null);
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync
                });
                throw fex;
            }
            catch (Exception ex)
            {
                var fex = DataPortal.NewDataPortalException(
                    "DataPortal.Delete " + Resources.FailedOnServer,
                    new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", ex),
                    null);
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync
                });
                throw fex;
            }
            finally
            {
                ClearContext(context);
            }
        }
Ejemplo n.º 4
0
        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 !(ANDROID || IOS) && !NETFX_CORE
                context.TransactionalType = method.TransactionalAttribute.TransactionType;
#else
                context.TransactionalType = method.TransactionalType;
#endif
                IDataPortalServer portal;
#if !(ANDROID || IOS) && !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 DataPortalBroker();
                    result = await portal.Update(obj, context, isSync).ConfigureAwait(false);

                    break;
                }
#else
                portal = new DataPortalBroker();
                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);
            }
        }
Ejemplo n.º 5
0
        /// <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 !SILVERLIGHT && !NETFX_CORE
                switch (method.TransactionalAttribute.TransactionType)
                {
#if !MONO
                case TransactionalTypes.EnterpriseServices:
                    portal = GetServicedComponentPortal(method.TransactionalAttribute);
                    try
                    {
                        result = await portal.Fetch(objectType, criteria, context, isSync);
                    }
                    finally
                    {
                        ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
                    }
                    break;
#endif
                case TransactionalTypes.TransactionScope:
                    portal = new TransactionalDataPortal(method.TransactionalAttribute);
                    result = await portal.Fetch(objectType, criteria, context, isSync);

                    break;

                default:
                    portal = new DataPortalSelector();
                    result = await portal.Fetch(objectType, criteria, context, isSync);

                    break;
                }
#else
                portal = new DataPortalSelector();
                result = await portal.Fetch(objectType, criteria, context, isSync);
#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);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
    /// <summary>
    /// Delete a 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>
    /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
    public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
    {
      try
      {
        SetContext(context);

        Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Delete, IsSync = isSync });

        AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Delete));
        DataPortalResult result;
        DataPortalMethodInfo method;
        var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
        if (factoryInfo != null)
        {
          var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
          string methodName = factoryInfo.DeleteMethodName;
          method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, criteria);
        }
        else
        {
          method = DataPortalMethodCache.GetMethodInfo(objectType, "DataPortal_Delete", criteria);
        }

        IDataPortalServer portal;
#if !SILVERLIGHT && !NETFX_CORE
        switch (method.TransactionalAttribute.TransactionType)
        {
#if !MONO
          case TransactionalTypes.EnterpriseServices:
            portal = GetServicedComponentPortal(method.TransactionalAttribute);
            try
            {
              result = await portal.Delete(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.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
            break;
          default:
            portal = new DataPortalSelector();
            result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
            break;
        }
#else
        portal = new DataPortalSelector();
        result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
#endif
        Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Delete, IsSync = isSync });
        return result;
      }
      catch (Csla.Server.DataPortalException ex)
      {
        Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Delete, 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.Delete " + Resources.FailedOnServer,
            new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", error),
            null);
        Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync });
        throw fex;
      }
      catch (Exception ex)
      {
        var fex = DataPortal.NewDataPortalException(
            "DataPortal.Delete " + Resources.FailedOnServer,
            new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", ex),
            null);
        Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync });
        throw fex;
      }
      finally
      {
        ClearContext(context);
      }
    }
Ejemplo n.º 8
0
    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);
      }
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Delete a 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>
        /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
        public async Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
        {
            try
            {
                SetContext(context);

                Initialize(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Delete, IsSync = isSync
                });

                AuthorizeRequest(new AuthorizeRequest(ApplicationContext, objectType, criteria, DataPortalOperations.Delete));
                DataPortalResult     result;
                DataPortalMethodInfo method;
                var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
                if (factoryInfo != null)
                {
                    var    factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
                    string methodName  = factoryInfo.DeleteMethodName;
                    method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, criteria);
                }
                else
                {
                    Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
                    if (criteria is EmptyCriteria)
                    {
                        serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <DeleteAttribute>(objectType, null);
                    }
                    else
                    {
                        serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <DeleteAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
                    }
                    serviceProviderMethodInfo.PrepForInvocation();
                    method = serviceProviderMethodInfo.DataPortalMethodInfo;
                }

                IDataPortalServer portal;
                switch (method.TransactionalAttribute.TransactionType)
                {
#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
                case TransactionalTypes.EnterpriseServices:
                    portal = GetServicedComponentPortal(method.TransactionalAttribute);
                    try
                    {
                        result = await portal.Delete(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.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);

                    break;

                default:
                    portal = ApplicationContext.CreateInstanceDI <DataPortalBroker>();
                    result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);

                    break;
                }
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Delete, IsSync = isSync
                });
                return(result);
            }
            catch (Csla.Server.DataPortalException ex)
            {
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Delete, 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(
                    ApplicationContext, "DataPortal.Delete " + Resources.FailedOnServer,
                    new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", error),
                    null);
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync
                });
                throw fex;
            }
            catch (Exception ex)
            {
                var fex = DataPortal.NewDataPortalException(
                    ApplicationContext, "DataPortal.Delete " + Resources.FailedOnServer,
                    new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", ex),
                    null);
                Complete(new InterceptArgs {
                    ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync
                });
                throw fex;
            }
            finally
            {
                ClearContext(context);
            }
        }
Ejemplo n.º 10
0
        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 });
                }
#if NET40
                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);
                }
#else
                else
                {
                    Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
                    var bbase = obj as Core.BusinessBase;
                    if (bbase != null)
                    {
                        if (bbase.IsDeleted)
                        {
                            serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <DeleteSelfAttribute>(objectType, null);
                        }
                        else
                        if (bbase.IsNew)
                        {
                            serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <InsertAttribute>(objectType, null);
                        }
                        else
                        {
                            serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <UpdateAttribute>(objectType, null);
                        }
                    }
                    else if (obj is Core.ICommandObject)
                    {
                        serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <ExecuteAttribute>(objectType, null);
                    }
                    else
                    {
                        serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod <UpdateAttribute>(objectType, null);
                    }

                    serviceProviderMethodInfo.PrepForInvocation();
                    method = serviceProviderMethodInfo.DataPortalMethodInfo;
                }
#endif

#if !(ANDROID || IOS) && !NETFX_CORE
                context.TransactionalType = method.TransactionalAttribute.TransactionType;
#else
                context.TransactionalType = method.TransactionalType;
#endif
                IDataPortalServer portal;
#if !(ANDROID || IOS) && !NETFX_CORE
                switch (method.TransactionalAttribute.TransactionType)
                {
#if !MONO && !NETSTANDARD2_0 && !NET5_0
                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 DataPortalBroker();
                    result = await portal.Update(obj, context, isSync).ConfigureAwait(false);

                    break;
                }
#else
                portal = new DataPortalBroker();
                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);
            }
Ejemplo n.º 11
0
        /// <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;

#if NET40
                method = DataPortalMethodCache.GetFetchMethod(objectType, criteria);
#else
                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;
#endif

                IDataPortalServer portal;
#if !(ANDROID || IOS) && !NETFX_CORE
                switch (method.TransactionalAttribute.TransactionType)
                {
#if !MONO && !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;
                }
#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);
            }
        }
Ejemplo n.º 12
0
        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;
                }

                AuthorizeRequest(new AuthorizeRequest(objectType, obj, operation));

                Initialize(new InterceptArgs {
                    ObjectType = objectType, Parameter = obj, Operation = operation, IsSync = isSync
                });

                DataPortalResult     result;
                DataPortalMethodInfo method;
                var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
                if (factoryInfo != null)
                {
                    string methodName;
                    var    factoryLoader = ApplicationContext.CurrentServiceProvider.GetService(typeof(Server.IObjectFactoryLoader)) as Server.IObjectFactoryLoader;
                    var    factoryType   = factoryLoader?.GetFactoryType(factoryInfo.FactoryTypeName);
                    if (obj is Core.BusinessBase bbase)
                    {
                        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
                {
                    Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
                    if (obj is Core.BusinessBase bbase)
                    {
                        if (bbase.IsDeleted)
                        {
                            serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <DeleteSelfAttribute>(objectType, null);
                        }
                        else
                        if (bbase.IsNew)
                        {
                            serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <InsertAttribute>(objectType, null);
                        }
                        else
                        {
                            serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <UpdateAttribute>(objectType, null);
                        }
                    }
                    else if (obj is Core.ICommandObject)
                    {
                        serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <ExecuteAttribute>(objectType, null);
                    }
                    else
                    {
                        serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod <UpdateAttribute>(objectType, null);
                    }

                    serviceProviderMethodInfo.PrepForInvocation();
                    method = serviceProviderMethodInfo.DataPortalMethodInfo;
                }

                context.TransactionalType = method.TransactionalAttribute.TransactionType;
                IDataPortalServer portal;
                switch (method.TransactionalAttribute.TransactionType)
                {
#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
                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:
                    var broker = ApplicationContext.CreateInstanceDI <DataPortalBroker>();
                    portal = new TransactionalDataPortal(broker, method.TransactionalAttribute);
                    result = await portal.Update(obj, context, isSync).ConfigureAwait(false);

                    break;

                default:
                    portal = ApplicationContext.CreateInstanceDI <DataPortalBroker>();
                    result = await portal.Update(obj, context, isSync).ConfigureAwait(false);

                    break;
                }
                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(
                    ApplicationContext, "DataPortal.Update " + Resources.FailedOnServer,
                    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(
                    ApplicationContext, "DataPortal.Update " + Resources.FailedOnServer,
                    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);
            }
        }
Ejemplo n.º 13
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);
            }
            finally
            {
                ClearContext(context);
            }
        }