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

Diagram serialization and GetNodeUniqueId receiving a node null

2 Answers 27 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 11 Jul 2016, 08:10 PM

Hello,

I'm having the following issue with the Serialization process in the diagram:

When I save the first time, it works great. (I can reload the layout several times and it works perfectly: my items go back to their saved positions)

However, if I saveLayout, then LoadLayout, the next time I'm going to call SaveLayout will fail because node is null in the GetNodeUniqueId override.

Any idea what could cause this? Thanks!

public class NodeViewModel : NodeViewModelBase
{
 
}
 
public class DiagramViewModel : SerializableGraphSourceBase<NodeViewModel, LinkViewModel>
{
 
public override string GetNodeUniqueId(NodeViewModel node)
       {
           if (node == null)
               return string.Empty; // Should not happen (but happens on a saveLayout after a LoadLayout)
           return node.ID;
       }
 
public override NodeViewModel DeserializeNode(IShape shape, SerializationInfo info)
        {
            NodeViewModel nodeViewModel = InternalItems.FirstOrDefault(p => p.DialogInfo.Tag == info["NodeUniqueIdKey"].ToString());
            if (nodeViewModel == null)
                return null;
 
            string position = info["Position"].ToString();
            string[] arr = position.Split(';');
            nodeViewModel.Position = new Point(float.Parse(arr[0], CultureInfo.InvariantCulture), float.Parse(arr[1], CultureInfo.InvariantCulture));
            return nodeViewModel;
        }
}

2 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
answered on 11 Jul 2016, 08:27 PM

In simpler words, if I do :

string xml = diagram.Save();
 
diagram.Load(xml);
 
xml = diagram.Save();

The second Save call with call the GetNodeUniqueId with node param being null. (the first call being fine)

 

 

 

 

0
Martin Ivanov
Telerik team
answered on 13 Jul 2016, 09:32 AM
Hi Thomas,

Without your implementation I cannot be sure what is causing the issue. However, it is possible to come from the override of the DeserializeNode() method of the graph source. You can double check if the method always returns a valid shape, instead of null. Note that DeserializeNode() is called for each shape loaded with the Load() method of the diagram.

If this doesn't help you can post a runnable code that isolates your implementation so I can test it on my side. Or you can open a new support ticket where you can attach .zip file with a project.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Diagram
Asked by
Thomas
Top achievements
Rank 1
Answers by
Thomas
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or