/// <summary> /// Create a new business object. /// </summary> /// <param name="request">The request parameter object.</param> public WcfResponse Create(CriteriaRequest request) { var result = new WcfResponse(); try { request = ConvertRequest(request); // unpack criteria data into object object criteria = GetCriteria(request.CriteriaData); // load type for business object var t = Type.GetType(request.TypeName); if (t == null) { throw new InvalidOperationException( string.Format(Resources.ObjectTypeCouldNotBeLoaded, request.TypeName)); } SetContext(request); object o = null; var factoryInfo = GetMobileFactoryAttribute(t); if (factoryInfo == null) { if (criteria != null) { o = YYT.DataPortal.Create(criteria); } else { o = YYT.DataPortal.Create(t); } } else { if (string.IsNullOrEmpty(factoryInfo.CreateMethodName)) { throw new InvalidOperationException(Resources.CreateMethodNameNotSpecified); } object f = FactoryLoader.GetFactory(factoryInfo.FactoryTypeName); if (criteria != null) { o = YYT.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName, criteria); } else { o = YYT.Reflection.MethodCaller.CallMethod(f, factoryInfo.CreateMethodName); } } result.ObjectData = MobileFormatter.Serialize(o); result.GlobalContext = MobileFormatter.Serialize(ApplicationContext.GlobalContext); } catch (YYT.Reflection.CallMethodException ex) { result.ErrorData = new WcfErrorInfo(ex.InnerException); } catch (Exception ex) { result.ErrorData = new WcfErrorInfo(ex); } finally { ClearContext(); } return(ConvertResponse(result)); }
/// <summary> /// Override to convert the response data after it /// comes back from the network. /// </summary> /// <param name="response">Response object.</param> protected virtual WcfResponse ConvertResponse(WcfResponse response) { return(response); }