Bunch of updater files

This commit is contained in:
tidusjar 2017-02-24 21:43:36 +00:00
commit 3d6264095e
16 changed files with 1063 additions and 4 deletions

35
Ombi.Updater/AppType.cs Normal file
View file

@ -0,0 +1,35 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: AppType.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
namespace Ombi.Updater
{
public enum AppType
{
Normal,
Console,
Service
}
}

View file

@ -0,0 +1,39 @@
using Ombi.Common;
using Ombi.Common.EnvironmentInfo;
using Ombi.Common.Processes;
namespace Ombi.Updater
{
public class DetectApplicationType
{
public DetectApplicationType()
{
_processProvider = new ProcessProvider();
_serviceProvider = new ServiceProvider(_processProvider);
}
private readonly IServiceProvider _serviceProvider;
private readonly IProcessProvider _processProvider;
public AppType GetAppType()
{
if (OsInfo.IsNotWindows)
{
// Technically it is the console, but it has been renamed for mono (Linux/OS X)
return AppType.Normal;
}
if (_serviceProvider.ServiceExist(ServiceProvider.OmbiServiceName)
)
{
return AppType.Service;
}
if (_processProvider.Exists(ProcessProvider.OmbiProcessName))
{
return AppType.Console;
}
return AppType.Normal;
}
}
}

View file

@ -0,0 +1,57 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: InstallService.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System.Linq;
using Ombi.Common;
using Ombi.Common.EnvironmentInfo;
using Ombi.Common.Processes;
namespace Ombi.Updater
{
public class InstallService
{
public void Start(string installFolder)
{
var dector = new DetectApplicationType();
var processProvider = new ProcessProvider();
var processId = processProvider.FindProcessByName(ProcessProvider.OmbiProcessName)?.FirstOrDefault()?.Id ?? -1;
// Log if process is -1
var appType = dector.GetAppType();
processProvider.FindProcessByName(ProcessProvider.OmbiProcessName);
if (OsInfo.IsWindows)
{
var terminator = new TerminateOmbi(new ServiceProvider(processProvider), processProvider);
terminator.Terminate(processId);
}
}
}
}

View file

@ -13,7 +13,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<OutputPath>bin\Debug\Updater\</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -22,12 +22,15 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<OutputPath>bin\Release\Updater\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.6\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="Polly, Version=4.3.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
<HintPath>..\packages\Polly-Signed.4.3.0\lib\net45\Polly.dll</HintPath>
<Private>True</Private>
@ -38,12 +41,20 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppType.cs" />
<Compile Include="DetectApplicationType.cs" />
<Compile Include="InstallService.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TerminateOmbi.cs" />
<Compile Include="Updater.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\Ombi.Common\Ombi.Common.csproj">
<Project>{bfd45569-90cf-47ca-b575-c7b0ff97f67b}</Project>
<Name>Ombi.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj">
<Project>{DD7DC444-D3BF-4027-8AB9-EFC71F5EC581}</Project>
<Name>Ombi.Core</Name>

View file

@ -0,0 +1,88 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: TerminateOmbi.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using NLog;
using Ombi.Common;
using Ombi.Common.EnvironmentInfo;
using Ombi.Common.Processes;
using IServiceProvider = Ombi.Common.IServiceProvider;
namespace Ombi.Updater
{
public interface ITerminateOmbi
{
void Terminate(int processId);
}
public class TerminateOmbi : ITerminateOmbi
{
private readonly IServiceProvider _serviceProvider;
private readonly IProcessProvider _processProvider;
private static Logger _logger = LogManager.GetCurrentClassLogger();
public TerminateOmbi(IServiceProvider serviceProvider, IProcessProvider processProvider)
{
_serviceProvider = serviceProvider;
_processProvider = processProvider;
}
public void Terminate(int processId)
{
if (OsInfo.IsWindows)
{
_logger.Info("Stopping all running services");
if (_serviceProvider.ServiceExist(ServiceProvider.OmbiServiceName))
{
try
{
_logger.Info("NzbDrone Service is installed and running");
_serviceProvider.Stop(ServiceProvider.OmbiServiceName);
}
catch (Exception e)
{
_logger.Error(e, "couldn't stop service");
}
}
_logger.Info("Killing all running processes");
_processProvider.KillAll(ProcessProvider.OmbiProcessName);
}
else
{
_logger.Info("Killing all running processes");
_processProvider.KillAll(ProcessProvider.OmbiProcessName);
_processProvider.Kill(processId);
}
}
}
}

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.3.6" targetFramework="net45" />
<package id="Polly-Signed" version="4.3.0" targetFramework="net45" />
</packages>