Skip to content

Commit cdb6a6c

Browse files
author
Josh McCullough
committed
removes references to QC Common DLL
adds extension methods to handle those now-missing references.
1 parent 216a338 commit cdb6a6c

10 files changed

Lines changed: 97 additions & 39 deletions

File tree

-266 KB
Binary file not shown.
-640 KB
Binary file not shown.

Source/STL/Extensions.cs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using QuantumConcepts.Common.Extensions;
3+
using System.Globalization;
74

85
namespace QuantumConcepts.Formats.StereoLithography
96
{
@@ -51,5 +48,72 @@ public static void Invert(this IEnumerable<Facet> facets)
5148
{
5249
facets.ForEach(f => f.Normal.Invert());
5350
}
51+
52+
/// <summary>Iterates the provided enumerable, applying the provided action to each element.</summary>
53+
/// <param name="items">The items upon which to apply the action.</param>
54+
/// <param name="action">The action to apply to each item.</param>
55+
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
56+
{
57+
if (items != null)
58+
{
59+
foreach (var item in items)
60+
{
61+
action(item);
62+
}
63+
}
64+
}
65+
66+
/// <summary>Iterates the provided enumerable, applying the provided action to each element.</summary>
67+
/// <param name="items">The items upon which to apply the action.</param>
68+
/// <param name="predicate">The action to apply to each item.</param>
69+
public static bool All<T>(this IEnumerable<T> items, Func<int, T, bool> predicate)
70+
{
71+
if (items != null)
72+
{
73+
var index = 0;
74+
75+
foreach (var item in items)
76+
{
77+
if (!predicate(index, item))
78+
{
79+
return false;
80+
}
81+
82+
index++;
83+
}
84+
}
85+
86+
return true;
87+
}
88+
89+
/// <summary>Checks if the provided value is null or empty.</summary>
90+
/// <param name="value">The value to check.</param>
91+
/// <returns>True if the provided value is null or empty.</returns>
92+
public static bool IsNullOrEmpty(this string value)
93+
{
94+
return string.IsNullOrEmpty(value);
95+
}
96+
97+
/// <summary>Interpolates the provided formatted string with the provided args using the default culture.</summary>
98+
/// <param name="format">The formatted string.</param>
99+
/// <param name="args">The values to use for interpolation.</param>
100+
public static string Interpolate(this string format, params object[] args)
101+
{
102+
return format.Interpolate(CultureInfo.InvariantCulture, args);
103+
}
104+
105+
/// <summary>Interpolates the provided formatted string with the provided args.</summary>
106+
/// <param name="format">The formatted string.</param>
107+
/// <param name="culture">The culture info to use.</param>
108+
/// <param name="args">The values to use for interpolation.</param>
109+
public static string Interpolate(this string format, CultureInfo culture, params object[] args)
110+
{
111+
if (format != null)
112+
{
113+
return string.Format(culture, format, args);
114+
}
115+
116+
return null;
117+
}
54118
}
55119
}

Source/STL/Facet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Text.RegularExpressions;
7-
using QuantumConcepts.Common.Extensions;
7+
using QuantumConcepts.Formats.StereoLithography;
88

