wasStitchNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 1  →  ?path2? @ 2
/Repository/Tools.cs
@@ -6,13 +6,16 @@
 
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Threading.Tasks;
using wasDAVClient;
using wasSharp;
using wasSharp.Linq;
using wasSharp.Web.Utilities;
using wasSharpNET.Cryptography;
 
namespace wasStitchNET.Repository
{
@@ -63,5 +66,63 @@
);
}
}
 
/// <summary>
/// Lists the release files for a given release version.
/// </summary>
/// <param name="server">the Stitch server to use</param>
/// <param name="release">the release to list files for</param>
/// <param name="timeout">the timeout connecting to the Stitch repository</param>
/// <returns>a list of Corrade files contained in the repository</returns>
public static async Task<IEnumerable<KeyValuePair<string, string>>> GetReleaseFileHashes(string server, Version release, int timeout)
{
using (var client = new Client(new NetworkCredential())
{
Timeout = timeout,
UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
Server = server,
BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
STITCH_CONSTANTS.PROGRESSIVE_PATH)
})
{
Console.WriteLine($"{release.Major}.{release.Minor}");
return (await client
.List(
string.Join(
Constants.DIRECTORY_SEPARATOR,
$"{release.Major}.{release.Minor}",
STITCH_CONSTANTS.UPDATE_DATA_PATH),
Constants.DavDepth.ALL)
)
.Select(async o =>
{
using (var memoryStream = new MemoryStream())
{
using (var stream = client.Download(o.Href).Result)
{
await stream.CopyToAsync(memoryStream);
}
return new KeyValuePair<string, string>(
string.Join(Constants.DIRECTORY_SEPARATOR,
o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
.Select(part =>
WebExtensions.URLUnescapeDataString(
part.Trim(Constants.DIRECTORY_SEPARATOR.First())
)
)
.Where(part => !string.IsNullOrEmpty(part))
.SequenceExceptAny(new[] {
STITCH_CONSTANTS.UPDATE_PATH,
STITCH_CONSTANTS.PROGRESSIVE_PATH,
$"{release.Major}.{release.Minor}",
STITCH_CONSTANTS.UPDATE_DATA_PATH
})
), System.Security.Cryptography.SHA1.Create().ToHex(memoryStream));
}
}
).Select(o => o.Result).OfType<KeyValuePair<string, string>>();
}
}
}
}