Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

DSGraphEdit: A Reasonable Facsimile of Microsoft's GraphEdit in .NET

, 19 Dec 2007
A library for adding DirectShow GraphEdit-like abilities to .NET applications.
dsgrapheditdemo.zip
dsgrapheditsrc.zip
DSGraphEdit
bin
Release
DSIcon.ico
Properties
Settings.settings
Referenced Libs
WeifenLuo.WinFormsUI.Docking.dll
RemoteGraphTile.jpg
DaggerLib
bin
Release
Core
Interfaces
Properties
SetGeneric
UI
DaggerLib.DSGraphEdit
DMOParameterControls
DSFilterTreeView
DSGraphEditControls
lib
Properties
ReferencedLibs
DirectShowLib-2005.dll
MediaFoundation.dll
DaggerLib.UI.Windows
AStar
bin
Debug
DaggerPropertyGrid
PropertyGridEx
Properties
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Runtime.Serialization;

namespace DaggerLib.Core
{
    [Serializable]
    internal class DaggerNodeNonSerializationAssistant : ISerializable
    {
        public List<DaggerInputPin> InputPins;
        public List<DaggerOutputPin> OutputPins;
        public Type NodeType;
        public Guid NodeInstanceGuid;

        public DaggerNodeNonSerializationAssistant(DaggerNode node)
        {
            NodeType = node.GetType();

            NodeInstanceGuid = node.InstanceGuid;

            InputPins = new List<DaggerInputPin>();
            foreach (DaggerInputPin pin in node.InputPins)
            {
                InputPins.Add(pin);
            }

            OutputPins = new List<DaggerOutputPin>();
            foreach (DaggerOutputPin pin in node.OutputPins)
            {
                OutputPins.Add(pin);
            }

            FieldInfo[] fi = NodeType.GetFields();

            for (int i = 0; i < fi.Length; i++)
            {
                if (fi[i].FieldType.IsSubclassOf(typeof(DaggerBasePin)))
                {
                    DaggerBasePin val = (DaggerBasePin)fi[i].GetValue(node);

                    if (val != null)
                    {
                        //if this pin is stored in the collection, serialize it's reflected FieldInfo
                        if (node.InputPins[val.InstanceGuid] != null || node.OutputPins[val.InstanceGuid] != null)
                        {
                            val._reflectedTargets.Add(fi[i]);
                        }
                    }
                }
            }
        }

        public DaggerNode CreateNode()
        {
            DaggerNode node = (DaggerNode)Activator.CreateInstance(NodeType);

            node.InputPins.Clear();
            node.OutputPins.Clear();
            
            //set it'a InstanceGuid
            node.InstanceGuid = NodeInstanceGuid;

            //give it the pins
            foreach (DaggerInputPin pin in InputPins)
            {
                node.InputPins.Add(pin);
            }

            foreach (DaggerOutputPin pin in OutputPins)
            {
                node.OutputPins.Add(pin);
            }

            // put pins into thier reflected fields
            foreach (DaggerInputPin pin in InputPins)
            {
                foreach (FieldInfo fi in pin._reflectedTargets)
                {
                    fi.SetValue(node, pin);
                }
            }
            foreach (DaggerOutputPin pin in OutputPins)
            {
                foreach (FieldInfo fi in pin._reflectedTargets)
                {
                    fi.SetValue(node, pin);
                }
            }

            return node;
        }

        public DaggerNodeNonSerializationAssistant(SerializationInfo info, StreamingContext ctxt)
        {
            NodeType = (Type)info.GetValue("NodeType", typeof(Type));
            InputPins = (List<DaggerInputPin>)info.GetValue("InputPins", typeof(List<DaggerInputPin>));
            OutputPins = (List<DaggerOutputPin>)info.GetValue("OutputPins", typeof(List<DaggerOutputPin>));
            NodeInstanceGuid = (Guid)info.GetValue("NodeGuid", typeof(Guid));
        }

        //Serialization function.
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("NodeType", NodeType);
            info.AddValue("NodeGuid", NodeInstanceGuid);
            info.AddValue("InputPins", InputPins);
            info.AddValue("OutputPins", OutputPins);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

JohnnyLocust
Software Developer (Senior) Haivision Network Video
United States United States
AKA Rich Insley.
 
I have over 25 years experience in programming, and I'm completely self taught. (Except for one year at California State University Fresno where I had to learn the God awful language Miranda (http://miranda.org.uk/). I've spent 10 years as a Paratrooper in the US Army during the Clinton Administration.
Follow on   LinkedIn

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 20 Dec 2007
Article Copyright 2007 by JohnnyLocust
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid