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

Load Save Diagram don t call DeserializeLink

10 Answers 83 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Jakub asked on 20 May 2015, 08:50 AM

 Hallo,



i m trying reload my diagram. Saving is going well but if i m try load data from xml string shapes are loaded correctly but there are no connections between shapes. I m using ObservableGraphSourceBase<GraphNode,Link> as graph source and it inherit ISerializableGraphSource interface. During the debug i ve found out that method DeserializeLink is never call. Could you be so kind and give some advice how to figure it out.



Thank you very much.

Best regards 

Jakub



ps: here my serialization class

 

001.public partial class KnihyXmlGraphSource : ISerializableGraphSource
002.    {
003.        private List<GraphNode> SerializedNodes = new List<GraphNode>();
004.        public void SerializeNode(object model, SerializationInfo info)
005.        {
006.            GraphNode node = model as GraphNode;
007.             
008.            string pom = node.ToString();
009.            info["Content"] = node.Content;
010.            info["ShapeType"] = node.ToString();
011.            info["Id"] = node.GetID();
012.             
013.        }
014. 
015.        public void SerializeLink(ILink link, SerializationInfo info)
016.        {
017.            var myLink = link as Link;
018.            if (myLink.Source != null)
019.            {
020.                info["Source"] = myLink.Source.GetID();
021.            }
022.            if (myLink.Target != null)
023.            {
024.                info["Target"] = myLink.Target.GetID();
025.            }
026.            if (myLink.Type != null)
027.            {
028.                info["Type"] = myLink.Type;
029.            }
030.        }
031.         
032.        public ILink DeserializeLink(IConnection connection, SerializationInfo info)
033.        {
034.            Link link = new Link();
035.            string sourceID = string.Empty;
036.            string targetID = string.Empty;
037. 
038. 
039.            if (info["Target"] != null)
040.            {
041.                targetID = info["Target"].ToString();
042.            }
043.            if (info["Source"] != null)
044.            {
045.                sourceID = info["Source"].ToString();
046.            }
047.            if (info["Type"] != null)
048.            {
049.                switch (info["Type"].ToString())
050.                {
051.                    case Constants.Type1:
052.                        link.Type = LinkType.Typ1;
053.                        break;
054.                    case Constants.Type2:
055.                        link.Type = LinkType.Typ2;
056.                        break;
057.                    default:
058.                        link.Type = LinkType.Typ3;
059.                        break;
060.                }
061.            }
062.            GraphNode source = SerializedNodes.FirstOrDefault(x => x.GetID().Equals(sourceID));
063.            if (source != null)
064.            {
065.                link.Source = source;
066.            }
067. 
068.            GraphNode target = SerializedNodes.FirstOrDefault(x => x.GetID().Equals(targetID));
069.            if (target != null)
070.            {
071.                link.Target = target;
072.            }
073. 
074.            if (info["Type"] != null)
075.            {
076.                string type = info["Source"].ToString();
077.                switch (type)
078.                {
079.                    case Constants.Type1:
080.                        link.Type = LinkType.Typ1;
081.                        break;
082.                    case Constants.Type2:
083.                        link.Type = LinkType.Typ2;
084.                        break;
085.                    case Constants.Type3:
086.                        link.Type = LinkType.Typ3;
087.                        break;
088.                    default:
089.                        break;
090.                }
091.            }
092.            return link;
093.        }
094. 
095.        public object DeserializeNode(IShape shape, SerializationInfo info)
096.        {
097.            GraphNode node = new GraphNode();
098. 
099.            string pom = string.Empty;
100.            if (info["ShapeType"] != null)
101.            {
102.                pom = (info["ShapeType"].ToString());
103.                pom = pom.Substring(23);
104.                switch (pom)
105.                {
106.                    case Constants.DescriptionNode:
107.                        node = new DescriptionNode();
108.                        node.shape = MindmapItem.ShapeTypes.Description;
109.                        break;
110.                    case Constants.AuthorNode:
111.                        node = new AuthorNode();
112.                        node.shape = MindmapItem.ShapeTypes.Author;
113.                        break;
114.                    case Constants.GenreNode:
115.                        node = new GenreNode();
116.                        node.shape = MindmapItem.ShapeTypes.Genre;
117.                        break;
118.                    case Constants.BookDescriptionNode:
119.                        node = new BookDescriptionNode();
120.                        node.shape = MindmapItem.ShapeTypes.BookDescription;
121.                        break;
122.                    default:
123.                        break;
124.                }
125.            }
126. 
127.            if (info["Position"] != null)
128.            {
129.                node.Position = Utils.ToPoint(info["Position"].ToString()).Value;
130.            }
131. 
132.            if (info["Content"] != null)
133.            {
134.                node.Content = info["Content"].ToString();
135.            }
136. 
137. 
138.            SerializedNodes.Add(node);
139.            return node;
140.        }
141.    }

10 Answers, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 21 May 2015, 10:56 AM
Hi Jakub,

Thank you for providing a sample code. It does not become clear however what might be causing the issue of the method not being called. I also tried to reproduce it using our SDK example and all the connections loaded correctly. I overrode the DeserializeLink method and it was called just fine.

Could you please take a look at the MVVM SDK sample as it might shed some light on the issue or attach a sample runnable copy of your project reproducing this behavior. As this is a forum thread you will need to use a third party web site for files sharing.

Attached is an archive containing the MVVM SDK sample and the exported diagram(Diagram.xml).

Regards,
Peshito
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
Jakub
Top achievements
Rank 1
answered on 03 Jun 2015, 09:08 AM

Here is a sample diagram with my problem.

Thank you for your approach :)

 Jakub

 

https://dl.dropboxusercontent.com/u/60389203/MindMapSample.zip

0
Peshito
Telerik team
answered on 08 Jun 2015, 08:46 AM
Hi Jakub,

Thank you for providing the running project. It helped in finding the reason for the issue you have experienced.

I am now attaching a modified version of the sample where the saving and loading are both working well. Simply what was wrong is that you implemented ObservableGraphSourceBase and we recommend using an approach with implementing SerializableGraphSourceBase. More on this matter can be found here.

Hope this helps.

Regards,
Peshito
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
Jakub
Top achievements
Rank 1
answered on 09 Jun 2015, 08:23 AM

Hi Peshito,

 

thank you for your answer it helps me a lot. There s some troubles i have with my scenario. After deserialize my links and nodes there's no style used in my connections. When i explore connection,  everything i need is there ( target node, source node, connection type) but  no style is used and connections are not connected to target or source shape at all. Could you be so kind and give me some advice with this problem?

 

Thank you so much

greetings Jakub.

0
Peshito
Telerik team
answered on 10 Jun 2015, 01:28 PM
Hi Jakub,

From the information provided I assume you are using implicit styles. If so, your connections may not be visible due to the fact that the styles are not Based On. By doing this, they should appear.

For instance:
<Style x:Key="pascalEdgeStyle" TargetType="telerik:RadDiagramConnection" BasedOn="{StaticResource RadDiagramConnectionStyle}">
     <Setter Property="TargetCapType" Value="Arrow1" />
     <Setter Property="ContentTemplate">
         <Setter.Value>
             <DataTemplate />
         </Setter.Value>
     </Setter>
 </Style>
If this is not what you had in mind. Please elaborate a bit more on the issue. Do you have any predefined style you are using? Any information will be useful.

Regards,
Peshito
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
Jakub
Top achievements
Rank 1
answered on 10 Jun 2015, 01:38 PM

Hallo Peshito,

yes i have predefined some styles and i'm using style selector to select which style should be used. I took it out from the sample for the simplification. Styles are defined in xaml file and this file is used like resource in my solution. Hope these information help a bit.

 

Regards.

Jakub

0
Jakub
Top achievements
Rank 1
answered on 10 Jun 2015, 01:43 PM

and for additional information. I have my custom graphSource class inherited from SerializableGraphSourceBase class. And i ve ovveride Deserialize and Serialize methos for links and nodes. here is piece of code for serialization and deserialization of link

 

public override Link DeserializeLink(IConnection connection, SerializationInfo info)
        {
            Link link = new Link();
            string targetId = string.Empty;
            string sourceId = string.Empty;
 
            string type = info["Type"].ToString();
            switch (type)
            {
                case Constants.Type1:
                    link.Type = LinkType.Typ1;
                    break;
                case Constants.Type2:
                    link.Type = LinkType.Typ2;
                    break;
                case Constants.Type3:
                    link.Type = LinkType.Typ3;
                    break;
                default:
                    break;
            }
 
            if (info["SourceID"] != null)
            {
                sourceId = info["SourceID"].ToString();
            }
 
            if (info["TargetID"] != null)
            {
                targetId = info["TargetID"].ToString();
            }
 
            var sourceModel = this.SerializedNodes.FirstOrDefault(x => x.HashID.Equals(sourceId));
            if (sourceModel != null)
            {
                link.Source = sourceModel;
            }
 
            var targetModel = this.SerializedNodes.FirstOrDefault(x => x.HashID.Equals(targetId));
            if (targetModel != null)
            {
                link.Target = targetModel;
            }
 
 
            return link;
        }
 
public override void SerializeLink(Link link, SerializationInfo info)
        {
            this.ClearCache();
            base.SerializeLink(link, info);
 
 
            if (link != null)
            {
                info["SourceID"] = link.Source.HashID;
                info["TargetID"] = link.Target.HashID;
                info["LinkType"] = link.Type.ToString();
            }
        }

0
Peshito
Telerik team
answered on 12 Jun 2015, 08:41 AM
Hello Jakub,

As this is a running app and it most likely differ from the last modified version attached, I would like to ask you to provide the running sample app reproducing the issue. I will then be able to take a closer look into your styles and investigate the reason for the unwanted behavior.

Attached is a version of the sample app already used in the thread where the styles have been properly applied over the connections and they are visible.

Regards,
Peshito
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
Jakub
Top achievements
Rank 1
answered on 12 Jun 2015, 12:33 PM

Hallo Peshito,

 thank you for your answer. I try explain my issue better. After loading of diagram shapes and connections are not connected. It looks OK but if you drag some shape away, connection stays on original place. Second issue i have in my scenario is that after loading is not applied style on my connections. It looks like there is default use first style but never used second style. I attached sample project. There is two connections and four shapes as you've seen before. Both connections have different styles. For styling i'm using styleselector and as source for diagram i'm using graphsource. 

 

thank you for your time and advices. 

Have a nice day

Jakub 

ps: here is my sample project: https://db.tt/CHo6qEiv

0
Peshito
Telerik team
answered on 17 Jun 2015, 11:23 AM
Hi Jakub,

Thank you for sharing the project and describing the issue in details. The reason why the styles are not being applied is because you should serialize and deserialize the links as well. For this purpose override the SerializeLink and DeserializeLink methods. As for the connections not being connected to the shapes after the diagram is reloaded, this happens due to the fact that the SerializationInfo uses an ID property by default and having set the mapping with info["ID"] overrides the default one. Simply edit the name to something else like info["IDNew"] for instance.

Attached is an updated version of the project having the above approach applied.

Hope this helps.

Regards,
Peshito
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
Jakub
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Jakub
Top achievements
Rank 1
Share this question
or