Esempio n. 1
0
        /// <summary>
        /// Get an existing business object.
        /// </summary>
        /// <param name="request">The request parameter object.</param>
#pragma warning disable 1998
        public async Task <DataPortalResponse> Fetch(CriteriaRequest request)
#pragma warning restore 1998
        {
            var result = new DataPortalResponse();

            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 dpr = await dataPortalServer.Fetch(objectType, criteria, context, true);

                if (dpr.Error != null)
                {
                    result.ErrorData = new DataPortalErrorInfo(dpr.Error);
                }
                result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
            }
            catch (Exception ex)
            {
                result.ErrorData = new DataPortalErrorInfo(ex);
                throw;
            }
            finally
            {
                result = ConvertResponse(result);
            }
            return(result);
        }
Esempio n. 2
0
        void DoFetch(object state)
        {
            FetchTask task = state as FetchTask;

            task.Result = Portal.Fetch(task.ObjectType, task.Criteria, task.Context);
        }