how use graphvis in C# application?

Posted by ghasedak - on Stack Overflow See other posts from Stack Overflow or by ghasedak -
Published on 2011-11-21T09:36:26Z Indexed on 2011/11/21 9:50 UTC
Read the original article Hit count: 217

Filed under:
|

i have a dot format file and i download graphvis for windows now how can i use graphvis to show a graph in my c# application?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VDS.RDF;
using VDS.RDF.Parsing;
using VDS.RDF.Query;
using System.IO;
using System.Windows;
using System.Runtime.InteropServices;
using VDS.RDF.Writing;
using System.Diagnostics;

namespace WindowsFormsApplication2
{
    public partial class first : Form

    {

         Graph g = new Graph();
         string s1 = null;

/**************************************DATA********************************************/
        public first()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {

            Stream myStream = null;

            var parser = new Notation3Parser();
            var graph = new Graph();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "RDF files (*.n3)|*.n3";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.Multiselect = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            string s = openFileDialog1.FileName.ToString();
                            string w= Directory.GetCurrentDirectory().ToString();
                            string Fname = openFileDialog1.SafeFileName.ToString();
                            File.Copy(s,Path.Combine(w,Fname),true);

                            // Insert code to read the stream here.
                            Win32.AllocConsole();
                            s1 = Path.Combine(w, Fname);
                            insertNodeButton.Visible = true;
                            delBut.Visible = true;
                            simi.Visible = true;
                            showNodes showNodes1 = new showNodes(s1);
                            g = showNodes1.returngraph();

                           Console.Read();
                           Win32.FreeConsole();
                          // g.SaveToFile("firstfile.n3");

                           this.Show();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
            GraphVizWriter hi = new GraphVizWriter();
            hi.Save(g, "c:\\ahmad.dot");

        }
        private void button2_Click(object sender, EventArgs e)
        {
            string strCmdLine = Application.StartupPath + "\\Tools\\rdfEditor.exe";
            //string strCmdLine = "DIR";
            MessageBox.Show(strCmdLine);
            System.Diagnostics.Process process1;
            process1 = new System.Diagnostics.Process();

            //Do not receive an event when the process exits.

            process1.EnableRaisingEvents = false;


            //The "/C" Tells Windows to Run The Command then Terminate 

            System.Diagnostics.Process.Start(strCmdLine);
            process1.Close();

        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }



        private void insertNodeButton_Click(object sender, EventArgs e)
        {
            //Graph parentvalue = this.g;
            //String parentvalueadress = this.s1;

            addTriple a1 = new addTriple();
            a1.G = g;
            a1.BringToFront();
            a1.ShowDialog();
            g = a1.G;
            g.SaveToFile("c:\\Hi.n3");


        }

this is my code i want to visul saly dot file format to show a graph with graphvis

© Stack Overflow or respective owner

Related posts about c#

Related posts about graphviz