コード例 #1
0
        /// <summary>
        /// Update a business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Result of the update operation - updated object</returns>
        public MobileResponse Update(MobileUpdateRequest request)
        {
            var    result = new MobileResponse();
            Type   t      = null;
            object obj    = null;

            try
            {
                // unpack object
                obj = request.ObjectToUpdate;

                // load type for business object
                t = obj.GetType();

                object o           = null;
                var    factoryInfo = GetMobileFactoryAttribute(t);
                if (factoryInfo == null)
                {
                    SetContext(request);

                    new Csla.Server.DataPortal().Authorize(new AuthorizeRequest(t, obj, DataPortalOperations.Update));

                    o = Csla.DataPortal.Update(obj);
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.UpdateMethodName))
                    {
                        throw new InvalidOperationException(Resources.UpdateMethodNameNotSpecified);
                    }

                    SetContext(request);

                    new Csla.Server.DataPortal().Authorize(new AuthorizeRequest(t, obj, DataPortalOperations.Update));

                    object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
                    o = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.UpdateMethodName, obj);
                }
                result.Object        = o;
                result.GlobalContext = ApplicationContext.GlobalContext;
            }
            catch (Csla.Reflection.CallMethodException ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(t, obj, "DataPortal.Update", ex);
                result.Error = inspected.InnerException;
            }
            catch (Exception ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(t, obj, "DataPortal.Update", ex);
                result.Error = inspected;
            }
            finally
            {
                ClearContext();
            }
            return(result);
        }
コード例 #2
0
 public TestableDataPortal(
     ApplicationContext applicationContext,
     IDashboard dashboard,
     CslaOptions options,
     IAuthorizeDataPortal authorizer,
     InterceptorManager interceptors,
     IObjectFactoryLoader factoryLoader,
     IDataPortalActivator activator,
     IDataPortalExceptionInspector exceptionInspector,
     DataPortalExceptionHandler exceptionHandler
     ) : base(
         applicationContext,
         dashboard,
         options,
         authorizer,
         interceptors,
         factoryLoader,
         activator,
         exceptionInspector,
         exceptionHandler
         )
 {
     _authorizer = authorizer;
 }
コード例 #3
0
        /// <summary>
        /// Create a new business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Resulf of the create operation - an instance of a business object</returns>
        public async Task <MobileResponse> Create(MobileCriteriaRequest request)
        {
            var    serverDataPortal   = new Csla.Server.DataPortal();
            var    result             = new MobileResponse();
            Type   businessObjectType = null;
            object criteria           = null;

            try
            {
                criteria = request.Criteria;
                // load type for business object
                businessObjectType = Type.GetType(request.TypeName);
                if (businessObjectType == null)
                {
                    throw new InvalidOperationException(
                              string.Format(Csla.Properties.Resources.ObjectTypeCouldNotBeLoaded, request.TypeName));
                }

                SetContext(request);

                serverDataPortal.Initialize(new InterceptArgs {
                    ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Create
                });
                serverDataPortal.Authorize(new AuthorizeRequest(businessObjectType, criteria, DataPortalOperations.Create));

                object newObject   = null;
                var    factoryInfo = GetMobileFactoryAttribute(businessObjectType);
                if (factoryInfo == null)
                {
                    if (criteria != null)
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "CreateAsync", new Type[] { businessObjectType }, true, criteria).ConfigureAwait(false);
                    }
                    else
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "CreateAsync", new Type[] { businessObjectType }, false, null).ConfigureAwait(false);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.CreateMethodName))
                    {
                        throw new InvalidOperationException(Resources.CreateMethodNameNotSpecified);
                    }

                    object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
                    if (criteria != null)
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.CreateMethodName, criteria).ConfigureAwait(false);
                    }
                    else
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.CreateMethodName).ConfigureAwait(false);
                    }
                }
                result.Object = newObject;
#pragma warning disable CS0618 // Type or member is obsolete
                result.GlobalContext = ApplicationContext.GlobalContext;
#pragma warning restore CS0618 // Type or member is obsolete
            }
            catch (Csla.Reflection.CallMethodException ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, criteria, "DataPortal.Create", ex);
                result.Error = inspected.InnerException;
            }
            catch (Exception ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, criteria, "DataPortal.Create", ex);
                result.Error = inspected;
            }
            finally
            {
                if (result.Error != null)
                {
                    serverDataPortal.Complete(new InterceptArgs {
                        ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Create, Exception = result.Error, Result = new DataPortalResult(result.Object, result.Error, result.GlobalContext)
                    });
                }
                else
                {
                    serverDataPortal.Complete(new InterceptArgs {
                        ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Create, Result = new DataPortalResult(result.Object, result.GlobalContext)
                    });
                }
                ClearContext();
            }
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Update a business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Result of the update operation - updated object</returns>
        public async Task <MobileResponse> Update(MobileUpdateRequest request)
        {
            var    serverDataPortal   = new Csla.Server.DataPortal();
            var    result             = new MobileResponse();
            Type   businessObjectType = null;
            object obj       = null;
            var    operation = DataPortalOperations.Update;

            try
            {
                // unpack object
                obj = request.ObjectToUpdate;

                if (obj is Csla.Core.ICommandObject)
                {
                    operation = DataPortalOperations.Execute;
                }

                // load type for business object
                businessObjectType = obj.GetType();

                SetContext(request);

                serverDataPortal.Initialize(new InterceptArgs {
                    ObjectType = businessObjectType, Parameter = obj, Operation = operation
                });
                serverDataPortal.Authorize(new AuthorizeRequest(businessObjectType, obj, operation));

                object newObject   = null;
                var    factoryInfo = GetMobileFactoryAttribute(businessObjectType);
                if (factoryInfo == null)
                {
                    newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "UpdateAsync", new Type[] { businessObjectType }, true, obj).ConfigureAwait(false);
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.UpdateMethodName))
                    {
                        throw new InvalidOperationException(Resources.UpdateMethodNameNotSpecified);
                    }

                    object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
                    newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.UpdateMethodName, obj).ConfigureAwait(false);
                }
                result.Object = newObject;
#pragma warning disable CS0618 // Type or member is obsolete
                result.GlobalContext = ApplicationContext.GlobalContext;
#pragma warning restore CS0618 // Type or member is obsolete
            }
            catch (Csla.Reflection.CallMethodException ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, obj, "DataPortal.Update", ex);
                result.Error = inspected.InnerException;
            }
            catch (Exception ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, obj, "DataPortal.Update", ex);
                result.Error = inspected;
            }
            finally
            {
                if (result.Error != null)
                {
                    serverDataPortal.Complete(new InterceptArgs {
                        ObjectType = businessObjectType, Parameter = obj, Operation = operation, Exception = result.Error, Result = new DataPortalResult(result.Object, result.Error, result.GlobalContext)
                    });
                }
                else
                {
                    serverDataPortal.Complete(new InterceptArgs {
                        ObjectType = businessObjectType, Parameter = obj, Operation = operation, Result = new DataPortalResult(result.Object, result.GlobalContext)
                    });
                }
                ClearContext();
            }
            return(result);
        }
コード例 #5
0
        public async Task <MobileResponse> Fetch(MobileCriteriaRequest request)
#endif
        {
            var    serverDataPortal   = new Csla.Server.DataPortal();
            var    result             = new MobileResponse();
            Type   businessObjectType = null;
            object criteria           = null;

            try
            {
                // unpack criteria data into object
                criteria = request.Criteria;

                // load type for business object
                businessObjectType = Type.GetType(request.TypeName);
                if (businessObjectType == null)
                {
                    throw new InvalidOperationException(
                              string.Format(Resources.ObjectTypeCouldNotBeLoaded, request.TypeName));
                }

                SetContext(request);

                serverDataPortal.Initialize(new InterceptArgs {
                    ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Fetch
                });
                serverDataPortal.Authorize(new AuthorizeRequest(businessObjectType, criteria, DataPortalOperations.Fetch));

                object newObject   = null;
                var    factoryInfo = GetMobileFactoryAttribute(businessObjectType);
                if (factoryInfo == null)
                {
#if NET40
                    if (criteria == null)
                    {
                        newObject = Csla.DataPortal.Fetch(businessObjectType, new EmptyCriteria());
                    }
                    else
                    {
                        newObject = Csla.DataPortal.Fetch(businessObjectType, criteria);
                    }
#else
                    if (criteria != null)
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "FetchAsync", new Type[] { businessObjectType }, true, criteria).ConfigureAwait(false);
                    }
                    else
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "FetchAsync", new Type[] { businessObjectType }, false, null).ConfigureAwait(false);
                    }
#endif
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.FetchMethodName))
                    {
                        throw new InvalidOperationException(Resources.FetchMethodNameNotSpecified);
                    }

                    object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
#if NET40
                    if (criteria != null)
                    {
                        newObject = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.FetchMethodName, criteria);
                    }
                    else
                    {
                        newObject = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.FetchMethodName);
                    }
#else
                    if (criteria != null)
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.FetchMethodName, criteria).ConfigureAwait(false);
                    }
                    else
                    {
                        newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.FetchMethodName).ConfigureAwait(false);
                    }
#endif
                }
                result.Object        = newObject;
                result.GlobalContext = ApplicationContext.GlobalContext;
            }
            catch (Csla.Reflection.CallMethodException ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, criteria, "DataPortal.Fetch", ex);
                result.Error = inspected.InnerException;
            }
            catch (Exception ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, criteria, "DataPortal.Fetch", ex);
                result.Error = inspected;
            }
            finally
            {
                if (result.Error != null)
                {
                    serverDataPortal.Complete(new InterceptArgs {
                        ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Fetch, Exception = result.Error, Result = new DataPortalResult(result.Object, result.Error, result.GlobalContext)
                    });
                }
                else
                {
                    serverDataPortal.Complete(new InterceptArgs {
                        ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Fetch, Result = new DataPortalResult(result.Object, result.GlobalContext)
                    });
                }
                ClearContext();
            }
            return(result);
        }
コード例 #6
0
    public async Task<MobileResponse> Create(MobileCriteriaRequest request)
#endif
    {
      var serverDataPortal = new Csla.Server.DataPortal();
      var result = new MobileResponse();
      Type businessObjectType = null;
      object criteria = null;
      try
      {
        criteria = request.Criteria;
        // load type for business object
        businessObjectType = Type.GetType(request.TypeName);
        if (businessObjectType == null)
          throw new InvalidOperationException(
            string.Format(Csla.Properties.Resources.ObjectTypeCouldNotBeLoaded, request.TypeName));

        SetContext(request);

        serverDataPortal.Initialize(new InterceptArgs { ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Create });
        serverDataPortal.Authorize(new AuthorizeRequest(businessObjectType, criteria, DataPortalOperations.Create));

        object newObject = null;
        var factoryInfo = GetMobileFactoryAttribute(businessObjectType);
        if (factoryInfo == null)
        {
#if NET40
          if (criteria != null)
            newObject = Csla.DataPortal.Create(businessObjectType, criteria);
          else
            newObject = Csla.DataPortal.Create(businessObjectType, new EmptyCriteria());
#else
          if (criteria != null)
            newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "CreateAsync", new Type[] { businessObjectType }, true, criteria).ConfigureAwait(false);
          else
            newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "CreateAsync", new Type[] { businessObjectType }, false, null).ConfigureAwait(false);
#endif
        }
        else
        {
          if (string.IsNullOrEmpty(factoryInfo.CreateMethodName))
            throw new InvalidOperationException(Resources.CreateMethodNameNotSpecified);

          object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
#if NET40
          if (criteria != null)
            newObject = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName, criteria);
          else
            newObject = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName);
#else
          if (criteria != null)
            newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.CreateMethodName, criteria).ConfigureAwait(false);
          else
            newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.CreateMethodName).ConfigureAwait(false);
#endif
        }
        result.Object = newObject;
        result.GlobalContext = ApplicationContext.GlobalContext;
      }
      catch (Csla.Reflection.CallMethodException ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, criteria, "DataPortal.Create", ex);
        result.Error = inspected.InnerException;
      }
      catch (Exception ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, criteria, "DataPortal.Create", ex);
        result.Error = inspected;
      }
      finally
      {
        if (result.Error != null)
          serverDataPortal.Complete(new InterceptArgs { ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Create, Exception = result.Error, Result = new DataPortalResult(result.Object, result.Error, result.GlobalContext) });
        else
          serverDataPortal.Complete(new InterceptArgs { ObjectType = businessObjectType, Parameter = criteria, Operation = DataPortalOperations.Create, Result = new DataPortalResult(result.Object, result.GlobalContext) });
        ClearContext();
      }
      return result;
    }
コード例 #7
0
    public async Task<MobileResponse> Update(MobileUpdateRequest request)
