wasStitchNET – Blame information for rev 3

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