Adding tooling for mirroring project k packages
This commit is contained in:
parent
752e559b2f
commit
34afda9dfc
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
|
||||
</startup>
|
||||
</configuration>
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NuGet;
|
||||
|
||||
namespace NuGetClone
|
||||
{
|
||||
public class MyService : ServiceBase
|
||||
{
|
||||
private static readonly Uri DeveloperFeed = new Uri("https://www.myget.org/F/aspnetvnext/api/v2");
|
||||
private static readonly ICredentials _credentials = new NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c");
|
||||
|
||||
private Timer _timer;
|
||||
private string _targetDirectory;
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
base.OnStart(args);
|
||||
Init();
|
||||
_timer = new Timer(Run, null, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(2));
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_targetDirectory = Environment.GetEnvironmentVariable("PROJECTK_PACKAGE_CACHE");
|
||||
if (string.IsNullOrEmpty(_targetDirectory))
|
||||
{
|
||||
_targetDirectory = @"c:\projectk-cache";
|
||||
}
|
||||
}
|
||||
|
||||
public void Run(object state)
|
||||
{
|
||||
try
|
||||
{
|
||||
RunFromGallery();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Trace.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void RunFromGallery()
|
||||
{
|
||||
Directory.CreateDirectory(_targetDirectory);
|
||||
|
||||
var client = new HttpClient(DeveloperFeed);
|
||||
client.SendingRequest += (sender, e) =>
|
||||
{
|
||||
e.Request.Credentials = _credentials;
|
||||
e.Request.PreAuthenticate = true;
|
||||
};
|
||||
var remoteRepo = new DataServicePackageRepository(client);
|
||||
var targetRepo = new LocalPackageRepository(_targetDirectory);
|
||||
var packages = remoteRepo.GetPackages()
|
||||
.Where(p => p.IsAbsoluteLatestVersion)
|
||||
.ToList();
|
||||
Parallel.ForEach(packages, package =>
|
||||
{
|
||||
if (!targetRepo.Exists(package))
|
||||
{
|
||||
PurgeOldVersions(targetRepo, package);
|
||||
|
||||
var packagePath = GetPackagePath(package);
|
||||
|
||||
using (var input = package.GetStream())
|
||||
using (var output = File.Create(packagePath))
|
||||
{
|
||||
input.CopyTo(output);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private string GetPackagePath(IPackage package)
|
||||
{
|
||||
return Path.Combine(_targetDirectory, package.Id + "." + package.Version + ".nupkg");
|
||||
}
|
||||
|
||||
private void PurgeOldVersions(LocalPackageRepository targetRepo, IPackage package)
|
||||
{
|
||||
foreach (var oldPackage in targetRepo.FindPackagesById(package.Id).Where(p => p.Version < package.Version))
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = GetPackagePath(oldPackage);
|
||||
File.Delete(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
base.OnStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration.Install;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NuGetClone
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
public class MyServiceInstaller : Installer
|
||||
{
|
||||
internal const string ServiceName = "ProjectKClone";
|
||||
|
||||
public MyServiceInstaller()
|
||||
{
|
||||
var processInstaller = new ServiceProcessInstaller();
|
||||
var serviceInstaller = new ServiceInstaller();
|
||||
|
||||
processInstaller.Account = ServiceAccount.LocalSystem;
|
||||
processInstaller.Username = null;
|
||||
processInstaller.Password = null;
|
||||
|
||||
serviceInstaller.ServiceName = ServiceName;
|
||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||
|
||||
serviceInstaller.ServiceName = ServiceName;
|
||||
|
||||
this.Installers.Add(processInstaller);
|
||||
this.Installers.Add(serviceInstaller);
|
||||
|
||||
this.Committed += new InstallEventHandler(ServiceInstaller_Committed);
|
||||
}
|
||||
|
||||
void ServiceInstaller_Committed(object sender, InstallEventArgs e)
|
||||
{
|
||||
// Auto Start the Service Once Installation is Finished.
|
||||
var controller = new ServiceController(ServiceName);
|
||||
controller.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration.Install;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NuGetClone
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ServiceBase[] ServicesToRun;
|
||||
ServicesToRun = new ServiceBase[]
|
||||
{
|
||||
new MyService()
|
||||
};
|
||||
ServiceBase.Run(ServicesToRun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ProjectKClone</RootNamespace>
|
||||
<AssemblyName>ProjectKClone</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Web.XmlTransform">
|
||||
<HintPath>packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NuGet.Core, Version=2.8.50126.400, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>packages\Nuget.Core.2.8.0\lib\net40-Client\NuGet.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.Services.Client" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MyService.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="MyServiceInstaller.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21126.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectKClone", "ProjectKClone.csproj", "{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("NuGetClone")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("NuGetClone")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("cfb7b99d-4f04-4c77-ab79-b4d05aa5a1f5")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Web.Xdt" version="1.0.0" targetFramework="net451" />
|
||||
<package id="Nuget.Core" version="2.8.0" targetFramework="net451" />
|
||||
</packages>
|
||||
Loading…
Reference in New Issue