Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit e006507

Browse files
committed
moved LineReplacer to the CassetteHelper project
1 parent 190d6b2 commit e006507

3 files changed

Lines changed: 41 additions & 35 deletions

File tree

‎CassetteHelper/CassetteHelper.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Compile Include="Connect.cs">
5555
<SubType>Code</SubType>
5656
</Compile>
57+
<Compile Include="LineReplacer.cs" />
5758
<Compile Include="MatchingLineVisitor.cs" />
5859
</ItemGroup>
5960
<ItemGroup>

‎CassetteHelper/LineReplacer.cs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace CassetteHelper
5+
{
6+
public class LineReplacer
7+
{
8+
private readonly string newReference;
9+
private readonly ILineVisitor visitor;
10+
11+
public LineReplacer(ILineVisitor visitor, string replacementUrl)
12+
{
13+
this.visitor = visitor;
14+
this.newReference = string.Format("/// <reference path=\"{0}\" />", replacementUrl);
15+
}
16+
17+
public void Replace(string targetFilePath)
18+
{
19+
if (string.IsNullOrEmpty(targetFilePath)) throw new ArgumentNullException("targetFilePath");
20+
if (!File.Exists(targetFilePath)) throw new FileNotFoundException("Could not find file to replace lines in", targetFilePath);
21+
22+
using (var stringWriter = new StringWriter())
23+
{
24+
bool containsReferences;
25+
26+
using (var inputStream = File.OpenText(targetFilePath))
27+
{
28+
containsReferences = visitor.Visit(inputStream,
29+
r => stringWriter.WriteLine(this.newReference),
30+
stringWriter.WriteLine);
31+
}
32+
33+
if (containsReferences)
34+
{
35+
File.WriteAllText(targetFilePath, stringWriter.ToString());
36+
}
37+
}
38+
}
39+
}
40+
}

‎CassetteHelperTests/LineReplacerTests.cs‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,4 @@ public bool Visit(StreamReader input, Action<string> onMatch, Action<string> onN
5454
}
5555
}
5656
}
57-
58-
public class LineReplacer
59-
{
60-
private readonly string newReference;
61-
private readonly ILineVisitor visitor;
62-
63-
public LineReplacer(ILineVisitor visitor, string replacementUrl)
64-
{
65-
this.visitor = visitor;
66-
this.newReference = string.Format("/// <reference path=\"{0}\" />", replacementUrl);
67-
}
68-
69-
public void Replace(string targetFilePath)
70-
{
71-
if (string.IsNullOrEmpty(targetFilePath)) throw new ArgumentNullException("targetFilePath");
72-
if (!File.Exists(targetFilePath)) throw new FileNotFoundException("Could not find file to replace lines in", targetFilePath);
73-
74-
using (var stringWriter = new StringWriter())
75-
{
76-
bool containsReferences;
77-
78-
using (var inputStream = File.OpenText(targetFilePath))
79-
{
80-
containsReferences = visitor.Visit(inputStream,
81-
r => stringWriter.WriteLine(this.newReference),
82-
stringWriter.WriteLine);
83-
}
84-
85-
if (containsReferences)
86-
{
87-
File.WriteAllText(targetFilePath, stringWriter.ToString());
88-
}
89-
}
90-
}
91-
}
9257
}

0 commit comments

Comments
 (0)