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.Threading;
using DaggerLib.Interfaces;

namespace DaggerLib.Core
{
    /// <summary>
    /// Threaded Graph scheduler class
    /// </summary>
    public class ThreadedOrdinalExecutionScheduler : IGraphScheduler
    {
        private DaggerGraph _graph;
        private List<DaggerNode> ordinals;
        private List<Thread> _threads = new List<Thread>();
        private ManualResetEvent mre = new ManualResetEvent(false);
        private int _nodesCompleted = 0;

        public DaggerGraph Graph
        {
            get
            {
                return _graph;
            }
            set
            {
                CancelProcessing();
                _graph = value;
            }
        }

        public void CancelProcessing()
        {

        }

        public void OnTopologyChanged()
        {

        }

        public void Dispose()
        {

        }

        /// <summary>
        /// Process the entire graph and it's subgraphs
        /// </summary>
        public void ProcessGraph()
        {
            if (_graph != null)
            {
                //get the subgraphs
                for (int subg = 0; subg < _graph.SubGraphCount; subg++)
                {
                    // if this subgraph has only one top level node, process graph from there
                    if (_graph[subg, 0].Count == 1)
                    {
                        ProcessGraph(_graph[subg, 0][0]);
                    }
                    else
                    {
                        // merge the descendents of all the top level nodes and process ordinal slices seperately
                        List<DaggerNode> nodes = new List<DaggerNode>();
                        foreach (DaggerNode tlnode in _graph[subg, 0])
                        {
                            // add the top level node
                            nodes.Add(tlnode);

                            // add it's decendents if it's not already on the list
                            foreach (DaggerNode node in tlnode._descendents)
                            {
                                if (!nodes.Contains(node))
                                {
                                    nodes.Add(node);
                                }
                            }
                        }

                        // sort the list of merged decendents by the ordinals
                        nodes.Sort(new OrdinalComparer());

                        // process each node in the merged list
                        foreach (DaggerNode node in nodes)
                        {
                            node.DoProcessing();
                        }
                    }
                }
            }
        }

        /// <summary>
        /// Process the graph from a given node
        /// </summary>
        /// <param name="node"></param>
        public void ProcessGraph(DaggerNode node)
        {
            node.DoProcessing();

            foreach (DaggerNode n in node._descendents)
            {
                n.DoProcessing();
            }
        }

        /*
        private void _process()
        {
            _nodesCompleted = 0;

            foreach (DaggerNode node in ordinals)
            {
                if (node.UINode != null)
                {
                    node.UINode.IsProcessing = true;
                }

                Thread t = new Thread(_processThread);
                t.IsBackground = true;
                t.Start(node);
            }

            WaitHandle.WaitAll(new WaitHandle[] { mre });
        }

        private void _processThread(object data)
        {
            DaggerNode node = data as DaggerNode;
            node.InvokeProcess();
            _processComplete(node);
        }

        private void _processComplete(DaggerNode node)
        {
            lock (this)
                _nodesCompleted++;

            if (node.UINode != null)
            {
                node.UINode.IsProcessing = false;
            }

            if (_nodesCompleted == ordinals.Count)
            {
                //signal that all nodes in the ordinal have been processed
                mre.Set();
            }
        }
        */
    }
}

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
Web01 | 2.8.140718.1 | Last Updated 20 Dec 2007
Article Copyright 2007 by JohnnyLocust
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid