Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
juleswhi committed Mar 19, 2024
1 parent 928de97 commit 24278fd
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 47 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions src/FormSystem/FormManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ public static class FormManager
#region State Management
public static State GlobalState { get; set; } = new State();

public static Forms.formMaster GetActiveForm()
public static Forms.formMaster GetActiveForm()
{
Form? active = Form.ActiveForm;

if(active is null)
if (active is null)
{
// Create form
return CreateForm<Forms.formMaster>()!;
}

if(active is Forms.formMaster master)
if (active is Forms.formMaster master)
{
return master;
}
Expand All @@ -38,7 +38,7 @@ public static Forms.formMaster GetActiveForm()

Panel? formHolder = GetActiveForm().Controls.OfType<Panel>().FirstOrDefault();

if(formHolder is null)
if (formHolder is null)
{
return;
}
Expand All @@ -64,7 +64,7 @@ public static Forms.formMaster GetActiveForm()
{
T instance = Activator.CreateInstance<T>();

if(instance is null)
if (instance is null)
{
return CreateFormInstace<T>();
}
Expand All @@ -76,7 +76,7 @@ public static Forms.formMaster GetActiveForm()
{
var method = typeof(IState).GetMethods()[0];

if(method is not null && typeof(IState).IsAssignableFrom(typeof(T)))
if (method is not null && typeof(IState).IsAssignableFrom(typeof(T)))
{
method!.Invoke(instance, [state]);
}
Expand Down
15 changes: 5 additions & 10 deletions src/Globals.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
global using State = System.Collections.Generic.Dictionary<System.Collections.Generic.IEnumerable<StateSystem.StateType>, object?>;

// State
global using static StateSystem.StateHelper;
global using static StateSystem.StateType;

// System namespaces
global using System.Reflection;
// FormManager
global using static FormSystem.FormHelper;

// Scraper
global using static Scraper.ScrapeType;

// System namespaces
global using System.Reflection;
// State
global using static StateSystem.StateHelper;
global using State = System.Collections.Generic.Dictionary<System.Collections.Generic.IEnumerable<StateSystem.StateType>, object?>;

14 changes: 8 additions & 6 deletions src/MiscTools/FileHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using UserSystem;
using Newtonsoft.Json;

using Newtonsoft.Json;
using UserSystem;
using JsonString = string;

namespace CourseworkTooling;
Expand Down Expand Up @@ -44,7 +43,7 @@ public static void SerializeWrite<T>(this T? data, string? path = null)

T? data = json.Deserialize<T>();

if(data is T val)
if (data is T val)
{
return val;
}
Expand Down Expand Up @@ -85,9 +84,12 @@ public static void Write<T>(this string data, string? path = null)
path ??= TypeToFilePathMap.ContainsKey(typeof(T)) ?
TypeToFilePathMap[typeof(T)] : null;

if (path is null) return;
if (path is null)
{
return;
}

using StreamWriter sw = new StreamWriter(path, false);
using StreamWriter sw = new(path, false);

sw.WriteLine(data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/MiscTools/HashTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static bool VerifyHash(UserBase user, string password)
HashAlgorithmName.SHA512,
64);

if(Encoding.UTF8.GetString(hashed) == user.Password.Value.Hashed)
if (Encoding.UTF8.GetString(hashed) == user.Password.Value.Hashed)
{
return true;
}
Expand Down
25 changes: 25 additions & 0 deletions src/SSDCourseworkTooling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,33 @@
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Title>SSD Coursework Tooling</Title>
<Version>0.1.0</Version>
<Authors>Jules White</Authors>
<Company>$(Authors), FSL</Company>
<Description>A collection of tools to improve the development experience of SSD Coursework
</Description>
<PackageProjectUrl>https://github.com/juleswhi/ssd-winforms-tooling</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/juleswhi/ssd-winforms-tooling</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>winforms tooling, ssd, fsl, software systems development, jules white, ssd coursework, coursework, juleswhite, ssd tooling</PackageTags>
<PackageReleaseNotes>Initial Commit!. Added: Form System, Logging System, Misc Tools, Scraper, State System and a User System!</PackageReleaseNotes>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\LICENSE">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
30 changes: 16 additions & 14 deletions src/Scraper/Scrape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Scrape(ScrapeType? scrapeType = null, Assembly? assembly = nu
scrapeType ??= Config.Type;
assembly ??= Assembly.GetCallingAssembly();

if(!File.Exists(Config.Path))
if (!File.Exists(Config.Path))
{
File.Create(Config.Path);
}
Expand All @@ -41,7 +41,7 @@ public static void Scrape(ScrapeType? scrapeType = null, Assembly? assembly = nu

using StreamWriter sw = new(Config.Path, true);

if(sw is null)
if (sw is null)
{
return;
}
Expand All @@ -51,7 +51,7 @@ public static void Scrape(ScrapeType? scrapeType = null, Assembly? assembly = nu
Type form = typeof(Form);
List<Type> forms = types.Where(x => x.IsSubclassOf(form) || x == form).ToList();

foreach(Type type in forms)
foreach (Type type in forms)
{
var instance = Activator.CreateInstance(type);

Expand All @@ -61,14 +61,14 @@ public static void Scrape(ScrapeType? scrapeType = null, Assembly? assembly = nu

var controlProp = type.GetProperty("Controls");

if(controlProp is null)
if (controlProp is null)
{
continue;
}

Control.ControlCollection? controls = controlProp.GetValue(instance) as Control.ControlCollection;

if(controls is null)
if (controls is null)
{
continue;
}
Expand All @@ -80,16 +80,16 @@ public static void Scrape(ScrapeType? scrapeType = null, Assembly? assembly = nu
_ => Config.ScrapeFilter.ToImmutableHashSet()
};

if(filter is null)
if (filter is null)
{
continue;
}

foreach(Control control in controls)
foreach (Control control in controls)
{
sw!.WriteLine($"{control.Name}:");

foreach(var str in GetInformation(control, filter))
foreach (var str in GetInformation(control, filter))
{
sw!.WriteLine(str);
}
Expand All @@ -101,7 +101,7 @@ public static void Scrape(ScrapeType? scrapeType = null, Assembly? assembly = nu
}
GC.Collect();
}


/// <summary>
/// Gets the property information of a control, and filters it by the appropriate hashset
Expand All @@ -114,9 +114,9 @@ private static IEnumerable<string> GetInformation<T>(T control, ImmutableHashSet
{
var props = control.GetType().GetProperties();

foreach(var prop in props)
foreach (var prop in props)
{
if(filter is null || !filter.Contains(prop.Name))
if (filter is null || !filter.Contains(prop.Name))
{
continue;
}
Expand All @@ -127,7 +127,7 @@ private static IEnumerable<string> GetInformation<T>(T control, ImmutableHashSet
{
str = $"\t\t{prop.Name}: {PrettyPrint(prop.GetMethod?.Invoke(control, []))}";
}
catch(Exception)
catch (Exception)
{
continue;
}
Expand Down Expand Up @@ -166,6 +166,8 @@ private static IEnumerable<string> GetInformation<T>(T control, ImmutableHashSet
/// Overwrites contents of a file with null text
/// </summary>
/// <param name="path">The path to the file</param>
private static void ClearFile(string path) => File.WriteAllText(path, "");

private static void ClearFile(string path)
{
File.WriteAllText(path, "");
}
}
2 changes: 1 addition & 1 deletion src/StateSystem/DefaultState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
public abstract class DefaultState : IState
{
public virtual void State(State state)
{}
{ }
}
4 changes: 2 additions & 2 deletions src/StateSystem/StateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static class StateHelper
/// <returns>A combined state</returns>
public static State AddState(this State a, State b)
{
foreach(var kvp in b)
foreach (var kvp in b)
{
if(!a.ContainsKey(kvp.Key))
if (!a.ContainsKey(kvp.Key))
{
a.Add(kvp.Key, kvp.Value);
}
Expand Down
22 changes: 15 additions & 7 deletions src/UserSystem/UserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace UserSystem;
public abstract class UserBase : IEquatable<UserBase>, IEquatable<string>, IComparable<UserBase>, IComparable<int>
{
// Properties that every user should have
public virtual string? Username { get; set; }
public virtual string? Username { get; set; }
public virtual Password? Password { get; set; }
public virtual MailAddress? Email { get; set; }
public virtual MailAddress? Email { get; set; }
public virtual DateTime? DOB { get; set; }
public virtual string[]? FullName { get; set; }
public virtual string[]? FullName { get; set; }


public static string UserPath = "users.json";
Expand All @@ -24,8 +24,16 @@ public abstract class UserBase : IEquatable<UserBase>, IEquatable<string>, IComp

public virtual bool Equals(string? other)
{
if (other is null) return false;
if (Username is null) return false;
if (other is null)
{
return false;
}

if (Username is null)
{
return false;
}

return Username.Equals(other);
}

Expand All @@ -34,12 +42,12 @@ public virtual bool Equals(UserBase? other)
return Equals(other);
}

public static bool operator==(UserBase a, UserBase b)
public static bool operator ==(UserBase a, UserBase b)
{
return a.Equals(b);
}

public static bool operator!=(UserBase a, UserBase b)
public static bool operator !=(UserBase a, UserBase b)
{
return !a.Equals(b);
}
Expand Down

0 comments on commit 24278fd

Please sign in to comment.