Hello, it’s me again.
I’ve got the most important problem for my project concerning the saving.
I took the source code of stateCharter to help me for this.
My problem is that when I save the diagram only this line is wrote :
And I don’t know where the problem is.
My source code is :
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using Northwoods.Go;
using Northwoods.Go.Xml;
namespace DiagramTiphaine
{
[Serializable]
public class ManageDocument : GoDocument
{
public ManageDocument() { }
// Chaque fois que le nom du document est changé, mise à jours de la nameTextBox dans le MainForm
public override String Name
{
set
{
if (base.Name != value)
{
base.Name = value;
MyMainForm.MainForm.UpdateForm();
}
}
}
// Garde une trace du fichier où le document est stocké
public virtual String Path
{
get { return myPath; }
set
{
String old = myPath;
if (old != value)
{
myPath = value;
RaiseChanged(ChangedPath, 0, null, 0, old, NullRect, 0, value, NullRect);
}
}
}
//Faire un commentaire
public static GoComment NewComment()
{
GoComment comment = new GoComment();
comment.Text = "Enter your comment here,\r\non multiple lines.";
comment.Label.Multiline = true;
comment.Label.Editable = true;
return comment;
}
//Création d'un lien entre deux éléments graphique
public virtual int NumLinksBetween(IGoPort a, IGoPort b)
{
int count = 0;
foreach (IGoLink l in a.DestinationLinks)
{
if (l.ToPort == b)
count++;
}
return count;
}
#region Version
public int Version
{
get { return 3; }
set
{
if (value != this.Version)
throw new NotSupportedException("For simplicity, this sample application does not handle different versions of saved documents");
}
}
#endregion
#region AdapterDocXml
// TODO: adapt the XML elements and attributes to match your classes and their properties
private static void InitReaderWriter(GoXmlReaderWriterBase rw)
{
GoXmlBindingTransformer.DefaultTracingEnabled = true; // Pour le débogage, vérifiez votre fenêtre de Production (trace l'auditeur)
GoXmlBindingTransformer t;
t = new GoXmlBindingTransformer("Diagramme", new ManageDocument());
t.AddBinding("version", "Version", GoXmlBindingFlags.RethrowsExceptions); // let exception from Version setter propagate out
t.AddBinding("name", "Name");
t.AddBinding("path", "Path");
t.AddBinding("customcolors", "CustomColors");
rw.AddTransformer(t);
t = new GoXmlBindingTransformer("Tache",new OneInOneOutBasicNode());
t.IdAttributeUsedForSharedObjects = true; // Chaque élément a un identifiant unique
t.HandlesNamedPorts = true; // Génère des attributs pour chacun des ports nommés, spécifiant leur IDS
t.AddBinding("label", "Text");
t.AddBinding("loc", "Location");
t.AddBinding("color", "Shape.BrushColor");
t.AddBinding("pos", "Rectangle.Position");
t.AddBinding("size", "Rectangle.Size");
rw.AddTransformer(t);
t = new GoXmlBindingTransformer("comment", NewComment());
t.IdAttributeUsedForSharedObjects = true; // each GoComment gets a unique ID
t.AddBinding("label", "Text");
t.AddBinding("center", "Center"); // last property, since it depends on content/alignment
rw.AddTransformer(t);
t = new GoXmlBindingTransformer("transition", new Transition());
t.AddBinding("from", "FromPort");
t.AddBinding("to", "ToPort");
t.AddBinding("label", "MidLabel.Text");
t.AddBinding("curviness", "Curviness");
t.AddBinding("color", "RealLink.PenColor");
t.AddBinding("brush", "RealLink.BrushColor");
t.AddBinding("adjusted", "RealLink.AdjustingStyle");
t.AddBinding("points", "RealLink.Points");
rw.AddTransformer(t);
}
public void StoreXml(FileStream ofile)
{
GoXmlWriter xw = new GoXmlWriter();
InitReaderWriter(xw);
xw.NodesGeneratedFirst = true;
xw.Objects = this;
xw.Generate(ofile);
}
public static ManageDocument LoadXml(Stream ifile)
{
GoXmlReader xr = new GoXmlReader();
InitReaderWriter(xr);
ManageDocument doc = xr.Consume(ifile) as ManageDocument;
if (doc == null) return null;
return doc;
}
#endregion
// handle undo and redo for the additional document state
public override void ChangeValue(GoChangedEventArgs e, bool undo)
{
switch (e.Hint)
{
case ChangedPath:
this.Path = (String)e.GetValue(undo);
break;
default:
base.ChangeValue(e, undo);
break;
}
}
public const int ChangedPath = GoDocument.LastHint + 1;
private String myPath = "";
}
[Serializable]
public class Transition : GoLabeledLink
{
public Transition()
{
this.Style = GoStrokeStyle.Bezier;
this.ToArrow = true;
this.RealLink.PenColor = Color.Black;
this.RealLink.PenWidth = 2;
GoText cond = new GoText();
cond.Selectable = false;
cond.Editable = true;
cond.Multiline = true;
cond.Text = "Lien";
this.MidLabel = cond;
this.MidLabelCentered = true;
}
public override GoLink CreateRealLink()
{
return new TransitionLink();
}
}
[Serializable]
public class TransitionLink : GoLink
{
public TransitionLink() { }
// Chaque fois que l'utilisateur redimenssionne un lien, ne recalcul pas automatiquement le coup, systématiquement
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint,
int whichHandle, GoInputState evttype, SizeF min, SizeF max)
{
base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
this.AdjustingStyle = GoLinkAdjustingStyle.Scale;
}
}
}
Can you help me?