Page Index Toggle Pages: [1] 2 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails (Read 18281 times)
PauliusP
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Feb 10th, 2017
diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Feb 10th, 2017 at 9:07am
Print Post  
I am trying to save diagram as xml string:
Code (Javascript)
Select All
MindFusion.Diagramming.Diagram.find("diagramView").saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) 



and got the error like in the attached image.

our custom node has this first liner in toJson method:

var data = DLXShapeNode.callBaseMethod(this, "toJson");
  

error.PNG ( 77 KB | 152 Downloads )
error.PNG
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #1 - Feb 10th, 2017 at 9:52am
Print Post  
The control does not convert Json to XML, instead you'll need to implement saveToXml and loadFromXml methods. Unfortunately we haven't added public APIs for serializing custom types to XML yet, but you can still implement that as below.

1. Add a saveToXml method to your node class if you need to append custom fields -

Code
Select All
saveToXml: function (xmlElement, context)
{
	mflayer.callBaseMethod(DLXShapeNode, this, "saveToXml", [xmlElement, context]);
	context.writeString(this.myField, "MyField", xmlElement);
},

loadFromXml: function (xmlElement, context)
{
	mflayer.callBaseMethod(DLXShapeNode, this, "loadFromXml", [xmlElement, context]);
	this.myField = context.readString("MyField", xmlElement));
} 



2. Add an object connecting XML attributes to your custom class' constructor for save to work, and append constructor to diagram's class-map dictionary for loadFromXml to work -

Code
Select All
diagram.xmlClassMap["my:DLXShapeNode"] = DLXShapeNode;
DLXShapeNode.xmlInfo = { classId: "my:DLXShapeNode", classVersion: 1 }; 



The strings here are set as Class attributes for nodes' XML elements, they don't have to match your constructor name.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
PauliusP
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Feb 10th, 2017
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #2 - Feb 10th, 2017 at 11:52am
Print Post  
what would be usage in client: what is context and what is xmlElement(any html element?) ?

for eg. diagram.saveToXml(?, ?)

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #3 - Feb 10th, 2017 at 12:26pm
Print Post  
You receive element and context objects when you implement your custom serialization in DiagramItem -derived classes. Element is a DOM Element object where you add XML child elements. We'll try to document the context class for upcoming release, for time being you can see what methods it offers from our .NET help reference -
http://www.mindfusion.eu/onlinehelp/flowchartnet/index.htm?T_MindFusion_Diagramm...

Diagram's saveToXml itself takes only a URL where it should post the XML string returned by saveToString; you'd need to handle the post separately on server to save the string to either a file or a database -

Code
Select All
/**
* Saves the diagram to an XML file.
* @param {String} url A URL specifying where the diagram's XML should be posted to.
*/
saveToXml: function (url)
{
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.send(
        this.saveToString(SaveToStringFormat.Xml));
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #4 - Feb 14th, 2017 at 9:30am
Print Post  
So as i do correctly understand,

you need to :
1) override savetToXml and loadFromXml in derrived class from ShapeNode (and other elements i guess like links?)
2) add to constructor of derived class strange line "CustomNode.xmlInfo = { classId: "CustomNode", classVersion: 1 };"
3) override diagram saveToXml(url) method
4) add to diagram constructor this liner "diagram.xmlClassMap["CustomNode"] = CustomNode;"

Is this correct flow?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #5 - Feb 14th, 2017 at 10:48am
Print Post  
You don't have to override Diagram.saveToXml, that's something you'd call to send XML directly to server. Alternatively you could call saveToString(Xml) and save the string in browser's local storage or post it to server by other means (e.g. hidden form field).

You need to override 1 if you have custom fields you need stored in XML, otherwise you can skip it. You'll need 2 and 4 even if you don't have custom fields, in order to restore objects as instances of your own class instead of its base class.

When we add public API support for custom XML serialization, 2 and 4 will be replaced by registerItemClass method as in .NET version here -
http://www.mindfusion.eu/onlinehelp/flowchartnet/index.htm?M_MindFusion_Diagramm...

So at this time 2 & 4 would be required just to deserialize XML elements as your class instance instead of e.g. ShapeNode. 1 is required if you have custom fields you must save and load.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #6 - Feb 15th, 2017 at 9:12am
Print Post  
Oh thanks for explanation : )

