mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
Code cleanup.
This commit is contained in:
parent
a563edb047
commit
de52f31d3f
22 changed files with 71 additions and 58 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<NoWarn>CA1051;CA1707;CA1711;CA1801;$(NoWarn)</NoWarn>
|
||||
<NoWarn>CA1051;CA1501;CA1707;CA1711;CA1801;$(NoWarn)</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ namespace Cosmos.Build.Builder
|
|||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
private void ShowErrorMessageBox(string message) =>
|
||||
private static void ShowErrorMessageBox(string message) =>
|
||||
MessageBox.Show(message, "Cosmos Kit Builder", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
|
||||
protected override IReadOnlyDictionary<string, string> Properties => _properties;
|
||||
|
||||
private Dictionary<string, string> _properties;
|
||||
private readonly Dictionary<string, string> _properties;
|
||||
|
||||
public BuildTask(
|
||||
IMSBuildService msBuildService,
|
||||
|
|
@ -28,9 +28,11 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
{
|
||||
ProjectFilePath = projectFilePath;
|
||||
|
||||
_properties = new Dictionary<string, string>();
|
||||
_properties.Add("OutputPath", outputPath);
|
||||
_properties.Add("VsixOutputPath", vsixOutputPath);
|
||||
_properties = new Dictionary<string, string>()
|
||||
{
|
||||
["OutputPath"] = outputPath,
|
||||
["VsixOutputPath"] = vsixOutputPath
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,10 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
{
|
||||
public override string Name => "Create Setup";
|
||||
|
||||
private IInnoSetupService _innoSetupService;
|
||||
private readonly IInnoSetupService _innoSetupService;
|
||||
|
||||
private string _scriptFilePath;
|
||||
|
||||
private Dictionary<string, string> _defines;
|
||||
private readonly string _scriptFilePath;
|
||||
private readonly Dictionary<string, string> _defines;
|
||||
|
||||
public CreateSetupTask(
|
||||
IInnoSetupService innoSetupService,
|
||||
|
|
@ -27,10 +26,11 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
|
||||
_scriptFilePath = scriptFilePath;
|
||||
|
||||
_defines = new Dictionary<string, string>();
|
||||
|
||||
_defines.Add("BuildConfiguration", configuration);
|
||||
_defines.Add("ChangeSetVersion", releaseVersion);
|
||||
_defines = new Dictionary<string, string>()
|
||||
{
|
||||
["BuildConfiguration"] = configuration,
|
||||
["ChangeSetVersion"] = releaseVersion
|
||||
};
|
||||
}
|
||||
|
||||
protected override string GetExePath()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
|
||||
protected abstract IReadOnlyDictionary<string, string> Properties { get; }
|
||||
|
||||
private IMSBuildService _msBuildService;
|
||||
private readonly IMSBuildService _msBuildService;
|
||||
|
||||
protected MSBuildTargetBuildTaskBase(IMSBuildService msBuildService)
|
||||
: base(true, false)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
|
||||
protected override IReadOnlyDictionary<string, string> Properties => _properties;
|
||||
|
||||
private Dictionary<string, string> _properties;
|
||||
private readonly Dictionary<string, string> _properties;
|
||||
|
||||
public PackTask(
|
||||
IMSBuildService msBuildService,
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
private bool _waitForExit;
|
||||
private bool _createWindow;
|
||||
private readonly bool _waitForExit;
|
||||
private readonly bool _createWindow;
|
||||
|
||||
protected ProcessBuildTaskBase(bool waitForExit, bool createWindow)
|
||||
{
|
||||
|
|
@ -56,7 +56,7 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
protected abstract string GetExePath();
|
||||
protected abstract string GetArguments();
|
||||
|
||||
private void WaitForExit(Process process)
|
||||
private static void WaitForExit(Process process)
|
||||
{
|
||||
process.WaitForExit();
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
}
|
||||
}
|
||||
|
||||
private async Task ReadOutputAsync(StreamReader reader, ILogger logger)
|
||||
private static async Task ReadOutputAsync(StreamReader reader, ILogger logger)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
|
||||
protected override IReadOnlyDictionary<string, string> Properties => _properties;
|
||||
|
||||
private Dictionary<string, string> _properties;
|
||||
private readonly Dictionary<string, string> _properties;
|
||||
|
||||
public PublishTask(
|
||||
IMSBuildService msBuildService,
|
||||
|
|
@ -27,8 +27,10 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
{
|
||||
ProjectFilePath = projectFilePath;
|
||||
|
||||
_properties = new Dictionary<string, string>();
|
||||
_properties.Add("PublishDir", publishOutputPath);
|
||||
_properties = new Dictionary<string, string>()
|
||||
{
|
||||
["PublishDir"] = publishOutputPath
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ namespace Cosmos.Build.Builder.BuildTasks
|
|||
{
|
||||
public override string Name => $"Run Process - {_processName ?? Path.GetFileNameWithoutExtension(_exePath)}";
|
||||
|
||||
private string _exePath;
|
||||
private string _args;
|
||||
private readonly string _exePath;
|
||||
private readonly string _args;
|
||||
|
||||
private string _processName;
|
||||
private readonly string _processName;
|
||||
|
||||
public StartProcessTask(
|
||||
string exePath,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Cosmos.Build.Builder
|
|||
public bool UserKit => GetSwitch();
|
||||
public string VsPath => GetOption();
|
||||
|
||||
private Dictionary<string, string> _args;
|
||||
private readonly Dictionary<string, string> _args;
|
||||
|
||||
public CommandLineBuilderConfiguration(string[] args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ namespace Cosmos.Build.Builder
|
|||
{
|
||||
internal class CosmosBuildDefinition : IBuildDefinition
|
||||
{
|
||||
private IInnoSetupService _innoSetupService;
|
||||
private IMSBuildService _msBuildService;
|
||||
private ISetupInstance2 _visualStudioInstance;
|
||||
private readonly IInnoSetupService _innoSetupService;
|
||||
private readonly IMSBuildService _msBuildService;
|
||||
private readonly ISetupInstance2 _visualStudioInstance;
|
||||
|
||||
private readonly string _cosmosDir;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
internal class InnoSetupDependency : IDependency
|
||||
{
|
||||
private const string InnoSetupInstallerUrl = "http://www.jrsoftware.org/download.php/is.exe";
|
||||
|
||||
public string Name => "Inno Setup";
|
||||
|
||||
private IInnoSetupService _innoSetupService;
|
||||
private readonly IInnoSetupService _innoSetupService;
|
||||
|
||||
public InnoSetupDependency(IInnoSetupService innoSetupService)
|
||||
{
|
||||
|
|
@ -46,7 +47,7 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
}
|
||||
|
||||
var process = Process.Start(setupFilePath);
|
||||
await Task.Run((Action)process.WaitForExit, cancellationToken).ConfigureAwait(false);
|
||||
await Task.Run(process.WaitForExit, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
.Select(r => DownloadRepoAsync(r, usesGit, cancellationToken)));
|
||||
}
|
||||
|
||||
private async Task DownloadRepoAsync(Repo repo, bool useGit, CancellationToken cancellationToken)
|
||||
private static async Task DownloadRepoAsync(Repo repo, bool useGit, CancellationToken cancellationToken)
|
||||
{
|
||||
if (useGit)
|
||||
{
|
||||
var process = Process.Start("git", $"clone \"{repo.Url}.git\" \"{repo.LocalPath}\"");
|
||||
await Task.Run((Action)process.WaitForExit).ConfigureAwait(false);
|
||||
await Task.Run(process.WaitForExit).ConfigureAwait(false);
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
|
||||
public string Name => $"Visual Studio {MinimumVsVersion.Major}.{MinimumVsVersion.Minor}+";
|
||||
|
||||
private ISetupInstance2 _visualStudioInstance;
|
||||
private readonly ISetupInstance2 _visualStudioInstance;
|
||||
|
||||
public VisualStudioDependency(ISetupInstance2 visualStudioInstance)
|
||||
{
|
||||
|
|
@ -41,7 +41,7 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
var args = $"update --passive --norestart --installPath \"{vsInstancePath}\"";
|
||||
|
||||
var process = Process.Start(vsInstallerPath, args);
|
||||
await Task.Run((Action)process.WaitForExit, cancellationToken).ConfigureAwait(false);
|
||||
await Task.Run(process.WaitForExit, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
|
||||
public string Name => "Visual Studio Workloads";
|
||||
|
||||
private ISetupInstance2 _visualStudioInstance;
|
||||
private readonly ISetupInstance2 _visualStudioInstance;
|
||||
|
||||
public VisualStudioWorkloadsDependency(ISetupInstance2 visualStudioInstance)
|
||||
{
|
||||
|
|
@ -52,7 +52,7 @@ namespace Cosmos.Build.Builder.Dependencies
|
|||
}
|
||||
|
||||
var process = Process.Start(vsInstallerPath, args);
|
||||
await Task.Run((Action)process.WaitForExit, cancellationToken).ConfigureAwait(false);
|
||||
await Task.Run(process.WaitForExit, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Cosmos.Build.Builder.Models
|
|||
public string Log => _logBuilder.ToString();
|
||||
public bool HasLoggedErrors { get; private set; }
|
||||
|
||||
private StringBuilder _logBuilder;
|
||||
private readonly StringBuilder _logBuilder;
|
||||
|
||||
public Section(string name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ namespace Cosmos.Build.Builder.Services
|
|||
{
|
||||
internal class DialogService<TView, TViewModel> : IDialogService<TViewModel> where TView : Window
|
||||
{
|
||||
private Func<TView> _dialogFactory;
|
||||
private Window _owner;
|
||||
private readonly Func<TView> _dialogFactory;
|
||||
private readonly Window _owner;
|
||||
|
||||
public DialogService(Func<TView> dialogFactory, Window owner = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Cosmos.Build.Builder.Services
|
|||
{
|
||||
internal class VisualStudioService : IVisualStudioService
|
||||
{
|
||||
private Lazy<IReadOnlyList<ISetupInstance2>> _instances;
|
||||
private readonly Lazy<IReadOnlyList<ISetupInstance2>> _instances;
|
||||
|
||||
public VisualStudioService()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Windows.Input;
|
|||
|
||||
namespace Cosmos.Build.Builder.ViewModels
|
||||
{
|
||||
internal class DependencyInstallationDialogViewModel : ViewModelBase
|
||||
internal sealed class DependencyInstallationDialogViewModel : ViewModelBase, IDisposable
|
||||
{
|
||||
private const string InstallationSucceededText = "{0} installed successfully!";
|
||||
private const string InstallationFailedText = "{0} failed to install!";
|
||||
|
|
@ -68,10 +68,16 @@ namespace Cosmos.Build.Builder.ViewModels
|
|||
OkCommand = new RelayCommand(p => Close(p as Window, true));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_installTask.Dispose();
|
||||
_installTaskCancellationTokenSource.Dispose();
|
||||
}
|
||||
|
||||
private void Install(object parameter) => _installTask = InstallAsync();
|
||||
private void CancelInstallation(object parameter) => _installTaskCancellationTokenSource.Cancel();
|
||||
|
||||
private void Close(Window window, bool? dialogResult)
|
||||
private static void Close(Window window, bool? dialogResult)
|
||||
{
|
||||
#if DEBUG
|
||||
if (window == null)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Cosmos.Build.Builder.ViewModels
|
|||
{
|
||||
private static readonly string[] NewLineStringArray = new string[] { Environment.NewLine };
|
||||
|
||||
private MainWindowViewModel _viewModel;
|
||||
private readonly MainWindowViewModel _viewModel;
|
||||
|
||||
public MainWindowLogger(MainWindowViewModel viewModel)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using Cosmos.Build.Builder.Services;
|
|||
|
||||
namespace Cosmos.Build.Builder.ViewModels
|
||||
{
|
||||
internal class MainWindowViewModel : ViewModelBase
|
||||
internal sealed class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private const int TailItemCount = 10;
|
||||
|
||||
|
|
@ -35,12 +35,12 @@ namespace Cosmos.Build.Builder.ViewModels
|
|||
set => SetAndRaiseIfChanged(ref _windowState, value);
|
||||
}
|
||||
|
||||
private ILogger _logger;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private IDialogService<DependencyInstallationDialogViewModel> _dependencyInstallationDialogService;
|
||||
private readonly IDialogService<DependencyInstallationDialogViewModel> _dependencyInstallationDialogService;
|
||||
|
||||
private IBuildDefinition _buildDefinition;
|
||||
private Task _buildTask;
|
||||
private readonly IBuildDefinition _buildDefinition;
|
||||
private readonly Task _buildTask;
|
||||
|
||||
private bool _closeWhenCompleted;
|
||||
|
||||
|
|
@ -109,12 +109,14 @@ namespace Cosmos.Build.Builder.ViewModels
|
|||
{
|
||||
_logger.LogMessage($"{dependency.Name} not found.");
|
||||
|
||||
var viewModel = new DependencyInstallationDialogViewModel(dependency);
|
||||
_dependencyInstallationDialogService.ShowDialog(viewModel);
|
||||
|
||||
if (!viewModel.InstallationSucceeded)
|
||||
using (var viewModel = new DependencyInstallationDialogViewModel(dependency))
|
||||
{
|
||||
throw new Exception($"Dependency installation failed! Dependency name: {dependency.Name}");
|
||||
_dependencyInstallationDialogService.ShowDialog(viewModel);
|
||||
|
||||
if (!viewModel.InstallationSucceeded)
|
||||
{
|
||||
throw new Exception($"Dependency installation failed! Dependency name: {dependency.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using Cosmos.Build.Builder.Services;
|
|||
|
||||
namespace Cosmos.Build.Builder.ViewModels
|
||||
{
|
||||
internal class VisualStudioInstanceDialogViewModel : ViewModelBase
|
||||
internal sealed class VisualStudioInstanceDialogViewModel : ViewModelBase
|
||||
{
|
||||
public IEnumerable<VisualStudioInstance> VisualStudioInstances { get; }
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ namespace Cosmos.Build.Builder.ViewModels
|
|||
public ICommand OkCommand { get; }
|
||||
public ICommand CancelCommand { get; }
|
||||
|
||||
private IVisualStudioService _visualStudioService;
|
||||
private readonly IVisualStudioService _visualStudioService;
|
||||
|
||||
private VisualStudioInstance _selectedVisualStudioInstance;
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ namespace Cosmos.Build.Builder.ViewModels
|
|||
CancelCommand = new RelayCommand(p => Close(p as Window, false));
|
||||
}
|
||||
|
||||
private void Close(Window window, bool? dialogResult)
|
||||
private static void Close(Window window, bool? dialogResult)
|
||||
{
|
||||
#if DEBUG
|
||||
if (window == null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue