예제 #1
0
        public WcfResponse Fetch(CriteriaRequest request)
        {
            Csla.Server.DataPortal portal     = new Csla.Server.DataPortal();
            Exception               error     = null;
            DataPortalResult        result    = null;
            WcfResponse             response  = null;
            ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter();

            try
            {
                request = ConvertRequest(request);
                DataPortalContext context = new DataPortalContext(
                    formatter.Deserialize(request.Principal) as IPrincipal,
                    true,
                    request.ClientCulture,
                    request.ClientUICulture,
                    formatter.Deserialize(request.ClientContext) as ContextDictionary,
                    formatter.Deserialize(request.GlobalContext) as ContextDictionary);
                result   = portal.Fetch(Type.GetType(request.TypeName), formatter.Deserialize(request.CriteriaData), context);
                response = new WcfResponse(
                    formatter.Serialize(result.ReturnObject),
                    formatter.Serialize(error),
                    formatter.Serialize(Csla.ApplicationContext.GlobalContext));
            }
            catch (Exception ex)
            {
                error    = ex;
                response = new WcfResponse(
                    null,
                    formatter.Serialize(error),
                    formatter.Serialize(Csla.ApplicationContext.GlobalContext));
            }
            return(ConvertResponse(response));
        }
예제 #2
0
파일: WcfPortal.cs 프로젝트: BiYiTuan/csla
 public WcfResponse Fetch(CriteriaRequest request)
 {
   Csla.Server.DataPortal portal = new Csla.Server.DataPortal();
   Exception error = null;
   DataPortalResult result = null;
   WcfResponse response = null;
   ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter();
   try
   {
     request = ConvertRequest(request);
     DataPortalContext context = new DataPortalContext(
         formatter.Deserialize(request.Principal) as IPrincipal,
         true,
         request.ClientCulture,
         request.ClientUICulture,
         formatter.Deserialize(request.ClientContext) as ContextDictionary,
         formatter.Deserialize(request.GlobalContext) as ContextDictionary);
     result = portal.Fetch(Type.GetType(request.TypeName), formatter.Deserialize(request.CriteriaData), context);
     response = new WcfResponse(
         formatter.Serialize(result.ReturnObject),
         formatter.Serialize(error),
         formatter.Serialize(Csla.ApplicationContext.GlobalContext));
   }
   catch (Exception ex)
   {
     error = ex;
     response = new WcfResponse(
        null,
        formatter.Serialize(error),
        formatter.Serialize(Csla.ApplicationContext.GlobalContext));
   }
   return ConvertResponse(response);
 }
        public async Task <WcfResponse> Update(UpdateRequest request)
        {
            Csla.Server.DataPortal portal = new Csla.Server.DataPortal();

            object result;

            try
            {
                result = await portal.Update(request.Object, request.Context, true);
            }
            catch (Exception ex)
            {
                result = ex;
            }

            return(new WcfResponse(result));
        }
예제 #4
0
파일: GrpcPortal.cs 프로젝트: ajj7060/csla
        /// <summary>
        /// Delete a business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        public async Task <HttpResponse> Delete(CriteriaRequest request)
        {
            var result = new HttpResponse();

            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 objectType = Csla.Reflection.MethodCaller.GetType(AssemblyNameTranslator.GetAssemblyQualifiedName(request.TypeName), true);
                var context    = new DataPortalContext(
                    (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal),
                    true,
                    request.ClientCulture,
                    request.ClientUICulture,
                    (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext),
                    (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext));

                var prtl = new Csla.Server.DataPortal();
                var dpr  = await prtl.Delete(objectType, criteria, context, true);

                if (dpr.Error != null)
                {
                    result.ErrorData = new HttpErrorInfo(dpr.Error);
                }
                result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext);
                result.ObjectData    = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
            }
            catch (Exception ex)
            {
                result.ErrorData = new HttpErrorInfo(ex);
                throw;
            }
            finally
            {
                result = ConvertResponse(result);
            }
            return(result);
        }
예제 #5
0
 /// <summary>
 /// Update a business object.
 /// </summary>
 /// <param name="objectData">Business object to update.</param>
 /// <param name="contextData">
 /// Server.DataPortalContext object passed to the server.
 /// </param>
 public async Task<byte[]> Update(byte[] objectData, byte[] contextData)
 {
   DataPortalResult result;
   try
   {
     var obj = Csla.Serialization.Mobile.MobileFormatter.Deserialize(objectData);
     var context = (DataPortalContext)Csla.Serialization.Mobile.MobileFormatter.Deserialize(contextData);
     var portal = new Csla.Server.DataPortal();
     result = await portal.Update(obj, context, false);
   }
   catch (Exception ex)
   {
     result = new DataPortalResult(null, ex, null);
   }
   var response = GetDataPortalResult(result);
   var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);
   return resultData;
 }
예제 #6
0
 /// <summary>
 /// Get an existing business object.
 /// </summary>
 /// <param name="objectTypeName">Type of business object to retrieve.</param>
 /// <param name="criteriaData">Criteria object describing business object.</param>
 /// <param name="contextData">
 /// Server.DataPortalContext object passed to the server.
 /// </param>
 public async Task<byte[]> Fetch(string objectTypeName, byte[] criteriaData, byte[] contextData)
 {
   DataPortalResult result;
   try
   {
     var objectType = Csla.Reflection.MethodCaller.GetType(objectTypeName);
     var criteria = Csla.Serialization.Mobile.MobileFormatter.Deserialize(criteriaData);
     var context = (DataPortalContext)Csla.Serialization.Mobile.MobileFormatter.Deserialize(contextData);
     var portal = new Csla.Server.DataPortal();
     result = await portal.Fetch(objectType, criteria, context, false);
   }
   catch (Exception ex)
   {
     result = new DataPortalResult(null, ex, null);
   }
   var response = GetDataPortalResult(result);
   var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);
   return resultData;
 }
예제 #7
0
        /// <summary>
        /// Update a business object.
        /// </summary>
        /// <param name="objectData">Business object to update.</param>
        /// <param name="contextData">
        /// Server.DataPortalContext object passed to the server.
        /// </param>
        public async Task <byte[]> Update(byte[] objectData, byte[] contextData)
        {
            DataPortalResult result;

            try
            {
                var obj     = Csla.Serialization.Mobile.MobileFormatter.Deserialize(objectData);
                var context = (DataPortalContext)Csla.Serialization.Mobile.MobileFormatter.Deserialize(contextData);
                var portal  = new Csla.Server.DataPortal();
                result = await portal.Update(obj, context, false);
            }
            catch (Exception ex)
            {
                result = new DataPortalResult(null, ex, null);
            }
            var response   = GetDataPortalResult(result);
            var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);

            return(resultData);
        }
예제 #8
0
        /// <summary>
        /// Get an existing business object.
        /// </summary>
        /// <param name="objectTypeName">Type of business object to retrieve.</param>
        /// <param name="criteriaData">Criteria object describing business object.</param>
        /// <param name="contextData">
        /// Server.DataPortalContext object passed to the server.
        /// </param>
        public async Task <byte[]> Fetch(string objectTypeName, byte[] criteriaData, byte[] contextData)
        {
            DataPortalResult result;

            try
            {
                var objectType = Csla.Reflection.MethodCaller.GetType(objectTypeName);
                var criteria   = Csla.Serialization.Mobile.MobileFormatter.Deserialize(criteriaData);
                var context    = (DataPortalContext)Csla.Serialization.Mobile.MobileFormatter.Deserialize(contextData);
                var portal     = new Csla.Server.DataPortal();
                result = await portal.Fetch(objectType, criteria, context, false);
            }
            catch (Exception ex)
            {
                result = new DataPortalResult(null, ex, null);
            }
            var response   = GetDataPortalResult(result);
            var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);

            return(resultData);
        }
예제 #9
0
파일: GrpcPortal.cs 프로젝트: ajj7060/csla
        /// <summary>
        /// Update a business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
        public async Task <HttpResponse> Update(UpdateRequest request)
        {
            var result = new HttpResponse();

            try
            {
                request = ConvertRequest(request);
                // unpack object
                object obj = GetCriteria(request.ObjectData);

                var context = new DataPortalContext(
                    (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal),
                    true,
                    request.ClientCulture,
                    request.ClientUICulture,
                    (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext),
                    (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext));

                var prtl = new Csla.Server.DataPortal();
                var dpr  = await prtl.Update(obj, context, true);

                if (dpr.Error != null)
                {
                    result.ErrorData = new HttpErrorInfo(dpr.Error);
                }

                result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext);
                result.ObjectData    = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
            }
            catch (Exception ex)
            {
                result.ErrorData = new HttpErrorInfo(ex);
                throw;
            }
            finally
            {
                result = ConvertResponse(result);
            }
            return(result);
        }
예제 #10
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
                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);
            }
        }
예제 #11
0
 private async Task InvokeOperationAsync(object criteria, bool isSync, Type attributeType)
 {
     object[] parameters = DataPortal <object> .GetCriteriaArray(criteria);
     await CallMethodTryAsyncDI(isSync, attributeType, parameters).ConfigureAwait(false);
 }