Skip to content

StyleCop fixes for CShell.Hosting #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Src/CShell.Hosting/DefaultReferences.cs
Original file line number Diff line number Diff line change
@@ -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<Assembly>();
AssemblyPaths = new List<string>();
Namespaces = new List<string>();
this.Assemblies = new List<Assembly>();
this.AssemblyPaths = new List<string>();
this.Namespaces = new List<string>();
}

public List<Assembly> Assemblies { get; private set; }

public List<string> AssemblyPaths { get; private set; }

public List<string> Namespaces { get; private set; }
}
}
9 changes: 1 addition & 8 deletions Src/CShell.Hosting/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -32,6 +26,5 @@ public override string NugetFile
{
get { return Constants.NugetFile; }
}

}
}
44 changes: 20 additions & 24 deletions Src/CShell.Hosting/HostingHelpers.cs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -40,7 +36,7 @@ private static void ConfigureHostingRegistrationBuilder(RegistrationBuilder buil
builder.ForTypesDerivedFrom<IReplCommand>().Export<IReplCommand>();

builder.ForType<ReplLogger>().SelectConstructor(b => b.First(c => c.GetParameters().Length == 1)).Export<ILog>();
builder.ForType<CShell.Hosting.FileSystem>().Export<IFileSystem>(); //override bin and nuget locations
builder.ForType<FileSystem>().Export<IFileSystem>(); // override bin and nuget locations
builder.ForType<FileSystemMigrator>().Export<IFileSystemMigrator>();
builder.ForType<ReplScriptHostFactory>().Export<IScriptHostFactory>();
builder.ForType<RoslynReplEngine>().Export<IScriptEngine>();
Expand Down Expand Up @@ -68,7 +64,7 @@ private static void ConfigureHostingRegistrationBuilder(RegistrationBuilder buil

private static void ConfigureHostingbatch(CompositionBatch batch)
{
//batch.AddExportedValue<IRepl>(null);
// batch.AddExportedValue<IRepl>(null);
}

public static void ConfigureModuleRegistrationBuilder(RegistrationBuilder builder)
Expand Down
18 changes: 8 additions & 10 deletions Src/CShell.Hosting/ObjectSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
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)
{
throw new NotImplementedException();
}
}

class MockConsole : IConsole
public class MockConsole : IConsole
{
public void Clear()
{
Expand All @@ -33,6 +30,7 @@ public ConsoleColor ForegroundColor
{
throw new NotImplementedException();
}

set
{
throw new NotImplementedException();
Expand Down
71 changes: 34 additions & 37 deletions Src/CShell.Hosting/Package/NugetInstallationProvider.cs
Original file line number Diff line number Diff line change
@@ -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<string> _repositoryUrls;
private readonly IFileSystem fileSystem;
private readonly ILog logger;
private PackageManager manager;
private IEnumerable<string> 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<string> 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);
Expand All @@ -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)
Expand All @@ -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;
}
}
}
17 changes: 9 additions & 8 deletions Src/CShell.Hosting/Package/NugetMachineWideSettings.cs
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<Settings>> _settings;
private readonly Lazy<IEnumerable<Settings>> settings;

public NugetMachineWideSettings()
{
var baseDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
_settings = new Lazy<IEnumerable<NuGet.Settings>>(() => NuGet.Settings.LoadMachineWideSettings(new PhysicalFileSystem(baseDirectory)));
this.settings = new Lazy<IEnumerable<Settings>>(() => NuGet.Settings.LoadMachineWideSettings(new PhysicalFileSystem(baseDirectory)));
}

public IEnumerable<Settings> Settings
{
get
{
return _settings.Value;
return this.settings.Value;
}
}
}
Expand Down
Loading