<span id=“result_” =""="" lang=“en”><span =“hps”="">I learned <span =“hps”="">how to save <span =“hps”="">chart data <span =“hps”="">to a file. <span =“hps”="">I decided to try <span =“hps”="">a <span =“hps”="">simple example: keep <span =“hps”="">only one node<span =""="">.
public void RegisterTransformers(GoXmlReaderWriterBase rw)
{
var doc = new GoDocument();
var bt = new GoXmlBindingTransformer("graph", doc);
rw.AddTransformer(bt);
var bn = new GoSimpleNode();
<font color="#CC0000"> bn.Initialize(null,null,"hello");</font>
var bt1 = new GoXmlBindingTransformer("node", bn);
// generates attributes for all named ports, to define their id's
// without generating separate elements for them
bt1.HandlesNamedPorts = true;
// map the "label" attribute to the GoBasicNode.Text property
bt1.AddBinding("label", "Text");
// the "color" attribute is the GoBasicNode.Shape.BrushColor property
bt1.AddBinding("color", "Shape.BrushColor");
bt1.AddBinding("loc", "Location");
bt1.AddBinding("figur", "Figure");
rw.AddTransformer(bt1);
}
My method for saving:
private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var xw = new GoXmlWriter();
RegisterTransformers(xw);
xw.Objects = goView1.Document;
using (var file = new StreamWriter(Application.UserAppDataPath+@"\test.xml"))
{
xw.Generate(file);
}
}
Method to read:
private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var xr = new GoXmlReader();
RegisterTransformers(xr);
using (var file = new StreamReader(Application.UserAppDataPath + @"\test.xml"))
{
goView1.Document = (GoDocument)xr.Consume(file);
}
}
And i have no result after reading method. Plz help.
next problem: how to save\read link.
now my RegisterTransformetrs look like:
public void RegisterTransformers(GoXmlReaderWriterBase rw)
{
var doc = new GoDocument();
var bt = new GoXmlBindingTransformer(“graph”, doc);
rw.AddTransformer(bt);
var bn = new GoSimpleNode();
bn.Initialize(null,null,“hello”);
// bn.OutPort
// bn.LabelSpot = GoObject.Middle;
bn.Text = “”;
var bt1 = new GoXmlBindingTransformer(“node”, bn);
// generates attributes for all named ports, to define their id’s
// without generating separate elements for them
bt1.HandlesNamedPorts = false;
// map the “label” attribute to the GoBasicNode.Text property
bt1.AddBinding(“label”, “Text”);
// the “color” attribute is the GoBasicNode.Shape.BrushColor property
bt1.AddBinding(“color”, “Shape.BrushColor”);
bt1.AddBinding(“loc”, “Location”);
bt1.AddBinding(“figur”, “Figure”);
bt1.AddBinding(“IPort”, “InPort”);
bt1.AddBinding(“OPort”, “OutPort”);
bt1.AddBinding(“IconSize”, “Icon.Size”);
bt1.AddBinding(“IconResizable”, “Icon.Resizable”);
bt1.AddBinding(“InPortStylegur”, “InPort.Style”);
bt1.AddBinding(“InPortPen”, “InPort.Pen”);
bt1.AddBinding(“InPortBrushColor”, “InPort.BrushColor”);
bt1.AddBinding(“OutPortStyle”, “OutPort.Style”);
bt1.AddBinding(“OutPortPen”, “OutPort.Pen”);
bt1.AddBinding(“OutPortBrushColor”, “OutPort.BrushColor”);
rw.AddTransformer(bt1);
var ll = new GoLink {ToArrow = true, AdjustingStyle = GoLinkAdjustingStyle.Calculate,};
var bt2 = new GoXmlBindingTransformer("link", ll);
bt2.AddBinding("from", "FromPort");
bt2.AddBinding("to", "ToPort");
rw.AddTransformer(bt2);
}
And now nodes are correct, but there are no links in doc.
Clicking on a port uses GoView.NewLinkClass or NewLinkPrototype to know what link object to create… check your app for setting of either of those properties.
2 nodes and 1 link.
In application i created 2 nodes and 1 link in user interface and then i saved xml file.
then i restart my appl and click on read button, which call method: var xr = new GoXmlReader();
RegisterTransformers(xr);
using (var file = new StreamReader(Application.UserAppDataPath + @"\test.xml"))
{
goView1.Document = (GoDocument)xr.Consume(file);
}
as the result was loaded 2 nodes whithout any link.
Goview.NewGoLink set on Northwoods.Go.GoLink
Goview.NewLinkPrototype set on Northwoods.Go.GoLink