This question is locked. New answers and comments are not allowed.
Hello people,
I use the diagram ( using MVVM ) to create hierarchy between my entities. There are 3 types of entities that I use. I serialize and save them, later I gather it from db and show it again. But With particular type of entity, My Graph Source does not hit the break points in DeserializeNode function and they disappear after deserialization.
Have you ever encouter such an issue?
My graphsource implementation is given below. Note that VSSerializableGraphSoourbase just inherits from the SerializableGraphSoourbase with no changes.
public class EntityGraphSource<T> : VSSerializableGraphSourceBase<Node<T>, Link> where T : class, ICLOCApplicable, new(){ #region Public Methods and Operators /// <summary> /// The serialize node. /// </summary> /// <param name="node">The node.</param> /// <param name="info">The info.</param> /// <exception cref="System.ArgumentNullException"> /// Node or info. /// </exception> public override void SerializeNode(Node<T> node, SerializationInfo info) { if (node == null) { throw new ArgumentNullException("node"); } if (info == null) { throw new ArgumentNullException("info"); } base.SerializeNode(node, info); if (typeof(T) == typeof(UnitObject)) { UnitObject unit = node.Entity as UnitObject; if (unit != null) { info["EntityId"] = unit.Id; info["UIC"] = unit.UIC; info["Affiliation"] = unit.Affiliation.ToString(); info["UnitName"] = unit.UnitName; info["UnitType"] = unit.UnitType; info["ServiceType"] = unit.ServiceType; info["Echelon"] = unit.Echelon; } } else if (typeof(T) == typeof(OrganisationObject)) { OrganisationObject organisation = node.Entity as OrganisationObject; if (organisation != null) { info["EntityId"] = organisation.Id; info["OrganisationName"] = organisation.OrganisationName; info["Affiliation"] = organisation.Affiliation.ToString(); info["Abbreviation"] = organisation.Abbreviation; } } else if (typeof(T) == typeof(NonMilitaryEntityObject)) { NonMilitaryEntityObject nonMilitaryEntity = node.Entity as NonMilitaryEntityObject; if (nonMilitaryEntity != null) { info["EntityId"] = nonMilitaryEntity.Id; info["Affiliation"] = nonMilitaryEntity.Affiliation.ToString(); info["Nation"] = nonMilitaryEntity.Nation; info["NonMilitaryEntityName"] = nonMilitaryEntity.NonMilitaryEntityName; info["Type"] = nonMilitaryEntity.Type; } } } /// <summary> /// The deserialize node. /// </summary> /// <param name="shape">The shape.</param> /// <param name="info">The info.</param> /// <returns> /// The <see cref="Node{T}" />. /// </returns> /// <exception cref="System.ArgumentNullException">The info.</exception> public override Node<T> DeserializeNode(IShape shape, SerializationInfo info) { if (info == null) { throw new ArgumentNullException("info"); } var node = base.DeserializeNode(shape, info); if (typeof(T) == typeof(UnitObject)) { UnitObject entity = new UnitObject(); entity.Id = (string)info["EntityId"]; entity.UIC = (string)info["UIC"]; entity.UnitType = (string)info["UnitType"]; entity.UnitName = (string)info["UnitName"]; AffiliationType affiliation; bool result = AffiliationType.TryParse(info["Affiliation"].ToString(), false, out affiliation); entity.Affiliation = result ? affiliation : AffiliationType.F; entity.ServiceType = (string)info["ServiceType"]; entity.Echelon = (string)info["Echelon"]; node.Entity = entity as T; } else if (typeof(T) == typeof(OrganisationObject)) { OrganisationObject entity = new OrganisationObject(); entity.Id = (string)info["EntityId"]; entity.OrganisationName = (string)info["OrganisationName"]; AffiliationType affiliation; bool result = AffiliationType.TryParse(info["Affiliation"].ToString(), false, out affiliation); entity.Affiliation = result ? affiliation : AffiliationType.F; entity.Abbreviation = (string)info["Abbreviation"]; node.Entity = entity as T; } else if (typeof(T) == typeof(NonMilitaryEntityObject)) { NonMilitaryEntityObject entity = new NonMilitaryEntityObject(); entity.Id = (string)info["EntityId"]; entity.NonMilitaryEntityName = (string)info["NonMilitaryEntityName"]; AffiliationType affiliation; bool result = AffiliationType.TryParse(info["Affiliation"].ToString(), false, out affiliation); entity.Affiliation = result ? affiliation : AffiliationType.F; entity.Nation = (string)info["Nation"]; entity.Type = (string)info["Type"]; node.Entity = entity as T; } if (info[this.NodeUniqueIdKey] != null) { var nodeUniquekey = info[this.NodeUniqueIdKey].ToString(); this.CachedNodes[nodeUniquekey] = node; } return node; } /// <summary> /// The serialize link. /// </summary> /// <param name="link"> /// The link. /// </param> /// <param name="info"> /// The info. /// </param> public override void SerializeLink(Link link, SerializationInfo info) { if (link == null) { throw new ArgumentNullException("link"); } if (info == null) { throw new ArgumentNullException("info"); } this.ClearCache(); base.SerializeLink(link, info); if (link.ClOCId.IsNullOrEmpty()) { link.ClOCId = Guid.NewGuid().ToString(); } info["ClOCId"] = link.ClOCId; info["RelationType"] = link.RelationType; } /// <summary> /// The get node unique id. /// </summary> /// <param name="node">The node.</param> /// <returns> /// The <see cref="string" />. /// </returns> public override string GetNodeUniqueId(Node<T> node) { if (node != null) { return node.Entity.GetIdentifier(); } return string.Empty; } /// <summary> /// Deserialize the link. /// </summary> /// <param name="connection">The connection.</param> /// <param name="info">The information.</param> /// <returns>The link.</returns> /// <exception cref="System.ArgumentNullException"> /// Connection or Info. /// </exception> public override Link DeserializeLink(IConnection connection, SerializationInfo info) { if (connection == null) { throw new ArgumentNullException("connection"); } if (info == null) { throw new ArgumentNullException("info"); } var link = base.DeserializeLink(connection, info); if (info["ClOCId"] != null) { CLOCRelationType relationType; bool result = CLOCRelationType.TryParse(info["RelationType"].ToString(), false, out relationType); link.RelationType = result ? relationType : CLOCRelationType.ORDINARY; ////var a = new CLOCDiagramRelation<ICLOCApplicable>(info["Id"].ToString(), link.RelationType, this.CachedNodes.First().Value.Entity, this.CachedNodes.Last().Value.Entity); link.ClOCId = info["ClOCId"].ToString(); if (info[this.SourceUniqueIdKey] != null) { var sourceUniquekey = info[this.SourceUniqueIdKey].ToString(); link.Source = this.CachedNodes[sourceUniquekey]; } if (info[this.TargetUniqueIdKey] != null) { var targetUniquekey = info[this.TargetUniqueIdKey].ToString(); link.Target = this.CachedNodes[targetUniquekey]; } } return link; } #endregion}
