wasStitchNET – Blame information for rev 5

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 using System;
8 using System.Collections.Generic;
9 using System.Linq;
10 using System.Net;
11 using System.Threading.Tasks;
12 using wasDAVClient;
13 using wasSharp;
14 using wasSharp.Linq;
15 using wasSharp.Web.Utilities;
2 office 16 using wasSharpNET.Cryptography;
1 office 17  
18 namespace wasStitchNET.Repository
19 {
20 public class Tools
21 {
22 /// <summary>
23 /// Lists the release files for a given release version.
24 /// </summary>
25 /// <param name="server">the Stitch server to use</param>
26 /// <param name="release">the release to list files for</param>
27 /// <param name="timeout">the timeout connecting to the Stitch repository</param>
28 /// <returns>a list of Corrade files contained in the repository</returns>
29 public static async Task<IEnumerable<string>> GetReleaseFiles(string server, Version release, int timeout)
30 {
31 using (var client = new Client(new NetworkCredential())
32 {
33 Timeout = timeout,
34 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
35 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
36 Server = server,
37 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
38 STITCH_CONSTANTS.PROGRESSIVE_PATH)
39 })
40 {
41 return (await client
42 .List(
43 string.Join(
44 Constants.DIRECTORY_SEPARATOR,
45 $"{release.Major}.{release.Minor}",
46 STITCH_CONSTANTS.UPDATE_DATA_PATH),
47 Constants.DavDepth.ALL)
48 )
49 .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR,
50 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
51 .Select(part =>
5 office 52 part.Trim(Constants.DIRECTORY_SEPARATOR.First()).URLUnescapeDataString()
1 office 53 )
54 .Where(part => !string.IsNullOrEmpty(part))
55 .SequenceExceptAny(new[] {
56 STITCH_CONSTANTS.UPDATE_PATH,
57 STITCH_CONSTANTS.PROGRESSIVE_PATH,
58 $"{release.Major}.{release.Minor}",
59 STITCH_CONSTANTS.UPDATE_DATA_PATH
60 })
61 )
62 );
63 }
64 }
2 office 65  
66 /// <summary>
67 /// Lists the release files for a given release version.
68 /// </summary>
69 /// <param name="server">the Stitch server to use</param>
70 /// <param name="release">the release to list files for</param>
71 /// <param name="timeout">the timeout connecting to the Stitch repository</param>
72 /// <returns>a list of Corrade files contained in the repository</returns>
3 office 73 public static IEnumerable<KeyValuePair<string, string>> GetReleaseFileHashes(string server, Version release, int timeout)
2 office 74 {
75 using (var client = new Client(new NetworkCredential())
76 {
77 Timeout = timeout,
78 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
79 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
80 Server = server,
81 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
82 STITCH_CONSTANTS.PROGRESSIVE_PATH)
83 })
84 {
3 office 85 return client
2 office 86 .List(
87 string.Join(
88 Constants.DIRECTORY_SEPARATOR,
89 $"{release.Major}.{release.Minor}",
90 STITCH_CONSTANTS.UPDATE_DATA_PATH),
91 Constants.DavDepth.ALL)
3 office 92 .Result
93 .AsParallel()
94 .Where(item => !item.IsCollection)
95 .ToDictionary(o => string.Join(Constants.DIRECTORY_SEPARATOR,
96 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
5 office 97 .Select(part => part.Trim(Constants.DIRECTORY_SEPARATOR.First()).URLUnescapeDataString()
3 office 98 )
99 .Where(part => !string.IsNullOrEmpty(part))
100 .SequenceExceptAny(new[] {
2 office 101 STITCH_CONSTANTS.UPDATE_PATH,
102 STITCH_CONSTANTS.PROGRESSIVE_PATH,
103 $"{release.Major}.{release.Minor}",
104 STITCH_CONSTANTS.UPDATE_DATA_PATH
3 office 105 })), o => System.Security.Cryptography.SHA1.Create().ToHex(client.Download(o.Href).Result));
2 office 106 }
107 }
1 office 108 }
109 }