Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Serialization (Read 4165 times)
DConroy
YaBB Newbies
*
Offline



Posts: 12
Joined: Nov 1st, 2005
Serialization
Nov 11th, 2005 at 1:11pm
Print Post  
Hi,

I need to XML serialize the contents of a diagram, including tags, but I need it to go to a string, not a file.

I can't seem to get the stream overload of XMLWriter.Write to work.

The SaveToString feature is not XML, and does not save tags.


I'm doing the following, after initializing my writer per the sample in the guide.

System.IO.MemoryStream ms = new System.IO.MemoryStream();
writer.Write(ms);
System.IO.StreamReader reader = new System.IO.StreamReader(ms);
string s = reader.rReadToEnd();

S is always empty.

Any ideas?
  
Back to top
 
IP Logged
 
DConroy
YaBB Newbies
*
Offline



Posts: 12
Joined: Nov 1st, 2005
Re: Serialization
Reply #1 - Nov 11th, 2005 at 1:14pm
Print Post  
Nevermind...my bad...needed to set the stream's position before reading...
  
Back to top
 
IP Logged
 
Iva
Junior Member
**
Offline


MindFusion support

Posts: 55
Joined: Aug 6th, 2005
Re: Serialization
Reply #2 - Nov 11th, 2005 at 4:17pm
Print Post  
Hi, handle the SerializeTag event to save tags in XML. Set the event argument to a string representation of the tag value. When loading use DeserializeTag to restore a tag from its string representation.
  
Back to top
 
IP Logged
 
DConroy
YaBB Newbies
*
Offline



Posts: 12
Joined: Nov 1st, 2005
Re: Serialization
Reply #3 - Nov 11th, 2005 at 4:41pm
Print Post  
No that part was clear... initially what I was trying to do was use the LoadFromString and SaveToString methods, not XML.

Now that I'm using the XML serialization, I'm still having quite a few problems.

I cannot deserialize.  After quite a few trial and error issues, I now have  an exception when I deserialize - "The Brushes element was invalid or missing"

Any ideas?

           MemoryStream ms = new MemoryStream();
           StreamWriter sw = new StreamWriter(ms);
                     
           sw.Write(contents);
           ms.Position = 0;
           System.Xml.XmlReader xr =   System.Xml.XmlReader.Create(ms);
           reader.Read(xr);
  
Back to top
 
IP Logged
 
Iva
Junior Member
**
Offline


MindFusion support

Posts: 55
Joined: Aug 6th, 2005
Re: Serialization
Reply #4 - Nov 11th, 2005 at 5:29pm
Print Post  
This works here:

private void button1_Click(object sender, System.EventArgs e)
{
MemoryStream stream = new MemoryStream();
MindFusion.FlowChartX.Xml.XmlWriter writer =
new MindFusion.FlowChartX.Xml.XmlWriter(fc);
writer.Write(stream);

fc.ClearAll();

stream.Position = 0;
MindFusion.FlowChartX.Xml.XmlReader reader =
new MindFusion.FlowChartX.Xml.XmlReader(fc);
reader.Read(stream);
}

Is it what you need ?
  
Back to top
 
IP Logged
 
DConroy
YaBB Newbies
*
Offline



Posts: 12
Joined: Nov 1st, 2005
Re: Serialization
Reply #5 - Nov 11th, 2005 at 5:48pm
Print Post  
Doesn't seem to work here...that's essentially what I've been doing.

Couple things of note:
I'm using the build for .Net 2.0
I'm using the demo
I calling this from within a method of a derived extension of the control.

I need to pass the method a string, containing the contents previously serialized by the control.  It needs to redraw the diagram based on the passed in string.

       public void LoadFromXml(string contents)
       {

           MindFusion.FlowChartX.Xml.XmlReader reader = new MindFusion.FlowChartX.Xml.XmlReader(this);
           ClearAll();
           reader.DeserializeTag += new MindFusion.FlowChartX.Xml.SerializeTagEvent(DeserializeTag);
           MemoryStream ms = new MemoryStream();
           StreamWriter sw = new StreamWriter(ms)
                       
           sw.Write(contents);
           ms.Position = 0;
           ClearAll();
           System.Xml.XmlReader xr = System.Xml.XmlReader.Create(ms);
           reader.Read(xr);

       }

which results in:

MindFusion.FlowChartX.Xml.InvalidFormatException: Brushes element missing or invalid
   at MindFusion.FlowChartX.Xml.XmlReader.Read(XmlReader reader)
   at Acsis.DataLink.UI.WorkflowPrototypePlugin.Controls.AcsisWorkflowChart.LoadFromXm
l(String contents) in C:\Code\RND\DataLink\Development\5.0\Acsis.DataLink.UI.WorkflowPrototypePlugin2\
Controls\AcsisWorkflowChart.cs:line 437
   at Acsis.DataLink.UI.WorkflowPrototypePlugin.Views.WorkSpace.flowChart1_BoxDblClick
ed(Object sender, BoxMouseArgs e) in C:\Code\RND\DataLink\Development\5.0\Acsis.DataLink.UI.WorkflowPrototypePlugin2\
Views\WorkSpace.cs:line 1078
   at MindFusion.FlowChartX.FlowChart.x33a6385620deccdc(ChartObject xa59bff7708de3a18, PointF x0b433f30d6157b49, MouseButtons x64c848779a37b985)
   at MindFusion.FlowChartX.FlowChart.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  
Back to top
 
IP Logged
 
DConroy
YaBB Newbies
*
Offline



Posts: 12
Joined: Nov 1st, 2005
Re: Serialization
Reply #6 - Nov 11th, 2005 at 6:09pm
Print Post  
Found the problem, again, on my side.  Needed to call flush on the streamwriter...

Thanks for your patience and help...

BTW, we love the control here....will probably be purchashing soon.
  
Back to top
 
IP Logged
 
Iva
Junior Member
**
Offline


MindFusion support

Posts: 55
Joined: Aug 6th, 2005
Re: Serialization
Reply #7 - Nov 11th, 2005 at 6:33pm
Print Post  
yep, I believe the Write method override from our example calls Flush internally so that's why it worked.

We are happy you love the control 8)
  
Back to top
 
IP Logged
 
Aaron
YaBB Newbies
*
Offline


Looking for support

Posts: 44
Joined: Nov 9th, 2007
Re: Serialization
Reply #8 - Jan 17th, 2008 at 6:13am
Print Post  
Quite on topic, but pretty much completely the opposite:

I'm using FC.NET 4.0.3

Is there a quick way to serialize binary (I'm using the SaveToString) but excluding the tags?!

I need to send the layout of the chart to a webservice (that will generate an image and do some stuff with it) so I only need the layout and the tags are not relevant.

I can think of several ways to do this, but somehow disabling the tag serialization would be very handy. But I don't think an event like the one with XML serialization is raised, or is it?

My tags are all serializable because I need them in the full XML serialization of my chart.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Serialization
Reply #9 - Jan 17th, 2008 at 6:31am
Print Post  
You cannot exclude the tags when using binary serialization and they are serializable. A quick way to send the chart without tags is to clone the primary chart:

FlowChart tempChart = new FlowChart();
tempChart.LoadFromString(chart.SaveToString());

then set Tag to null for all items in tempChart, and finally send tempChart.SaveToString() to the service.

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


Looking for support

Posts: 44
Joined: Nov 9th, 2007
Re: Serialization
Reply #10 - Jan 17th, 2008 at 9:23am
Print Post  
Thanks!

That's exactly how I'm doing it now, I was just wondering if there might have been a quicker way.

I'll settle with it Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint