* Adding trace listener to ProjectKClone
* Setting Max degrees of parallelism to 4 since too many connections is * causing MyGet to time out
This commit is contained in:
parent
bbf51f3556
commit
bacc8d1737
|
|
@ -6,6 +6,7 @@ using System.Net;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
using NuGet;
|
using NuGet;
|
||||||
|
|
||||||
namespace NuGetClone
|
namespace NuGetClone
|
||||||
|
|
@ -32,6 +33,17 @@ namespace NuGetClone
|
||||||
{
|
{
|
||||||
_targetDirectory = @"c:\projectk-cache";
|
_targetDirectory = @"c:\projectk-cache";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fileTraceListener = new FileLogTraceListener
|
||||||
|
{
|
||||||
|
AutoFlush = true,
|
||||||
|
Location = LogFileLocation.Custom,
|
||||||
|
CustomLocation = _targetDirectory,
|
||||||
|
BaseFileName = "ProjectKClone",
|
||||||
|
TraceOutputOptions = TraceOptions.DateTime,
|
||||||
|
LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly
|
||||||
|
};
|
||||||
|
Trace.Listeners.Add(fileTraceListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run(object state)
|
public void Run(object state)
|
||||||
|
|
@ -42,7 +54,7 @@ namespace NuGetClone
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Trace.WriteLine(ex.Message);
|
Trace.WriteLine(String.Format("{0}: ERROR {1}", DateTime.Now, ex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,8 +73,9 @@ namespace NuGetClone
|
||||||
var packages = remoteRepo.GetPackages()
|
var packages = remoteRepo.GetPackages()
|
||||||
.Where(p => p.IsAbsoluteLatestVersion)
|
.Where(p => p.IsAbsoluteLatestVersion)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
Parallel.ForEach(packages,
|
||||||
Parallel.ForEach(packages, package =>
|
new ParallelOptions { MaxDegreeOfParallelism = 4 },
|
||||||
|
package =>
|
||||||
{
|
{
|
||||||
// Some packages are updated without revving the version. We'll only opt not to re-download
|
// Some packages are updated without revving the version. We'll only opt not to re-download
|
||||||
// a package if an identical version does not exist on disk.
|
// a package if an identical version does not exist on disk.
|
||||||
|
|
@ -71,8 +84,7 @@ namespace NuGetClone
|
||||||
if (existingPackage == null ||
|
if (existingPackage == null ||
|
||||||
!existingPackage.GetHash(dataServicePackage.PackageHashAlgorithm).Equals(dataServicePackage.PackageHash, StringComparison.Ordinal))
|
!existingPackage.GetHash(dataServicePackage.PackageHashAlgorithm).Equals(dataServicePackage.PackageHash, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
PurgeOldVersions(targetRepo, package);
|
Trace.WriteLine(string.Format("{0}: Adding package {1}", DateTime.Now, package.GetFullName()));
|
||||||
|
|
||||||
var packagePath = GetPackagePath(package);
|
var packagePath = GetPackagePath(package);
|
||||||
|
|
||||||
using (var input = package.GetStream())
|
using (var input = package.GetStream())
|
||||||
|
|
@ -80,6 +92,8 @@ namespace NuGetClone
|
||||||
{
|
{
|
||||||
input.CopyTo(output);
|
input.CopyTo(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PurgeOldVersions(targetRepo, package);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -91,11 +105,12 @@ namespace NuGetClone
|
||||||
|
|
||||||
private void PurgeOldVersions(LocalPackageRepository targetRepo, IPackage package)
|
private void PurgeOldVersions(LocalPackageRepository targetRepo, IPackage package)
|
||||||
{
|
{
|
||||||
foreach (var oldPackage in targetRepo.FindPackagesById(package.Id).Where(p => p.Version <= package.Version))
|
foreach (var oldPackage in targetRepo.FindPackagesById(package.Id).Where(p => p.Version < package.Version))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var path = GetPackagePath(oldPackage);
|
var path = GetPackagePath(oldPackage);
|
||||||
|
Trace.WriteLine(string.Format("Deleting package {0}", oldPackage.GetFullName()));
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
<Reference Include="Microsoft.Web.XmlTransform">
|
<Reference Include="Microsoft.Web.XmlTransform">
|
||||||
<HintPath>packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
|
<HintPath>packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue