Exemple #1
0
    public async Task<WcfResponse> Create(CriteriaRequest request)
#endif
    {
      var result = new WcfResponse();
      try
      {
        request = ConvertRequest(request);

        // unpack criteria data into object
        object criteria = GetCriteria(request.CriteriaData);
        if (criteria is Csla.DataPortalClient.PrimitiveCriteria)
        {
          criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
        }

        var processor = new MobileRequestProcessor();
        var createRequest = new MobileCriteriaRequest(
          request.TypeName,
          criteria,
          (IPrincipal)MobileFormatter.Deserialize(request.Principal),
          (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext),
          (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext),
          request.ClientCulture,
          request.ClientUICulture);

#if NET40
        var createResponse = processor.Create(createRequest);
#else
        var createResponse = await processor.Create(createRequest).ConfigureAwait(false);
#endif
        if (createResponse.Error != null)
        {
          result.ErrorData = new WcfErrorInfo(createResponse.Error);
        }
        result.GlobalContext = MobileFormatter.Serialize(createResponse.GlobalContext);
        result.ObjectData = MobileFormatter.Serialize(createResponse.Object);
      }
      catch (Exception ex)
      {
        result.ErrorData = new WcfErrorInfo(ex);
      }
      finally
      {
        MobileRequestProcessor.ClearContext();
      }
      return ConvertResponse(result);

    }
Exemple #2
0
        public async Task <WcfResponse> Create(CriteriaRequest request)
#endif
        {
            var result = new WcfResponse();

            try
            {
                request = ConvertRequest(request);

                // unpack criteria data into object
                object criteria = GetCriteria(request.CriteriaData);
                if (criteria is Csla.DataPortalClient.PrimitiveCriteria)
                {
                    criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
                }

                var processor     = new MobileRequestProcessor();
                var createRequest = new MobileCriteriaRequest(
                    request.TypeName,
                    criteria,
                    (IPrincipal)MobileFormatter.Deserialize(request.Principal),
                    (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext),
                    (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext),
                    request.ClientCulture,
                    request.ClientUICulture);

#if NET40
                var createResponse = processor.Create(createRequest);
#else
                var createResponse = await processor.Create(createRequest).ConfigureAwait(false);
#endif
                if (createResponse.Error != null)
                {
                    result.ErrorData = new WcfErrorInfo(createResponse.Error);
                }
                result.GlobalContext = MobileFormatter.Serialize(createResponse.GlobalContext);
                result.ObjectData    = MobileFormatter.Serialize(createResponse.Object);
            }
            catch (Exception ex)
            {
                result.ErrorData = new WcfErrorInfo(ex);
            }
            finally
            {
                MobileRequestProcessor.ClearContext();
            }
            return(ConvertResponse(result));
        }
Exemple #3
0
        public WcfResponse Fetch(CriteriaRequest request)
        {
            var result = new WcfResponse();

            try
            {
                request = ConvertRequest(request);
                // unpack criteria data into object
                object criteria = GetCriteria(request.CriteriaData);
                if (criteria is Csla.DataPortalClient.PrimitiveCriteria)
                {
                    criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
                }
                var processor    = new MobileRequestProcessor();
                var fetchRequest = new MobileCriteriaRequest(
                    request.TypeName,
                    criteria,
                    (IPrincipal)MobileFormatter.Deserialize(request.Principal),
                    (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext),
                    (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext),
                    request.ClientCulture,
                    request.ClientUICulture);

                var fetchResponse = processor.Fetch(fetchRequest);
                if (fetchResponse.Error != null)
                {
                    result.ErrorData = new WcfErrorInfo(fetchResponse.Error);
                }
                result.GlobalContext = MobileFormatter.Serialize(fetchResponse.GlobalContext);
                result.ObjectData    = MobileFormatter.Serialize(fetchResponse.Object);
            }
            catch (Exception ex)
            {
                result.ErrorData = new WcfErrorInfo(ex);
            }
            finally
            {
                MobileRequestProcessor.ClearContext();
            }
            return(ConvertResponse(result));
        }
Exemple #4
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);
        }
        /// <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>
#if NET40
        public MobileResponse Create(MobileCriteriaRequest request)
        /// <summary>
        /// Delete a business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Result of the delete operation</returns>
#if NET40
        public MobileResponse Delete(MobileCriteriaRequest request)
        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);
        }
        /// <summary>
        /// Get an existing business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        /// <returns>Result of the fetch operation - an instance of a business object</returns>
#if NET40
        public MobileResponse Fetch(MobileCriteriaRequest request)
Exemple #9
0
    public WcfResponse Fetch(CriteriaRequest request)
    {
      var result = new WcfResponse();
      try
      {
        request = ConvertRequest(request);
        // unpack criteria data into object
        object criteria = GetCriteria(request.CriteriaData);
        if (criteria is Csla.DataPortalClient.PrimitiveCriteria)
        {
          criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value;
        }
        var processor = new MobileRequestProcessor();
        var fetchRequest = new MobileCriteriaRequest(
          request.TypeName,
          criteria,
          (IPrincipal)MobileFormatter.Deserialize(request.Principal),
          (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext),
          (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext),
          request.ClientCulture,
          request.ClientUICulture);

        var fetchResponse = processor.Fetch(fetchRequest);
        if (fetchResponse.Error != null)
        {
          result.ErrorData = new WcfErrorInfo(fetchResponse.Error);
        }
        result.GlobalContext = MobileFormatter.Serialize(fetchResponse.GlobalContext);
        result.ObjectData = MobileFormatter.Serialize(fetchResponse.Object);
      }
      catch (Exception ex)
      {
        result.ErrorData = new WcfErrorInfo(ex);
      }
      finally
      {
        MobileRequestProcessor.ClearContext();
      }
      return ConvertResponse(result);
    }
    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;
    }
    /// <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>
#if NET40
    public MobileResponse Create(MobileCriteriaRequest request)
    /// <summary>
    /// Delete a business object.
    /// </summary>
    /// <param name="request">The request parameter object.</param>
    /// <returns>Result of the delete operation</returns>
#if NET40
    public MobileResponse Delete(MobileCriteriaRequest request)
    /// <summary>
    /// Get an existing business object.
    /// </summary>
    /// <param name="request">The request parameter object.</param>
    /// <returns>Result of the fetch operation - an instance of a business object</returns>
#if NET40
    public MobileResponse Fetch(MobileCriteriaRequest request)
    /// <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;
    }
        /// <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);
        }