Skip to content

Commit

Permalink
#59 [FEATURE REQUEST]
Browse files Browse the repository at this point in the history
First try of implementing local running instances without app configuration
  • Loading branch information
androidseb25 committed May 27, 2024
1 parent 6f7beab commit 221186f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Controller/DeviceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)
bool resultBool;

Console.WriteLine($"ClientToken: {deviceModel.ClientToken}");
Console.WriteLine($"DeviceToken: {DeviceModel.DeviceToken}");
Console.WriteLine($"GotifyUrl: {DeviceModel.GotifyUrl}");
Console.WriteLine($"DeviceToken: {deviceModel.DeviceToken}");
Console.WriteLine($"GotifyUrl: {deviceModel.GotifyUrl}");

if (
deviceModel.ClientToken.Length == 0 || deviceModel.ClientToken == "string" ||
DeviceModel.DeviceToken.Length == 0 || DeviceModel.DeviceToken.Length < 60 || DeviceModel.DeviceToken == "string" ||
DeviceModel.GotifyUrl.Length == 0 || DeviceModel.GotifyUrl == "string"
deviceModel.DeviceToken.Length == 0 || deviceModel.DeviceToken.Length < 60 || deviceModel.DeviceToken == "string" ||
deviceModel.GotifyUrl.Length == 0 || deviceModel.GotifyUrl == "string"
)
{
result = "Fehler beim hinzugefügen des Gerätes!";
Expand All @@ -38,7 +38,7 @@ public async Task<IActionResult> PostDeviceModel(DeviceModel deviceModel)
if (await deviceModel.Insert())
{
GotifySocketService.getInstance();
GotifySocketService.StartWsThread(DeviceModel.GotifyUrl, deviceModel.ClientToken);
GotifySocketService.StartWsThread(deviceModel.GotifyUrl, deviceModel.ClientToken);
result = "Gerät erfolgreich hinzugefügt";
resultBool = true;
} else {
Expand Down
6 changes: 3 additions & 3 deletions Models/DeviceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace iGotify_Notification_Assist.Models;

public class DeviceModel
{
public string ClientToken { get; init; } = "";
public static string DeviceToken => "";
public static string GotifyUrl => "";
public string ClientToken { get; set; }

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, armv7)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, armv7)

Non-nullable property 'ClientToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 8 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Non-nullable member is uninitialized.

Non-nullable property 'ClientToken' is uninitialized. Consider declaring the property as nullable.
public string DeviceToken { get; set; }

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, armv7)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, armv7)

Non-nullable property 'DeviceToken' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 9 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Non-nullable member is uninitialized.

Non-nullable property 'DeviceToken' is uninitialized. Consider declaring the property as nullable.
public string GotifyUrl { get; set; }

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, amd64)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, arm64)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, armv7)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Build dotNet (8.x, armv7)

Non-nullable property 'GotifyUrl' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 10 in Models/DeviceModel.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Non-nullable member is uninitialized.

Non-nullable property 'GotifyUrl' is uninitialized. Consider declaring the property as nullable.

/// <summary>
/// Add device token to txt file
Expand Down
2 changes: 1 addition & 1 deletion Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static async Task<bool> InsertUser(DeviceModel dm)
dbConnection.Open();

// Create a sample table
var insertQuery = $"insert into Users (ClientToken, DeviceToken, GotifyUrl) values ('{dm.ClientToken}', '{DeviceModel.DeviceToken}', '{DeviceModel.GotifyUrl}');";
var insertQuery = $"insert into Users (ClientToken, DeviceToken, GotifyUrl) values ('{dm.ClientToken}', '{dm.DeviceToken}', '{dm.GotifyUrl}');";
var id = await dbConnection.ExecuteAsync(insertQuery);

inserted = id > 0;
Expand Down
55 changes: 55 additions & 0 deletions Services/GotifySocketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,61 @@ public async void Start()
{
var secntfyUrl = Environment.GetEnvironmentVariable("SECNTFY_SERVER_URL") ?? "https://api.secntfy.app";

// [FEATURE REQUEST] #59 - https://github.com/androidseb25/iGotify-Notification-Assistent/issues/59
// First try of implementing local running instances without app configuration
var gotifyServers = Environment.GetEnvironmentVariable("GOTIFY_SERVERS") ?? "";
var gotifyClientTokens = Environment.GetEnvironmentVariable("GOTIFY_CLIENTS") ?? "";
var ntfyTokens = Environment.GetEnvironmentVariable("NTFY_TOKENS") ?? "";

var gotifyServerList = new List<string>();
var gotifyClientList = new List<string>();
var ntfyTokenList = new List<string>();

if (gotifyServers.Length > 0 && gotifyClientTokens.Length > 0 && ntfyTokens.Length > 0)
{
try
{
gotifyServerList = gotifyServers.Split(";").ToList();
gotifyClientList = gotifyClientTokens.Split(";").ToList();
ntfyTokenList = ntfyTokens.Split(";").ToList();

var clientCounter = 0;
foreach (string client in gotifyClientList)
{
var dm = new DeviceModel();
dm.ClientToken = client;
if (!await DatabaseService.CheckIfUserExists(dm))
{
dm.GotifyUrl = gotifyServerList.ElementAt(clientCounter);
dm.DeviceToken = ntfyTokenList.ElementAt(clientCounter);
if (!await DatabaseService.InsertUser(dm))
{
throw new ApplicationException("Insert Database Exception!");
}
}

clientCounter++;
}
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
Console.WriteLine("Something went wrong when inserting you're connection!");
Console.WriteLine("Please check you're environment lists!");
}
}
else
{
var statusServerList = gotifyServerList.Count == 0 ? "empty" : "filled";
Console.WriteLine($"Gotify Server list is: {statusServerList}");
var statusClientList = gotifyClientList.Count == 0 ? "empty" : "filled";
Console.WriteLine($"Gotify Client list is: {statusClientList}");
var statusNtfyList = ntfyTokenList.Count == 0 ? "empty" : "filled";
Console.WriteLine($"NTFY Token list is: {statusNtfyList}");
Console.WriteLine($"If one or more lists are empty please check the environment variable! GOTIFY_SERVERS or GOTIFY_CLIENTS or NTFY_TOKENS");
Console.WriteLine($"If all lists are empty do nothing, you will configure the gotify server over the iGotify app.");
}

var userList = await DatabaseService.GetUsers();

StartConnection(userList, secntfyUrl);
Expand Down
6 changes: 3 additions & 3 deletions iGotify Notification Assist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<PackageReference Include="Dapper" Version="2.1.44" />
<PackageReference Include="Dapper.Contrib" Version="2.0.78" />
<PackageReference Include="Dapper.Mapper" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.5" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="secntfy.nuget" Version="1.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Websocket.Client" Version="5.1.1" />
</ItemGroup>

Expand Down

0 comments on commit 221186f

Please sign in to comment.