Copy and Paste

Hi Support!

I would like to enable Copy/Paste in my application.

I copied MinimalApp form to my project and call it. Everything is ok with paste…

public class MinimalApp : Form
{
public MinimalApp()
{
this.Text = “Minimal GoDiagram App”;

  // create a Go view (a Control) and add to the form
  GoView myView = new GoView();
  myView.Dock = DockStyle.Fill;
  this.Controls.Add(myView);


  // create two nodes for fun...
  GoBasicNode node1 = new GoBasicNode();
  // specify position, label and color
  node1.Location = new PointF(100, 100);
  node1.Text = "first";
  node1.Editable = true;  // first node is editable with F2 only
  node1.Shape.BrushColor = Color.Blue;
  // add to the document, not to the view
  myView.Document.Add(node1);

  GoBasicNode node2 = new GoBasicNode();
  node2.Location = new PointF(200, 100);
  node2.Text = "second";
  node2.Label.Editable = true;  // second node is editable by clicking only
  node2.Shape.BrushColor = Color.Magenta;
  myView.Document.Add(node2);

}

}

But after, I inserted a class, and create a MyDisplay99 object… and paste stopped!! Why?? This is a simple example with this class MyDisplay99 .

See my code:

using System;
using System.Drawing;
using System.Windows.Forms;
using Northwoods.Go;

public class MinimalApp : Form
{
public MinimalApp()
{
this.Text = “Minimal GoDiagram App”;

  // create a Go view (a Control) and add to the form
  GoView myView = new GoView();
  myView.Dock = DockStyle.Fill;
  this.Controls.Add(myView);


  // create two nodes for fun...
  GoBasicNode node1 = new GoBasicNode();
  // specify position, label and color
  node1.Location = new PointF(100, 100);
  node1.Text = "first";
  node1.Editable = true;  // first node is editable with F2 only
  node1.Shape.BrushColor = Color.Blue;
  // add to the document, not to the view
  myView.Document.Add(node1);

  GoBasicNode node2 = new GoBasicNode();
  node2.Location = new PointF(200, 100);
  node2.Text = "second";
  node2.Label.Editable = true;  // second node is editable by clicking only
  node2.Shape.BrushColor = Color.Magenta;
  myView.Document.Add(node2);


  //NEW CODE!!
  MyDisplay99 mytest = new MyDisplay99();
  myView.Document.Add(mytest);

}

}

[Serializable]
public class MyDisplay99 : GoBasicNode
{
public MyDisplay99()
{
this.Text = “first”;
this.Shape.BrushColor = Color.Red;
}

}

Most likely the MyDisplay99 object isn’t serializable. Our built-in nodes are, but with extensible nodes, it is pretty easy to introduce your own problems. You can use GoDocument:TestSerialization() to check. (See the API reference)

  1. I created this MyDisplay99 Class very, very… simple, just has a constructor, and it is based on GoBasicNode.

  2. I inserted [Serializable] in MyDisplay99… and is it not sufficient ?

Just do the TestSerialization to check. It’s easier for the code to check this.

I inserted:

private void button1_Click(object sender, EventArgs e)
{
((GoView)this.Controls[1]).Document = TestSerialization();
}

public GoDocument TestSerialization()
{
    System.IO.MemoryStream memstream = new System.IO.MemoryStream();
    
    System.Runtime.Serialization.IFormatter oformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    oformatter.Serialize(memstream, ((GoView)this.Controls[1]).Document); 
    
    memstream.Position = 0;
    
    System.Runtime.Serialization.IFormatter iformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
    return iformatter.Deserialize(memstream) as GoDocument;
}

The result was: SerializationException:

<span id=“result_” =“short_text” lang=“en”><span title=“Clique para mostrar traduções alternativas” =“hps”>Can not <span title=“Clique para mostrar traduções alternativas” =“hps”>find <span title=“Clique para mostrar traduções alternativas” =“hps”>the assembly ‘MyProjectDll, Version=4.2.4064.20473, Culture=neutral, PublicKeyToken=null’.

I should insert [Serializable] in my dll ?

Thanks!

Have you extended the GoDocument class?



(You can just call doc.TestSerialization(), you don’t have to insert the code above… we’ve added that call to the product now)

I am using Deserization to store the the graph, However, when I load the graph from the saved binary file, it gives me the following error:

end of stream encountered before parsing was completed.