Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

New Definitions #42

Merged
merged 22 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ dotnet_analyzer_diagnostic.category-Style.severity = none
# CS8625: Cannot convert null literal to non-nullable reference type.
dotnet_diagnostic.CS8625.severity = silent

# CS8602: Dereference of a possibly null reference.
dotnet_diagnostic.CS8602.severity = suggestion

# CS1998: Async method lacks 'await' operators and will run synchronously
dotnet_diagnostic.CS1998.severity = suggestion

[src/{Compilers,ExpressionEvaluator,Scripting}/**Test**/*.{cs,vb}]

# IDE0060: Remove unused parameter
Expand Down
14 changes: 7 additions & 7 deletions Crash.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crash", "src\Crash\Crash.csproj", "{FF5923AC-5721-4C5D-B92D-36FA02C68515}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crash.ClientTestApp", "tests\Crash.ClientTestApp\Crash.ClientTestApp.csproj", "{3D8DFE22-47A0-4B8B-BB14-79B560B1760E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F8397E91-1EEA-4960-9685-7F76B23F642D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crash.Client.Tests", "tests\Crash.Client.Tests\Crash.Client.Tests.csproj", "{770CF273-241F-401E-BCB8-C82482398042}"
Expand All @@ -31,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crash.Common.Tests", "tests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crash.Integration.Tests", "tests\Crash.Integration.Tests\Crash.Integration.Tests.csproj", "{BAB96982-1FB2-4EDF-88A5-DFA0A0EC9A36}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crash.Handlers.Tests", "tests\Crash.Handlers.Tests\Crash.Handlers.Tests.csproj", "{054BCE61-C86B-4C0B-B4FC-9B11B9D6D78F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,10 +41,6 @@ Global
{FF5923AC-5721-4C5D-B92D-36FA02C68515}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF5923AC-5721-4C5D-B92D-36FA02C68515}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF5923AC-5721-4C5D-B92D-36FA02C68515}.Release|Any CPU.Build.0 = Release|Any CPU
{3D8DFE22-47A0-4B8B-BB14-79B560B1760E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D8DFE22-47A0-4B8B-BB14-79B560B1760E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D8DFE22-47A0-4B8B-BB14-79B560B1760E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D8DFE22-47A0-4B8B-BB14-79B560B1760E}.Release|Any CPU.Build.0 = Release|Any CPU
{770CF273-241F-401E-BCB8-C82482398042}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{770CF273-241F-401E-BCB8-C82482398042}.Debug|Any CPU.Build.0 = Debug|Any CPU
{770CF273-241F-401E-BCB8-C82482398042}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -65,15 +61,19 @@ Global
{BAB96982-1FB2-4EDF-88A5-DFA0A0EC9A36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAB96982-1FB2-4EDF-88A5-DFA0A0EC9A36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAB96982-1FB2-4EDF-88A5-DFA0A0EC9A36}.Release|Any CPU.Build.0 = Release|Any CPU
{054BCE61-C86B-4C0B-B4FC-9B11B9D6D78F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{054BCE61-C86B-4C0B-B4FC-9B11B9D6D78F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{054BCE61-C86B-4C0B-B4FC-9B11B9D6D78F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{054BCE61-C86B-4C0B-B4FC-9B11B9D6D78F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3D8DFE22-47A0-4B8B-BB14-79B560B1760E} = {F8397E91-1EEA-4960-9685-7F76B23F642D}
{770CF273-241F-401E-BCB8-C82482398042} = {F8397E91-1EEA-4960-9685-7F76B23F642D}
{9CAFF6D2-E619-44BB-8BEC-75BCC9B45E40} = {F8397E91-1EEA-4960-9685-7F76B23F642D}
{BAB96982-1FB2-4EDF-88A5-DFA0A0EC9A36} = {F8397E91-1EEA-4960-9685-7F76B23F642D}
{054BCE61-C86B-4C0B-B4FC-9B11B9D6D78F} = {F8397E91-1EEA-4960-9685-7F76B23F642D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D9F64F3-0D9F-4D7F-9445-5215BF29D663}
Expand Down
5 changes: 3 additions & 2 deletions src/Crash.Common/Changes/CameraChange.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json;
using System.Text.Json;

using Crash.Common.View;

Expand Down Expand Up @@ -26,7 +26,7 @@ public ChangeAction Action
set => Change.Action = value;
}

public string Type { get; } = nameof(CameraChange);
public string Type => $"{nameof(Crash)}.{nameof(CameraChange)}";

public CameraChange()
{
Expand All @@ -36,6 +36,7 @@ public CameraChange()
public CameraChange(IChange change)
{
Change = change;
Change.Action = ChangeAction.Camera;

if (string.IsNullOrEmpty(Change.Payload))
{
Expand Down
16 changes: 8 additions & 8 deletions src/Crash.Common/Collections/FixedSizedQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ namespace Crash.Common.Collections
/// <summary>A Queue of a predetermined size</summary>
public sealed class FixedSizedQueue<T> : IReadOnlyCollection<T>
{
private readonly Queue<T> _queue;
private readonly Queue<T> _idleQueue;

public readonly int Size;

/// <summary></summary>
public FixedSizedQueue(int size)
{
Size = size;
_queue = new Queue<T>();
_idleQueue = new Queue<T>();
}

/// <summary>Adds an item to the Queue, removing the first item if adding would put it oversize.</summary>
public void Enqueue(T item)
{
if (_queue.Count >= Size)
if (_idleQueue.Count >= Size)
{
_queue.Dequeue();
_idleQueue.Dequeue();
}

_queue.Enqueue(item);
_idleQueue.Enqueue(item);
}

/// <summary></summary>
public int Count => _queue.Count;
public int Count => _idleQueue.Count;

/// <summary></summary>
public IEnumerator<T> GetEnumerator() => _queue.GetEnumerator();
public IEnumerator<T> GetEnumerator() => _idleQueue.GetEnumerator();

/// <summary></summary>
IEnumerator IEnumerable.GetEnumerator() => _queue.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => _idleQueue.GetEnumerator();

}

Expand Down
28 changes: 24 additions & 4 deletions src/Crash.Common/Communications/CrashClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;

using Crash.Common.Document;
using Crash.Common.Events;

using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR.Client;
Expand Down Expand Up @@ -130,7 +131,7 @@ internal void RegisterConnections()
_connection.Reconnecting += ConnectionReconnectingAsync;
}

public async Task StartLocalClientAsync(Action<IEnumerable<Change>> onInit)
public async Task StartLocalClientAsync()
{
if (null == _crashDoc)
{
Expand All @@ -143,13 +144,19 @@ public async Task StartLocalClientAsync(Action<IEnumerable<Change>> onInit)
throw new Exception("A User has not been assigned!");
}

this.OnInitialize += onInit;
this.OnInitialize += Init;

// TODO : Check for successful connection
await this.StartAsync();
}

public static async Task CloseLocalServerAsync(CrashDoc crashDoc)
// This isn't calling, and needs to call the Event Dispatcher
private void Init(IEnumerable<Change> changes)
{
OnInit?.Invoke(this, new CrashInitArgs(_crashDoc, changes));
}

public static void CloseLocalServer(CrashDoc crashDoc)
{
crashDoc?.LocalServer?.Stop();
crashDoc?.LocalServer?.Dispose();
Expand Down Expand Up @@ -236,7 +243,20 @@ public async Task CameraChangeAsync(Change Change)
/// Start the async connection
/// </summary>
/// <returns></returns>
public Task StartAsync() => _connection.StartAsync();
private Task StartAsync() => _connection.StartAsync();

public static event EventHandler<CrashInitArgs> OnInit;

public sealed class CrashInitArgs : CrashEventArgs
{
public readonly IEnumerable<Change> Changes;

public CrashInitArgs(CrashDoc crashDoc, IEnumerable<Change> changes)
: base(crashDoc)
{
Changes = changes;
}
}

}

Expand Down
41 changes: 22 additions & 19 deletions src/Crash.Common/Communications/CrashServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class CrashServer : IDisposable

public Process? process { get; set; }

public bool IsRunning => process is object && !process.HasExited;
public bool IsRunning => process is not null && !process.HasExited;
public bool Connected { get; private set; }

public const string ProcessName = "Crash.Server";
Expand All @@ -32,6 +32,17 @@ public CrashServer(CrashDoc crashDoc)
_crashDoc = crashDoc;
}

public const string EXTRACTED_SERVER_FILENAME = $"{CrashServer.ProcessName}.exe";
public static string BASE_DIRECTORY;
public static string SERVER_DIRECTORY => Path.Combine(BASE_DIRECTORY, "Server");
public static string SERVER_FILEPATH => Path.Combine(SERVER_DIRECTORY, EXTRACTED_SERVER_FILENAME);

static CrashServer()
{
var app_data = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create);
BASE_DIRECTORY = Path.Combine(app_data, "Crash");
}

~CrashServer()
{
Dispose(false);
Expand All @@ -54,8 +65,7 @@ public void CloseLocalServer()

internal void Start(ProcessStartInfo startInfo, int timeout = 3000)
{
string errorMessage = "Server Started Successfully";

string errorMessage;
if (checkForPreExistingServer())
{
errorMessage = "Server Process is already running!";
Expand Down Expand Up @@ -109,17 +119,12 @@ public static bool ForceCloselocalServers(int timeout = 0)

internal string getServerExecutablePath()
{
string currentDirectory = typeof(CrashServer).Assembly.Location;
string[] serverExes = Array.Empty<string>();
do
if (!File.Exists(SERVER_FILEPATH))
{
currentDirectory = Path.GetDirectoryName(currentDirectory);
serverExes = Directory.GetFiles(currentDirectory, $"{ProcessName}.exe", SearchOption.AllDirectories);
throw new DirectoryNotFoundException("Could not find server executable directory!");
}
while (null == serverExes || serverExes.Length == 0);

var serverExecutable = serverExes.FirstOrDefault();
return serverExecutable;
return SERVER_FILEPATH;
}

// https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output
Expand All @@ -141,13 +146,11 @@ internal ProcessStartInfo getStartInfo(string serverExecutable, string url)
// https://stackoverflow.com/questions/285760/how-to-spawn-a-process-and-capture-its-stdout-in-net
internal void createAndRegisterServerProcess(ProcessStartInfo startInfo)
{
if (null == startInfo)
throw new ArgumentNullException("Process Info is null");

process = new Process();
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
// process.Refresh(); // May be useful?
process = new Process
{
StartInfo = startInfo ?? throw new ArgumentNullException("Process Info is null"),
EnableRaisingEvents = true
};

// Register fresh
process.Disposed += Process_Exited;
Expand Down Expand Up @@ -221,7 +224,7 @@ public void Stop()
{
try
{
if (process is object)
if (process is not null)
{
// De-Register first to avoid duplicate calls
process.Disposed -= Process_Exited;
Expand Down
4 changes: 2 additions & 2 deletions src/Crash.Common/Communications/Logging/LogFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ private void writeLogMessage(object sender, CrashLogger.LoggingEvent e)
{
File.AppendAllLines(_logFilePath, new string[] { e.Message });
}
catch (Exception ex)
catch (Exception)
{
;

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Crash.Common/Crash.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<RootNamespace>Crash.Common</RootNamespace>
Expand All @@ -16,7 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="Crash.Changes" Version="1.0.0" />
<PackageReference Include="Crash.Changes" Version="1.0.2" />
</ItemGroup>

</Project>
8 changes: 2 additions & 6 deletions src/Crash.Common/Document/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ public struct User : IEquatable<User>

public bool Visible { get; set; } = true;

/// <summary>
/// Name of the user
/// </summary>
/// <summary>Name of the user</summary>
public string Name
{
get => _name;
set => _name = CleanedUserName(value);
}

/// <summary>
/// Color of the user
/// </summary>
/// <summary>Color of the user</summary>
public Color Color { get; set; }

public CameraState Camera { get; set; } = CameraState.Visible;
Expand Down
3 changes: 2 additions & 1 deletion src/Crash.Common/Serialization/CameraConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace Crash.Common.Serialization
/// <summary>
/// Converts the Camera class to and from JSON efficiently
/// </summary>
public class CameraConverter : JsonConverter<Camera>
public sealed class CameraConverter : JsonConverter<Camera>
{

/// <inheritdoc/>
public override Camera Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Expand Down
15 changes: 9 additions & 6 deletions src/Crash.Common/Tables/CacheTable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;

using Crash.Common.Document;

Expand All @@ -10,10 +10,10 @@ public sealed class ChangeTable : IEnumerable<IChange>
private readonly CrashDoc _crashDoc;

// TODO : Should this be async? Or Concurrent?
private ConcurrentDictionary<Guid, IChange> _cache { get; set; }
private readonly ConcurrentDictionary<Guid, IChange> _cache;

public bool IsInit = false;
public bool SomeoneIsDone = false;
public bool IsInit { get; set; } = false;
public bool SomeoneIsDone { get; set; } = false;

/// <summary>
/// Local cache constructor subscribing to RhinoApp_Idle
Expand Down Expand Up @@ -74,14 +74,17 @@ public void RemoveChanges(IEnumerable<IChange> Changes)

public bool TryGetValue<T>(Guid id, out T change) where T : IChange
{
if (_cache.TryGetValue(id, out IChange cachedChange) &&
change = default;

if (_cache.TryGetValue(id, out IChange? cachedChange) &&
cachedChange is T changeConverted)
{
if (cachedChange == default) return false;

change = changeConverted;
return true;
}

change = default;
return false;
}

Expand Down
Loading