would other types would have different approach of implementing this saveTo... functionality?

for example custom DiagramLink does not work the same as ShapeNode...

an error hapens in
Code (Javascript)
Select All
 saveToXml: function (xmlElement, context) {
        CustomDiagramLink.callBaseMethod(this, "saveToXml", [xmlElement, context]);
 


and i have in constructor this liner:
Code (Javascript)
Select All
 CustomDiagramLink.xmlInfo = { classId: "CustomDiagramLink", classVersion: 1 };
 



I am getting an error:
Uncaught Error: Key type not supported.
at a.HashTable.b.hashCode (eval at <anonymous> (ScriptResource.axd?d=NBS99sn4hN-SzMzn4tICCPcA-6j-sFKO0T6He6kv35tXwxgXBblHO5Mh6M
gZHJ-scfdKb47jcDnwJr…:1), <anonymous>:1:13707)
at a.HashTable.b.bucket (eval at <anonymous> (ScriptResource.axd?d=NBS99sn4hN-SzMzn4tICCPcA-6j-sFKO0T6He6kv35tXwxgXBblHO5Mh6M
gZHJ-scfdKb47jcDnwJr…:1), <anonymous>:1:13321)
at a.HashTable.b.get (eval at <anonymous> (ScriptResource.axd?d=NBS99sn4hN-SzMzn4tICCPcA-6j-sFKO0T6He6kv35tXwxgXBblHO5Mh6M
gZHJ-scfdKb47jcDnwJr…:1), <anonymous>:1:12827)
at a.HashTable.b.contains (eval at <anonymous> (ScriptResource.axd?d=NBS99sn4hN-SzMzn4tICCPcA-6j-sFKO0T6He6kv35tXwxgXBblHO5Mh6M
gZHJ-scfdKb47jcDnwJr…:1), <anonymous>:1:12946)
at b.Dictionary.a.contains (eval at <anonymous> (ScriptResource.axd?d=NBS99sn4hN-SzMzn4tICCPcA-6j-sFKO0T6He6kv35tXwxgXBblHO5Mh6M
gZHJ-scfdKb47jcDnwJr…:1), <anonymous>:1:10996)
at b.XmlPersistContext.writeResource (eval at <anonymous> (MindFusion.Diagramming.js:1), <anonymous>:1:503074)
at b.XmlPersistContext.writeStyle (eval at <anonymous> (MindFusion.Diagramming.js:1), <anonymous>:1:506528)
at CustomDiagramLink.saveToXml (eval at <anonymous> (MindFusion.Diagramming.js:1), <anonymous>:1:186716)
at Function.Type$callBaseMethod [as callBaseMethod] (ScriptResource.axd?d=xAP30EJC1uto2ocBoZGz0WrboLPcU9x9sb9g6Aj4Jzj09VOgdk0khgyARw
yOFsp88Egggj5GW3WfnR…:1546)
at Object.callBaseMethod (eval at <anonymous> (ScriptResource.axd?d=NBS99sn4hN-SzMzn4tICCPcA-6j-sFKO0T6He6kv35tXwxgXBblHO5Mh6M
gZHJ-scfdKb47jcDnwJr…:1), <anonymous>:1:850)
« Last Edit: Feb 17th, 2017 at 12:03pm by Gravity »  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #7 - Feb 20th, 2017 at 10:40am
Print Post  
No response on that? : /
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #8 - Feb 20th, 2017 at 10:47am
Print Post  
Sorry, haven't noticed your edit - better post replies. If it's the base saveToXml method throwing exception, then it's probably not related to yours being a custom class. The stack trace shows a writeStyle method - what values are you storing in the links' style objects?
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #9 - Feb 20th, 2017 at 12:04pm
Print Post  
Slavcho wrote on Feb 20th, 2017 at 10:47am:
Sorry, haven't noticed your edit - better post replies. If it's the base saveToXml method throwing exception, then it's probably not related to yours being a custom class. The stack trace shows a writeStyle method - what values are you storing in the links' style objects?



I have two string properties, but right now, i am not using them

here is js code:
Code (Javascript)
Select All
/// <reference path="../MindFusion/MindFusion.Diagramming.js" />

CustomDiagramLink = function (parent, origin, destination) {

    CustomDiagramLink.initializeBase(this, [parent, origin, destination]);
    CustomDiagramLink.xmlInfo = { classId: "local:CustomDiagramLink", classVersion: 1 };

    this.style();
}

CustomDiagramLink.prototype =
{
    initialize: function () {
        CustomDiagramLink.callBaseMethod(this, 'initialize');
    },

    dispose: function () {
        CustomDiagramLink.callBaseMethod(this, 'dispose');
    },

    toJson: function () {
        var data = CustomDiagramLink.callBaseMethod(this, "toJson");


        return data;
    },

    fromJson: function (json) {
        CustomDiagramLink.callBaseMethod(this, "fromJson", [json]);

        return json;
    },

    saveToXml: function (xmlElement, context) {
        CustomDiagramLink.callBaseMethod(this, "saveToXml", [xmlElement, context]);
    },

    // not used, since loading done in backend
    loadFromXml: function (xmlElement, context) {
        CustomDiagramLink.callBaseMethod(this, "loadFromXml", [xmlElement, context]);
    }


};

if (typeof (Sys) !== 'undefined')
    Sys.Application.notifyScriptLoaded();
 



Well same thing works with ShapeNode, although had some problems with values, but resolved it.
An error happens here:

Code (Javascript)
Select All
  saveToXml: function (xmlElement, context) {
        CustomDiagramLink.callBaseMethod(this, "saveToXml", [xmlElement, context]);
    },
 



Not sure what does this causing, right now we don't have source code, we are still in development.
How do i identify which versions is this Mindfusion.Diagramming.js file is?

Update: well i want to say, that we do loading through backend, and saving through client side. i removed all styling from client side : / exception message still the same
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #10 - Feb 20th, 2017 at 1:12pm
Print Post  
Seeing this line in constructor -
Code
Select All
this.style(); 



I guess you have a style() function defined in prototype - that might be hiding standard DiagramItem.style field and breaking writeStyle serialization code. Try renaming your function, to e.g. applyStyle.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #11 - Feb 20th, 2017 at 1:21pm
Print Post  
Oh, i found this piece of code is causing that issue:

Code (Javascript)
Select All
var DrawLinksBehavior = MindFusion.Diagramming.DrawLinksBehavior;

DrawLinksBehavior.prototype.createLink = function (origin, point) {
    var link = new CustomDiagramLink(this.diagram, origin, point);
    link.originConnection.chooseBestAnchorPoint(point);
    return link;
}


 

  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #12 - Feb 20th, 2017 at 1:22pm
Print Post  
Slavcho wrote on Feb 20th, 2017 at 1:12pm:
Seeing this line in constructor -
Code
Select All
this.style(); 



I guess you have a style() function defined in prototype - that might be hiding standard DiagramItem.style field and breaking writeStyle serialization code. Try renaming your function, to e.g. applyStyle.

Regards,
Slavcho


Yeah yeah...I had : ) but this was not style related issue, but behavior something...i don't know yet...what is causing it...
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #13 - Feb 20th, 2017 at 1:35pm
Print Post  
Quote:
Oh, i found this piece of code is causing that issue:


That would cause the issue only because it creates your custom objects which delete our style field replacing it with a function. Are you still seeing same exception after renaming style() to another name? Without the DrawLinksBehavior.prototype.createLink override interactive drawing would create standard DiagramLinks.
  
Back to top
 
IP Logged
 
Gravity
Junior Member
**
Offline


I Love MindFusion!

Posts: 52
Joined: Sep 21st, 2016
Re: diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml) fails
Reply #14 - Feb 20th, 2017 at 1:59pm
Print Post  
Slavcho wrote on Feb 20th, 2017 at 1:35pm:
Quote:
Oh, i found this piece of code is causing that issue:


That would cause the issue only because it creates your custom objects which delete our style field replacing it with a function. Are you still seeing same exception after renaming style() to another name? Without the DrawLinksBehavior.prototype.createLink override interactive drawing would create standard DiagramLinks.



Oh, that's right.

I simplified to this
Code (Javascript)
Select All
DrawLinksBehavior.prototype.createLink = function (origin, point) {
    return new CustomDiagramLink(this.diagram, origin, point);
}
 



Is there some required parameters needed to set here or in custom derived class ?

But still can't figure out why the error is happening on calling
Code (Javascript)
Select All
 diagram.saveToString(MindFusion.Diagramming.SaveToStringFormat.Xml)
 



  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 3 
Send TopicPrint