Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Fishbone Sample, Problem Loading From saved Xml (Read 3539 times)
Thoufiq
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Mar 29th, 2009
Fishbone Sample, Problem Loading From saved Xml
Mar 30th, 2009 at 2:45pm
Print Post  
From the sample, which is found in the installed folder
C:\Program Files\MindFusion\FlowChart.NET Professional Edition\VS2005 (.NET 2.0)\Samples\VB.NET\Fishbone

I saved the diagram into xml, when loading back the xml I get the following error. Could you please review the code and let me know what is the reason for this problem?

"Failed to Instantiate item of type 'Fishbone.CauseNode' . "

Code
Select All
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        MindFusion.Diagramming.Diagram.RegisterItemClass(GetType(CauseNode), GetType(CauseNode).Name, 1)
        MindFusion.Diagramming.Diagram.RegisterItemClass(GetType(AspectNode), GetType(AspectNode).Name, 1)
        MindFusion.Diagramming.Diagram.RegisterItemClass(GetType(FishboneBehavior), GetType(FishboneBehavior).Name, 1)


        diagram.ShadowsStyle = ShadowsStyle.None

        backbone = diagram.Factory.CreateShapeNode( _
         0, 60, 300, 1.5F, Shapes.Rectangle)
        backbone.Brush = New SolidBrush(Color.Black)
        backbone.EnabledHandles = AdjustmentHandles.None
        backbone.HandlesStyle = HandlesStyle.Invisible

        diagramView.CustomBehavior = New Fishbone.FishboneBehavior(diagramView, backbone)
    End Sub
    Dim backbone As ShapeNode

    Private Sub diagram_NodeCreated(ByVal sender As Object, ByVal e As MindFusion.Diagramming.NodeEventArgs) Handles diagram.NodeCreated
        If TypeOf e.Node Is Fishbone.CauseNode Then
            e.Node.Constraints.MoveDirection = DirectionConstraint.Horizontal
        End If
    End Sub

    Private Sub miSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miSave.Click

        diagramView.SaveToXml(dlgSaveFile.FileName)

    End Sub

    Private Sub miOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miOpen.Click

        diagram.ClearAll()

        Try
            diagramView.LoadFromXml(dlgOpenFile.FileName)
        Catch ex As Exception
' Failed to Instantiate item of type 'Fishbone.CauseNode' .
            MessageBox.Show(ex.Message, ex.Source)
        End Try

    End Sub 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Fishbone Sample, Problem Loading From saved Xm
Reply #1 - Mar 30th, 2009 at 3:03pm
Print Post  
You must override the SaveToXml and LoadFromXml methods of DiagramNode to enable XML serialization, and also use the RegisterItemClass method to register a string ID used to identify custom classes in the saved XML.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Thoufiq
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Mar 29th, 2009
Re: Fishbone Sample, Problem Loading From saved Xm
Reply #2 - Mar 31st, 2009 at 8:45am
Print Post  
Thanks for your reply

There was another problem after overriding SaveToXml and LoadFromXml.

The problem is while loading the saved XML, the following exception occured

"Cannot create an object of type CauseNode. Make sure the class provides a constructor with the appropriate prototype."


did little modification on the constructor of causenode and everything work fine.

Code
Select All
 Public Sub New()
        MyBase.New()
    End Sub

Private _Backbone As DiagramNode

    Public ReadOnly Property Backbone() As DiagramNode
        Get
            If Me._Backbone Is Nothing Then
                'In the parent form which contains the diagram, specify the tag
                'Backbone.Tag = "I_AM_BACKBONE"

                Dim o As ShapeNode = Me.Parent.FindNode("I_AM_BACKBONE")
                If o IsNot Nothing Then
                    Me._Backbone = o
                End If
            End If
            Return Me._Backbone
        End Get
    End Property
 



  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Fishbone Sample, Problem Loading From saved Xm
Reply #3 - Mar 31st, 2009 at 9:25am
Print Post  
That's right, for deserialization the class must provide either a no-args constructor or one that takes a Diagram argument.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint