Brunet.BootStrapTester.ToDotFile C# (CSharp) Method

ToDotFile() public method

public ToDotFile ( ) : void
return void
    public void ToDotFile()
    {
      ArrayList node_list = _node_list;
      int index = _idx;
      //Make the list of all addresses:
      ArrayList all_adds = new ArrayList();
      Hashtable addresses = new Hashtable();
      foreach(Node item in node_list) {
        Address a = item.Address;
        if( addresses.Contains(a) == false ) {
          all_adds.Add(a);
          addresses[a] = a;
        }
        foreach(Connection con in item.ConnectionTable) {
          a = con.Address;
          if( addresses.Contains(a) == false ) {
            all_adds.Add(a);
            addresses[a] = a;
          }
        }
      }
      all_adds.Sort(new AHAddressComparer());

      string file_name = string.Format("BootGraph_{0:000000}",index); 
      StreamWriter sw = File.CreateText(file_name);
      sw.WriteLine("digraph bootgraph { ");
      //sw.WriteLine("size=\"8,8\";");
      sw.WriteLine("graph [bb=\"0,0,800,800\"];");
      
      double nodesize = .50;
      int canvassize = 576;
      double r = (double)canvassize/2.0 - 1.0 -36.0*nodesize;
      int c = canvassize/2;
      int nodes = all_adds.Count;
      int position = 0;
      double phi = Math.PI/(2*((double)nodes));
      //double r = Math.Cos(phi)/(2.0*nodesize);
      //double r =((double)(canvassize-1-2-Math.Ceiling(nodesize )))/2.0;
      double theta = 0.0;
      int ringlayoutx = 0;
      int ringlayouty = 0;
      
      foreach( Address item in all_adds)
      {
         theta = (double)(4*(position))*phi;
         ringlayoutx = c + (int)(r*Math.Sin(theta));
         ringlayouty = c - (int)(r*Math.Cos(theta));
	 
	 //Find the index of this address:
	 int idx = all_adds.IndexOf( item );

         string node_line = 
           String.Format("{0} [pos=\"{1:D},{2:D}\", width=\"{3:F2}\",height=\"{4:F2}\"];",
                //item.ToBigInteger().IntValue(),
		idx,
                ringlayoutx,
                ringlayouty,
                nodesize,
                nodesize);
          sw.WriteLine(node_line);
	  sw.WriteLine("//{0} = {1}",idx, item);
         position++;
      }
      
      foreach( Node item in node_list)
      {
          string color = "";
	  int item_idx = all_adds.IndexOf( item.Address );
          foreach(Connection con in item.ConnectionTable) {
	    int con_idx = all_adds.IndexOf( con.Address );
            if( con.MainType == ConnectionType.Leaf ) {
              color = " [color= blue]";
	    }
	    else if (con.MainType == ConnectionType.Structured ) {
              color = " [color= red]";
	    }
	    else if (con.MainType == ConnectionType.Unstructured ) {
              color = " [color= green]";
	    }
           string graph_line = String.Format("{0} -> {1}{2};",
		                                          item_idx, con_idx, color);
            sw.WriteLine(graph_line);
	    
	  }
      }
      sw.WriteLine("}");
      sw.Close();
      //We just wrote the file out.
#if USE_GRAPHVIZ
      string neato_command = String.Format("/usr/bin/neato");
      string neato_args =String.Format("-Tps -o {0}_circle.ps -n -s72 {0}",file_name );
      string dot_command = String.Format("/usr/bin/dot");
      string dot_args = String.Format("-Tps -o {0}.ps {1}",file_name,file_name);
      //string touch_cmd = String.Format("/usr/bin/touch");
      //string touch_args = String.Format(" t_movie.ps movie.ps");
      //string cat_cmd = String.Format("/bin/cat");
      //string cat_args = String.Format(" t_movie.ps {0}.ps > t_movie.ps",file_name);
      //string ps2ps_cmd = String.Format("/usr/bin/ps2ps");
      //string ps2ps_args = String.Format("t_movie.ps movie.ps");
#endif
    }
    static void Ping(IList nodes) {