Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic nullreferenceexception for custom node with image on server side (Read 3452 times)
shashi123
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Jul 27th, 2016
nullreferenceexception for custom node with image on server side
Jul 27th, 2016 at 8:56am
Print Post  
Hi,
i am trying to add image to custom node.I set node.setNodeImageLocation and added it to NodeListView in javascript code.
I can now view it in NodeListView and can also drag and drop in on diagramview on user interface.But when I try to submit it,it throws null referenceexception on server side.
I need to save that diagram with custom node in XML format.It throws exception when i try to access diagramview on server side as 'ViewBag.DiagramView = DiagramView.FromRequest("diagramView", Request);'.
The exception is:

[NullReferenceException: Object reference not set to an instance of an object.]
at MindFusion.Diagramming.Mvc.DiagramView.c85b69f44585ac91a2b0f5af4d909c5c9(String cc3c2a12fbc775c67cb644523ed85822b)
   at MindFusion.Diagramming.Mvc.DiagramView.FromJson(String json)
   at MindFusion.Diagramming.Mvc.DiagramView.FromRequest(String id, HttpRequestBase request)
   at Tutorial7.Controllers.HomeController.Index(String submitButton) in c:\Program Files (x86)\MindFusion\MindFusion.Diagramming for ASP.NET MVC\ASP.NET MVC 5 (VS2013)\Samples\CSharp\Tutorial7\Tutorial7\Controllers\HomeController.cs:line 26
 
Note : I referred tutorial 7 from samples.
  

customNode1.png ( 226 KB | 155 Downloads )
customNode1.png
customNode.png ( 159 KB | 149 Downloads )
customNode.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: nullreferenceexception for custom node with image on server side
Reply #1 - Jul 27th, 2016 at 10:01am
Print Post  
Hi,

If posting to the server you will have to create a corresponding custom node class in .NET and associate it with the client-side class by calling the DiagramView.RegisterItemType method. If you need to post custom properties between the client and server, you will also have to derive from JavaScriptConverter and register your converter by calling DiagramView.RegisterConverters. E.g. here's what our ShapeNodeConverter class look like -

Code
Select All
/// <summary>
/// Serializes ShapeNode instances.
/// </summary>
public class ShapeNodeConverter : DiagramNodeConverter
{
    /// <summary>
    /// Creates a new instance of the ShapeNodeConverter class.
    /// </summary>
    public ShapeNodeConverter(DiagramView view): base(view)
    {
        this.view = view;
    }

    /// <summary>
    /// SupportedTypes override.
    /// </summary>
    public override IEnumerable<Type> SupportedTypes
    {
        get
        {
            return new List<Type>(new Type[] { typeof(MindFusion.Diagramming.ShapeNode) });
        }
    }

    /// <summary>
    /// Deserialize override.
    /// </summary>
    public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
    {
        ShapeNode node = (ShapeNode)Activator.CreateInstance(type);

        SerializationUtils.DeserializeNode(node as DiagramNode, dictionary, serializer, view);

        if (dictionary.ContainsKey("shape") && dictionary["shape"] != null)
            node.Shape = Shape.FromId(dictionary["shape"].ToString());
        if (dictionary.ContainsKey("rotateText") && dictionary["rotateText"] != null)
            node.RotateText = (bool)dictionary["rotateText"];
        if (dictionary.ContainsKey("text") && dictionary["text"] != null)
            node.Text = dictionary["text"].ToString();
        if (dictionary.ContainsKey("transparent") && dictionary["transparent"] != null)
            node.Transparent = (bool)dictionary["transparent"];
        // more properties ...
        return node;
    }

    /// <summary>
    /// Serialize override.
    /// </summary>
    public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
    {
        IDictionary<string, object> json = base.Serialize(obj, serializer);
        MindFusion.Diagramming.ShapeNode node = (MindFusion.Diagramming.ShapeNode)obj;

        json.Add("shape", node.Shape.Id);
        json.Add("text", node.Text);
        json.Add("transparent", node.Transparent);
        json.Add("rotateText", node.RotateText);
        // more properties
        return json;
    }

    private DiagramView view;
} 



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


tech.support

Posts: 3154
Joined: Oct 19th, 2005
Re: nullreferenceexception for custom node with image on server side
Reply #2 - Aug 4th, 2016 at 10:00am
Print Post  
Hi,

Check this extended tutorial, it now shows a server-side OrgChartNode class and converter that will let you post the diagram to server and send back. It also shows how to implement XMl serialization to let you save diagrams on server -
https://mindfusion.eu/_samples/mvc.tutorial7.zip

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


I Love MindFusion!

Posts: 2
Joined: Jul 27th, 2016
Re: nullreferenceexception for custom node with image on server side
Reply #3 - Aug 22nd, 2016 at 6:21am
Print Post  
It worked.Thanks.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint