From 5c67ad9507f81440632417aebd1cf06203504307 Mon Sep 17 00:00:00 2001 From: TheElderWand Date: Tue, 3 Nov 2015 22:48:27 +0530 Subject: [PATCH 1/2] Added Settings.stylecop --- Src/Settings.stylecop | 284 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 Src/Settings.stylecop diff --git a/Src/Settings.stylecop b/Src/Settings.stylecop new file mode 100644 index 0000000..5db6c96 --- /dev/null +++ b/Src/Settings.stylecop @@ -0,0 +1,284 @@ + + + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + + + + + + False + + + + + + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + False + + + + + + + \ No newline at end of file From 45916e82f8b6667f7febdd7e1e91d9ec78aeb10c Mon Sep 17 00:00:00 2001 From: TheElderWand Date: Tue, 3 Nov 2015 22:48:39 +0530 Subject: [PATCH 2/2] CShell.Hosting: Stylecop fixes --- Src/CShell.Hosting/DefaultReferences.cs | 18 +- Src/CShell.Hosting/FileSystem.cs | 9 +- Src/CShell.Hosting/HostingHelpers.cs | 44 ++--- Src/CShell.Hosting/ObjectSerializer.cs | 18 +- .../Package/NugetInstallationProvider.cs | 71 ++++--- .../Package/NugetMachineWideSettings.cs | 17 +- .../Package/PackageContainer.cs | 52 ++--- .../Package/PackageInstaller.cs | 31 +-- Src/CShell.Hosting/Package/PackageObject.cs | 45 +++-- .../ReplCommands/ClearCommand.cs | 12 +- .../ReplCommands/HelpCommand.cs | 21 +- .../ReplCommands/InstallCommand.cs | 48 ++--- .../ReplCommands/ResetCommand.cs | 6 +- Src/CShell.Hosting/ReplLogger.cs | 63 +++--- Src/CShell.Hosting/ReplScriptExecutor.cs | 185 ++++++++++-------- .../ReplScriptExecutorFactory.cs | 38 ++-- Src/CShell.Hosting/ReplScriptHost.cs | 9 +- Src/CShell.Hosting/ScriptResultExtensions.cs | 59 ++++-- 18 files changed, 393 insertions(+), 353 deletions(-) diff --git a/Src/CShell.Hosting/DefaultReferences.cs b/Src/CShell.Hosting/DefaultReferences.cs index 51d7346..cfd7eea 100644 --- a/Src/CShell.Hosting/DefaultReferences.cs +++ b/Src/CShell.Hosting/DefaultReferences.cs @@ -1,19 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace CShell.Hosting +namespace CShell.Hosting { + using System.Collections.Generic; + using System.Reflection; + public class DefaultReferences : IDefaultReferences { public DefaultReferences() { - Assemblies = new List(); - AssemblyPaths = new List(); - Namespaces = new List(); + this.Assemblies = new List(); + this.AssemblyPaths = new List(); + this.Namespaces = new List(); } + public List Assemblies { get; private set; } + public List AssemblyPaths { get; private set; } + public List Namespaces { get; private set; } } } diff --git a/Src/CShell.Hosting/FileSystem.cs b/Src/CShell.Hosting/FileSystem.cs index 4a2e64e..d6674c8 100644 --- a/Src/CShell.Hosting/FileSystem.cs +++ b/Src/CShell.Hosting/FileSystem.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CShell.Hosting +namespace CShell.Hosting { public class FileSystem : ScriptCs.FileSystem { @@ -32,6 +26,5 @@ public override string NugetFile { get { return Constants.NugetFile; } } - } } diff --git a/Src/CShell.Hosting/HostingHelpers.cs b/Src/CShell.Hosting/HostingHelpers.cs index 11632f7..0d1420e 100644 --- a/Src/CShell.Hosting/HostingHelpers.cs +++ b/Src/CShell.Hosting/HostingHelpers.cs @@ -1,33 +1,29 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.ComponentModel.Composition.Hosting; -using System.ComponentModel.Composition.Registration; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using CShell.Hosting.Package; -using CShell.Hosting.ReplCommands; -using ScriptCs; -using ScriptCs.Contracts; -using ScriptCs.Engine.Roslyn; -using ScriptCs.Logging; - -namespace CShell.Hosting +namespace CShell.Hosting { + using System.ComponentModel.Composition.Hosting; + using System.ComponentModel.Composition.Registration; + using System.Linq; + + using CShell.Hosting.Package; + + using ScriptCs; + using ScriptCs.Contracts; + using ScriptCs.Engine.Roslyn; + using ScriptCs.Logging; + public static class HostingHelpers { public static void ConfigureHostingCatalog(AggregateCatalog catalog) { - //add types from dlls + // add types from dlls var hostingBuilder = new RegistrationBuilder(); ConfigureHostingRegistrationBuilder(hostingBuilder); - catalog.Catalogs.Add(new AssemblyCatalog(typeof(IScriptEngine).Assembly, hostingBuilder)); //ScriptCS.Contracts - catalog.Catalogs.Add(new AssemblyCatalog(typeof(ScriptServices).Assembly, hostingBuilder)); //ScriptCS.Core - catalog.Catalogs.Add(new AssemblyCatalog(typeof(RoslynScriptEngine).Assembly, hostingBuilder)); //CShell.Engine.Roslyn - catalog.Catalogs.Add(new AssemblyCatalog(typeof(HostingHelpers).Assembly, hostingBuilder)); //CShell.Hosting + catalog.Catalogs.Add(new AssemblyCatalog(typeof(IScriptEngine).Assembly, hostingBuilder)); // ScriptCS.Contracts + catalog.Catalogs.Add(new AssemblyCatalog(typeof(ScriptServices).Assembly, hostingBuilder)); // ScriptCS.Core + catalog.Catalogs.Add(new AssemblyCatalog(typeof(RoslynScriptEngine).Assembly, hostingBuilder)); // CShell.Engine.Roslyn + catalog.Catalogs.Add(new AssemblyCatalog(typeof(HostingHelpers).Assembly, hostingBuilder)); // CShell.Hosting - //add singletons + // add singletons var container = new CompositionContainer(catalog); var batch = new CompositionBatch(); ConfigureHostingbatch(batch); @@ -40,7 +36,7 @@ private static void ConfigureHostingRegistrationBuilder(RegistrationBuilder buil builder.ForTypesDerivedFrom().Export(); builder.ForType().SelectConstructor(b => b.First(c => c.GetParameters().Length == 1)).Export(); - builder.ForType().Export(); //override bin and nuget locations + builder.ForType().Export(); // override bin and nuget locations builder.ForType().Export(); builder.ForType().Export(); builder.ForType().Export(); @@ -68,7 +64,7 @@ private static void ConfigureHostingRegistrationBuilder(RegistrationBuilder buil private static void ConfigureHostingbatch(CompositionBatch batch) { - //batch.AddExportedValue(null); + // batch.AddExportedValue(null); } public static void ConfigureModuleRegistrationBuilder(RegistrationBuilder builder) diff --git a/Src/CShell.Hosting/ObjectSerializer.cs b/Src/CShell.Hosting/ObjectSerializer.cs index 4f24048..864312e 100644 --- a/Src/CShell.Hosting/ObjectSerializer.cs +++ b/Src/CShell.Hosting/ObjectSerializer.cs @@ -1,13 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ScriptCs.Contracts; - -namespace CShell.Hosting +namespace CShell.Hosting { - class ObjectSerializer : IObjectSerializer + using System; + + using ScriptCs.Contracts; + + public class ObjectSerializer : IObjectSerializer { public string Serialize(object value) { @@ -15,7 +12,7 @@ public string Serialize(object value) } } - class MockConsole : IConsole + public class MockConsole : IConsole { public void Clear() { @@ -33,6 +30,7 @@ public ConsoleColor ForegroundColor { throw new NotImplementedException(); } + set { throw new NotImplementedException(); diff --git a/Src/CShell.Hosting/Package/NugetInstallationProvider.cs b/Src/CShell.Hosting/Package/NugetInstallationProvider.cs index 6d1599b..2c55d62 100644 --- a/Src/CShell.Hosting/Package/NugetInstallationProvider.cs +++ b/Src/CShell.Hosting/Package/NugetInstallationProvider.cs @@ -1,63 +1,60 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using NuGet; -using ScriptCs.Contracts; -using ScriptCs.Logging; -using IFileSystem = ScriptCs.Contracts.IFileSystem; - -namespace CShell.Hosting.Package +namespace CShell.Hosting.Package { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + + using NuGet; + + using ScriptCs.Contracts; + using ScriptCs.Logging; + + using IFileSystem = ScriptCs.Contracts.IFileSystem; + public class NugetInstallationProvider : IInstallationProvider { - private readonly IFileSystem _fileSystem; - private readonly ILog _logger; - private PackageManager _manager; - private IEnumerable _repositoryUrls; + private readonly IFileSystem fileSystem; + private readonly ILog logger; + private PackageManager manager; + private IEnumerable repositoryUrls; private static readonly Version EmptyVersion = new Version(); public NugetInstallationProvider(IFileSystem fileSystem, ILog logger) { - _fileSystem = fileSystem; - _logger = logger; + this.fileSystem = fileSystem; + this.logger = logger; } public void Initialize() { - var path = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.PackagesFolder); - _repositoryUrls = GetRepositorySources(path); - var remoteRepository = new AggregateRepository(PackageRepositoryFactory.Default, _repositoryUrls, true); - _manager = new PackageManager(remoteRepository, path); + var path = Path.Combine(this.fileSystem.CurrentDirectory, this.fileSystem.PackagesFolder); + this.repositoryUrls = this.GetRepositorySources(path); + var remoteRepository = new AggregateRepository(PackageRepositoryFactory.Default, this.repositoryUrls, true); + this.manager = new PackageManager(remoteRepository, path); } public IEnumerable GetRepositorySources(string path) { var configFileSystem = new PhysicalFileSystem(path); - ISettings settings; - var localNuGetConfigFile = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.NugetFile); - if (_fileSystem.FileExists(localNuGetConfigFile)) - { - settings = Settings.LoadDefaultSettings(configFileSystem, localNuGetConfigFile, null); - } - else - { - settings = Settings.LoadDefaultSettings(configFileSystem, null, new NugetMachineWideSettings()); - } + var localNuGetConfigFile = Path.Combine(this.fileSystem.CurrentDirectory, this.fileSystem.NugetFile); + var settings = this.fileSystem.FileExists(localNuGetConfigFile) + ? Settings.LoadDefaultSettings(configFileSystem, localNuGetConfigFile, null) + : Settings.LoadDefaultSettings(configFileSystem, null, new NugetMachineWideSettings()); if (settings == null) { - return new[] { Constants.DefaultRepositoryUrl }; + return new[] { CShell.Constants.DefaultRepositoryUrl }; } var sourceProvider = new PackageSourceProvider(settings); - var sources = sourceProvider.LoadPackageSources().Where(i => i.IsEnabled == true); + var sources = sourceProvider.LoadPackageSources().Where(i => i.IsEnabled); - if (sources == null || !sources.Any()) + if (!sources.Any()) { - return new[] { Constants.DefaultRepositoryUrl }; + return new[] { CShell.Constants.DefaultRepositoryUrl }; } return sources.Select(i => i.Source); @@ -67,8 +64,8 @@ public void InstallPackage(IPackageReference packageId, bool allowPreRelease = f { var version = GetVersion(packageId); var packageName = packageId.PackageId + " " + (version == null ? string.Empty : packageId.Version.ToString()); - _manager.InstallPackage(packageId.PackageId, version, allowPrereleaseVersions: allowPreRelease, ignoreDependencies: false); - _logger.Info("Installed: " + packageName); + this.manager.InstallPackage(packageId.PackageId, version, allowPrereleaseVersions: allowPreRelease, ignoreDependencies: false); + this.logger.Info("Installed: " + packageName); } private static SemanticVersion GetVersion(IPackageReference packageReference) @@ -79,7 +76,7 @@ private static SemanticVersion GetVersion(IPackageReference packageReference) public bool IsInstalled(IPackageReference packageReference, bool allowPreRelease = false) { var version = GetVersion(packageReference); - return _manager.LocalRepository.FindPackage(packageReference.PackageId, version, allowPreRelease, allowUnlisted: false) != null; + return this.manager.LocalRepository.FindPackage(packageReference.PackageId, version, allowPreRelease, allowUnlisted: false) != null; } } } \ No newline at end of file diff --git a/Src/CShell.Hosting/Package/NugetMachineWideSettings.cs b/Src/CShell.Hosting/Package/NugetMachineWideSettings.cs index e9423a5..2146f12 100644 --- a/Src/CShell.Hosting/Package/NugetMachineWideSettings.cs +++ b/Src/CShell.Hosting/Package/NugetMachineWideSettings.cs @@ -1,24 +1,25 @@ -using System; -using System.Collections.Generic; -using NuGet; - -namespace CShell.Hosting.Package +namespace CShell.Hosting.Package { + using System; + using System.Collections.Generic; + + using NuGet; + internal class NugetMachineWideSettings : IMachineWideSettings { - private readonly Lazy> _settings; + private readonly Lazy> settings; public NugetMachineWideSettings() { var baseDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); - _settings = new Lazy>(() => NuGet.Settings.LoadMachineWideSettings(new PhysicalFileSystem(baseDirectory))); + this.settings = new Lazy>(() => NuGet.Settings.LoadMachineWideSettings(new PhysicalFileSystem(baseDirectory))); } public IEnumerable Settings { get { - return _settings.Value; + return this.settings.Value; } } } diff --git a/Src/CShell.Hosting/Package/PackageContainer.cs b/Src/CShell.Hosting/Package/PackageContainer.cs index 12bc518..c1c5db6 100644 --- a/Src/CShell.Hosting/Package/PackageContainer.cs +++ b/Src/CShell.Hosting/Package/PackageContainer.cs @@ -1,38 +1,40 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.Versioning; -using NuGet; -using ScriptCs.Contracts; -using ScriptCs.Logging; -using IFileSystem = ScriptCs.Contracts.IFileSystem; -using PackageReference = ScriptCs.PackageReference; - namespace CShell.Hosting.Package { + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Runtime.Versioning; + + using NuGet; + + using ScriptCs.Contracts; + using ScriptCs.Logging; + + using IFileSystem = ScriptCs.Contracts.IFileSystem; + using PackageReference = ScriptCs.PackageReference; + public class PackageContainer : IPackageContainer { private const string DotNetFramework = ".NETFramework"; private const string DotNetPortable = ".NETPortable"; - private readonly IFileSystem _fileSystem; + private readonly IFileSystem fileSystem; - private readonly ILog _logger; + private readonly ILog logger; public PackageContainer(IFileSystem fileSystem, ILog logger) { - _fileSystem = fileSystem; - _logger = logger; + this.fileSystem = fileSystem; + this.logger = logger; } public void CreatePackageFile() { - var packagesFile = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.PackagesFile); + var packagesFile = Path.Combine(this.fileSystem.CurrentDirectory, this.fileSystem.PackagesFile); var packageReferenceFile = new PackageReferenceFile(packagesFile); - var packagesFolder = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.PackagesFolder); + var packagesFolder = Path.Combine(this.fileSystem.CurrentDirectory, this.fileSystem.PackagesFolder); var repository = new LocalPackageRepository(packagesFolder); var newestPackages = repository.GetPackages().GroupBy(p => p.Id) @@ -40,11 +42,11 @@ public void CreatePackageFile() if (!newestPackages.Any()) { - _logger.Info("No packages found!"); + this.logger.Info("No packages found!"); return; } - _logger.InfoFormat("{0} {1}...", (File.Exists(packagesFile) ? "Updating" : "Creating"), _fileSystem.PackagesFile); + this.logger.InfoFormat("{0} {1}...", File.Exists(packagesFile) ? "Updating" : "Creating", this.fileSystem.PackagesFile); foreach (var package in newestPackages) { @@ -56,20 +58,20 @@ public void CreatePackageFile() if (newestFramework == null) { - _logger.InfoFormat("Added {0} (v{1}) to {2}", package.Id, package.Version, _fileSystem.PackagesFile); + this.logger.InfoFormat("Added {0} (v{1}) to {2}", package.Id, package.Version, this.fileSystem.PackagesFile); } else { - _logger.InfoFormat("Added {0} (v{1}, .NET {2}) to {3}", package.Id, package.Version, newestFramework.Version, _fileSystem.PackagesFile); + this.logger.InfoFormat("Added {0} (v{1}, .NET {2}) to {3}", package.Id, package.Version, newestFramework.Version, this.fileSystem.PackagesFile); } continue; } - _logger.InfoFormat("Skipped {0} because it already exists.", package.Id); + this.logger.InfoFormat("Skipped {0} because it already exists.", package.Id); } - _logger.InfoFormat("Successfully {0} {1}.", (File.Exists(packagesFile) ? "updated" : "created"), _fileSystem.PackagesFile); + this.logger.InfoFormat("Successfully {0} {1}.", File.Exists(packagesFile) ? "updated" : "created", this.fileSystem.PackagesFile); } public IPackageObject FindPackage(string path, IPackageReference packageRef) @@ -103,8 +105,8 @@ public IEnumerable FindReferences(string path) } // No packages.config, check packages folder - var packagesFolder = Path.Combine(_fileSystem.GetWorkingDirectory(path), _fileSystem.PackagesFolder); - if (!_fileSystem.DirectoryExists(packagesFolder)) + var packagesFolder = Path.Combine(this.fileSystem.GetWorkingDirectory(path), this.fileSystem.PackagesFolder); + if (!this.fileSystem.DirectoryExists(packagesFolder)) { yield break; } diff --git a/Src/CShell.Hosting/Package/PackageInstaller.cs b/Src/CShell.Hosting/Package/PackageInstaller.cs index 2459907..3f69675 100644 --- a/Src/CShell.Hosting/Package/PackageInstaller.cs +++ b/Src/CShell.Hosting/Package/PackageInstaller.cs @@ -1,20 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using ScriptCs.Contracts; -using ScriptCs.Logging; - -namespace CShell.Hosting.Package +namespace CShell.Hosting.Package { + using System; + using System.Collections.Generic; + using System.Linq; + + using ScriptCs.Contracts; + using ScriptCs.Logging; + public class PackageInstaller : IPackageInstaller { - private readonly IInstallationProvider _installer; - private readonly ILog _logger; + private readonly IInstallationProvider installer; + private readonly ILog logger; public PackageInstaller(IInstallationProvider installer, ILog logger) { - _installer = installer; - _logger = logger; + this.installer = installer; + this.logger = logger; } public void InstallPackages(IEnumerable packageIds, bool allowPreRelease = false) @@ -28,25 +29,25 @@ public void InstallPackages(IEnumerable packageIds, bool allo if (!packageIds.Any()) { - _logger.Info("Nothing to install."); + this.logger.Info("Nothing to install."); return; } var exceptions = new List(); foreach (var packageId in packageIds) { - if (_installer.IsInstalled(packageId, allowPreRelease)) + if (this.installer.IsInstalled(packageId, allowPreRelease)) { continue; } try { - _installer.InstallPackage(packageId, allowPreRelease); + this.installer.InstallPackage(packageId, allowPreRelease); } catch (Exception ex) { - _logger.ErrorException(ex.Message, ex); + this.logger.ErrorException(ex.Message, ex); exceptions.Add(ex); } } diff --git a/Src/CShell.Hosting/Package/PackageObject.cs b/Src/CShell.Hosting/Package/PackageObject.cs index 16e5e9b..eccd139 100644 --- a/Src/CShell.Hosting/Package/PackageObject.cs +++ b/Src/CShell.Hosting/Package/PackageObject.cs @@ -1,39 +1,41 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Versioning; -using NuGet; -using ScriptCs.Contracts; - namespace CShell.Hosting.Package { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Runtime.Versioning; + + using NuGet; + + using ScriptCs.Contracts; + internal class PackageObject : IPackageObject { private const string Dll = ".dll"; private const string Exe = ".exe"; - private readonly IPackage _package; + private readonly IPackage package; public PackageObject(IPackage package, FrameworkName frameworkName) { - _package = package; - FrameworkName = frameworkName; - Id = package.Id; - Version = package.Version.Version; - TextVersion = package.Version.ToString(); - FrameworkAssemblies = package.FrameworkAssemblies + this.package = package; + this.FrameworkName = frameworkName; + this.Id = package.Id; + this.Version = package.Version.Version; + this.TextVersion = package.Version.ToString(); + this.FrameworkAssemblies = package.FrameworkAssemblies .Where(x => x.SupportedFrameworks.Any(y => y == frameworkName)) .Select(x => x.AssemblyName); - var dependencies = _package.GetCompatiblePackageDependencies(frameworkName); + var dependencies = this.package.GetCompatiblePackageDependencies(frameworkName); if (dependencies != null) { - Dependencies = dependencies.Select(i => new PackageObject(i.Id) { FrameworkName = frameworkName }); + this.Dependencies = dependencies.Select(i => new PackageObject(i.Id) { FrameworkName = frameworkName }); } } public PackageObject(string packageId) { - Id = packageId; + this.Id = packageId; } public IEnumerable FrameworkAssemblies { get; private set; } @@ -50,12 +52,12 @@ public PackageObject(string packageId) public string FullName { - get { return Id + "." + TextVersion; } + get { return this.Id + "." + this.TextVersion; } } public IEnumerable GetCompatibleDlls(FrameworkName frameworkName) { - var dlls = _package.GetLibFiles().Where(i => i.EffectivePath.EndsWith(Dll) || i.EffectivePath.EndsWith(Exe)); + var dlls = this.package.GetLibFiles().Where(i => i.EffectivePath.EndsWith(Dll) || i.EffectivePath.EndsWith(Exe)); IEnumerable compatibleFiles; VersionUtility.TryGetCompatibleItems(frameworkName, dlls, out compatibleFiles); @@ -64,10 +66,7 @@ public IEnumerable GetCompatibleDlls(FrameworkName frameworkName) public IEnumerable GetContentFiles() { - foreach (var file in _package.GetContentFiles()) - { - yield return file.Path; - } + return this.package.GetContentFiles().Select(file => file.Path); } } } \ No newline at end of file diff --git a/Src/CShell.Hosting/ReplCommands/ClearCommand.cs b/Src/CShell.Hosting/ReplCommands/ClearCommand.cs index 8d64eed..19928c0 100644 --- a/Src/CShell.Hosting/ReplCommands/ClearCommand.cs +++ b/Src/CShell.Hosting/ReplCommands/ClearCommand.cs @@ -1,9 +1,9 @@ -using CShell.Framework.Services; -using CShell.Hosting.ReplCommands; -using ScriptCs.Contracts; - -namespace CShell.Hosting.ReplCommands +namespace CShell.Hosting.ReplCommands { + using CShell.Framework.Services; + + using ScriptCs.Contracts; + public class ClearCommand : IReplCommand { private readonly IReplOutput replOutput; @@ -25,7 +25,7 @@ public string Description public object Execute(IRepl repl, object[] args) { - replOutput.Clear(); + this.replOutput.Clear(); return null; } } diff --git a/Src/CShell.Hosting/ReplCommands/HelpCommand.cs b/Src/CShell.Hosting/ReplCommands/HelpCommand.cs index 134f5bf..26748d3 100644 --- a/Src/CShell.Hosting/ReplCommands/HelpCommand.cs +++ b/Src/CShell.Hosting/ReplCommands/HelpCommand.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using CShell.Framework.Services; -using ScriptCs.Contracts; - -namespace CShell.Hosting.ReplCommands +namespace CShell.Hosting.ReplCommands { + using System.Linq; + + using CShell.Framework.Services; + + using ScriptCs.Contracts; + public class HelpCommand : IReplCommand { private readonly IReplOutput replOutput; @@ -29,11 +27,12 @@ public string Description public object Execute(IRepl repl, object[] args) { - replOutput.WriteLine("The following commands are available in the REPL:"); + this.replOutput.WriteLine("The following commands are available in the REPL:"); foreach (var command in repl.Commands.OrderBy(x => x.Key)) { - replOutput.WriteLine(string.Format(":{0,-15}{1,10}", command.Key, command.Value.Description)); + this.replOutput.WriteLine(string.Format(":{0,-15}{1,10}", command.Key, command.Value.Description)); } + return null; } } diff --git a/Src/CShell.Hosting/ReplCommands/InstallCommand.cs b/Src/CShell.Hosting/ReplCommands/InstallCommand.cs index 9a903aa..de6467d 100644 --- a/Src/CShell.Hosting/ReplCommands/InstallCommand.cs +++ b/Src/CShell.Hosting/ReplCommands/InstallCommand.cs @@ -1,17 +1,18 @@ -using System.Linq; -using System.Runtime.Versioning; -using ScriptCs; -using ScriptCs.Contracts; -using ScriptCs.Logging; - -namespace CShell.Hosting.ReplCommands +namespace CShell.Hosting.ReplCommands { + using System.Linq; + using System.Runtime.Versioning; + + using ScriptCs; + using ScriptCs.Contracts; + using ScriptCs.Logging; + public class InstallCommand : IReplCommand { - private readonly IPackageInstaller _packageInstaller; - private readonly IPackageAssemblyResolver _packageAssemblyResolver; - private readonly ILog _logger; - private readonly IInstallationProvider _installationProvider; + private readonly IPackageInstaller packageInstaller; + private readonly IPackageAssemblyResolver packageAssemblyResolver; + private readonly ILog logger; + private readonly IInstallationProvider installationProvider; public InstallCommand( IPackageInstaller packageInstaller, @@ -19,10 +20,10 @@ public InstallCommand( ILog logger, IInstallationProvider installationProvider) { - _packageInstaller = packageInstaller; - _packageAssemblyResolver = packageAssemblyResolver; - _logger = logger; - _installationProvider = installationProvider; + this.packageInstaller = packageInstaller; + this.packageAssemblyResolver = packageAssemblyResolver; + this.logger = logger; + this.installationProvider = installationProvider; } public string CommandName @@ -43,32 +44,31 @@ public object Execute(IRepl repl, object[] args) } string version = null; - var allowPre = false; if (args.Length >= 2) { version = args[1].ToString(); } - allowPre = args.Length >= 3 && args[2].ToString().ToUpperInvariant() == "PRE"; + var allowPre = args.Length >= 3 && args[2].ToString().ToUpperInvariant() == "PRE"; - _logger.InfoFormat("Installing {0}", args[0]); + this.logger.InfoFormat("Installing {0}", args[0]); - _installationProvider.Initialize(); + this.installationProvider.Initialize(); var packageRef = new PackageReference( - args[0].ToString(), new FrameworkName(Constants.NetFrameworkName), version); + args[0].ToString(), new FrameworkName(CShell.Constants.NetFrameworkName), version); - _packageInstaller.InstallPackages(new[] { packageRef }, allowPre); - _packageAssemblyResolver.SavePackages(); + this.packageInstaller.InstallPackages(new[] { packageRef }, allowPre); + this.packageAssemblyResolver.SavePackages(); - var dlls = _packageAssemblyResolver.GetAssemblyNames(repl.FileSystem.CurrentDirectory) + var dlls = this.packageAssemblyResolver.GetAssemblyNames(repl.FileSystem.CurrentDirectory) .Except(repl.References.Paths).ToArray(); repl.AddReferences(dlls); foreach (var dll in dlls) { - _logger.InfoFormat("Added reference to {0}", dll); + this.logger.InfoFormat("Added reference to {0}", dll); } return null; diff --git a/Src/CShell.Hosting/ReplCommands/ResetCommand.cs b/Src/CShell.Hosting/ReplCommands/ResetCommand.cs index 1a0b3d6..b6e2be5 100644 --- a/Src/CShell.Hosting/ReplCommands/ResetCommand.cs +++ b/Src/CShell.Hosting/ReplCommands/ResetCommand.cs @@ -1,7 +1,7 @@ -using ScriptCs.Contracts; - -namespace CShell.Hosting.ReplCommands +namespace CShell.Hosting.ReplCommands { + using ScriptCs.Contracts; + public class ResetCommand : IReplCommand { public string CommandName diff --git a/Src/CShell.Hosting/ReplLogger.cs b/Src/CShell.Hosting/ReplLogger.cs index 9e98cb1..1ea5122 100644 --- a/Src/CShell.Hosting/ReplLogger.cs +++ b/Src/CShell.Hosting/ReplLogger.cs @@ -1,15 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Windows.Media; -using CShell.Framework.Services; -using ScriptCs.Logging; - -namespace CShell.Hosting +namespace CShell.Hosting { + using System; + using System.Collections.Generic; + using System.Windows.Media; + + using CShell.Framework.Services; + + using ScriptCs.Logging; + public class ReplLogger : ILog { - private readonly LogLevel _consoleLogLevel; - private readonly IReplOutput _replOutput; + private readonly LogLevel consoleLogLevel; + private readonly IReplOutput replOutput; private readonly Dictionary colors = new Dictionary { @@ -22,54 +24,67 @@ public class ReplLogger : ILog }; public ReplLogger(IReplOutput repl) - :this(repl, LogLevel.Info) - {} + : this(repl, LogLevel.Info) + { + } public ReplLogger(IReplOutput repl, LogLevel consoleLogLevel) { - if (repl == null) throw new ArgumentNullException("repl"); + if (repl == null) + { + throw new ArgumentNullException("repl"); + } - _consoleLogLevel = consoleLogLevel; - _replOutput = repl; + this.consoleLogLevel = consoleLogLevel; + this.replOutput = repl; } public bool Log(LogLevel logLevel, Func messageFunc, Exception exception = null, params object[] formatParameters) { - if (logLevel < _consoleLogLevel) + if (logLevel < this.consoleLogLevel) + { return false; + } if (messageFunc == null) + { return true; + } var message = messageFunc(); if (message == null) - message = String.Empty; + { + message = string.Empty; + } - if(formatParameters != null && formatParameters.Length > 0) - message = String.Format(message, formatParameters); + if (formatParameters != null && formatParameters.Length > 0) + { + message = string.Format(message, formatParameters); + } var prefix = logLevel == LogLevel.Info ? null : string.Concat(logLevel.ToString().ToUpperInvariant(), ": "); - var originalOutputColor = _replOutput.ResultColor; + var originalOutputColor = this.replOutput.ResultColor; Color color; - if (!colors.TryGetValue(logLevel, out color)) + if (!this.colors.TryGetValue(logLevel, out color)) { color = Colors.Black; } - _replOutput.ResultColor = color; + + this.replOutput.ResultColor = color; try { - _replOutput.WriteLine(prefix + message); + this.replOutput.WriteLine(prefix + message); } finally { - _replOutput.ResultColor = originalOutputColor; + this.replOutput.ResultColor = originalOutputColor; } + return true; } - } } diff --git a/Src/CShell.Hosting/ReplScriptExecutor.cs b/Src/CShell.Hosting/ReplScriptExecutor.cs index 5e79fd8..e70c93d 100644 --- a/Src/CShell.Hosting/ReplScriptExecutor.cs +++ b/Src/CShell.Hosting/ReplScriptExecutor.cs @@ -1,17 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Reflection; -using CShell.Completion; -using CShell.Framework.Services; -using ScriptCs; -using ScriptCs.Contracts; -using ILog = ScriptCs.Logging.ILog; - -namespace CShell.Hosting +namespace CShell.Hosting { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Reflection; + + using CShell.Completion; + using CShell.Framework.Services; + + using ScriptCs; + using ScriptCs.Contracts; + + using ILog = ScriptCs.Logging.ILog; + public class ReplScriptExecutor : ScriptExecutor, IReplScriptExecutor { private readonly IReplOutput replOutput; @@ -32,27 +35,37 @@ public ReplScriptExecutor( this.replOutput = replOutput; this.serializer = serializer; this.defaultReferences = defaultReferences; - Commands = replCommands != null ? replCommands - .Where(x => x.GetType().Namespace.StartsWith("CShell")) //hack to only include CShell commands for now + this.Commands = replCommands != null ? replCommands + .Where(x => x.GetType().Namespace.StartsWith("CShell")) // hack to only include CShell commands for now .Where(x => x.CommandName != null) .ToDictionary(x => x.CommandName, x => x) : new Dictionary(); - replCompletion = new CSharpCompletion(true); - replCompletion.AddReferences(GetReferencesAsPaths()); - //since it's quite expensive to initialize the "System." references we clone the REPL code completion - documentCompletion = replCompletion.Clone(); + this.replCompletion = new CSharpCompletion(true); + this.replCompletion.AddReferences(this.GetReferencesAsPaths()); + + // since it's quite expensive to initialize the "System." references we clone the REPL code completion + this.documentCompletion = this.replCompletion.Clone(); - AddDefaultReferencesAndNamespaces(); + this.AddDefaultReferencesAndNamespaces(); } - public string WorkspaceDirectory { get { return base.FileSystem.CurrentDirectory; } } + public string WorkspaceDirectory + { + get + { + return base.FileSystem.CurrentDirectory; + } + } public event EventHandler AssemblyReferencesChanged; protected virtual void OnAssemblyReferencesChanged() { - EventHandler handler = AssemblyReferencesChanged; - if (handler != null) handler(this, EventArgs.Empty); + var handler = this.AssemblyReferencesChanged; + if (handler != null) + { + handler(this, EventArgs.Empty); + } } private readonly ICompletion replCompletion; @@ -60,15 +73,14 @@ protected virtual void OnAssemblyReferencesChanged() public ICompletion ReplCompletion { - get { return replCompletion; } + get { return this.replCompletion; } } public ICompletion DocumentCompletion { - get { return documentCompletion; } + get { return this.documentCompletion; } } - public string Buffer { get; private set; } public Dictionary Commands { get; private set; } @@ -76,8 +88,8 @@ public ICompletion DocumentCompletion public override void Initialize(IEnumerable paths, IEnumerable scriptPacks, params string[] scriptArgs) { base.Initialize(paths, scriptPacks, scriptArgs); - ExecuteReferencesScript(); - ExecuteConfigScript(); + this.ExecuteReferencesScript(); + this.ExecuteConfigScript(); } public override ScriptResult Execute(string script, params string[] scriptArgs) @@ -85,20 +97,25 @@ public override ScriptResult Execute(string script, params string[] scriptArgs) ScriptResult result = null; try { - replOutput.EvaluateStarted(script, null); + this.replOutput.EvaluateStarted(script, null); if (script.StartsWith(":")) { var tokens = script.Split(' '); if (tokens[0].Length > 1) { - if (Commands.ContainsKey(tokens[0].Substring(1))) + if (this.Commands.ContainsKey(tokens[0].Substring(1))) { - var command = Commands[tokens[0].Substring(1)]; + var command = this.Commands[tokens[0].Substring(1)]; var argsToPass = new List(); foreach (var argument in tokens.Skip(1)) { - var argumentResult = ScriptEngine.Execute(argument, scriptArgs, References, Namespaces, ScriptPackSession); + var argumentResult = this.ScriptEngine.Execute( + argument, + scriptArgs, + this.References, + this.Namespaces, + this.ScriptPackSession); if (argumentResult.CompileExceptionInfo != null) { @@ -124,9 +141,13 @@ public override ScriptResult Execute(string script, params string[] scriptArgs) var commandResult = command.Execute(this, argsToPass.ToArray()); if (commandResult is ScriptResult) + { result = commandResult as ScriptResult; + } else + { result = new ScriptResult(commandResult); + } } else { @@ -136,31 +157,31 @@ public override ScriptResult Execute(string script, params string[] scriptArgs) } else { - var preProcessResult = FilePreProcessor.ProcessScript(script); + var preProcessResult = this.FilePreProcessor.ProcessScript(script); - ImportNamespaces(preProcessResult.Namespaces.ToArray()); + this.ImportNamespaces(preProcessResult.Namespaces.ToArray()); foreach (var reference in preProcessResult.References) { - var referencePath = FileSystem.GetFullPath(Path.Combine(FileSystem.BinFolder, reference)); - AddReferences(FileSystem.FileExists(referencePath) ? referencePath : reference); + var referencePath = this.FileSystem.GetFullPath(Path.Combine(this.FileSystem.BinFolder, reference)); + this.AddReferences(this.FileSystem.FileExists(referencePath) ? referencePath : reference); } - InjectScriptLibraries(FileSystem.CurrentDirectory, preProcessResult, ScriptPackSession.State); + this.InjectScriptLibraries(this.FileSystem.CurrentDirectory, preProcessResult, this.ScriptPackSession.State); - Buffer = (Buffer == null) + this.Buffer = (this.Buffer == null) ? preProcessResult.Code - : Buffer + Environment.NewLine + preProcessResult.Code; + : this.Buffer + Environment.NewLine + preProcessResult.Code; - var namespaces = Namespaces.Union(preProcessResult.Namespaces).ToList(); - var references = References.Union(preProcessResult.References); + var namespaces = this.Namespaces.Union(preProcessResult.Namespaces).ToList(); + var references = this.References.Union(preProcessResult.References); if (preProcessResult.References != null && preProcessResult.References.Count > 0) { - OnAssemblyReferencesChanged(); + this.OnAssemblyReferencesChanged(); } - result = ScriptEngine.Execute(Buffer, scriptArgs, references, namespaces, ScriptPackSession); + result = this.ScriptEngine.Execute(this.Buffer, scriptArgs, references, namespaces, this.ScriptPackSession); if (result == null) { @@ -170,33 +191,33 @@ public override ScriptResult Execute(string script, params string[] scriptArgs) { if (result.InvalidNamespaces.Any()) { - RemoveNamespaces(result.InvalidNamespaces.ToArray()); + this.RemoveNamespaces(result.InvalidNamespaces.ToArray()); } if (result.IsCompleteSubmission) { - Buffer = null; + this.Buffer = null; } } } } catch (FileNotFoundException fileEx) { - RemoveReferences(fileEx.FileName); - result = new ScriptResult(compilationException:fileEx); + this.RemoveReferences(fileEx.FileName); + result = new ScriptResult(compilationException: fileEx); } catch (Exception ex) { - result = new ScriptResult(executionException:ex); + result = new ScriptResult(executionException: ex); } finally { - replOutput.EvaluateCompleted(result); + this.replOutput.EvaluateCompleted(result); } + return result ?? ScriptResult.Empty; } - private static string GetInvalidCommandArgumentMessage(string argument) { return string.Format(CultureInfo.InvariantCulture, "Argument is not a valid expression: {0}", argument); @@ -204,106 +225,106 @@ private static string GetInvalidCommandArgumentMessage(string argument) private void AddDefaultReferencesAndNamespaces() { - AddReferences(typeof(Shell).Assembly); - ImportNamespaces(typeof(Shell).Namespace); - AddReferences(this.defaultReferences.Assemblies.Distinct().ToArray()); - AddReferences(this.defaultReferences.AssemblyPaths.Distinct().ToArray()); - ImportNamespaces(this.defaultReferences.Namespaces.Distinct().ToArray()); + this.AddReferences(typeof(Shell).Assembly); + this.ImportNamespaces(typeof(Shell).Namespace); + this.AddReferences(this.defaultReferences.Assemblies.Distinct().ToArray()); + this.AddReferences(this.defaultReferences.AssemblyPaths.Distinct().ToArray()); + this.ImportNamespaces(this.defaultReferences.Namespaces.Distinct().ToArray()); } public override void AddReferences(params Assembly[] references) { base.AddReferences(references); - replCompletion.AddReferences(references); - documentCompletion.AddReferences(references); - OnAssemblyReferencesChanged(); + this.replCompletion.AddReferences(references); + this.documentCompletion.AddReferences(references); + this.OnAssemblyReferencesChanged(); } public override void RemoveReferences(params Assembly[] references) { base.RemoveReferences(references); - replCompletion.RemoveReferences(references); - documentCompletion.RemoveReferences(references); - OnAssemblyReferencesChanged(); + this.replCompletion.RemoveReferences(references); + this.documentCompletion.RemoveReferences(references); + this.OnAssemblyReferencesChanged(); } public override void AddReferences(params string[] references) { base.AddReferences(references); - replCompletion.AddReferences(references); - documentCompletion.AddReferences(references); - OnAssemblyReferencesChanged(); + this.replCompletion.AddReferences(references); + this.documentCompletion.AddReferences(references); + this.OnAssemblyReferencesChanged(); } public override void RemoveReferences(params string[] references) { base.RemoveReferences(references); - replCompletion.RemoveReferences(references); - documentCompletion.RemoveReferences(references); - OnAssemblyReferencesChanged(); + this.replCompletion.RemoveReferences(references); + this.documentCompletion.RemoveReferences(references); + this.OnAssemblyReferencesChanged(); } public string[] GetReferencesAsPaths() { var paths = new List(); - paths.AddRange(References.Paths); - paths.AddRange(References.Assemblies.Select(a=>a.GetName().Name)); + paths.AddRange(this.References.Paths); + paths.AddRange(this.References.Assemblies.Select(a => a.GetName().Name)); return paths.ToArray(); } public string[] GetNamespaces() { - return Namespaces.ToArray(); + return this.Namespaces.ToArray(); } public override void Reset() { base.Reset(); - AddDefaultReferencesAndNamespaces(); - replOutput.Clear(); - ExecuteReferencesScript(); + this.AddDefaultReferencesAndNamespaces(); + this.replOutput.Clear(); + this.ExecuteReferencesScript(); } public string[] GetVariables() { - var replEngine = ScriptEngine as IReplEngine; + var replEngine = this.ScriptEngine as IReplEngine; if (replEngine != null) { - var varsArray = replEngine.GetLocalVariables(ScriptPackSession) + var varsArray = replEngine.GetLocalVariables(this.ScriptPackSession) .Where(x => !x.StartsWith("submission", StringComparison.OrdinalIgnoreCase)) .ToArray(); return varsArray; } + return new string[0]; } - public void ExecuteConfigScript() { - var configPath = Path.Combine(WorkspaceDirectory, CShell.Constants.ConfigFile); + var configPath = Path.Combine(this.WorkspaceDirectory, CShell.Constants.ConfigFile); if (File.Exists(configPath)) { var configScript = File.ReadAllText(configPath); - Execute(configScript); + this.Execute(configScript); } } public void ExecuteReferencesScript() { - var refPath = Path.Combine(WorkspaceDirectory, CShell.Constants.ReferencesFile); + var refPath = Path.Combine(this.WorkspaceDirectory, CShell.Constants.ReferencesFile); if (File.Exists(refPath)) { var configScript = File.ReadAllText(refPath); - Execute(configScript); + this.Execute(configScript); } - var binPath = Path.Combine(WorkspaceDirectory, CShell.Constants.BinFolder); + var binPath = Path.Combine(this.WorkspaceDirectory, CShell.Constants.BinFolder); if (Directory.Exists(binPath)) { var binFiles = Directory.EnumerateFiles(binPath, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || s.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) .ToArray(); - AddReferences(binFiles); + this.AddReferences(binFiles); } } } diff --git a/Src/CShell.Hosting/ReplScriptExecutorFactory.cs b/Src/CShell.Hosting/ReplScriptExecutorFactory.cs index 19c4c54..283a1ba 100644 --- a/Src/CShell.Hosting/ReplScriptExecutorFactory.cs +++ b/Src/CShell.Hosting/ReplScriptExecutorFactory.cs @@ -1,8 +1,9 @@ -using CShell.Framework.Services; -using ScriptCs; - -namespace CShell.Hosting +namespace CShell.Hosting { + using CShell.Framework.Services; + + using ScriptCs; + public class ReplScriptExecutorFactory : IReplScriptExecutorFactory { private readonly IReplOutput replOutput; @@ -18,25 +19,24 @@ public ReplScriptExecutorFactory(ScriptServices scriptServices, IReplOutput repl public IReplScriptExecutor Create(string workspaceDirectory) { - scriptServices.FileSystem.CurrentDirectory = workspaceDirectory; - scriptServices.InstallationProvider.Initialize(); + this.scriptServices.FileSystem.CurrentDirectory = workspaceDirectory; + this.scriptServices.InstallationProvider.Initialize(); var replExecutor = new ReplScriptExecutor( - replOutput, - scriptServices.ObjectSerializer, - scriptServices.FileSystem, - scriptServices.FilePreProcessor, - scriptServices.Engine, - scriptServices.Logger, - scriptServices.ReplCommands, - defaultReferences - ); - - var assemblies = scriptServices.AssemblyResolver.GetAssemblyPaths(scriptServices.FileSystem.CurrentDirectory); - var scriptPacks = scriptServices.ScriptPackResolver.GetPacks(); + this.replOutput, + this.scriptServices.ObjectSerializer, + this.scriptServices.FileSystem, + this.scriptServices.FilePreProcessor, + this.scriptServices.Engine, + this.scriptServices.Logger, + this.scriptServices.ReplCommands, + this.defaultReferences); + + var assemblies = this.scriptServices.AssemblyResolver.GetAssemblyPaths(this.scriptServices.FileSystem.CurrentDirectory); + var scriptPacks = this.scriptServices.ScriptPackResolver.GetPacks(); replExecutor.Initialize(assemblies, scriptPacks); - replOutput.Initialize(replExecutor); + this.replOutput.Initialize(replExecutor); return replExecutor; } diff --git a/Src/CShell.Hosting/ReplScriptHost.cs b/Src/CShell.Hosting/ReplScriptHost.cs index a40ae47..c07e844 100644 --- a/Src/CShell.Hosting/ReplScriptHost.cs +++ b/Src/CShell.Hosting/ReplScriptHost.cs @@ -1,9 +1,8 @@ -using CShell.Framework.Services; -using ScriptCs; -using ScriptCs.Contracts; - -namespace CShell.Hosting +namespace CShell.Hosting { + using ScriptCs; + using ScriptCs.Contracts; + public class ReplScriptHost : ScriptHost { public ReplScriptHost(IScriptPackManager scriptPackManager, ScriptEnvironment environment) diff --git a/Src/CShell.Hosting/ScriptResultExtensions.cs b/Src/CShell.Hosting/ScriptResultExtensions.cs index e11eaa2..98d77a4 100644 --- a/Src/CShell.Hosting/ScriptResultExtensions.cs +++ b/Src/CShell.Hosting/ScriptResultExtensions.cs @@ -1,9 +1,10 @@ -using System; -using System.Collections.Generic; -using ScriptCs.Contracts; - -namespace CShell.Hosting +namespace CShell.Hosting { + using System; + using System.Collections.Generic; + + using ScriptCs.Contracts; + public static class ScriptResultExtensions { public static bool HasWarnings(this ScriptResult scriptResult) @@ -12,14 +13,20 @@ public static bool HasWarnings(this ScriptResult scriptResult) { var ex = scriptResult.CompileExceptionInfo.SourceException; if (IsMessage(ex.Message, "warning")) + { return true; + } } + if (scriptResult.ExecuteExceptionInfo != null) { var ex = scriptResult.ExecuteExceptionInfo.SourceException; if (IsMessage(ex.Message, "warning")) + { return true; + } } + return false; } @@ -29,29 +36,16 @@ public static bool HasErrors(this ScriptResult scriptResult) { var ex = scriptResult.CompileExceptionInfo.SourceException; if (IsMessage(ex.Message, "error")) + { return true; + } } + if (scriptResult.ExecuteExceptionInfo != null) { return true; } - return false; - } - private static bool IsMessage(string message, string messageType) - { - //the messages have following format - // (2,1): error (123): Bla bla bla - // or - // error (123): Bla bla bla - var messageParts = message.Split(':'); - if (messageParts.Length >= 2) - { - var type1 = messageParts[0].Trim(); - var type2 = messageParts[1].Trim(); - if (type1.StartsWith(messageType, StringComparison.OrdinalIgnoreCase) || type2.StartsWith(messageType, StringComparison.OrdinalIgnoreCase)) - return true; - } return false; } @@ -63,12 +57,35 @@ public static string[] GetMessages(this ScriptResult scriptResult) var ex = scriptResult.CompileExceptionInfo.SourceException; msgs.Add(ex.Message); } + if (scriptResult.ExecuteExceptionInfo != null) { var ex = scriptResult.ExecuteExceptionInfo.SourceException; msgs.Add(ex.Message); } + return msgs.ToArray(); } + + private static bool IsMessage(string message, string messageType) + { + // the messages have following format + // (2,1): error (123): Bla bla bla + // or + // error (123): Bla bla bla + var messageParts = message.Split(':'); + if (messageParts.Length >= 2) + { + var type1 = messageParts[0].Trim(); + var type2 = messageParts[1].Trim(); + if (type1.StartsWith(messageType, StringComparison.OrdinalIgnoreCase) + || type2.StartsWith(messageType, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + + return false; + } } }