private void SynchronizeData(ClientTransaction targetTransaction, IEnumerable <Tuple <TransportItem, DataContainer> > sourceToTargetMapping) { foreach (Tuple <TransportItem, DataContainer> sourceToTargetContainer in sourceToTargetMapping) { TransportItem transportItem = sourceToTargetContainer.Item1; DataContainer targetContainer = sourceToTargetContainer.Item2; PropertyIndexer targetProperties = new PropertyIndexer(targetContainer.DomainObject); foreach (KeyValuePair <string, object> sourceProperty in transportItem.Properties) { PropertyAccessor targetProperty = targetProperties[sourceProperty.Key, targetTransaction]; switch (targetProperty.PropertyData.Kind) { case PropertyKind.PropertyValue: targetProperty.SetValueWithoutTypeCheck(sourceProperty.Value); break; case PropertyKind.RelatedObject: if (!targetProperty.PropertyData.RelationEndPointDefinition.IsVirtual) { var relatedObjectID = (ObjectID)sourceProperty.Value; var targetRelatedObject = relatedObjectID != null?targetTransaction.GetObject(relatedObjectID, false) : null; targetProperty.SetValueWithoutTypeCheck(targetRelatedObject); } break; } } } }
/// <summary> /// Exports the objects loaded into this transporter (including their contents) in a custom format for transport to another system. /// At the target system, the data can be loaded via <see cref="LoadTransportData(Stream,IImportStrategy)"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> to which to export the loaded objects.</param> /// <param name="strategy">The strategy to be used for exporting data. This must match the strategy used with /// <see cref="LoadTransportData(System.IO.Stream,Remotion.Data.DomainObjects.DomainImplementation.Transport.IImportStrategy)"/>.</param> public void Export(Stream stream, IExportStrategy strategy) { IEnumerable <DataContainer> transportedContainers = GetTransportedContainers(); TransportItem[] transportItems = TransportItem.PackageDataContainers(transportedContainers).ToArray(); strategy.Export(stream, transportItems); }
/// <summary> /// Packages the data held by a <see cref="DataContainer"/> into a <see cref="TransportItem"/>. This method is only meant for internal purposes. /// </summary> /// <param name="container">The container to package.</param> /// <returns>A <see cref="TransportItem"/> holding the same data as <paramref name="container"/>.</returns> public static TransportItem PackageDataContainer (DataContainer container) { ArgumentUtility.CheckNotNull ("container", container); TransportItem item = new TransportItem (container.ID); foreach (var propertyDefinition in container.ClassDefinition.GetPropertyDefinitions()) item.Properties.Add (propertyDefinition.PropertyName, container.GetValue (propertyDefinition)); return item; }
public void ReadXml(XmlReader reader) { ArgumentUtility.CheckNotNull("reader", reader); string idString = reader.GetAttribute("ID"); ObjectID id = ObjectID.Parse(idString); reader.Read(); List <KeyValuePair <string, object> > properties = DeserializeProperties(reader, id.ClassDefinition); reader.ReadEndElement(); _transportItem = CreateTransportItem(id, properties); }
private DataContainer GetTargetDataContainer(TransportItem transportItem, Dictionary <ObjectID, DomainObject> existingObjects, ClientTransaction bindingTargetTransaction) { DomainObject existingObject; if (existingObjects.TryGetValue(transportItem.ID, out existingObject)) { return(bindingTargetTransaction.DataManager.GetDataContainerWithLazyLoad(existingObject.ID, throwOnNotFound: true)); } else { var id = transportItem.ID; var instance = bindingTargetTransaction.GetInvalidObjectReference(id); ResurrectionService.ResurrectInvalidObject(bindingTargetTransaction, id); var newDataContainer = DataContainer.CreateNew(id); newDataContainer.SetDomainObject(instance); bindingTargetTransaction.DataManager.RegisterDataContainer(newDataContainer); return(newDataContainer); } }
public XmlTransportItem(TransportItem itemToBeSerialized) { _transportItem = itemToBeSerialized; }