Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 63  →  ?path2? @ 64
/trunk/Winify/Gotify/GotifyConnection.cs
@@ -112,15 +112,19 @@
message.Server = _server;
 
var cachedImage = _applicationImageCache.Get($"{message.AppId}");
if (cachedImage is Image applicationImage)
if (cachedImage is Stream cachedImageStream)
{
using var cachedImageMemoryStream = new MemoryStream();
await cachedImageStream.CopyToAsync(cachedImageMemoryStream);
 
var cachedApplicationImage = new Bitmap(cachedImageMemoryStream);
GotifyNotification?.Invoke(this,
new GotifyNotificationEventArgs(message, applicationImage));
new GotifyNotificationEventArgs(message, cachedApplicationImage));
 
return;
}
 
using (var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken))
{
using var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken);
if (imageStream == null || imageStream.Length == 0)
{
Log.Warning("Could not find any application image for notification");
@@ -127,19 +131,22 @@
return;
}
 
var image = Image.FromStream(imageStream);
using var memoryStream = new MemoryStream();
 
var clone = new Bitmap(image);
await imageStream.CopyToAsync(memoryStream);
 
_applicationImageCache.Add($"{message.AppId}", clone,
var imageBytes = memoryStream.ToArray();
 
_applicationImageCache.Add($"{message.AppId}", imageBytes,
new CacheItemPolicy
{
SlidingExpiration = TimeSpan.FromHours(1)
});
 
var image = new Bitmap(memoryStream);
 
GotifyNotification?.Invoke(this,
new GotifyNotificationEventArgs(message, image));
}
 
Log.Debug($"Notification message received: {message.Message}");
 
@@ -425,14 +432,20 @@
message.Server = _server;
 
var cachedImage = _applicationImageCache.Get($"{message.AppId}");
if (cachedImage is Image applicationImage)
if (cachedImage is Stream cachedImageStream)
{
using var cachedImageMemoryStream = new MemoryStream();
await cachedImageStream.CopyToAsync(cachedImageMemoryStream);
 
var cachedApplicationImage = new Bitmap(cachedImageMemoryStream);
GotifyNotification?.Invoke(this,
new GotifyNotificationEventArgs(message, applicationImage));
new GotifyNotificationEventArgs(message, cachedApplicationImage));
 
return;
}
 
using var imageStream = await RetrieveGotifyApplicationImage(message.AppId, _cancellationToken);
 
if (imageStream == null || imageStream.Length == 0)
{
Log.Warning("Could not find any application image for notification");
@@ -439,16 +452,20 @@
continue;
}
 
var image = Image.FromStream(imageStream);
using var memoryStream = new MemoryStream();
 
var clone = new Bitmap(image);
await imageStream.CopyToAsync(memoryStream);
 
_applicationImageCache.Add($"{message.AppId}", clone,
var imageBytes = memoryStream.ToArray();
 
_applicationImageCache.Add($"{message.AppId}", imageBytes,
new CacheItemPolicy
{
SlidingExpiration = TimeSpan.FromHours(1)
});
 
var image = new Bitmap(memoryStream);
 
GotifyNotification?.Invoke(this,
new GotifyNotificationEventArgs(message, image));
}