mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Medium Trust: Removing dead code that is generating secannotate warnings.
--HG-- branch : dev
This commit is contained in:
parent
25a6225ae7
commit
b67664f55b
@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security;
|
||||
using System.Web.Compilation;
|
||||
|
||||
namespace Orchard.Environment.Extensions.Compilers {
|
||||
/// <summary>
|
||||
/// Compile a C# extension into an assembly given a directory location
|
||||
/// Note: Currently not used...
|
||||
/// </summary>
|
||||
public class CSharpExtensionDirectoryCompiler {
|
||||
private readonly IBuildManager _buildManager;
|
||||
|
||||
public CSharpExtensionDirectoryCompiler(IBuildManager buildManager) {
|
||||
_buildManager = buildManager;
|
||||
}
|
||||
|
||||
public CompilerResults CompileProject(string location) {
|
||||
var codeProvider = CodeDomProvider.CreateProvider("cs");
|
||||
|
||||
var references = GetAssemblyReferenceNames();
|
||||
var options = new CompilerParameters(references.ToArray());
|
||||
|
||||
var fileNames = GetSourceFileNames(location);
|
||||
var results = codeProvider.CompileAssemblyFromFile(options, fileNames.ToArray());
|
||||
return results;
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetAssemblyReferenceNames() {
|
||||
return _buildManager
|
||||
.GetReferencedAssemblies()
|
||||
.Select(x => x.Location)
|
||||
.Where(x => !string.IsNullOrEmpty(x))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetSourceFileNames(string path) {
|
||||
foreach (var file in Directory.GetFiles(path, "*.cs")) {
|
||||
yield return file;
|
||||
}
|
||||
|
||||
foreach (var folder in Directory.GetDirectories(path)) {
|
||||
if (Path.GetFileName(folder).StartsWith("."))
|
||||
continue;
|
||||
|
||||
foreach (var file in GetSourceFileNames(folder)) {
|
||||
yield return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
|
||||
namespace Orchard.Environment.Extensions.Compilers {
|
||||
/// <summary>
|
||||
/// Compile a C# extension into an assembly given a directory location
|
||||
/// Note: currently not used...
|
||||
/// </summary>
|
||||
public class CSharpProjectFullTrustCompiler {
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
private readonly IBuildManager _buildManager;
|
||||
|
||||
public CSharpProjectFullTrustCompiler(IVirtualPathProvider virtualPathProvider, IBuildManager buildManager) {
|
||||
_virtualPathProvider = virtualPathProvider;
|
||||
_buildManager = buildManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compile a csproj file given its virtual path. Use the CSharp CodeDomProvider
|
||||
/// class, which is only available in full trust.
|
||||
/// </summary>
|
||||
public CompilerResults CompileProject(string virtualPath, string outputDirectory) {
|
||||
var codeProvider = CodeDomProvider.CreateProvider("cs");
|
||||
var directory = _virtualPathProvider.GetDirectoryName(virtualPath);
|
||||
|
||||
using (var stream = _virtualPathProvider.OpenFile(virtualPath)) {
|
||||
var descriptor = new DefaultProjectFileParser().Parse(stream);
|
||||
|
||||
var references = GetReferencedAssembliesLocation();
|
||||
var options = new CompilerParameters(references.ToArray());
|
||||
options.GenerateExecutable = false;
|
||||
options.OutputAssembly = Path.Combine(outputDirectory, descriptor.AssemblyName + ".dll");
|
||||
|
||||
var fileNames = descriptor.SourceFilenames
|
||||
.Select(f => _virtualPathProvider.Combine(directory, f))
|
||||
.Select(f => _virtualPathProvider.MapPath(f));
|
||||
|
||||
var results = codeProvider.CompileAssemblyFromFile(options, fileNames.ToArray());
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetReferencedAssembliesLocation() {
|
||||
return _buildManager.GetReferencedAssemblies()
|
||||
.Select(a => a.Location)
|
||||
.Where(a => !string.IsNullOrEmpty(a))
|
||||
.Distinct();
|
||||
}
|
||||
}
|
||||
}
|
@ -555,9 +555,7 @@
|
||||
<Compile Include="FileSystems\VirtualPath\IVirtualPathMonitor.cs" />
|
||||
<Compile Include="FileSystems\Dependencies\IDependenciesFolder.cs" />
|
||||
<Compile Include="Environment\Extensions\Compilers\IExtensionCompiler.cs" />
|
||||
<Compile Include="Environment\Extensions\Compilers\CSharpExtensionDirectoryCompiler.cs" />
|
||||
<Compile Include="Environment\Extensions\Compilers\DefaultExtensionCompiler.cs" />
|
||||
<Compile Include="Environment\Extensions\Compilers\CSharpProjectFullTrustCompiler.cs" />
|
||||
<Compile Include="Environment\Extensions\Compilers\DefaultProjectFileParser.cs" />
|
||||
<Compile Include="Environment\IAssemblyBuilder.cs" />
|
||||
<Compile Include="Environment\IBuildManager.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user