Exemplo n.º 1
0
        public WcfResponse Update(UpdateRequest request)
        {
            var result = new WcfResponse();

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

                SilverlightRequestProcessor processor     = new SilverlightRequestProcessor();
                SilverlightUpdateRequest    updateRequest = new SilverlightUpdateRequest(
                    obj,
                    (IPrincipal)MobileFormatter.Deserialize(request.Principal),
                    (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext),
                    (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext));

                SilverlightResponse updateResponse = processor.Update(updateRequest);
                if (updateResponse.Error != null)
                {
                    result.ErrorData = new WcfErrorInfo(updateResponse.Error);
                }
                result.GlobalContext = MobileFormatter.Serialize(updateResponse.GlobalContext);
                result.ObjectData    = MobileFormatter.Serialize(updateResponse.Object);
            }
            catch (Exception ex)
            {
                result.ErrorData = new WcfErrorInfo(ex);
            }
            finally
            {
                SilverlightRequestProcessor.ClearContext();
            }
            return(ConvertResponse(result));
        }
Exemplo n.º 2
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 SilverlightResponse Update(SilverlightUpdateRequest request)
        {
            var    result = new SilverlightResponse();
            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);
                    o = Csla.DataPortal.Update(obj);
                }
                else
                {
                    if (string.IsNullOrEmpty(factoryInfo.UpdateMethodName))
                    {
                        throw new InvalidOperationException(Resources.UpdateMethodNameNotSpecified);
                    }

                    SetContext(request);
                    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);
        }