wasStitchNET – Blame information for rev 13

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;
10 office 13 using wasDAVClient.Helpers;
1 office 14 using wasSharp;
15 using wasSharp.Linq;
16 using wasSharp.Web.Utilities;
2 office 17 using wasSharpNET.Cryptography;
13 office 18 using SHA1 = System.Security.Cryptography.SHA1;
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 {
10 office 33 try
1 office 34 {
10 office 35 using (var client = new Client(new NetworkCredential())
36 {
37 Timeout = timeout,
38 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
39 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
40 Server = server,
41 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
42 STITCH_CONSTANTS.PROGRESSIVE_PATH)
43 })
44 {
45 return (await client
46 .List(
47 string.Join(
48 Constants.DIRECTORY_SEPARATOR,
1 office 49 $"{release.Major}.{release.Minor}",
10 office 50 STITCH_CONSTANTS.UPDATE_DATA_PATH),
51 Constants.DavDepth.ALL)
1 office 52 )
10 office 53 .Select(o => string.Join(Constants.DIRECTORY_SEPARATOR,
54 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
55 .Select(part =>
56 part.Trim(Constants.DIRECTORY_SEPARATOR.First()).URLUnescapeDataString()
57 )
58 .Where(part => !string.IsNullOrEmpty(part))
59 .SequenceExceptAny(new[]
60 {
61 STITCH_CONSTANTS.UPDATE_PATH,
62 STITCH_CONSTANTS.PROGRESSIVE_PATH,
63 $"{release.Major}.{release.Minor}",
64 STITCH_CONSTANTS.UPDATE_DATA_PATH
65 })
66 )
67 );
68 }
1 office 69 }
10 office 70 catch (wasDAVConflictException ex)
71 {
72 throw new StitchException(ex);
73 }
1 office 74 }
2 office 75  
76 /// <summary>
77 /// Lists the release files for a given release version.
78 /// </summary>
79 /// <param name="server">the Stitch server to use</param>
80 /// <param name="release">the release to list files for</param>
81 /// <param name="timeout">the timeout connecting to the Stitch repository</param>
82 /// <returns>a list of Corrade files contained in the repository</returns>
13 office 83 public static IEnumerable<KeyValuePair<string, string>> GetReleaseFileHashes(string server, Version release,
84 int timeout)
2 office 85 {
10 office 86 try
2 office 87 {
10 office 88 using (var client = new Client(new NetworkCredential())
89 {
90 Timeout = timeout,
91 UserAgent = STITCH_CONSTANTS.USER_AGENT.Product.Name,
92 UserAgentVersion = STITCH_CONSTANTS.USER_AGENT.Product.Version,
93 Server = server,
94 BasePath = string.Join(@"/", STITCH_CONSTANTS.UPDATE_PATH,
95 STITCH_CONSTANTS.PROGRESSIVE_PATH)
96 })
97 {
98 return client
99 .List(
100 string.Join(
101 Constants.DIRECTORY_SEPARATOR,
102 $"{release.Major}.{release.Minor}",
103 STITCH_CONSTANTS.UPDATE_DATA_PATH),
2 office 104 Constants.DavDepth.ALL)
10 office 105 .Result
106 .AsParallel()
107 .Where(item => !item.IsCollection)
108 .ToDictionary(o => string.Join(Constants.DIRECTORY_SEPARATOR,
3 office 109 o.Href.PathSplit(Constants.DIRECTORY_SEPARATOR.First())
10 office 110 .Select(part => part.Trim(Constants.DIRECTORY_SEPARATOR.First())
111 .URLUnescapeDataString()
112 )
113 .Where(part => !string.IsNullOrEmpty(part))
114 .SequenceExceptAny(new[]
115 {
2 office 116 STITCH_CONSTANTS.UPDATE_PATH,
117 STITCH_CONSTANTS.PROGRESSIVE_PATH,
118 $"{release.Major}.{release.Minor}",
119 STITCH_CONSTANTS.UPDATE_DATA_PATH
10 office 120 })),
13 office 121 o => SHA1.Create().ToHex(client.Download(o.Href).Result));
10 office 122 }
2 office 123 }
10 office 124 catch (wasDAVException ex)
125 {
126 throw new StitchException(ex);
127 }
2 office 128 }
1 office 129 }
13 office 130 }