Skip to content

Commit

Permalink
Minor bug avoidace and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsen9026 committed Nov 19, 2023
1 parent 5d749aa commit bf8cb40
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 74 deletions.
3 changes: 2 additions & 1 deletion BLAZAM.Tests/Mocks/Mock_UpdateService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

using BLAZAM.Common.Data;
using BLAZAM.FileSystem;
using BLAZAM.Update;
using BLAZAM.Update.Services;
using System;
using System.Collections.Generic;
Expand All @@ -23,7 +24,7 @@ public Mock_UpdateService() : base(new Mock_HttpClientFactory(), new()
},null)
{

SelectedBranch = "Stable";
SelectedBranch = ApplicationReleaseBranches.Stable;
}
}
}
1 change: 0 additions & 1 deletion BLAZAM/Pages/Configure/Audit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@


@code {
IEnumerable<DateTime> allDates;
List<LogonAuditLog> logonEntries = new();
List<DirectoryEntryAuditLog> auditEntries = new();
List<SystemAuditLog> systemAuditEntries = new();
Expand Down
1 change: 1 addition & 0 deletions BLAZAM/Pages/SSO.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public async Task<IActionResult> OnPost([FromFormAttribute]LoginRequest req)
}
catch (Exception ex)
{

//return new ObjectResult(ex.Message);
}
if (req.ReturnUrl.IsUrlLocalToHost())
Expand Down
2 changes: 0 additions & 2 deletions BLAZAM/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class Program



private static IAppDatabaseFactory? _programDbFactory;




Expand Down
2 changes: 1 addition & 1 deletion BLAZAMActiveDirectory/ActiveDirectoryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void Connect()
if (Status != DirectoryConnectionStatus.OK)
{
//Ok get the latest settings
ADSettings ad = Context?.ActiveDirectorySettings.FirstOrDefault();
ADSettings? ad = Context?.ActiveDirectorySettings.FirstOrDefault();
ConnectionSettings = ad;

if (ad != null)
Expand Down
3 changes: 3 additions & 0 deletions BLAZAMActiveDirectory/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~F:BLAZAM.ActiveDirectory.Searchers.ADSearch._searchResults")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:BLAZAM.ActiveDirectory.Adapters.ADOrganizationalUnit.CreateGroup(System.String)~BLAZAM.ActiveDirectory.Interfaces.IADGroup")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:BLAZAM.ActiveDirectory.Adapters.ADOrganizationalUnit.CreateUser(System.String)~BLAZAM.ActiveDirectory.Interfaces.IADUser")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:BLAZAM.ActiveDirectory.ActiveDirectoryContext.Authenticate(BLAZAM.Common.Data.LoginRequest)~BLAZAM.ActiveDirectory.Interfaces.IADUser")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~P:BLAZAM.ActiveDirectory.ActiveDirectoryContext.DirectoryContext")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~P:BLAZAM.ActiveDirectory.ActiveDirectoryContext.DomainControllers")]
3 changes: 2 additions & 1 deletion BLAZAMCommon.Tests/EncryptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void CanDecrypt()
[InlineData("sho")]
[InlineData("shor")]
[InlineData("short")]
[InlineData("short")]
[InlineData("longlonglonglong")]
[InlineData("longlonglonglonglonglonglonglonglonglonglonglong")]
[InlineData("longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong")]
Expand Down Expand Up @@ -172,7 +171,9 @@ public void Key_Tests()

}
[Theory]
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
[InlineData((string)null)]
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
[InlineData("")]
public void Key_Null_ForInvalid_EncryptionKeyString(string? seedString)
{
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMCommon/Helpers/NetworkTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static bool IsPortOpen(string hostNameOrAddress, int port)
public static bool IsAnyPortOpen(string hostNameOrAddress, int[] ports)
{
bool portOpen = false;
IPAddress ip;
IPAddress? ip;
IPAddress.TryParse(hostNameOrAddress, out ip);

foreach (int port in ports)
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMDatabase/Context/DatabaseContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ public void Export(string directory)
// Write the rows
foreach (DataRow row in table.Rows)
{
var fields = row.ItemArray.Select(f => f.ToString());
var fields = row.ItemArray.Select(f => f?.ToString());
List<string> lines = new();
foreach(var field in fields)
{
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMGui/UI/Settings/AvailableUpdate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
{
get
{
if (Update.Branch == "Stable")
if (Update.Branch == ApplicationReleaseBranches.Stable)
return Update.Version.ReleaseDate.ToLongDateString();
else
return DateTime.Parse(Update.Release.ReleaseTime.ToString()).ToLongDateString();
Expand Down
2 changes: 0 additions & 2 deletions BLAZAMGui/UI/Settings/Permissions/DelegateListItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
Group = Directory.FindEntryBySID(Level.DelegateSid);
}

bool collapse1Visible = false;

async Task DeleteDelegate()
{
Expand All @@ -75,7 +74,6 @@
}
protected async override void Save()
{
collapse1Visible = false;
Level.DelegateSid = Group.SID;
await Context.SaveChangesAsync();
await InvokeAsync(StateHasChanged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ ParentTemplateChanged(null);
@bind-SelectedResult="@SelectedGroup" />
<MudFab Size="Size.Small" StartIcon=@Icons.Material.Filled.Add
Color="Color.Primary"
OnClick="@(()=>{if(SelectedGroup!=null) AssignGroup(SelectedGroup as IADGroup);})" />
OnClick="@(async()=>{if(SelectedGroup!=null) await AssignGroup(SelectedGroup as IADGroup);})" />
</MudStack>

</Section>
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMGui/UI/Settings/UpdateSettings.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

<SettingsField Label="@AppLocalization["Update Credential Source"]">

<MudTextField T="string" Label="@AppLocalization["Update Credential Source"]" Disabled=true Value="@updateCredential.ToString().Replace('_',' ')" />
<MudTextField T="string" Label="@AppLocalization["Update Credential Source"]" Disabled=true Value="@updateCredential?.ToString().Replace('_',' ')" />
</SettingsField>

<SettingsField Label="@AppLocalization["Update Credentials"]">
Expand Down
5 changes: 4 additions & 1 deletion BLAZAMServices/AuditLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.EntityFrameworkCore;
using Serilog.Parsing;
using System.Threading.Channels;
using BLAZAM.Logger;

namespace BLAZAM.Services
{
Expand Down Expand Up @@ -172,8 +173,10 @@ private async Task<bool> Log(string action, IADComputer searchedComputer)
context.SaveChanges();
return true;
}
catch
catch(Exception ex)
{
Loggers.SystemLogger.Error("Unable to write Log to database", ex);

return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion BLAZAMServices/Background/ConnMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ConnMonitor
public ServiceConnectionState? DatabaseConnected { get => DatabaseMonitor.Status; }
public ServiceConnectionState? DirectoryConnected { get => DirectoryMonitor.Status; }

private bool _fatalDBError;
/// <summary>
/// Indicated whether the application is ready to serve users.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion BLAZAMServices/Chat/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BLAZAM.Database.Models.Chat;
using BLAZAM.Database.Models.User;
using BLAZAM.Helpers;
using BLAZAM.Logger;
using BLAZAM.Server.Data;
using BLAZAM.Session.Interfaces;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void CreateChatRoom(ChatRoom room)
}
catch (Exception ex)
{

Loggers.DatabaseLogger.Error("Unable to creat private chat room", ex);
}
}
return chat;
Expand Down
31 changes: 17 additions & 14 deletions BLAZAMSession/CurentUserStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,29 @@ public CurrentUserStateService(IApplicationUserStateService applicationUserState
if (State is null)
{
_retryTimer = new Timer(RetryGetCurrentUserState, null, 500, 500);
return;
}
if (State.IsAuthenticated)
State.IPAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress;

}

private void RetryGetCurrentUserState(object? state = null)
{

try
{
State = _applicationUserStateService.GetUserState(_httpContextAccessor.HttpContext?.User);
_retryTimer?.Dispose();

}
catch (Exception ex)
{
return;
}


try
{
State = _applicationUserStateService.GetUserState(_httpContextAccessor.HttpContext?.User);
if (State !=null && State.IsAuthenticated)
State.IPAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress;
_retryTimer?.Dispose();

}
catch (Exception ex)
{
Loggers.SystemLogger.Error("Error trying to get current user state", ex);
return;
}


}

public void Dispose()
Expand Down
2 changes: 1 addition & 1 deletion BLAZAMStatic/StaticAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class StaticAssets
public static string ApplicationIconUri = "/static/img/appicon.png";
public static string FaviconUri = "/static/img/favicon.ico";

public static byte[] AppIcon(int size = 250)
public static byte[]? AppIcon(int size = 250)
{

var dbIcon = DatabaseCache.AppIcon;
Expand Down
9 changes: 9 additions & 0 deletions BLAZAMUpdate/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~M:BLAZAM.Update.ApplicationUpdate.StartUpdate~System.String")]
[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>", Scope = "member", Target = "~P:BLAZAM.Update.Services.UpdateService.UpdateCredential")]
Loading

0 comments on commit bf8cb40

Please sign in to comment.