1. roundcrisis
  2. CodeShape

Source

CodeShape / src / CodeShapes / Renderer.cs

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;

namespace CodeShapes
{


	public class Renderer
	{
		static public string AssemblyDirectory
		{
			get
			{
				string codeBase = typeof(ClassAnalyzer).Assembly.CodeBase;
				var uri = new UriBuilder(codeBase);
				string path = Uri.UnescapeDataString(uri.Path);
				return Path.GetDirectoryName(path);
			}
		}

		private readonly string _pathToDotRenderer;
		
		private string _dotFilesLocation;
		
		private readonly Status _status;

		public Renderer()
		{
			_status = new Status();
			_pathToDotRenderer = Path.Combine(AssemblyDirectory, "graphviz");
			if(!Directory.Exists(_pathToDotRenderer))
			{
				_status = new Status("The dot.exe path was not found. Please check configuration options and set the Renderer path. ");
			}
			_dotFilesLocation = DefaultDotFilesLocation;
		}

		public string DefaultDotFilesLocation
		{
			get {
				return Path.Combine(AssemblyDirectory, "DotFiles");
			}
		}

		public string PathToDotRenderer
		{
			get { return _pathToDotRenderer; }
		}

		public Status Status
		{
			get { return _status; }
		}


		public void RenderPng(string[] filesToRender)
		{
			var graphviz = new Process {EnableRaisingEvents = false, StartInfo = new ProcessStartInfo(PathToDotRenderer, " -Tpng -O " + string.Join(" ", filesToRender))};
		}
	}

	public class Status
	{
		public Status()
		{
			Message = "All Clear";
			Ready = true;
		}

		public Status(string errorMessage)
		{
			Message = errorMessage;
			Ready = false;
		}

		public bool Ready { get; set; }

		public string Message { get; set; }
	}
}