#endif
    {
      var serverDataPortal = new Csla.Server.DataPortal();
      var result = new MobileResponse();
      Type businessObjectType = null;
      object obj = null;
      var operation = DataPortalOperations.Update;
      try
      {
        // unpack object
        obj = request.ObjectToUpdate;

        if (obj is Csla.Core.ICommandObject)
          operation = DataPortalOperations.Execute;

        // load type for business object
        businessObjectType = obj.GetType();

        SetContext(request);

        serverDataPortal.Initialize(new InterceptArgs { ObjectType = businessObjectType, Parameter = obj, Operation = operation });
        serverDataPortal.Authorize(new AuthorizeRequest(businessObjectType, obj, operation));

        object newObject = null;
        var factoryInfo = GetMobileFactoryAttribute(businessObjectType);
        if (factoryInfo == null)
        {
#if NET40
          newObject = Csla.DataPortal.Update(obj);
#else
          newObject = await Csla.Reflection.MethodCaller.CallGenericStaticMethodAsync(typeof(Csla.DataPortal), "UpdateAsync", new Type[] { businessObjectType }, true, obj).ConfigureAwait(false);
#endif
        }
        else
        {
          if (string.IsNullOrEmpty(factoryInfo.UpdateMethodName))
            throw new InvalidOperationException(Resources.UpdateMethodNameNotSpecified);

          object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
#if NET40
          newObject = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.UpdateMethodName, obj);
#else
          newObject = await Csla.Reflection.MethodCaller.CallMethodTryAsync(f, factoryInfo.UpdateMethodName, obj).ConfigureAwait(false);
#endif
        }
        result.Object = newObject;
        result.GlobalContext = ApplicationContext.GlobalContext;
      }
      catch (Csla.Reflection.CallMethodException ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, obj, "DataPortal.Update", ex);
        result.Error = inspected.InnerException;
      }
      catch (Exception ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(businessObjectType, obj, "DataPortal.Update", ex);
        result.Error = inspected;
      }
      finally
      {
        if (result.Error != null)
          serverDataPortal.Complete(new InterceptArgs { ObjectType = businessObjectType, Parameter = obj, Operation = operation, Exception = result.Error, Result = new DataPortalResult(result.Object, result.Error, result.GlobalContext) });
        else
          serverDataPortal.Complete(new InterceptArgs { ObjectType = businessObjectType, Parameter = obj, Operation = operation, Result = new DataPortalResult(result.Object, result.GlobalContext) });
        ClearContext();
      }
      return result;
    }
コード例 #8
0
    /// <summary>
    /// Create a new business object.
    /// </summary>
    /// <param name="request">The request parameter object.</param>
    /// <returns>Resulf of the create operation - an instance of a business object</returns>
    public MobileResponse Create(MobileCriteriaRequest request)
    {
      var result = new MobileResponse();
      Type t = null;
      object criteria = null;
      try
      {
        criteria = request.Criteria;
        // load type for business object
        t = Type.GetType(request.TypeName);
        if (t == null)
          throw new InvalidOperationException(
            string.Format(Csla.Properties.Resources.ObjectTypeCouldNotBeLoaded, request.TypeName));

        SetContext(request);

        new Csla.Server.DataPortal().Authorize(new AuthorizeRequest(t, criteria, DataPortalOperations.Create));

        object o = null;
        var factoryInfo = GetMobileFactoryAttribute(t);
        if (factoryInfo == null)
        {
          if (criteria != null)
          {
            o = Csla.DataPortal.Create(t, criteria);
          }
          else
          {
            o = Csla.DataPortal.Create(t, new EmptyCriteria());
          }
        }
        else
        {
          if (string.IsNullOrEmpty(factoryInfo.CreateMethodName))
            throw new InvalidOperationException(Resources.CreateMethodNameNotSpecified);

          object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
          if (criteria != null)
            o = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName, criteria);
          else
            o = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName);
        }
        result.Object = o;
        result.GlobalContext = ApplicationContext.GlobalContext;
      }
      catch (Csla.Reflection.CallMethodException ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(t, criteria, "DataPortal.Create", ex);
        result.Error = inspected.InnerException;
      }
      catch (Exception ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(t, criteria, "DataPortal.Create", ex);
        result.Error = inspected;
      }
      finally
      {
        ClearContext();
      }
      return result;
    }
コード例 #9
0
    /// <summary>
    /// Update a business object.
    /// </summary>
    /// <param name="request">The request parameter object.</param>
    /// <returns>Result of the update operation - updated object</returns>
    public MobileResponse Update(MobileUpdateRequest request)
    {
      var result = new MobileResponse();
      Type t = null;
      object obj = null;
      try
      {
        // unpack object
        obj = request.ObjectToUpdate;

        // load type for business object
        t = obj.GetType();

        object o = null;
        var factoryInfo = GetMobileFactoryAttribute(t);
        if (factoryInfo == null)
        {
          SetContext(request);

          new Csla.Server.DataPortal().Authorize(new AuthorizeRequest(t, obj, DataPortalOperations.Update));

          o = Csla.DataPortal.Update(obj);
        }
        else
        {
          if (string.IsNullOrEmpty(factoryInfo.UpdateMethodName))
            throw new InvalidOperationException(Resources.UpdateMethodNameNotSpecified);

          SetContext(request);

          new Csla.Server.DataPortal().Authorize(new AuthorizeRequest(t, obj, DataPortalOperations.Update));

          object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
          o = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.UpdateMethodName, obj);
        }
        result.Object = o;
        result.GlobalContext = ApplicationContext.GlobalContext;
      }
      catch (Csla.Reflection.CallMethodException ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(t, obj, "DataPortal.Update", ex);
        result.Error = inspected.InnerException;
      }
      catch (Exception ex)
      {
        var inspected = new DataPortalExceptionHandler().InspectException(t, obj, "DataPortal.Update", ex);
        result.Error = inspected;
      }
      finally
      {
        ClearContext();
      }
      return result;
    }
コード例 #10
0
        /// <summary>
        /// Create a new business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Resulf of the create operation - an instance of a business object</returns>
        public SilverlightResponse Create(SilverlightCriteriaRequest request)
        {
            var    result   = new SilverlightResponse();
            Type   t        = null;
            object criteria = null;

            try
            {
                criteria = request.Criteria;
                // load type for business object
                t = Type.GetType(request.TypeName);
                if (t == null)
                {
                    throw new InvalidOperationException(
                              string.Format(Csla.Properties.Resources.ObjectTypeCouldNotBeLoaded, request.TypeName));
                }

                SetContext(request);
                object o           = null;
                var    factoryInfo = GetMobileFactoryAttribute(t);
                if (factoryInfo == null)
                {
                    if (criteria != null)
                    {
                        o = Csla.DataPortal.Create(t, criteria);
                    }
                    else
                    {
                        o = Csla.DataPortal.Create(t);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.CreateMethodName))
                    {
                        throw new InvalidOperationException(Resources.CreateMethodNameNotSpecified);
                    }

                    object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
                    if (criteria != null)
                    {
                        o = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName, criteria);
                    }
                    else
                    {
                        o = Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName);
                    }
                }
                result.Object        = o;
                result.GlobalContext = ApplicationContext.GlobalContext;
            }
            catch (Csla.Reflection.CallMethodException ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(t, criteria, "DataPortal.Create", ex);
                result.Error = inspected.InnerException;
            }
            catch (Exception ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(t, criteria, "DataPortal.Create", ex);
                result.Error = inspected;
            }
            finally
            {
                ClearContext();
            }
            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Delete a business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Result of the delete operation</returns>
        public MobileResponse Delete(MobileCriteriaRequest request)
        {
            var    result   = new MobileResponse();
            Type   t        = null;
            object criteria = null;

            try
            {
                // unpack criteria data into object
                criteria = request.Criteria;

                // load type for business object
                t = Type.GetType(request.TypeName);
                if (t == null)
                {
                    throw new InvalidOperationException(
                              string.Format(Resources.ObjectTypeCouldNotBeLoaded, request.TypeName));
                }

                SetContext(request);

                new Csla.Server.DataPortal().Authorize(new AuthorizeRequest(t, criteria, DataPortalOperations.Delete));

                var factoryInfo = GetMobileFactoryAttribute(t);
                if (factoryInfo == null)
                {
                    Csla.DataPortal.Delete(t, criteria);
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.DeleteMethodName))
                    {
                        throw new InvalidOperationException(Resources.DeleteMethodNameNotSpecified);
                    }

                    object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName);
                    if (criteria != null)
                    {
                        Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.DeleteMethodName, criteria);
                    }
                    else
                    {
                        Csla.Reflection.MethodCaller.CallMethod(f, factoryInfo.DeleteMethodName);
                    }
                }
                result.GlobalContext = ApplicationContext.GlobalContext;
            }
            catch (Csla.Reflection.CallMethodException ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(t, criteria, "DataPortal.Delete", ex);
                result.Error = inspected.InnerException;
            }
            catch (Exception ex)
            {
                var inspected = new DataPortalExceptionHandler().InspectException(t, criteria, "DataPortal.Delete", ex);
                result.Error = inspected;
            }
            finally
            {
                ClearContext();
            }
            return(result);
        }