wasStitchNET – Blame information for rev 10

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