Shifted references to IFileInvoker to Dependencies.cs, added factory func to Dependencies.cs for providing IFileInvoker.

This commit is contained in:
Michael Smith 2016-02-24 23:17:35 -08:00
parent 8b05e2af6a
commit 2976110f05
7 changed files with 34 additions and 11 deletions

View File

@ -148,7 +148,7 @@ namespace OSCADSharp.UnitTests
var mock = new Mock<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { output = contents; });
Settings.FileWriter = mock.Object;
Dependencies.FileWriter = mock.Object;
cube.ToFile("myFile");
@ -165,7 +165,7 @@ namespace OSCADSharp.UnitTests
var mock = new Mock<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { output = contents; });
Settings.FileWriter = mock.Object;
Dependencies.FileWriter = mock.Object;
cube.ToFile("myFile");

View File

@ -24,7 +24,7 @@ namespace OSCADSharp.UnitTests
var mock = new Mock<IFileWriter>();
mock.Setup(_wrtr => _wrtr.WriteAllLines(It.IsAny<string>(), It.IsAny<string[]>()))
.Callback<string, string[]>((path, contents) => { output = contents; });
Settings.FileWriter = mock.Object;
Dependencies.FileWriter = mock.Object;
cube.ToFile("myFile");

View File

@ -0,0 +1,25 @@
using OSCADSharp.Files;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp
{
/// <summary>
/// Contains definitions for external APIs used by OSCADSharp
/// </summary>
public static class Dependencies
{
/// <summary>
/// Used to write scripts to file
/// </summary>
public static IFileWriter FileWriter = new DefaultFileWriter();
/// <summary>
/// Factory method to provide the class used to perform actions on output scripts
/// </summary>
public static Func<string, IFileInvoker> FileInvokerFactory = (path) => { return new DefaultFileInvoker(path); };
}
}

View File

@ -8,6 +8,8 @@ namespace OSCADSharp.Files
{
/// <summary>
/// Invokes OpenSCAD actions on output files
///
/// If these methods don't work, double check that your Settings.OpenSCADPath value is correct
/// </summary>
public interface IFileInvoker
{

View File

@ -331,14 +331,14 @@ namespace OSCADSharp
path += ".scad";
}
Settings.FileWriter.WriteAllLines(path, new string[]
Dependencies.FileWriter.WriteAllLines(path, new string[]
{
Settings.OSCADSharpHeader,
Variables.Global.ToString(),
this.ToString()
});
return new DefaultFileInvoker(filePath);
return Dependencies.FileInvokerFactory(filePath);
}
#endregion

View File

@ -42,6 +42,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Dependencies.cs" />
<Compile Include="Files\DefaultFileInvoker.cs" />
<Compile Include="Files\DefaultFileWriter.cs" />
<Compile Include="Files\IFileInvoker.cs" />

View File

@ -18,12 +18,7 @@ namespace OSCADSharp
/// </summary>
public static readonly string OSCADSharpHeader = String.Format("/*Code Generated using OSCADSharp on {0}. {1}{2}For more information, please visit https://github.com/Exolun/OSCADSharp */{3}",
DateTime.Now.ToString(), Environment.NewLine, Environment.NewLine, Environment.NewLine);
/// <summary>
/// Used to write scripts to file
/// </summary>
public static IFileWriter FileWriter = new DefaultFileWriter();
/// <summary>
/// Path to the OpenSCAD executable for file invocation
/// (Default value is set the default install directory on Windows)