Winify – Diff between revs 18 and 21

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 18 Rev 21
Line 106... Line 106...
106 { 106 {
107 do 107 do
108 { 108 {
109 try 109 try
110 { 110 {
111 _webSocketClient = new ClientWebSocket(); 111 using (_webSocketClient = new ClientWebSocket())
112   -  
113 var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}")); -  
114   -  
115 _webSocketClient.Options.SetRequestHeader("Authorization", $"Basic {auth}"); -  
116   -  
117 await _webSocketClient.ConnectAsync(webSocketsUri, cancellationToken); -  
118   -  
119 do -  
120 { 112 {
121 var payload = new ArraySegment<byte>(new byte[1024]); 113 var auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
Line 122... Line 114...
122   114  
Line 123... Line 115...
123 await _webSocketClient.ReceiveAsync(payload, cancellationToken); 115 _webSocketClient.Options.SetRequestHeader("Authorization", $"Basic {auth}");
124   -  
125 if (payload.Array == null || payload.Count == 0) -  
126 { -  
Line 127... Line -...
127 continue; -  
128 } -  
129   -  
130 var message = Encoding.UTF8.GetString(payload.Array, 0, payload.Count); 116  
131   117 await _webSocketClient.ConnectAsync(webSocketsUri, cancellationToken);
132 var gotifyNotification = JsonConvert.DeserializeObject<GotifyNotification>(message); 118  
133 if (gotifyNotification == null) -  
Line 134... Line 119...
134 { 119 do
-   120 {
-   121 var payload = new ArraySegment<byte>(new byte[1024]);
135 continue; 122  
136 } 123 var result = await _webSocketClient.ReceiveAsync(payload, cancellationToken);
137   124  
Line 138... Line 125...
138 if (!Uri.TryCreate($"{httpUri}/application", UriKind.Absolute, out var applicationUri)) 125 if (result.Count == 0)
-   126 {
-   127 continue;
-   128 }
Line 139... Line 129...
139 { 129  
140 continue; -  
141 } -  
142   -  
143 var applications = await _httpClient.GetStringAsync(applicationUri); -  
Line 144... Line 130...
144   130 if (payload.Array == null || payload.Count == 0)
145 var gotifyApplications = JsonConvert.DeserializeObject<GotifyApplication[]>(applications); -  
146 if (gotifyApplications == null) 131 {
147 { 132 continue;
148 continue; 133 }
149 } 134  
Line 150... Line 135...
150   135 var message = Encoding.UTF8.GetString(payload.Array, 0, payload.Count);
151 foreach (var application in gotifyApplications) -  
152 { 136  
153 if (application.Id != gotifyNotification.AppId) 137 var gotifyNotification = JsonConvert.DeserializeObject<GotifyNotification>(message);
154 { 138 if (gotifyNotification == null)
Line 155... Line 139...
155 continue; 139 {
Line -... Line 140...
-   140 continue;
-   141 }
156 } 142  
157   143 if (!Uri.TryCreate($"{httpUri}/application", UriKind.Absolute, out var applicationUri))
158 if (!Uri.TryCreate($"{httpUri}/{application.Image}", UriKind.Absolute, 144 {
159 out var applicationImageUri)) 145 continue;
Line 160... Line 146...
160 { 146 }
161 continue; 147  
-   148 var applications = await _httpClient.GetStringAsync(applicationUri);
-   149  
-   150 var gotifyApplications =
-   151 JsonConvert.DeserializeObject<GotifyApplication[]>(applications);
-   152 if (gotifyApplications == null)
-   153 {
-   154 continue;
-   155 }
-   156  
-   157 foreach (var application in gotifyApplications)
-   158 {
-   159 if (application.Id != gotifyNotification.AppId)
-   160 {
-   161 continue;
-   162 }
-   163  
-   164 if (!Uri.TryCreate($"{httpUri}/{application.Image}", UriKind.Absolute,
-   165 out var applicationImageUri))
-   166 {
-   167 continue;
162 } 168 }
-   169  
-   170 var imageBytes = await _httpClient.GetByteArrayAsync(applicationImageUri);
-   171  
-   172 if (imageBytes == null || imageBytes.Length == 0)
Line 163... Line -...
163   -  
164 var imageBytes = await _httpClient.GetByteArrayAsync(applicationImageUri); -  
165   -  
Line -... Line 173...
-   173 {
-   174 continue;
Line 166... Line 175...
166 if (imageBytes == null || imageBytes.Length == 0) 175 }
167 { 176  
Line 168... Line 177...
168 continue; 177 using (var memoryStream = new MemoryStream(imageBytes))
169 } 178 {
-   179 var image = Image.FromStream(memoryStream);
Line 170... Line -...
170   -  
171 using (var memoryStream = new MemoryStream(imageBytes)) 180  
172 { 181 GotifyNotification?.Invoke(this,
173 var image = Image.FromStream(memoryStream); 182 new GotifyNotificationEventArgs(gotifyNotification, image));
174   183 }
175 GotifyNotification?.Invoke(this, 184