Skip to content

Commit

Permalink
[FIXED #48]
Browse files Browse the repository at this point in the history
  • Loading branch information
w8tcha committed May 6, 2024
1 parent 954f27b commit 97ea82f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
12 changes: 6 additions & 6 deletions BootstrapEmailNet.Tests/BootstrapEmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public BootstrapEmailTests(ITestOutputHelper testOutputHelper)
[Fact]
public void ParallelTests()
{
var compiler = new BootstrapEmail();
var compiler = new BootstrapEmail();

var tasks = Enumerable.Range(0, 50)
.Select(_ => (Action)(() =>
var tasks = Enumerable.Range(0, 50)
.Select(_ => (Action)(() =>
{
var html = compiler.Compile(
var html = compiler.Compile(
"""<a href="#" class="btn btn-primary">A button</a> <a href="#" class="btn btn-secondary">B button</a>""",
string.Empty,
InputType.String);
Expand Down Expand Up @@ -84,8 +84,8 @@ public void ParallelTests()
Assert.Equal(expected, html, ignoreLineEndingDifferences: true, ignoreAllWhiteSpace: true);
}))
.ToArray();
Parallel.Invoke(tasks);
.ToArray();
Parallel.Invoke(tasks);
}

/// <summary>
Expand Down
27 changes: 20 additions & 7 deletions BootstrapEmailNet/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ public class Compiler
public string InputHtml { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="Compiler"/> class.
/// The lock
/// </summary>
/// <param name="input">The input.</param>
/// <param name="config">The configuration.</param>
/// <param name="type">The type.</param>
public Compiler(string input, ConfigStore config, InputType type = InputType.String)
private static readonly ReaderWriterLockSlim Lock = new();

/// <summary>
/// Initializes a new instance of the <see cref="Compiler"/> class.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="config">The configuration.</param>
/// <param name="type">The type.</param>
public Compiler(string input, ConfigStore config, InputType type = InputType.String)
{
this.Config = new Config(config);
this.Type = type;
Expand Down Expand Up @@ -266,8 +271,16 @@ private static void WriteResourceToFile(Assembly assembly, string resourceName,
Directory.CreateDirectory(dirName);
}

using var file = new FileStream(fileName, FileMode.Create, FileAccess.Write);
Lock.EnterWriteLock();

resource?.CopyTo(file);
try
{
using var fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
resource?.CopyTo(fs);
}
finally
{
Lock.ExitWriteLock();
}
}
}
9 changes: 7 additions & 2 deletions BootstrapEmailNet/SassCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BootstrapEmail.Net;

using System;
using System.IO;
using System.Security.Cryptography;

/// <summary>
Expand Down Expand Up @@ -68,7 +69,9 @@ public string Compile()
return ReadFile(filePath);
}

break;
throw new FileNotFoundException(
$"The Email Path does not exist: {this.config.ConfigStore.CssEmailPath}",
this.config.ConfigStore.CssEmailPath);
}
case SassTypes.Head when !string.IsNullOrEmpty(this.config.ConfigStore.CssHeadPath):
{
Expand All @@ -79,7 +82,9 @@ public string Compile()
return ReadFile(filePath);
}

break;
throw new FileNotFoundException(
$"The Email Path does not exist: {this.config.ConfigStore.CssHeadPath}",
this.config.ConfigStore.CssEmailPath);
}
}

Expand Down

0 comments on commit 97ea82f

Please sign in to comment.