Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
adding functionality for scheduled tasks, fixing some UI issues, coup…
Browse files Browse the repository at this point in the history
…le other minor tweaks, moving config file to json
  • Loading branch information
WereDev committed May 1, 2021
1 parent 4610554 commit 219bfef
Show file tree
Hide file tree
Showing 37 changed files with 921 additions and 250 deletions.
2 changes: 2 additions & 0 deletions WereDev.Utils.Wu10Man.Core/DependencyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public static class DependencyManager
public static IHostsFileEditor HostsFileEditor { get; set; }

public static IWindowsServiceManager WindowsServiceManager { get; set; }

public static IWindowsTaskManager WindowsTaskManager { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace WereDev.Utils.Wu10Man.Core.Interfaces
{
public interface IWindowsPackageManager
{
Declutter GetDeclutterConfig();
DeclutterConfig GetDeclutterConfig();

PackageInfo[] ListInstalledPackages();

Expand Down
19 changes: 19 additions & 0 deletions WereDev.Utils.Wu10Man.Core/Interfaces/IWindowsTaskManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using WereDev.Utils.Wu10Man.Core.Models;

namespace WereDev.Utils.Wu10Man.Core.Interfaces
{
public interface IWindowsTaskManager
{
WindowsTask[] GetTasks();

WindowsTask GetTask(string path);

WindowsTask[] DisableTasks();

WindowsTask DisableTask(string path);

WindowsTask[] EnableTasks();

WindowsTask EnableTask(string path);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using WereDev.Utils.Wu10Man.Core.Models;

namespace WereDev.Utils.Wu10Man.Core.Interfaces.Providers
{
public interface IWindowsTaskProvider
{
WindowsTask GetTask(string fullPath);

void EnableTask(string fullPath);

void DisableTask(string fullPath);
}
}
16 changes: 0 additions & 16 deletions WereDev.Utils.Wu10Man.Core/Models/Declutter.cs

This file was deleted.

9 changes: 9 additions & 0 deletions WereDev.Utils.Wu10Man.Core/Models/DeclutterConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace WereDev.Utils.Wu10Man.Core.Models
{
public class DeclutterConfig
{
public AppInfo[] Microsoft { get; set; }

public AppInfo[] ThirdParty { get; set; }
}
}
11 changes: 11 additions & 0 deletions WereDev.Utils.Wu10Man.Core/Models/WindowsTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace WereDev.Utils.Wu10Man.Core.Models
{
public class WindowsTask
{
public string Name { get; set; }

public string FullPath { get; set; }

public bool Enabled { get; set; }
}
}
9 changes: 9 additions & 0 deletions WereDev.Utils.Wu10Man.Core/Models/WindowsTaskConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace WereDev.Utils.Wu10Man.Core.Models
{
public class WindowsTaskConfig
{
public string TaskName { get; set; }

public string TaskPath { get; set; }
}
}
9 changes: 4 additions & 5 deletions WereDev.Utils.Wu10Man.Core/Services/HostsFileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class HostsFileEditor : IHostsFileEditor
private const string NullEndpoint = "0.0.0.0\t";

private readonly IFileIoProvider _fileIoProvider;
private readonly IConfigurationReader _configurationReader;
private readonly string[] _windowsUpdateUrls;

public HostsFileEditor(IFileIoProvider fileIoProvider, IConfigurationReader configurationReader)
public HostsFileEditor(IFileIoProvider fileIoProvider, string[] windowsUpateUrls)
{
_fileIoProvider = fileIoProvider ?? throw new ArgumentNullException(nameof(fileIoProvider));
_configurationReader = configurationReader ?? throw new ArgumentNullException(nameof(configurationReader));
_windowsUpdateUrls = windowsUpateUrls ?? new string[0];
}

private string HostsFile => _fileIoProvider.Combine(Environment.SystemDirectory, HostsFilePath);
Expand Down Expand Up @@ -58,8 +58,7 @@ public string[] GetHostsInFile()

public string[] GetManagedHosts()
{
var windowsUpdateUrls = _configurationReader.GetWindowsUpdateHosts();
var uniques = windowsUpdateUrls.Select(x => StandardizeHostUrl(x)).Distinct();
var uniques = _windowsUpdateUrls.Select(x => StandardizeHostUrl(x)).Distinct();
return uniques.ToArray();
}

Expand Down
10 changes: 5 additions & 5 deletions WereDev.Utils.Wu10Man.Core/Services/WindowsPackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ namespace WereDev.Utils.Wu10Man.Core.Services
public class WindowsPackageManager : IWindowsPackageManager
{
private readonly IWindowsPackageProvider _packageProvider;
private readonly IConfigurationReader _configReader;
private readonly DeclutterConfig _declutterConfig;

public WindowsPackageManager(IWindowsPackageProvider packageProvider, IConfigurationReader configReader)
public WindowsPackageManager(IWindowsPackageProvider packageProvider, DeclutterConfig declutterConfig)
{
_packageProvider = packageProvider ?? throw new ArgumentNullException(nameof(packageProvider));
_configReader = configReader ?? throw new ArgumentNullException(nameof(configReader));
_declutterConfig = declutterConfig ?? new DeclutterConfig();
}

public Declutter GetDeclutterConfig()
public DeclutterConfig GetDeclutterConfig()
{
return _configReader.GetDeclutter();
return _declutterConfig;
}

public PackageInfo[] ListInstalledPackages()
Expand Down
8 changes: 4 additions & 4 deletions WereDev.Utils.Wu10Man.Core/Services/WindowsServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public class WindowsServiceManager : IWindowsServiceManager
private readonly IWindowsServiceProviderFactory _providerFactory;
private readonly IRegistryEditor _registryEditor; // TODO: Not a fan of this because of possible circular reference
private readonly IFileManager _fileManager;
private readonly IConfigurationReader _configurationReader;
private readonly string[] _windowsServices;

public WindowsServiceManager(IWindowsServiceProviderFactory providerFactory, IRegistryEditor registryEditor, IFileManager fileManager, IConfigurationReader configurationReader)
public WindowsServiceManager(IWindowsServiceProviderFactory providerFactory, IRegistryEditor registryEditor, IFileManager fileManager, string[] windowsServices)
{
_providerFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
_registryEditor = registryEditor ?? throw new ArgumentNullException(nameof(registryEditor));
_fileManager = fileManager ?? throw new ArgumentNullException(nameof(fileManager));
_configurationReader = configurationReader ?? throw new ArgumentNullException(nameof(configurationReader));
_windowsServices = windowsServices ?? new string[0];
}

public string[] ListAllServices()
{
return _configurationReader.GetWindowsServices();
return _windowsServices;
}

public bool ServiceExists(string serviceName)
Expand Down
78 changes: 78 additions & 0 deletions WereDev.Utils.Wu10Man.Core/Services/WindowsTaskManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Linq;
using WereDev.Utils.Wu10Man.Core.Interfaces;
using WereDev.Utils.Wu10Man.Core.Interfaces.Providers;
using WereDev.Utils.Wu10Man.Core.Models;

namespace WereDev.Utils.Wu10Man.Core.Services
{
public class WindowsTaskManager : IWindowsTaskManager
{
private readonly IWindowsTaskProvider _taskProvider;
private readonly WindowsTaskConfig[] _windowsTaskConfigs;

public WindowsTaskManager(IWindowsTaskProvider taskProvider, WindowsTaskConfig[] windowsTaskConfigs)
{
_taskProvider = taskProvider ?? throw new ArgumentNullException(nameof(taskProvider));
_windowsTaskConfigs = windowsTaskConfigs ?? new WindowsTaskConfig[0];
var distinct = _windowsTaskConfigs.GroupBy(x => x.TaskPath)
.Select(x => x.First())
.ToArray();
_windowsTaskConfigs = distinct;
}

public WindowsTask[] DisableTasks()
{
foreach (var config in _windowsTaskConfigs)
{
_taskProvider.DisableTask(config.TaskPath);
}

return GetTasks();
}

public WindowsTask DisableTask(string path)
{
_taskProvider.DisableTask(path);
return _taskProvider.GetTask(path);
}

public WindowsTask[] EnableTasks()
{
foreach (var config in _windowsTaskConfigs)
{
_taskProvider.EnableTask(config.TaskPath);
}

return GetTasks();
}

public WindowsTask EnableTask(string path)
{
_taskProvider.EnableTask(path);
return _taskProvider.GetTask(path);
}

public WindowsTask[] GetTasks()
{
var tasks = new WindowsTask[_windowsTaskConfigs.Length];
for (int i = 0; i < tasks.Length; i++)
{
var windowsTaskConfig = _windowsTaskConfigs[i];
var task = _taskProvider.GetTask(windowsTaskConfig.TaskPath);
task.Name = windowsTaskConfig.TaskName;
tasks[i] = task;
}

return tasks;
}

public WindowsTask GetTask(string path)
{
var task = _taskProvider.GetTask(path);
var taskFromCollection = _windowsTaskConfigs.FirstOrDefault(x => x.TaskPath.Equals(path, StringComparison.OrdinalIgnoreCase));
task.Name = taskFromCollection?.TaskName ?? task.Name;
return task;
}
}
}
8 changes: 6 additions & 2 deletions WereDev.Utils.Wu10Man.Core/WereDev.Utils.Wu10Man.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<Compile Include="Exceptions\EntityNotFoundException.cs" />
<Compile Include="Enums\WindowsApiPrivelegeNames.cs" />
<Compile Include="Interfaces\IWindowsPackageManager.cs" />
<Compile Include="Interfaces\Providers\IConfigurationReader.cs" />
<Compile Include="Interfaces\IWindowsTaskManager.cs" />
<Compile Include="Interfaces\Providers\IFileIoProvider.cs" />
<Compile Include="Interfaces\IFileManager.cs" />
<Compile Include="Interfaces\IHostsFileEditor.cs" />
Expand All @@ -72,17 +72,21 @@
<Compile Include="Interfaces\Providers\IWindowsPackageProvider.cs" />
<Compile Include="Interfaces\Providers\IWindowsServiceProvider.cs" />
<Compile Include="Interfaces\Providers\IWindowsServiceProviderFactory.cs" />
<Compile Include="Interfaces\Providers\IWindowsTaskProvider.cs" />
<Compile Include="Models\AppInfo.cs" />
<Compile Include="Models\Declutter.cs" />
<Compile Include="Models\DeclutterConfig.cs" />
<Compile Include="Models\PackageInfo.cs" />
<Compile Include="Models\AppInfoExtended.cs" />
<Compile Include="Models\SplitHostsFile.cs" />
<Compile Include="Models\WindowsTask.cs" />
<Compile Include="Models\WindowsTaskConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\FileManager.cs" />
<Compile Include="Services\HostsFileEditor.cs" />
<Compile Include="Services\RegistryEditor.cs" />
<Compile Include="Services\WindowsPackageManager.cs" />
<Compile Include="Services\WindowsServiceManager.cs" />
<Compile Include="Services\WindowsTaskManager.cs" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\stylecop.json">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<CodeAnalysisRuleSet>..\stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.9.1.0, Culture=neutral, PublicKeyToken=e25603a88b3aa7da, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.9.1\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
Expand All @@ -44,7 +47,10 @@
<Reference Include="System.Diagnostics.EventLog, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.EventLog.5.0.1\lib\net461\System.Diagnostics.EventLog.dll</HintPath>
</Reference>
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
Expand All @@ -66,6 +72,7 @@
<HintPath>..\packages\System.ServiceProcess.ServiceController.5.0.0\lib\net461\System.ServiceProcess.ServiceController.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.Web.Services" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
Expand All @@ -78,6 +85,7 @@
<Compile Include="WindowsApiProvider.cs" />
<Compile Include="WindowsServiceProvider.cs" />
<Compile Include="WindowsServiceProviderFactory.cs" />
<Compile Include="WindowsTaskProvider.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WereDev.Utils.Win32Wrappers\WereDev.Utils.Win32Wrappers.csproj">
Expand Down

0 comments on commit 219bfef

Please sign in to comment.