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)); }
/// <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); }
public WcfResponse Create(CriteriaRequest request) { var result = new WcfResponse(); try { request = ConvertRequest(request); // unpack criteria data into object object criteria = GetCriteria(request.CriteriaData); if (criteria is PrimitiveCriteria) { criteria = ((PrimitiveCriteria)criteria).Value; } SilverlightRequestProcessor processor = new SilverlightRequestProcessor(); SilverlightCriteriaRequest createRequest = new SilverlightCriteriaRequest( request.TypeName, criteria, (IPrincipal)MobileFormatter.Deserialize(request.Principal), (ContextDictionary)MobileFormatter.Deserialize(request.GlobalContext), (ContextDictionary)MobileFormatter.Deserialize(request.ClientContext)); SilverlightResponse createResponse = processor.Create(createRequest); 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 { SilverlightRequestProcessor.ClearContext(); } return(ConvertResponse(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 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); }