99
namespace QuantumConcepts.Formats.StereoLithography
1010
{
@@ -71,7 +71,7 @@ public void Write(BinaryWriter writer)
7171
/// <summary>Returns the string representation of this <see cref="Facet"/>.</summary>
7272
public override string ToString()
7373
{
74-
return "facet {0}".FormatString(this.Normal);
74+
return "facet {0}".Interpolate(this.Normal);
7575
}
7676

7777
/// <summary>Determines whether or not this instance is the same as the <paramref name="other"/> instance.</summary>

Source/STL/Normal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Text;
6-
using QuantumConcepts.Common.Extensions;
6+
using QuantumConcepts.Formats.StereoLithography;
77
using System.Globalization;
88

99
namespace QuantumConcepts.Formats.StereoLithography

Source/STL/STL.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@
3535
<Prefer32Bit>false</Prefer32Bit>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<Reference Include="QuantumConcepts.Common, Version=1.0.1.0, Culture=neutral, PublicKeyToken=ab18da1c1d053b41, processorArchitecture=MSIL">
39-
<SpecificVersion>False</SpecificVersion>
40-
<HintPath>..\..\Components\QuantumConcepts.Common.dll</HintPath>
41-
</Reference>
4238
<Reference Include="System" />
4339
<Reference Include="System.Core" />
4440
<Reference Include="System.Xml.Linq" />

Source/STL/STLDocument.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Text.RegularExpressions;
7-
using QuantumConcepts.Common.Extensions;
7+
using QuantumConcepts.Formats.StereoLithography;
88

99
namespace QuantumConcepts.Formats.StereoLithography
1010
{
@@ -53,7 +53,7 @@ public void WriteText(Stream stream)
5353
this.Facets.ForEach(o => o.Write(writer));
5454

5555
//Write the footer.
56-
writer.Write("end{0}".FormatString(this.ToString()));
56+
writer.Write("end{0}".Interpolate(this.ToString()));
5757
}
5858
}
5959

@@ -131,7 +131,7 @@ public static bool IsText(Stream stream)
131131
//Read the header as ASCII.
132132
header = Encoding.ASCII.GetString(buffer);
133133

134-
return solid.EqualsIgnoreCase(header);
134+
return solid.Equals(header, StringComparison.InvariantCultureIgnoreCase);
135135
}
136136

137137
/// <summary>Determines if the <see cref="STLDocument"/> contained within the <paramref name="stream"/> is binary-based.</summary>
@@ -193,7 +193,7 @@ public static STLDocument Read(StreamReader reader)
193193

194194
//Check the header.
195195
if (!headerMatch.Success)
196-
throw new FormatException("Invalid STL header, expected \"solid [name]\" but found \"{0}\".".FormatString(header));
196+
throw new FormatException("Invalid STL header, expected \"solid [name]\" but found \"{0}\".".Interpolate(header));
197197

198198
//Create the STL and extract the name (optional).
199199
stl = new STLDocument()
@@ -285,7 +285,7 @@ public static STLDocument CopyAsBinary(Stream inStream, Stream outStream)
285285
/// <summary>Returns the header representation of this <see cref="STLDocument"/>.</summary>
286286
public override string ToString()
287287
{
288-
return "solid {0}".FormatString(this.Name);
288+
return "solid {0}".Interpolate(this.Name);
289289
}
290290

291291
/// <summary>Determines whether or not this instance is the same as the <paramref name="other"/> instance.</summary>

Source/STL/Vertex.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Linq;
66
using System.Text;
77
using System.Text.RegularExpressions;
8-
using QuantumConcepts.Common.Extensions;
8+
using QuantumConcepts.Formats.StereoLithography;
99

