Skip to content

Commit

Permalink
Fixed a error #30 “Conflict of using multiple sites in one applicatio…
Browse files Browse the repository at this point in the history
…n pool”
  • Loading branch information
Taritsyn committed Sep 7, 2018
1 parent 4e414ef commit 9e88344
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
3 changes: 1 addition & 2 deletions src/LibSassHost/LibSassHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ This package does not contain the native implementations of LibSass. Therefore,
<RepositoryUrl>https://github.com/Taritsyn/LibSassHost</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>LibSass;Sass;SCSS;CSS</PackageTags>
<PackageReleaseNotes>1. Added support of LibSass version 3.5.4;
2. In compilation options was added one new property - `AdditionalImportExtensions` (default `.css`).</PackageReleaseNotes>
<PackageReleaseNotes>Fixed a error #30 “Conflict of using multiple sites in one application pool”.</PackageReleaseNotes>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
Expand Down
63 changes: 40 additions & 23 deletions src/LibSassHost/SassCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;

using LibSassHost.Internal;
using LibSassHost.Resources;
Expand Down Expand Up @@ -36,9 +37,9 @@ public static class SassCompiler
private static IFileManager _fileManager;

/// <summary>
/// Synchronizer of file manager
/// Instance of mutex
/// </summary>
private static readonly object _fileManagerSynchronizer = new object();
private static Mutex _mutex = new Mutex();

/// <summary>
/// Gets a version of the LibSass library
Expand All @@ -61,21 +62,8 @@ public static string LanguageVersion
/// </summary>
public static IFileManager FileManager
{
get
{
lock (_fileManagerSynchronizer)
{
return _fileManager;
}
}
set
{
lock (_fileManagerSynchronizer)
{
_fileManager = value;
FileManagerMarshaler.SetFileManager(_fileManager);
}
}
get { return _fileManager; }
set { _fileManager = value; }
}


Expand Down Expand Up @@ -221,14 +209,27 @@ public static CompilationResult Compile(string content, bool indentedSyntax, Com
private static CompilationResult InnerCompile(string content, bool indentedSyntax, string inputPath,
string outputPath, string sourceMapPath, CompilationOptions options)
{
CompilationResult result;
var dataContext = new SassDataContext
{
SourceString = content
};

BeginCompile(dataContext, indentedSyntax, inputPath, outputPath, sourceMapPath, options);
SassCompilerProxy.Compile(dataContext);
CompilationResult result = EndCompile(dataContext);

try
{
_mutex.WaitOne();
FileManagerMarshaler.SetFileManager(_fileManager);
SassCompilerProxy.Compile(dataContext);
}
finally
{
FileManagerMarshaler.UnsetFileManager();
_mutex.ReleaseMutex();
}

result = EndCompile(dataContext);

return result;
}
Expand Down Expand Up @@ -263,7 +264,8 @@ public static CompilationResult Compile(string content, bool indentedSyntax, Com
);
}

if (_fileManager != null && !_fileManager.FileExists(inputPath))
IFileManager fileManager = _fileManager;
if (fileManager != null && !fileManager.FileExists(inputPath))
{
string text = string.Format("File to read not found or unreadable: {0}", inputPath);
string message = string.Format("Internal Error: {0}", text);
Expand All @@ -279,12 +281,27 @@ public static CompilationResult Compile(string content, bool indentedSyntax, Com
};
}

CompilationResult result;
var fileContext = new SassFileContext();
bool indentedSyntax = GetIndentedSyntax(inputPath);

BeginCompile(fileContext, indentedSyntax, inputPath, outputPath, sourceMapPath, options);
SassCompilerProxy.CompileFile(fileContext);
CompilationResult result = EndCompile(fileContext);

try
{
_mutex.WaitOne();
FileManagerMarshaler.SetFileManager(fileManager);
SassCompilerProxy.CompileFile(fileContext);
}
finally
{
FileManagerMarshaler.UnsetFileManager();
_mutex.ReleaseMutex();
}

GC.KeepAlive(fileManager);

result = EndCompile(fileContext);

return result;
}
Expand Down Expand Up @@ -330,8 +347,8 @@ public static CompilationResult Compile(string content, bool indentedSyntax, Com
private static CompilationResult EndCompile(SassContextBase context)
{
CompilationResult result;

SassErrorInfo error = context.Error;

if (error == null)
{
result = new CompilationResult
Expand Down
4 changes: 1 addition & 3 deletions src/LibSassHost/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
=============
RELEASE NOTES
=============
1. Added support of LibSass version 3.5.4;
2. In compilation options was added one new property -
`AdditionalImportExtensions` (default `.css`).
Fixed a error #30 “Conflict of using multiple sites in one application pool”.

============
PROJECT SITE
Expand Down

0 comments on commit 9e88344

Please sign in to comment.