Winify – Diff between revs 63 and 64

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 63 Rev 64
Line 110... Line 110...
110 var webSocketActionBlock = new ActionBlock<GotifyMessage>(async message => 110 var webSocketActionBlock = new ActionBlock<GotifyMessage>(async message =>
111 { 111 {
112 message.Server = _server; 112 message.Server = _server;
Line 113... Line 113...
113   113  
114 var cachedImage = _applicationImageCache.Get($"{message.AppId}"); 114 var cachedImage = _applicationImageCache.Get($"{message.AppId}");
115 if (cachedImage is Image applicationImage) 115 if (cachedImage is Stream cachedImageStream)
-   116 {
-   117 using var cachedImageMemoryStream = new MemoryStream();
-   118 await cachedImageStream.CopyToAsync(cachedImageMemoryStream);
-   119  
116 { 120 var cachedApplicationImage = new Bitmap(cachedImageMemoryStream);
117 GotifyNotification?.Invoke(this, 121 GotifyNotification?.Invoke(this,
-   122 new GotifyNotificationEventArgs(message, cachedApplicationImage));
118 new GotifyNotificationEventArgs(message, applicationImage)); 123  
119 return; 124 return;
Line 120... Line 125...
120 } 125 }
121   -  
122 using (var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken)) 126  
123 { 127 using var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken);
124 if (imageStream == null || imageStream.Length == 0) 128 if (imageStream == null || imageStream.Length == 0)
125 { 129 {
126 Log.Warning("Could not find any application image for notification"); 130 Log.Warning("Could not find any application image for notification");
Line 127... Line 131...
127 return; 131 return;
Line 128... Line 132...
128 } 132 }
Line -... Line 133...
-   133  
-   134 using var memoryStream = new MemoryStream();
129   135  
130 var image = Image.FromStream(imageStream); 136 await imageStream.CopyToAsync(memoryStream);
131   137  
132 var clone = new Bitmap(image); 138 var imageBytes = memoryStream.ToArray();
133   139  
Line -... Line 140...
-   140 _applicationImageCache.Add($"{message.AppId}", imageBytes,
-   141 new CacheItemPolicy
134 _applicationImageCache.Add($"{message.AppId}", clone, 142 {
135 new CacheItemPolicy 143 SlidingExpiration = TimeSpan.FromHours(1)
136 { -  
Line 137... Line 144...
137 SlidingExpiration = TimeSpan.FromHours(1) 144 });
Line 138... Line 145...
138 }); 145  
Line 423... Line 430...
423 foreach (var message in gotifyMessageQuery.Messages.Where(message => message.Date >= DateTime.Now - TimeSpan.FromHours(_configuration.RetrievePastNotificationHours))) 430 foreach (var message in gotifyMessageQuery.Messages.Where(message => message.Date >= DateTime.Now - TimeSpan.FromHours(_configuration.RetrievePastNotificationHours)))
424 { 431 {
425 message.Server = _server; 432 message.Server = _server;
Line 426... Line 433...
426   433  
427 var cachedImage = _applicationImageCache.Get($"{message.AppId}"); 434 var cachedImage = _applicationImageCache.Get($"{message.AppId}");
428 if (cachedImage is Image applicationImage) 435 if (cachedImage is Stream cachedImageStream)
-   436 {
-   437 using var cachedImageMemoryStream = new MemoryStream();
-   438 await cachedImageStream.CopyToAsync(cachedImageMemoryStream);
-   439  
429 { 440 var cachedApplicationImage = new Bitmap(cachedImageMemoryStream);
430 GotifyNotification?.Invoke(this, 441 GotifyNotification?.Invoke(this,
-   442 new GotifyNotificationEventArgs(message, cachedApplicationImage));
431 new GotifyNotificationEventArgs(message, applicationImage)); 443  
432 return; 444 return;
Line 433... Line 445...
433 } 445 }
-   446  
434   447 using var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken);
435 using var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken); 448  
436 if (imageStream == null || imageStream.Length == 0) 449 if (imageStream == null || imageStream.Length == 0)
437 { 450 {
438 Log.Warning("Could not find any application image for notification"); 451 Log.Warning("Could not find any application image for notification");
Line 439... Line 452...
439 continue; 452 continue;
Line 440... Line 453...
440 } 453 }
Line -... Line 454...
-   454  
-   455 using var memoryStream = new MemoryStream();
441   456  
442 var image = Image.FromStream(imageStream); 457 await imageStream.CopyToAsync(memoryStream);
443   458  
444 var clone = new Bitmap(image); 459 var imageBytes = memoryStream.ToArray();
445   460  
Line -... Line 461...
-   461 _applicationImageCache.Add($"{message.AppId}", imageBytes,
-   462 new CacheItemPolicy
446 _applicationImageCache.Add($"{message.AppId}", clone, 463 {
447 new CacheItemPolicy 464 SlidingExpiration = TimeSpan.FromHours(1)
448 { 465 });
Line 449... Line 466...
449 SlidingExpiration = TimeSpan.FromHours(1) 466