1010
namespace QuantumConcepts.Formats.StereoLithography
1111
{
@@ -49,7 +49,7 @@ public void Shift(Vertex shift)
4949
/// <param name="writer">The writer to which the <see cref="Vertex"/> will be written at the current position.</param>
5050
public void Write(StreamWriter writer)
5151
{
52-
writer.WriteLine("\t\t\t{0}".FormatString(this.ToString()));
52+
writer.WriteLine("\t\t\t{0}".Interpolate(this.ToString()));
5353
}
5454

5555
/// <summary>Writes the <see cref="Vertex"/> as binary to the <paramref name="writer"/>.</summary>
@@ -105,13 +105,13 @@ public static Vertex Read(StreamReader reader)
105105

106106
//Parse the three coordinates.
107107
if (!float.TryParse(match.Groups["X"].Value, numberStyle, CultureInfo.InvariantCulture, out x))
108-
throw new FormatException("Could not parse X coordinate \"{0}\" as a decimal.".FormatString(match.Groups["X"]));
108+
throw new FormatException("Could not parse X coordinate \"{0}\" as a decimal.".Interpolate(match.Groups["X"]));
109109

110110
if (!float.TryParse(match.Groups["Y"].Value, numberStyle, CultureInfo.InvariantCulture, out y))
111-
throw new FormatException("Could not parse Y coordinate \"{0}\" as a decimal.".FormatString(match.Groups["Y"]));
111+
throw new FormatException("Could not parse Y coordinate \"{0}\" as a decimal.".Interpolate(match.Groups["Y"]));
112112

113113
if (!float.TryParse(match.Groups["Z"].Value, numberStyle, CultureInfo.InvariantCulture, out z))
114-
throw new FormatException("Could not parse Z coordinate \"{0}\" as a decimal.".FormatString(match.Groups["Z"]));
114+
throw new FormatException("Could not parse Z coordinate \"{0}\" as a decimal.".Interpolate(match.Groups["Z"]));
115115

116116
return new Vertex()
117117
{
@@ -139,7 +139,7 @@ public static Vertex Read(BinaryReader reader)
139139
if (bytesRead == 0)
140140
return null;
141141
else if (bytesRead != data.Length)
142-
throw new FormatException("Could not convert the binary data to a vertex. Expected {0} bytes but found {1}.".FormatString(vertexSize, bytesRead));
142+
throw new FormatException("Could not convert the binary data to a vertex. Expected {0} bytes but found {1}.".Interpolate(vertexSize, bytesRead));
143143

144144
//Convert the read bytes to their numeric representation.
145145
return new Vertex()

Source/Test/STLTests.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
using System;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
5+
using System.Linq;
46
using System.Reflection;
57
using System.Text;
6-
using Microsoft.VisualStudio.TestTools.UnitTesting;
7-
using QuantumConcepts.Formats.StereoLithography;
8-
using QuantumConcepts.Common.Extensions;
9-
using System.Linq;
10-
using QuantumConcepts.Common.IO;
11-
using System.Diagnostics;
128

139
namespace QuantumConcepts.Formats.StereoLithography.Test
1410
{
@@ -95,17 +91,22 @@ public void FromFile()
9591
{
9692
STLDocument stl = null;
9793

98-
using (Stream stream = GetData("ASCII.stl"))
94+
using (Stream inStream = GetData("ASCII.stl"))
9995
{
10096
string tempFilePath = Path.GetTempFileName();
10197

102-
using (TemporaryFileStream tempStream = new TemporaryFileStream(tempFilePath))
98+
using (var outStream = File.Create(tempFilePath))
99+
{
100+
inStream.CopyTo(outStream);
101+
}
102+
103+
stl = STLDocument.Open(tempFilePath);
104+
105+
try
103106
{
104-
stream.CopyTo(tempStream);
105-
tempStream.Flush();
106-
tempStream.Close();
107-
stl = STLDocument.Open(tempFilePath);
107+
File.Delete(tempFilePath);
108108
}
109+
catch { /* Ignore. */ }
109110
}
110111

111112
ValidateSTL(stl);
@@ -388,7 +389,7 @@ public void InvertFacets()
388389

389390
private Stream GetData(string filename)
390391
{
391-
return Assembly.GetExecutingAssembly().GetManifestResourceStream("QuantumConcepts.Formats.StereoLithography.Test.Data.{0}".FormatString(filename));
392+
return Assembly.GetExecutingAssembly().GetManifestResourceStream("QuantumConcepts.Formats.StereoLithography.Test.Data.{0}".Interpolate(filename));
392393
}
393394

394395
private void ValidateSTL(STLDocument stl, int expectedFacetCount = 12)

Source/Test/Test.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
<WarningLevel>4</WarningLevel>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="QuantumConcepts.Common">
40-
<HintPath>..\..\Components\QuantumConcepts.Common.dll</HintPath>
41-
</Reference>
4239
<Reference Include="System" />
4340
</ItemGroup>
4441
<Choose>

0 commit comments

Comments
 (0)