Skip to content

Commit

Permalink
Major code refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Plenyx committed Jan 31, 2025
1 parent bce6225 commit bbc11c0
Show file tree
Hide file tree
Showing 159 changed files with 10,291 additions and 10,298 deletions.
38 changes: 38 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

[*]

# Microsoft .NET properties
csharp_new_line_before_members_in_object_initializers = false
dotnet_sort_system_directives_first = false

# ReSharper properties
resharper_blank_lines_after_block_statements = 0
resharper_blank_lines_around_auto_property = 0
resharper_blank_lines_around_property = 0
resharper_braces_for_for = required
resharper_braces_for_foreach = required
resharper_braces_for_ifelse = not_required
resharper_braces_redundant = false
resharper_csharp_blank_lines_around_field = 0
resharper_csharp_blank_lines_around_invocable = 0
resharper_csharp_blank_lines_around_region = 0
resharper_csharp_blank_lines_inside_region = 0
resharper_csharp_empty_block_style = together_same_line
resharper_csharp_insert_final_newline = true
resharper_csharp_max_line_length = 438
resharper_csharp_remove_blank_lines_near_braces_in_code = false
resharper_csharp_remove_blank_lines_near_braces_in_declarations = false
resharper_csharp_wrap_before_binary_opsign = true
resharper_csharp_wrap_before_ternary_opsigns = false
resharper_csharp_wrap_ternary_expr_style = wrap_if_long
resharper_instance_members_qualify_declared_in =
resharper_method_or_operator_body = expression_body
resharper_parentheses_non_obvious_operations = none, multiplicative, additive, arithmetic, shift, relational, equality, bitwise_and, bitwise_exclusive_or, bitwise_inclusive_or, bitwise
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_expr_accessor_on_single_line = true
resharper_place_expr_property_on_single_line = true
resharper_place_simple_accessor_on_single_line = false
resharper_place_simple_initializer_on_single_line = false
resharper_trailing_comma_in_multiline_lists = true
resharper_wrap_before_arrow_with_expressions = true
resharper_wrap_object_and_collection_initializer_style = chop_always
23 changes: 11 additions & 12 deletions Aleeva/AleevaAddReport.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Newtonsoft.Json;

namespace PlenBotLogUploader.Aleeva
namespace PlenBotLogUploader.Aleeva;

internal sealed class AleevaAddReport
{
internal sealed class AleevaAddReport
{
[JsonProperty("sendNotification")]
internal bool SendNotification { get; set; }
[JsonProperty("sendNotification")]
internal bool SendNotification { get; set; }

[JsonProperty("notificationServerId")]
internal string NotificationServerId { get; set; }
[JsonProperty("notificationServerId")]
internal string NotificationServerId { get; set; }

[JsonProperty("notificationChannelId")]
internal string NotificationChannelId { get; set; }
[JsonProperty("notificationChannelId")]
internal string NotificationChannelId { get; set; }

[JsonProperty("dpsReportPermalink")]
internal string DpsReportPermalink { get; set; }
}
[JsonProperty("dpsReportPermalink")]
internal string DpsReportPermalink { get; set; }
}
15 changes: 7 additions & 8 deletions Aleeva/AleevaAddReportResponse.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Newtonsoft.Json;

namespace PlenBotLogUploader.Aleeva
namespace PlenBotLogUploader.Aleeva;

internal sealed class AleevaAddReportResponse : AleevaResponseStatus
{
internal sealed class AleevaAddReportResponse : AleevaResponseStatus
{
[JsonProperty("dpsReport")]
internal string DpsReport { get; set; }
[JsonProperty("dpsReport")]
internal string DpsReport { get; set; }

[JsonProperty("fromCache")]
internal bool FromCache { get; set; }
}
[JsonProperty("fromCache")]
internal bool FromCache { get; set; }
}
31 changes: 15 additions & 16 deletions Aleeva/AleevaAuthToken.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using Newtonsoft.Json;

namespace PlenBotLogUploader.Aleeva
namespace PlenBotLogUploader.Aleeva;

