wasStitchNET – Diff between revs 13 and 20

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