Feature/netcore preparation (#2072)

* Use platform detection that works on mono 4.6+

* Move to use package reference for restoring nuget packages.

* DateTimeRoutines does not have Nuget packages that support .NET Standard (and therefore .NET Core). We will have to include them for now until we can get rid of this dependency.

* Start spliting some interfaces into their own files - this will help by allowing us to split them out in the future into a seperate project so the actual implementations can stay within their respective architectures when required

* Move out common libraries

* Few more tidy up tasks to get things working with .NET Standard

* Restructure the solution layout

* Encoding work to reduce rework later on platforms without Windows codepages (or require compliance with RFC1345)

* Move folder structure around to have more natural layout of the solutions

* DI server configuration to get rid of "temporary" hack and dependency circle for serverservice

* Make all encoding consistent to match the expected encoding casing for earlier versions of mono.
This commit is contained in:
Nathan Holland
2017-11-05 22:42:03 +13:00
committed by flightlevel
parent 47a2ffa313
commit 571c52a0f2
235 changed files with 967 additions and 1001 deletions

View File

@@ -42,6 +42,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http.WebRequest" />
@@ -65,6 +66,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceConfigService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@@ -77,6 +79,10 @@
<Project>{74420a79-cc16-442c-8b1e-7c1b913844f0}</Project>
<Name>CurlSharp</Name>
</ProjectReference>
<ProjectReference Include="..\Jackett.Common\Jacket.Common.csproj">
<Project>{6B854A1B-9A90-49C0-BC37-9A35C75BCA73}</Project>
<Name>Jacket.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Jackett\Jackett.csproj">
<Project>{e636d5f8-68b4-4903-b4ed-ccfd9c9e899f}</Project>
<Name>Jackett</Name>

View File

@@ -0,0 +1,134 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Jackett.Services.Interfaces;
namespace Jackett.Services
{
public class ServiceConfigService : IServiceConfigService
{
private const string NAME = "Jackett";
private const string DESCRIPTION = "Additional indexers for Sonarr";
private const string SERVICEEXE = "JackettService.exe";
private IConfigurationService configService;
private Logger logger;
public ServiceConfigService(IConfigurationService c, Logger l)
{
configService = c;
logger = l;
}
public bool ServiceExists()
{
return GetService(NAME) != null;
}
public bool ServiceRunning()
{
var service = GetService(NAME);
if (service == null)
return false;
return service.Status == ServiceControllerStatus.Running;
}
public void Start()
{
var service = GetService(NAME);
service.Start();
}
public void Stop()
{
var service = GetService(NAME);
service.Stop();
}
public ServiceController GetService(string serviceName)
{
return ServiceController.GetServices().FirstOrDefault(c => String.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase));
}
public void Install()
{
if (ServiceExists())
{
logger.Warn("The service is already installed!");
}
else
{
var installer = new ServiceProcessInstaller
{
Account = ServiceAccount.LocalSystem
};
var serviceInstaller = new ServiceInstaller();
var exePath = Path.Combine(configService.ApplicationFolder(), SERVICEEXE);
if (!File.Exists(exePath) && Debugger.IsAttached)
{
exePath = Path.Combine(configService.ApplicationFolder(), "..\\..\\..\\Jackett.Service\\bin\\Debug", SERVICEEXE);
}
string[] cmdline = { @"/assemblypath=" + exePath};
var context = new InstallContext("jackettservice_install.log", cmdline);
serviceInstaller.Context = context;
serviceInstaller.DisplayName = NAME;
serviceInstaller.ServiceName = NAME;
serviceInstaller.Description = DESCRIPTION;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.Parent = installer;
serviceInstaller.Install(new ListDictionary());
}
}
public void Uninstall()
{
RemoveService();
var serviceInstaller = new ServiceInstaller();
var context = new InstallContext("jackettservice_uninstall.log", null);
serviceInstaller.Context = context;
serviceInstaller.ServiceName = NAME;
serviceInstaller.Uninstall(null);
logger.Info("The service was uninstalled.");
}
public void RemoveService()
{
var service = GetService(NAME);
if(service == null)
{
logger.Warn("The service is already uninstalled");
return;
}
if (service.Status != ServiceControllerStatus.Stopped)
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));
service.Refresh();
if (service.Status == ServiceControllerStatus.Stopped)
logger.Info("Service stopped.");
else
logger.Error("Failed to stop the service");
}
else
logger.Warn("The service was already stopped");
}
}
}