This is a migrated thread and some comments may be shown as answers.

Deserialization problem in Diagram

3 Answers 68 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Barış
Top achievements
Rank 1
Barış asked on 27 Aug 2015, 08:19 AM

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
}
  

 

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 31 Aug 2015, 01:01 PM
Hi Barış,

I am afraid that without a runnable version of your implementation I won't be able to investigate the reason behind the described behavior. However, you can keep in mind that the DeserializeNode() method will be called only for RadDiagramShape and RadDiagramContainerShape elements. Also, the method will be called when specific operations are executed - as paste or drop from a toolbox. In addition if you copy/paste a text on the diagram surface the method won't be fired.

If you prepare a small runnable project demonstrating your implementation I will be able to check it out locally and see why the method isn't called. Also, can you tell me in what scenario the DeserializedNode() is not executed?

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Barış
Top achievements
Rank 1
answered on 01 Sep 2015, 10:26 AM

Hello Martin,

Thank you for your reply, while I wait a reply from telerik team for 4 days, I found out that the problem was setting type info["Type"]. serializebase functions writes "....RadDiagramShape" to info["Type"]. By changing the Type to something else, I overcome this issue. 

I think there are lots of subjects that is needed to documented well. We had the ​similar issue with the info["Id"]. â€‹

info["Type"] = nonMilitaryEntity.Type;

0
Martin Ivanov
Telerik team
answered on 03 Sep 2015, 07:55 AM
Hi Barış,

I am glad to hear to you managed to resolved the issue. As for the documentation, thank you for the feedback we will take it in account and at some point we will update our help documentation with the corresponding information.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Diagram
Asked by
Barış
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Barış
Top achievements
Rank 1
Share this question
or