Commits

roundcrisis committed f8b6d25

latest on code shapes

  • Participants
  • Parent commits 860d998

Comments (0)

Files changed (3)

src/CodeShapes/CodeShapes.csproj

     <Compile Include="Shapes\Visibility.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Shapes\MethodCodeShape.cs" />
+    <Compile Include="Status.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>

src/CodeShapes/Renderer.cs

 using System;
 using System.Diagnostics;
 using System.IO;
-using System.Reflection;
 
 namespace CodeShapes
 {
-
-
 	public class Renderer
 	{
 		static public string AssemblyDirectory
 		}
 
 		private readonly string _pathToDotRenderer;
-		
+
 		private string _dotFilesLocation;
-		
+
 		private readonly Status _status;
 
-		public Renderer()
+		public Renderer(string dotFileLocation = null)
 		{
 			_status = new Status();
 			_pathToDotRenderer = Path.Combine(AssemblyDirectory, "graphviz");
-			if(!Directory.Exists(_pathToDotRenderer))
+			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;
+			_dotFilesLocation = dotFileLocation ?? DefaultDotFilesLocation;
 		}
-
+		
 		public string DefaultDotFilesLocation
 		{
-			get {
+			get
+			{
 				return Path.Combine(AssemblyDirectory, "DotFiles");
 			}
 		}
 		}
 
 
-		public void RenderPng(string[] filesToRender)
+		public void RenderPng()
 		{
-			var graphviz = new Process {EnableRaisingEvents = false, StartInfo = new ProcessStartInfo(PathToDotRenderer, " -Tpng -O " + string.Join(" ", filesToRender))};
+			string[] filesWithDotExtension = null;
+			if (Directory.Exists(_dotFilesLocation))
+			{
+				filesWithDotExtension = Directory.GetFiles(_dotFilesLocation, ".dot", SearchOption.AllDirectories);
+			}
+			else
+			{
+				Status.ErrorMessage(string.Format("Directory {0} doesnt exist", _dotFilesLocation));
+				return;
+			}
+			var dot = new Process
+						{
+							EnableRaisingEvents = false,
+							StartInfo = new ProcessStartInfo(PathToDotRenderer, " -Tpng -O " + string.Join(" ", filesWithDotExtension))
+						};
+			dot.Start();
 		}
 	}
-
-	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; }
-	}
 }

src/CodeShapesTests/RedererTests.cs

 		public void When_dot_exe_found_Then_renderer_status_is_ready()
 		{
 			var renderer = new Renderer();
-			Assert.True(renderer.Status.Ready);
+			Assert.True(renderer.Status.Success);
 		}
 
 		[Test]
-		public void When_something_then_something()
+		public void When_render_to_png_with_non_existent_files_Then_error_message()
 		{
+			var renderer = new Renderer();
+			
+			renderer.RenderPng();
+
+			Assert.False(renderer.Status.Success);
 		}
-
 	}
 }