Skip to content

Commit

Permalink
Get rid of newtonsoft json
Browse files Browse the repository at this point in the history
  • Loading branch information
RainOrigami committed Oct 2, 2023
1 parent 82c9bc0 commit 30260de
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 69 deletions.
15 changes: 5 additions & 10 deletions BBRAPIModuleVerfication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using BattleBitAPIRunner;
using BBRAPIModules;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Microsoft.CodeAnalysis.CSharp;
using System.Text;
using System.Collections.ObjectModel;
using System.Text.Json;

namespace BBRAPIModuleVerification;

Expand All @@ -28,7 +23,7 @@ static void Main(string[] args)
}
catch (Exception e)
{
Console.WriteLine(JsonConvert.SerializeObject(new VerificationResponse(false, Path.GetFileNameWithoutExtension(filePath), null, null, null, null, e.Message)));
Console.WriteLine(JsonSerializer.Serialize(new VerificationResponse(false, Path.GetFileNameWithoutExtension(filePath), null, null, null, null, e.Message)));
return;
}

Expand All @@ -49,7 +44,7 @@ static void Main(string[] args)

if (missingDependencies.Count > 0)
{
Console.WriteLine(JsonConvert.SerializeObject(new VerificationResponse(false, module.Name, module.Description, module.Version, module.RequiredDependencies, module.OptionalDependencies, $"Missing dependencies: {string.Join(", ", missingDependencies)}")));
Console.WriteLine(JsonSerializer.Serialize(new VerificationResponse(false, module.Name, module.Description, module.Version, module.RequiredDependencies, module.OptionalDependencies, $"Missing dependencies: {string.Join(", ", missingDependencies)}")));
return;
}

Expand All @@ -62,11 +57,11 @@ static void Main(string[] args)
}
File.WriteAllBytes($"./cache/modules/{module.Name}/{module.Name}.dll", module.AssemblyBytes);

Console.WriteLine(JsonConvert.SerializeObject(new VerificationResponse(true, module.Name, module.Description, module.Version, module.RequiredDependencies, module.OptionalDependencies, null)));
Console.WriteLine(JsonSerializer.Serialize(new VerificationResponse(true, module.Name, module.Description, module.Version, module.RequiredDependencies, module.OptionalDependencies, null)));
}
catch (Exception e)
{
Console.WriteLine(JsonConvert.SerializeObject(new VerificationResponse(false, module.Name, module.Description, module.Version, module.RequiredDependencies, module.OptionalDependencies, e.Message)));
Console.WriteLine(JsonSerializer.Serialize(new VerificationResponse(false, module.Name, module.Description, module.Version, module.RequiredDependencies, module.OptionalDependencies, e.Message)));
return;
}
}
Expand Down
8 changes: 1 addition & 7 deletions BBRAPIModules/ModuleAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BBRAPIModules;
namespace BBRAPIModules;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class ModuleAttribute : Attribute
Expand Down
7 changes: 1 addition & 6 deletions BBRAPIModules/ModuleConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;

namespace BBRAPIModules
{
Expand Down
8 changes: 1 addition & 7 deletions BBRAPIModules/ModuleReferenceAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BBRAPIModules
namespace BBRAPIModules
{
[AttributeUsage(AttributeTargets.Property)]
public class ModuleReferenceAttribute : Attribute
Expand Down
8 changes: 1 addition & 7 deletions BBRAPIModules/RequireModuleAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BBRAPIModules
namespace BBRAPIModules
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class RequireModuleAttribute : Attribute
Expand Down
1 change: 0 additions & 1 deletion BBRAPIModules/RunnerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using log4net;
using System.Diagnostics;
using System.Net;
using System.Runtime.CompilerServices;

namespace BBRAPIModules
{
Expand Down
1 change: 0 additions & 1 deletion BattleBitAPIRunner/BattleBitAPIRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 3 additions & 10 deletions BattleBitAPIRunner/Module.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
using BattleBitAPI.Common;
using BattleBitAPI;
using BattleBitAPI;
using BBRAPIModules;
using log4net;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Loader;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using BattleBitAPI.Server;
using log4net;

[assembly: InternalsVisibleTo("BBRAPIModuleVerification")]

Expand Down Expand Up @@ -127,7 +120,7 @@ private void initialize()

this.getDependencies();
this.getMetadata();

logger.Info($"Module {this.Name} has {this.RequiredDependencies.Length} required and {this.OptionalDependencies.Length} optional dependencies");

Check warning on line 124 in BattleBitAPIRunner/Module.cs

View workflow job for this annotation

GitHub Actions / build-artifacts

Dereference of a possibly null reference.

Check warning on line 124 in BattleBitAPIRunner/Module.cs

View workflow job for this annotation

GitHub Actions / build-artifacts

Dereference of a possibly null reference.
}

Expand Down
8 changes: 1 addition & 7 deletions BattleBitAPIRunner/ModuleDependencyResolver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BattleBitAPIRunner
namespace BattleBitAPIRunner
{
internal class ModuleDependencyResolver
{
Expand Down
22 changes: 14 additions & 8 deletions BattleBitAPIRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
using BBRAPIModules;
using log4net;
using log4net.Config;
using log4net.Core;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Linq;
using System.Text.Json;

namespace BattleBitAPIRunner
{
Expand Down Expand Up @@ -550,7 +547,10 @@ private void ModuleConfiguration_OnSavingRequest(object? sender, BattleBitModule
return; // nothing to save
}

File.WriteAllText(filePath, JsonConvert.SerializeObject(configurationValue, Formatting.Indented));
File.WriteAllText(filePath, JsonSerializer.Serialize(configurationValue, new JsonSerializerOptions()
{
WriteIndented = true
}));
}

private void ModuleConfiguration_OnLoadingRequest(object? sender, BattleBitModule module, PropertyInfo property, string serverName)
Expand All @@ -572,7 +572,7 @@ private void ModuleConfiguration_OnLoadingRequest(object? sender, BattleBitModul

if (File.Exists(filePath))
{
configurationValue = JsonConvert.DeserializeObject(File.ReadAllText(filePath), property.PropertyType, new JsonSerializerSettings() { ObjectCreationHandling = ObjectCreationHandling.Replace }) as ModuleConfiguration;
configurationValue = JsonSerializer.Deserialize(File.ReadAllText(filePath), property.PropertyType) as ModuleConfiguration;

if (configurationValue is null)
{
Expand All @@ -589,7 +589,10 @@ private void ModuleConfiguration_OnLoadingRequest(object? sender, BattleBitModul

if (!File.Exists(filePath))
{
File.WriteAllText(filePath, JsonConvert.SerializeObject(configurationValue, Formatting.Indented));
File.WriteAllText(filePath, JsonSerializer.Serialize(configurationValue, new JsonSerializerOptions()
{
WriteIndented = true
}));
}
}

Expand Down Expand Up @@ -617,7 +620,10 @@ private void loadConfiguration()
{
if (!File.Exists("appsettings.json"))
{
File.WriteAllText("appsettings.json", JsonConvert.SerializeObject(this.configuration, Formatting.Indented));
File.WriteAllText("appsettings.json", JsonSerializer.Serialize(this.configuration, new JsonSerializerOptions()
{
WriteIndented = true
}));
}

new ConfigurationBuilder()
Expand Down
5 changes: 0 additions & 5 deletions BattleBitAPIRunner/ServerConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using BattleBitAPI.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace BattleBitAPIRunner
{
Expand Down

0 comments on commit 30260de

Please sign in to comment.