private async void InvokePortal(BasicDeliverEventArgs ea, byte[] requestData) { var result = new DataPortalResponse(); try { var request = SerializationFormatterFactory.GetFormatter().Deserialize(requestData); result = await CallPortal(ea.BasicProperties.Type, request); } catch (Exception ex) { result.ErrorData = new DataPortalErrorInfo(ex); } try { var response = SerializationFormatterFactory.GetFormatter().Serialize(result); SendMessage(ea.BasicProperties.ReplyTo, ea.BasicProperties.CorrelationId, response); } catch (Exception ex) { try { result = new DataPortalResponse { ErrorData = new DataPortalErrorInfo(ex) }; var response = SerializationFormatterFactory.GetFormatter().Serialize(result); SendMessage(ea.BasicProperties.ReplyTo, ea.BasicProperties.CorrelationId, response); } catch (Exception ex1) { Console.Error.WriteLine($"## ERROR {ex1.Message}"); } } }
/// <summary> /// Override this method to insert your field values /// into the MobileFormatter serialzation stream. /// </summary> /// <param name="info"> /// Object containing the data to serialize. /// </param> /// <param name="mode"> /// The StateMode indicating why this method was invoked. /// </param> protected override void OnGetState(SerializationInfo info, StateMode mode) { info.AddValue("_businessObjectType", _businessObjectType); if (mode == StateMode.Serialization && _stateStack.Count > 0) { info.AddValue("_stateStack", _stateStack.ToArray()); } foreach (IFieldData data in _fieldData) { if (data != null) { if (data.Value is IUndoableObject) { info.AddValue("child_" + data.Name, true, false); } else if (mode == StateMode.Undo && data.Value is IMobileObject) { info.AddValue(data.Name, SerializationFormatterFactory.GetFormatter().Serialize(data.Value), data.IsDirty); } else if (!(data.Value is IMobileObject)) { info.AddValue(data.Name, data.Value, data.IsDirty); } } } base.OnGetState(info, mode); }
public WcfResponse Update(UpdateRequest request) { var portal = new DataPortal(); Exception error = null; WcfResponse response; var formatter = SerializationFormatterFactory.GetFormatter(); try { request = ConvertRequest(request); var 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); var result = portal.Update(formatter.Deserialize(request.ObjectData), context, true); response = new WcfResponse( formatter.Serialize(result.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 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)); }
/// <summary> /// Called by <see cref="DataPortal" /> to create a /// new business object. /// </summary> /// <param name="objectType">Type of business object to create.</param> /// <param name="criteria">Criteria object describing business object.</param> /// <param name="context"> /// <see cref="Server.DataPortalContext" /> object passed to the server. /// </param> public DataPortalResult Create(Type objectType, object criteria, DataPortalContext context) { ChannelFactory <IExtendableWcfPortalForDotNet> cf = GetChannelFactory(); IExtendableWcfPortalForDotNet svr = GetProxy(cf); WcfResponse response = null; ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter(); try { response = svr.Create(GetRequest(formatter, objectType, criteria, context)); if (cf != null) { cf.Close(); } } catch { cf.Abort(); throw; } DataPortalResult result = GetResult(formatter, response); Exception error = (Exception)formatter.Deserialize(response.Error); if (error != null) { throw error; } return(result); }
private DataPortalResult Create() { var cf = GetChannelFactory(); var svr = GetProxy(cf); WcfResponse response; var formatter = SerializationFormatterFactory.GetFormatter(); try { response = svr.Create(GetRequest(formatter, _objectType, _criteria, _context)); if (cf != null) { cf.Close(); } } catch { cf.Abort(); throw; } var result = GetResult(formatter, response); var error = (Exception)formatter.Deserialize(response.Error); if (error != null) { throw error; } return(result); }
protected internal void CopyState(int parentEditLevel) { CopyingState(); Type currentType = this.GetType(); HybridDictionary state = new HybridDictionary(); if (this.EditLevel + 1 > parentEditLevel) { throw new UndoException(string.Format(Resources.EditLevelMismatchException, "CopyState")); } do { // get the list of fields in this type List <DynamicMemberHandle> handlers = UndoableHandler.GetCachedFieldHandlers(currentType); foreach (var h in handlers) { var value = h.DynamicMemberGet(this); if (typeof(YYT.Core.IUndoableObject).IsAssignableFrom(h.MemberType)) { // make sure the variable has a value if (value == null) { // variable has no value - store that fact //state.Add(h.MemberFullName, null); state.Add(h.MemberName, null); } else { // this is a child object, cascade the call ((Core.IUndoableObject)value).CopyState(this.EditLevel + 1, BindingEdit); } } else { // this is a normal field, simply trap the value //state.Add(h.MemberFullName, value); state.Add(h.MemberName, value); } } currentType = currentType.BaseType; } while (currentType != typeof(UndoableBase)); // serialize the state and stack it using (MemoryStream buffer = new MemoryStream()) { ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter(); formatter.Serialize(buffer, state); _stateStack.Push(buffer.ToArray()); } CopyStateComplete(); }
/// <summary> /// Clones an object. /// </summary> /// <param name="obj">The object to clone.</param> /// <remarks> /// <para>The object to be cloned must be serializable.</para> /// <para>The serialization is performed using the formatter /// specified in ApplicationContext.</para> /// <para>The default is to use the MobileFormatter.</para> /// </remarks> public object Clone(object obj) { using var buffer = new MemoryStream(); ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter(ApplicationContext); formatter.Serialize(buffer, obj); buffer.Position = 0; return(formatter.Deserialize(buffer)); }
private static object GetCriteria(ApplicationContext applicationContext, byte[] criteriaData) { object criteria = null; if (criteriaData != null) { criteria = SerializationFormatterFactory.GetFormatter(applicationContext).Deserialize(criteriaData); } return(criteria); }
private static object GetCriteria(byte[] criteriaData) { object criteria = null; if (criteriaData != null) { criteria = SerializationFormatterFactory.GetFormatter().Deserialize(criteriaData); } return(criteria); }
/// <summary> /// 使用序列化器来序列化反序列化的方式,深度复制一个对象 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static T Clone <T>(T obj) { using (MemoryStream buffer = new MemoryStream()) { var formatter = SerializationFormatterFactory.GetFormatter(); formatter.Serialize(buffer, obj); buffer.Position = 0; object temp = formatter.Deserialize(buffer); return((T)temp); } }
public void UseCustomSerializationFormatter() { TestDIContext customDIContext = TestDIContextFactory.CreateContext(options => options .Serialization(cfg => cfg .SerializationFormatter(typeof(NetDataContractSerializerWrapper)))); ApplicationContext applicationContext = customDIContext.CreateTestApplicationContext(); var formatter = SerializationFormatterFactory.GetFormatter(applicationContext); Assert.IsInstanceOfType(formatter, typeof(NetDataContractSerializerWrapper)); }
private UpdateRequest GetBaseUpdateCriteriaRequest() { return(new UpdateRequest { ObjectData = null, ClientContext = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.ClientContext), Principal = SerializationFormatterFactory.GetFormatter() .Serialize(ApplicationContext.AuthenticationType == "Windows" ? null : ApplicationContext.User), ClientCulture = Thread.CurrentThread.CurrentCulture.Name, ClientUICulture = Thread.CurrentThread.CurrentUICulture.Name }); }
private CriteriaRequest GetBaseCriteriaRequest() { return(new CriteriaRequest { CriteriaData = null, ClientContext = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.ClientContext), Principal = SerializationFormatterFactory.GetFormatter() .Serialize(ApplicationContext.AuthenticationType == "Windows" ? null : ApplicationContext.User), ClientCulture = System.Globalization.CultureInfo.CurrentCulture.Name, ClientUICulture = System.Globalization.CultureInfo.CurrentUICulture.Name }); }
/// <summary> /// Called by <see cref="DataPortal" /> to delete a /// business object. /// </summary> /// <param name="objectType">Type of business object to create.</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> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync) { if (isSync) { throw new NotSupportedException("isSync == true"); } InitializeRabbitMQ(); DataPortalResult result; try { var request = GetBaseCriteriaRequest(); request.TypeName = AssemblyNameTranslator.GetAssemblyQualifiedName(objectType.AssemblyQualifiedName); if (!(criteria is IMobileObject)) { criteria = new PrimitiveCriteria(criteria); } request.CriteriaData = SerializationFormatterFactory.GetFormatter().Serialize(criteria); request = ConvertRequest(request); var serialized = SerializationFormatterFactory.GetFormatter().Serialize(request); serialized = await CallDataPortalServer(serialized, "delete"); var response = (Server.Hosts.HttpChannel.HttpResponse)SerializationFormatterFactory.GetFormatter().Deserialize(serialized); response = ConvertResponse(response); var globalContext = (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(response.GlobalContext); if (response != null && response.ErrorData == null) { var obj = SerializationFormatterFactory.GetFormatter().Deserialize(response.ObjectData); result = new DataPortalResult(obj, null, globalContext); } else if (response != null && response.ErrorData != null) { var ex = new DataPortalException(response.ErrorData); result = new DataPortalResult(null, ex, globalContext); } else { throw new DataPortalException("null response", null); } } catch (Exception ex) { result = new DataPortalResult(null, ex, null); } if (result.Error != null) { throw result.Error; } return(result); }
private UpdateRequest GetBaseUpdateCriteriaRequest() { var result = ApplicationContext.CreateInstanceDI <UpdateRequest>(); result.ObjectData = null; result.ClientContext = SerializationFormatterFactory.GetFormatter(ApplicationContext).Serialize(ApplicationContext.ClientContext); result.Principal = SerializationFormatterFactory.GetFormatter(ApplicationContext) .Serialize(ApplicationContext.AuthenticationType == "Windows" ? null : ApplicationContext.User); result.ClientCulture = Thread.CurrentThread.CurrentCulture.Name; result.ClientUICulture = Thread.CurrentThread.CurrentUICulture.Name; return(result); }
private static T SerializeAndDeserializeObjects <T>(T original) { using (var buffer = new MemoryStream()) { var formatter = SerializationFormatterFactory.GetFormatter(); Debug.Assert(formatter.GetType() == typeof(MobileFormatter)); formatter.Serialize(buffer, original); buffer.Position = 0; var copy = formatter.Deserialize(buffer); return((T)copy); } }
public void UseNetDataContractSerializer() { System.Configuration.ConfigurationManager.AppSettings["CslaSerializationFormatter"] = "NetDataContractSerializer"; try { var formatter = SerializationFormatterFactory.GetFormatter(); Assert.AreEqual(ApplicationContext.SerializationFormatter, ApplicationContext.SerializationFormatters.NetDataContractSerializer); Assert.IsInstanceOfType(formatter, typeof(NetDataContractSerializerWrapper)); } finally { System.Configuration.ConfigurationManager.AppSettings["CslaSerializationFormatter"] = null; } }
private static UpdateRequest GetBaseUpdateCriteriaRequest() { return(new UpdateRequest { ObjectData = null, ClientContext = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.ClientContext), #pragma warning disable CS0618 // Type or member is obsolete GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.GlobalContext), #pragma warning restore CS0618 // Type or member is obsolete Principal = SerializationFormatterFactory.GetFormatter() .Serialize(ApplicationContext.AuthenticationType == "Windows" ? null : ApplicationContext.User), ClientCulture = Thread.CurrentThread.CurrentCulture.Name, ClientUICulture = Thread.CurrentThread.CurrentUICulture.Name }); }
void Core.IUndoableObject.UndoChanges(int parentEditLevel, bool parentBindingEdit) { if (EditLevel > 0) { if (this.EditLevel - 1 != parentEditLevel) { throw new UndoException(string.Format(Resources.EditLevelMismatchException, "UndoChanges"), this.GetType().Name, _parent != null ? _parent.GetType().Name : null, this.EditLevel, parentEditLevel + 1); } IFieldData[] state = null; using (MemoryStream buffer = new MemoryStream(_stateStack.Pop())) { buffer.Position = 0; var formatter = SerializationFormatterFactory.GetFormatter(); state = ((MobileList <IFieldData>)(formatter.Deserialize(buffer))).ToArray(); } for (var index = 0; index < _fieldData.Length; index++) { var oldItem = state[index]; var item = _fieldData[index]; if (item != null) { if (item.Value is IUndoableObject undoable) { // current value is undoable var doUndo = (oldItem != null); if (!doUndo) { var propInfo = _propertyList.Where(r => r.Index == index).First(); doUndo = propInfo.RelationshipType.HasFlag(RelationshipTypes.LazyLoad); } if (doUndo) { undoable.UndoChanges(parentEditLevel, parentBindingEdit); } else { _fieldData[index] = null; } continue; } } // restore IFieldData object into field collection _fieldData[index] = oldItem; } } }
/// <summary> /// Called by <see cref="DataPortal" /> to update a /// business object. /// </summary> /// <param name="obj">The business object to update.</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> Update(object obj, DataPortalContext context, bool isSync) { if (isSync) { throw new NotSupportedException("isSync == true"); } InitializeRabbitMQ(); DataPortalResult result; try { var request = GetBaseUpdateCriteriaRequest(); request.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(obj); request = ConvertRequest(request); var serialized = SerializationFormatterFactory.GetFormatter().Serialize(request); serialized = await CallDataPortalServer(serialized, "update"); var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)SerializationFormatterFactory.GetFormatter().Deserialize(serialized); response = ConvertResponse(response); var globalContext = (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(response.GlobalContext); if (response != null && response.ErrorData == null) { var newobj = SerializationFormatterFactory.GetFormatter().Deserialize(response.ObjectData); result = new DataPortalResult(newobj, null, globalContext); } else if (response != null && response.ErrorData != null) { var ex = new DataPortalException(response.ErrorData); result = new DataPortalResult(null, ex, globalContext); } else { throw new DataPortalException("null response", null); } } catch (Exception ex) { result = new DataPortalResult(null, ex, null); } if (result.Error != null) { throw result.Error; } return(result); }
/// <summary> /// Called by <see cref="DataPortal" /> to delete a /// business object. /// </summary> /// <param name="objectType">Type of business object to create.</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 virtual Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync) { DataPortalResult result; try { var request = GetBaseCriteriaRequest(); request.TypeName = AssemblyNameTranslator.GetAssemblyQualifiedName(objectType.AssemblyQualifiedName); if (!(criteria is IMobileObject)) { criteria = new PrimitiveCriteria(criteria); } request.CriteriaData = SerializationFormatterFactory.GetFormatter().Serialize(criteria); request = ConvertRequest(request); var serialized = SerializationFormatterFactory.GetFormatter().Serialize(request); serialized = await CallDataPortalServer(serialized, "delete", GetRoutingToken(objectType), isSync); var response = (DataPortalResponse)SerializationFormatterFactory.GetFormatter().Deserialize(serialized); response = ConvertResponse(response); var globalContext = (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(response.GlobalContext); if (response.ErrorData == null) { result = new DataPortalResult(null, null, globalContext); } else if (response.ErrorData != null) { var ex = new DataPortalException(response.ErrorData); result = new DataPortalResult(null, ex, globalContext); } else { throw new DataPortalException("null response", null); } } catch (Exception ex) { result = new DataPortalResult(null, ex, null); } if (result.Error != null) { throw result.Error; } return(result); }
/// <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 prtl = new Csla.Server.DataPortal(); var dpr = await prtl.Fetch(objectType, criteria, context, true); if (dpr.Error != null) { result.ErrorData = new DataPortalErrorInfo(dpr.Error); } result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext); result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject); } catch (Exception ex) { result.ErrorData = new DataPortalErrorInfo(ex); throw; } finally { result = ConvertResponse(result); } return(result); }
public async Task <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 Csla.DataPortalClient.PrimitiveCriteria) { criteria = ((Csla.DataPortalClient.PrimitiveCriteria)criteria).Value; } var processor = new MobileRequestProcessor(); var createRequest = new MobileCriteriaRequest( request.TypeName, criteria, (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.Principal), (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.GlobalContext), (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(request.ClientContext), request.ClientCulture, request.ClientUICulture); var createResponse = await processor.Create(createRequest).ConfigureAwait(false); if (createResponse.Error != null) { result.ErrorData = new WcfErrorInfo(createResponse.Error); } result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(createResponse.GlobalContext); result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(createResponse.Object); } catch (Exception ex) { result.ErrorData = new WcfErrorInfo(ex); } finally { MobileRequestProcessor.ClearContext(); } return(ConvertResponse(result)); }
void Core.IUndoableObject.UndoChanges(int parentEditLevel, bool parentBindingEdit) { if (EditLevel > 0) { if (this.EditLevel - 1 != parentEditLevel) { throw new UndoException(string.Format(Properties.Resources.EditLevelMismatchException, "UndoChanges")); } IFieldData[] state = null; using (MemoryStream buffer = new MemoryStream(_stateStack.Pop())) { buffer.Position = 0; var formatter = SerializationFormatterFactory.GetFormatter(); state = (IFieldData[])(formatter.Deserialize(buffer)); } for (var index = 0; index < _fieldData.Length; index++) { var oldItem = state[index]; var item = _fieldData[index]; if (item != null) { var undoable = item.Value as IUndoableObject; if (undoable != null) { // current value is undoable if (oldItem != null) { undoable.UndoChanges(parentEditLevel, parentBindingEdit); } else { _fieldData[index] = null; } continue; } } // restore IFieldData object into field collection _fieldData[index] = oldItem; } } }
/// <summary> /// Delete a business object. /// </summary> /// <param name="request">The request parameter object.</param> public async Task <DataPortalResponse> Delete(CriteriaRequest request) { var result = ApplicationContext.CreateInstanceDI <DataPortalResponse>(); try { request = ConvertRequest(request); // unpack criteria data into object object criteria = GetCriteria(ApplicationContext, 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( ApplicationContext, (IPrincipal)SerializationFormatterFactory.GetFormatter(ApplicationContext).Deserialize(request.Principal), true, request.ClientCulture, request.ClientUICulture, (ContextDictionary)SerializationFormatterFactory.GetFormatter(ApplicationContext).Deserialize(request.ClientContext)); var dpr = await dataPortalServer.Delete(objectType, criteria, context, true); if (dpr.Error != null) { result.ErrorData = ApplicationContext.CreateInstanceDI <DataPortalErrorInfo>(dpr.Error); } result.ObjectData = SerializationFormatterFactory.GetFormatter(ApplicationContext).Serialize(dpr.ReturnObject); } catch (Exception ex) { result.ErrorData = ApplicationContext.CreateInstanceDI <DataPortalErrorInfo>(ex); throw; } finally { result = ConvertResponse(result); } return(result); }
/// <summary> /// Called by <see cref="DataPortal" /> to update a /// business object. /// </summary> /// <param name="obj">The business object to update.</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 virtual Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { DataPortalResult result; try { var request = GetBaseUpdateCriteriaRequest(); request.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(obj); request = ConvertRequest(request); var serialized = SerializationFormatterFactory.GetFormatter().Serialize(request); serialized = await CallDataPortalServer(serialized, "update", GetRoutingToken(obj.GetType()), isSync); var response = (DataPortalResponse)SerializationFormatterFactory.GetFormatter().Deserialize(serialized); response = ConvertResponse(response); var globalContext = (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(response.GlobalContext); if (response.ErrorData == null) { var newobj = SerializationFormatterFactory.GetFormatter().Deserialize(response.ObjectData); result = new DataPortalResult(newobj, null, globalContext); } else if (response.ErrorData != null) { var ex = new DataPortalException(response.ErrorData); result = new DataPortalResult(null, ex, globalContext); } else { throw new DataPortalException("null response", null); } } catch (Exception ex) { result = new DataPortalResult(null, ex, null); } if (result.Error != null) { throw result.Error; } return(result); }
/// <summary> /// Update a business object. /// </summary> /// <param name="request">The request parameter object.</param> #pragma warning disable 1998 public async Task <DataPortalResponse> Update(UpdateRequest request) #pragma warning restore 1998 { var result = new DataPortalResponse(); 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 DataPortalErrorInfo(dpr.Error); } result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext); result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject); } catch (Exception ex) { result.ErrorData = new DataPortalErrorInfo(ex); throw; } finally { result = ConvertResponse(result); } return(result); }
private Csla.Server.Hosts.HttpChannel.UpdateRequest GetBaseUpdateCriteriaRequest() { var request = new Csla.Server.Hosts.HttpChannel.UpdateRequest(); request.ObjectData = null; request.ClientContext = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.ClientContext); #pragma warning disable CS0618 // Type or member is obsolete request.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.GlobalContext); #pragma warning restore CS0618 // Type or member is obsolete if (ApplicationContext.AuthenticationType == "Windows") { request.Principal = SerializationFormatterFactory.GetFormatter().Serialize(null); } else { request.Principal = SerializationFormatterFactory.GetFormatter().Serialize(ApplicationContext.User); } request.ClientCulture = Thread.CurrentThread.CurrentCulture.Name; request.ClientUICulture = Thread.CurrentThread.CurrentUICulture.Name; return(request); }
public async Task Can_Serialise_and_Deserialise() { var root = Root.NewRoot(); root.Data = "ya"; var formatter = SerializationFormatterFactory.GetFormatter(); using (var memoryStream = new MemoryStream()) { formatter.Serialize(memoryStream, root); memoryStream.Position = 0; var originalBytes = memoryStream.ToArray(); memoryStream.Position = 0; var result = formatter.Deserialize(memoryStream); var newRoot = result as Root; Assert.NotNull(newRoot); } }