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

Commit 3831d92

Browse files
Unizip Task & Test
1 parent 926e19d commit 3831d92

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<Compile Include="Application\ApplicationManagerBase.cs" />
118118
<Compile Include="Helpers\Constants.cs" />
119119
<Compile Include="Helpers\Validation.cs" />
120+
<Compile Include="Installer\UnzipTask.cs" />
120121
<Compile Include="OutputProcessors\GitAheadBehindStatusOutputProcessor.cs" />
121122
<Compile Include="OutputProcessors\LfsVersionOutputProcessor.cs" />
122123
<Compile Include="OutputProcessors\VersionOutputProcessor.cs" />

src/GitHub.Api/Installer/UnzipTask.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
namespace GitHub.Unity
6+
{
7+
class UnzipTask: TaskBase
8+
{
9+
protected static ILogging Logger { get; } = Logging.GetLogger<UnzipTask>();
10+
11+
private string archiveFilePath;
12+
private string extractedPath;
13+
private IProgress<float> zipFileProgress;
14+
private IProgress<long> estimatedDurationProgress;
15+
16+
public UnzipTask(CancellationToken token, string archiveFilePath, string extractedPath, IProgress<float> zipFileProgress = null, IProgress<long> estimatedDurationProgress = null)
17+
: base(token)
18+
{
19+
this.archiveFilePath = archiveFilePath;
20+
this.extractedPath = extractedPath;
21+
this.zipFileProgress = zipFileProgress;
22+
this.estimatedDurationProgress = estimatedDurationProgress;
23+
}
24+
25+
protected override void Run(bool success)
26+
{
27+
base.Run(success);
28+
29+
UnzipArchive();
30+
}
31+
32+
private void UnzipArchive()
33+
{
34+
Logger.Trace("Zip File: {0}", archiveFilePath);
35+
Logger.Trace("Target Path: {0}", extractedPath);
36+
37+
ZipHelper.ExtractZipFile(archiveFilePath, extractedPath, Token, zipFileProgress, estimatedDurationProgress);
38+
39+
Logger.Trace("Completed");
40+
}
41+
}
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using GitHub.Unity;
4+
using Microsoft.Win32.SafeHandles;
5+
using NSubstitute;
6+
using NUnit.Framework;
7+
using Rackspace.Threading;
8+
9+
namespace IntegrationTests
10+
{
11+
[TestFixture]
12+
class UnzipTaskTests : BaseTaskManagerTest
13+
{
14+
[Test]
15+
public void UnzipTest()
16+
{
17+
InitializeTaskManager();
18+
19+
var cacheContainer = Substitute.For<ICacheContainer>();
20+
Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory);
21+
22+
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", TestBasePath.Combine("gip_zip_extracted"), Environment);
23+
24+
Logger.Trace("ArchiveFilePath: {0}", archiveFilePath);
25+
Logger.Trace("TestBasePath: {0}", TestBasePath);
26+
27+
var extractedPath = TestBasePath.Combine("git_zip_extracted");
28+
extractedPath.CreateDirectory();
29+
30+
var zipProgress = 0;
31+
Logger.Trace("Pct Complete {0}%", zipProgress);
32+
var unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath,
33+
new Progress<float>(zipFileProgress => {
34+
var zipFileProgressInteger = (int) (zipFileProgress * 100);
35+
if (zipProgress != zipFileProgressInteger)
36+
{
37+
zipProgress = zipFileProgressInteger;
38+
Logger.Trace("Pct Complete {0}%", zipProgress);
39+
}
40+
}));
41+
42+
unzipTask.Start().Wait();
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)