internal sealed class AleevaAuthToken
{
internal sealed class AleevaAuthToken
{
[JsonProperty("grant_type")]
internal string GrantType { get; set; }
[JsonProperty("grant_type")]
internal string GrantType { get; set; }

[JsonProperty("client_id")]
internal string ClientId { get; } = "plen_bot_log_uploader";
[JsonProperty("client_id")]
internal string ClientId { get; } = "plen_bot_log_uploader";

[JsonProperty("client_secret")]
internal string ClientSecret { get; } = "5d5c6e0e-f658-4083-b0f1-db30f8a2e1ce";
[JsonProperty("client_secret")]
internal string ClientSecret { get; } = "5d5c6e0e-f658-4083-b0f1-db30f8a2e1ce";

[JsonProperty("access_code")]
internal string AccessCode { get; set; }
[JsonProperty("access_code")]
internal string AccessCode { get; set; }

[JsonProperty("refresh_token")]
internal string RefreshToken { get; set; }
[JsonProperty("refresh_token")]
internal string RefreshToken { get; set; }

[JsonProperty("scope")]
internal string[] Scope { get; set; }
}
[JsonProperty("scope")]
internal string[] Scope { get; set; }
}
27 changes: 13 additions & 14 deletions Aleeva/AleevaAuthTokenResponse.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using Newtonsoft.Json;

namespace PlenBotLogUploader.Aleeva
namespace PlenBotLogUploader.Aleeva;

internal sealed class AleevaAuthTokenResponse : AleevaResponseStatus
{
internal sealed class AleevaAuthTokenResponse : AleevaResponseStatus
{
[JsonProperty("accessToken")]
internal string AccessToken { get; set; }
[JsonProperty("accessToken")]
internal string AccessToken { get; set; }

[JsonProperty("refreshToken")]
internal string RefreshToken { get; set; }
[JsonProperty("refreshToken")]
internal string RefreshToken { get; set; }

[JsonProperty("tokenType")]
internal string TokenType { get; set; }
[JsonProperty("tokenType")]
internal string TokenType { get; set; }

[JsonProperty("refreshExpiresIn")]
internal int RefreshExpiresIn { get; set; }
[JsonProperty("refreshExpiresIn")]
internal int RefreshExpiresIn { get; set; }

[JsonProperty("expiresIn")]
internal int ExpiresIn { get; set; }
}
[JsonProperty("expiresIn")]
internal int ExpiresIn { get; set; }
}
17 changes: 8 additions & 9 deletions Aleeva/AleevaChannel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using Newtonsoft.Json;

namespace PlenBotLogUploader.Aleeva
namespace PlenBotLogUploader.Aleeva;

internal sealed class AleevaChannel
{
internal sealed class AleevaChannel
{
[JsonProperty("id")]
internal string Id { get; set; }
[JsonProperty("id")]
internal string Id { get; set; }

[JsonProperty("name")]
internal string Name { get; set; }
[JsonProperty("name")]
internal string Name { get; set; }

public override string ToString() => $"{Name} ({Id})";
}
public override string ToString() => $"{Name} ({Id})";
}
139 changes: 70 additions & 69 deletions Aleeva/AleevaIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,97 +10,98 @@
using System.Text;
using System.Threading.Tasks;

namespace PlenBotLogUploader.Aleeva
namespace PlenBotLogUploader.Aleeva;

[JsonObject(MemberSerialization.OptIn)]
internal class AleevaIntegration : IListViewItemInfo<AleevaIntegration>
{
[JsonObject(MemberSerialization.OptIn)]
internal class AleevaIntegration : IListViewItemInfo<AleevaIntegration>
{
[JsonProperty("active")]
internal bool Active { get; set; } = true;
private Team _team;

[JsonProperty("name")]
internal string Name { get; set; } = "";
[JsonProperty("active")]
internal bool Active { get; set; } = true;

[JsonProperty("channel")]
internal string Channel { get; set; } = "";
[JsonProperty("name")]
internal string Name { get; set; } = "";

[JsonProperty("sendNotification")]
internal bool SendNotification { get; set; } = false;
[JsonProperty("channel")]
internal string Channel { get; set; } = "";

[JsonProperty("sendOnSuccessOnly")]
internal bool SendOnSuccessOnly { get; set; } = false;
[JsonProperty("sendNotification")]
internal bool SendNotification { get; set; }

[JsonProperty("server")]
internal string Server { get; set; } = "";
[JsonProperty("sendOnSuccessOnly")]
internal bool SendOnSuccessOnly { get; set; }

[JsonProperty("teamId")]
internal int TeamId { get; set; } = 0;
[JsonProperty("server")]
internal string Server { get; set; } = "";

/// <summary>
/// A selected integration team, with which the Aleeva integration should evaluate itself
/// </summary>
internal Team Team
[JsonProperty("teamId")]
internal int TeamId { get; set; }

/// <summary>
/// A selected integration team, with which the Aleeva integration should evaluate itself
/// </summary>
internal Team Team
{
get
{
get
if (_team is null && Teams.Teams.All.TryGetValue(TeamId, out var team))
{
if ((_team is null) && Teams.Teams.All.TryGetValue(TeamId, out var team))
{
_team = team;
}
return _team;
}
set
{
_team = value;
TeamId = value.Id;
_team = team;
}
return _team;
}
set
{
_team = value;
TeamId = value.Id;
}
}

private Team _team;

internal bool Valid => !string.IsNullOrWhiteSpace(Server) && !string.IsNullOrWhiteSpace(Channel);

internal List<ListViewItemCustom<AleevaIntegration>> _connectedItems = [];
internal bool Valid => !string.IsNullOrWhiteSpace(Server) && !string.IsNullOrWhiteSpace(Channel);

string IListViewItemInfo<AleevaIntegration>.NameToDisplay => Name;
string IListViewItemInfo<AleevaIntegration>.NameToDisplay => Name;

string IListViewItemInfo<AleevaIntegration>.TextToDisplay => (!string.IsNullOrWhiteSpace(Name)) ? Name : (!string.IsNullOrWhiteSpace(Channel) ? $"C{Channel}" : $"S{Server}");
string IListViewItemInfo<AleevaIntegration>.TextToDisplay => !string.IsNullOrWhiteSpace(Name) ? Name : !string.IsNullOrWhiteSpace(Channel) ? $"C{Channel}" : $"S{Server}";

bool IListViewItemInfo<AleevaIntegration>.CheckedToDisplay => Active;
bool IListViewItemInfo<AleevaIntegration>.CheckedToDisplay => Active;

List<ListViewItemCustom<AleevaIntegration>> IListViewItemInfo<AleevaIntegration>.ConnectedItems => _connectedItems;
List<ListViewItemCustom<AleevaIntegration>> IListViewItemInfo<AleevaIntegration>.ConnectedItems { get; } = [];

internal async Task PostLogToAleeva(FormMain mainLink, HttpClientController controller, DpsReportJson reportJSON, List<LogPlayer> players)
internal async Task PostLogToAleeva(FormMain mainLink, HttpClientController controller, DpsReportJson reportJson, List<LogPlayer> players)
{
if (!ApplicationSettings.Current.Aleeva.Authorised)
{
if (!ApplicationSettings.Current.Aleeva.Authorised)
{
return;
}
if (ApplicationSettings.Current.Aleeva.AccessTokenExpire <= DateTime.Now)
{
await AleevaStatics.GetAleevaTokenFromRefreshToken(mainLink, controller);
}
if ((SendOnSuccessOnly && !(reportJSON.Encounter.Success ?? false)) ||
(!(Team?.IsSatisfied(players) ?? false)))
{
return;
}
try
return;
}
if (ApplicationSettings.Current.Aleeva.AccessTokenExpire <= DateTime.Now)
{
await AleevaStatics.GetAleevaTokenFromRefreshToken(mainLink, controller);
}
if ((SendOnSuccessOnly && !(reportJson.Encounter.Success ?? false))
|| !(Team?.IsSatisfied(players) ?? false))
{
return;
}
try
{
var logObject = new AleevaAddReport
{
var logObject = new AleevaAddReport() { DpsReportPermalink = reportJSON.ConfigAwarePermalink, SendNotification = SendNotification };
if (SendNotification)
{
logObject.NotificationServerId = Server;
logObject.NotificationChannelId = Channel;
}
var jsonLogObject = JsonConvert.SerializeObject(logObject);
using var content = new StringContent(jsonLogObject, Encoding.UTF8, "application/json");
await controller.PostAsync($"{AleevaStatics.ApiBaseUrl}/report", content);
}
catch
DpsReportPermalink = reportJson.ConfigAwarePermalink,
SendNotification = SendNotification,
};
if (SendNotification)
{
// do nothing
logObject.NotificationServerId = Server;
logObject.NotificationChannelId = Channel;
}
var jsonLogObject = JsonConvert.SerializeObject(logObject);
using var content = new StringContent(jsonLogObject, Encoding.UTF8, "application/json");
await controller.PostAsync($"{AleevaStatics.ApiBaseUrl}/report", content);
}
catch
{
// do nothing
}
}
}
Loading

0 comments on commit bbc11c0

Please sign in to comment.