Winify

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 27  →  ?path2? @ 28
/trunk/Winify/Gotify/GotifyApplication.cs
@@ -6,14 +6,11 @@
{
#region Public Enums, Properties and Fields
 
[JsonProperty(PropertyName = "id")]
public int Id { get; set; }
[JsonProperty(PropertyName = "id")] public int Id { get; set; }
 
[JsonProperty(PropertyName = "token")]
public string Token { get; set; }
[JsonProperty(PropertyName = "token")] public string Token { get; set; }
 
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "name")] public string Name { get; set; }
 
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
@@ -21,8 +18,7 @@
[JsonProperty(PropertyName = "internal")]
public bool Internal { get; set; }
 
[JsonProperty(PropertyName = "image")]
public string Image { get; set; }
[JsonProperty(PropertyName = "image")] public string Image { get; set; }
 
#endregion
}
/trunk/Winify/Gotify/GotifyConnection.cs
@@ -56,15 +56,12 @@
 
public void Start()
{
if (!Uri.TryCreate(_server.Url, UriKind.Absolute, out var httpUri))
{
return;
}
if (!Uri.TryCreate(_server.Url, UriKind.Absolute, out var httpUri)) return;
 
// Build the web sockets URI.
var webSocketsUriBuilder = new UriBuilder(httpUri);
webSocketsUriBuilder.Scheme = "ws";
webSocketsUriBuilder.Path = $"{webSocketsUriBuilder.Path}/stream";
webSocketsUriBuilder.Path = Path.Combine($"{webSocketsUriBuilder.Path}", "stream");
var webSocketsUri = webSocketsUriBuilder.Uri;
 
_cancellationTokenSource = new CancellationTokenSource();
@@ -75,10 +72,7 @@
 
public void Stop()
{
if (_cancellationTokenSource != null)
{
_cancellationTokenSource.Cancel();
}
if (_cancellationTokenSource != null) _cancellationTokenSource.Cancel();
}
 
#endregion
@@ -86,7 +80,7 @@
#region Private Methods
 
private async Task Run(Uri webSocketsUri, Uri httpUri, string username, string password,
CancellationToken cancellationToken)
CancellationToken cancellationToken)
{
try
{
@@ -108,20 +102,15 @@
 
var result = await webSocketClient.ReceiveAsync(payload, cancellationToken);
 
if (result.Count == 0)
{
continue;
}
if (result.Count == 0) continue;
 
if (payload.Array == null || payload.Count == 0)
{
continue;
}
if (payload.Array == null || payload.Count == 0) continue;
 
var message = Encoding.UTF8.GetString(payload.Array, 0, payload.Count);
 
if (!(JsonConvert.DeserializeObject<GotifyNotification>(message) is GotifyNotification
gotifyNotification))
var gotifyNotification = JsonConvert.DeserializeObject<GotifyNotification>(message);
 
if (gotifyNotification == null)
{
Log.Warning($"Could not deserialize gotify notification: {message}");
 
@@ -130,11 +119,9 @@
 
gotifyNotification.Server = _server;
 
if (!Uri.TryCreate($"{httpUri}/application", UriKind.Absolute,
out var applicationUri))
{
if (!Uri.TryCreate(Path.Combine($"{httpUri}", "application"), UriKind.Absolute,
out var applicationUri))
continue;
}
 
var image = await RetrieveGotifyApplicationImage(gotifyNotification.AppId, httpUri,
applicationUri, auth, cancellationToken);
@@ -165,8 +152,8 @@
}
 
private static async Task<Image> RetrieveGotifyApplicationImage(int appId, Uri httpUri, Uri applicationUri,
string auth,
CancellationToken cancellationToken)
string auth,
CancellationToken cancellationToken)
{
using (var httpClient = new HttpClient())
{
@@ -180,23 +167,15 @@
var gotifyApplications =
JsonConvert.DeserializeObject<GotifyApplication[]>(applications);
 
if (gotifyApplications == null)
{
return null;
}
if (gotifyApplications == null) return null;
 
foreach (var application in gotifyApplications)
{
if (application.Id != appId)
{
continue;
}
if (application.Id != appId) continue;
 
if (!Uri.TryCreate($"{httpUri}/{application.Image}", UriKind.Absolute,
out var applicationImageUri))
{
if (!Uri.TryCreate(Path.Combine($"{httpUri}", $"{application.Image}"), UriKind.Absolute,
out var applicationImageUri))
continue;
}
 
var imageResponse = await httpClient.GetAsync(applicationImageUri, cancellationToken);
 
/trunk/Winify/Gotify/GotifyNotification.cs
@@ -4,29 +4,29 @@
 
namespace Winify.Gotify
{
/// <summary>
/// {"id":22,"appid":1,"message":"iot","title":"Arcade
/// Netplay","priority":0,"date":"2022-10-26T14:55:59.050734643+03:00"}
/// </summary>
public class GotifyNotification
{
#region Public Enums, Properties and Fields
 
[JsonProperty(PropertyName = "id")]
public int Id { get; set; }
[JsonProperty(PropertyName = "id")] public int Id { get; set; }
 
[JsonProperty(PropertyName = "appid")]
public int AppId { get; set; }
[JsonProperty(PropertyName = "appid")] public int AppId { get; set; }
 
[JsonProperty(PropertyName = "message")]
public string Message { get; set; }
 
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }
[JsonProperty(PropertyName = "title")] public string Title { get; set; }
 
[JsonProperty(PropertyName = "priority")]
public int Priority { get; set; }
 
[JsonProperty(PropertyName = "date")]
public DateTime Date { get; set; }
[JsonProperty(PropertyName = "date")] public DateTime Date { get; set; }
 
public Server Server { get; set; }
[JsonIgnore] public Server Server { get; set; }
 
#endregion
}
/trunk/Winify/Gotify/GotifyNotificationEventArgs.cs
@@ -5,14 +5,6 @@
{
public class GotifyNotificationEventArgs : EventArgs
{
#region Public Enums, Properties and Fields
 
public GotifyNotification Notification { get; set; }
 
public Image Image { get; set; }
 
#endregion
 
#region Constructors, Destructors and Finalizers
 
public GotifyNotificationEventArgs(GotifyNotification notification, Image image)
@@ -22,5 +14,13 @@
}
 
#endregion
 
#region Public Enums, Properties and Fields
 
public GotifyNotification Notification { get; set; }
 
public Image Image { get; set; }
 
#endregion
}
}