Skip to content

Commit

Permalink
Unit test added, toolbox build started with numerous utilities, exten…
Browse files Browse the repository at this point in the history
…sions, and other useful tools.
  • Loading branch information
mathis1337 committed Aug 15, 2023
1 parent 85f4be5 commit 0a85da4
Show file tree
Hide file tree
Showing 38 changed files with 2,821 additions and 14 deletions.
14 changes: 14 additions & 0 deletions ArcherConsole/ArcherConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ArcherCore\ArcherCore.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions ArcherConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// See https://aka.ms/new-console-template for more information

using ArcherCore.Http;
using Newtonsoft.Json;
using System;
using System.Net.Http.Headers;
using static ArcherCore.APIs.APIUtilities;

internal class Program
{
private static async Task Main(string[] args)
{
await ArcherCore.Archer.SetupHttpClientFactory();

//var _httpClientFactory = HttpVariables.HttpClientFactory;
//using(var client = _httpClientFactory.CreateClient())
//{
// var productValue = new ProductInfoHeaderValue("RBX-Version-Check", "1.0");

// client.DefaultRequestHeaders.UserAgent.Add(productValue);
// var httpResponse = await client.GetAsync("https://api.github.com/repos/ReserveBlockIO/ReserveBlock-Core/releases/latest");
// var responseString = await httpResponse.Content.ReadAsStringAsync();
// var release = JsonConvert.DeserializeObject<Release>(responseString.ToString());
//}

while (true)
{
Console.Write("» ");
var input = Console.ReadLine();
var isUpper = ArcherCore.Strings.StringUtilities.StartsWithUpper(input);
var isLower = ArcherCore.Strings.StringUtilities.StartsWithLower(input);
var upperResult = isUpper ? "Yes" : "No";
var lowerResult = isLower ? "Yes" : "No";
Console.WriteLine($"Is Upper? {upperResult}");
Console.WriteLine($"Is Lower? {lowerResult}");
}
}
}
14 changes: 13 additions & 1 deletion ArcherCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArcherCore", "ArcherCore\ArcherCore.csproj", "{167CDD94-CB03-44EE-8782-B61274EF4F44}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArcherCore", "ArcherCore\ArcherCore.csproj", "{167CDD94-CB03-44EE-8782-B61274EF4F44}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArcherConsole", "ArcherConsole\ArcherConsole.csproj", "{1AFC7564-4A73-4CD9-82B9-EFBDA49634DD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArcherTest", "ArcherTest\ArcherTest.csproj", "{1146157E-7887-400F-8D67-74EADE1C99F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +19,14 @@ Global
{167CDD94-CB03-44EE-8782-B61274EF4F44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{167CDD94-CB03-44EE-8782-B61274EF4F44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{167CDD94-CB03-44EE-8782-B61274EF4F44}.Release|Any CPU.Build.0 = Release|Any CPU
{1AFC7564-4A73-4CD9-82B9-EFBDA49634DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AFC7564-4A73-4CD9-82B9-EFBDA49634DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AFC7564-4A73-4CD9-82B9-EFBDA49634DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AFC7564-4A73-4CD9-82B9-EFBDA49634DD}.Release|Any CPU.Build.0 = Release|Any CPU
{1146157E-7887-400F-8D67-74EADE1C99F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1146157E-7887-400F-8D67-74EADE1C99F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1146157E-7887-400F-8D67-74EADE1C99F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1146157E-7887-400F-8D67-74EADE1C99F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
137 changes: 137 additions & 0 deletions ArcherCore/APIs/APIUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace ArcherCore.APIs
{
public static class APIUtilities
{
//"https://api.github.com/repos/ReserveBlockIO/ReserveBlock-Core/releases/latest"
public static async Task<Release?> GetLatestGithubRelease(string url)
{
try
{
HttpClient client = new HttpClient();
var productValue = new ProductInfoHeaderValue("RBX-Version-Check", "1.0");

client.DefaultRequestHeaders.UserAgent.Add(productValue);
var httpResponse = await client.GetAsync(url);
var responseString = await httpResponse.Content.ReadAsStringAsync();
var release = JsonConvert.DeserializeObject<Release>(responseString.ToString());

return release;
}
catch { return null; }

}
public class Release
{
public string url { get; set; }

public string html_url { get; set; }

public string assets_url { get; set; }

public string upload_url { get; set; }

public int id { get; set; }
public string node_id { get; set; }

public string tag_name { get; set; }

public string target_commitish { get; set; }

public string name { get; set; }

public string body { get; set; }

public bool draft { get; set; }

public bool prerelease { get; set; }

public DateTimeOffset created_at { get; set; }

public DateTimeOffset? published_at { get; set; }

public Author author { get; set; }

public string tarball_url { get; set; }

public string zipball_url { get; set; }

public IReadOnlyList<ReleaseAsset> assets { get; set; }
}

public class ReleaseAsset
{

public string url { get; set; }

public int id { get; set; }
public string node_id { get; set; }

public string name { get; set; }

public string label { get; set; }

public string State { get; set; }

public string content_type { get; set; }

public int size { get; set; }

public int download_count { get; set; }

public DateTimeOffset created_at { get; set; }

public DateTimeOffset updated_at { get; set; }

public string browser_download_url { get; set; }

public Author uploader { get; set; }

}

public class Author
{
public string login { get; set; }

Check warning on line 101 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'login' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public int Id { get; set; }

public string node_id { get; set; }

Check warning on line 105 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'node_id' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string avatar_url { get; set; }

Check warning on line 107 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'avatar_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string url { get; set; }

Check warning on line 109 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string html_url { get; set; }

Check warning on line 111 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'html_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string followers_url { get; set; }

Check warning on line 113 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'followers_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string following_url { get; set; }

Check warning on line 115 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'following_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string gists_url { get; set; }

Check warning on line 117 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'gists_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string starred_url { get; set; }

Check warning on line 119 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'starred_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string subscriptions_url { get; set; }

Check warning on line 121 in ArcherCore/APIs/APIUtilities.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'subscriptions_url' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public string organizations_url { get; set; }

public string repos_url { get; set; }

public string events_url { get; set; }

public string received_events_url { get; set; }

public string type { get; set; }

public bool site_admin { get; set; }

}
}
}
50 changes: 50 additions & 0 deletions ArcherCore/Archer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using ArcherCore.Email;
using ArcherCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Globalization;
using System.Net.Mail;

namespace ArcherCore
{
public static class Archer
{
public static async Task SetupEmail(string host, int port, SmtpDeliveryMethod deliveryMethod, bool enableSsl = true, bool useDefaultCreds = false)
{
EmailVariables.Host = host;
EmailVariables.Port = port;
EmailVariables.SmtpDeliveryMethod = deliveryMethod;
EmailVariables.EnableSSL = enableSsl;
EmailVariables.UseDefaultCredentials = useDefaultCreds;
}

public static async Task SetupHttpClientFactory(bool enableLogging = false, string[]? args = null)
{
var httpClientBuilder = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHttpClient();
services.AddTransient<HttpService>();
})
.ConfigureLogging(enableLogging ? loggingBuilder => loggingBuilder.AddSimpleConsole() : loggingBuilder => loggingBuilder.ClearProviders())
.Build();

await httpClientBuilder.StartAsync();
HttpVariables.HttpClientFactory = httpClientBuilder.Services.GetRequiredService<HttpService>().HttpClientFactory();
}

public static async Task ForceUSCulture()
{
var culture = CultureInfo.GetCultureInfo("en-US");
if (Thread.CurrentThread.CurrentCulture.Name != "en-US")
{
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
}
}
}
11 changes: 5 additions & 6 deletions ArcherCore/ArcherCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@

<ItemGroup>
<Folder Include="Logging\" />
<Folder Include="ElipticCurve\" />
<Folder Include="Encryption\" />
<Folder Include="Email\" />
<Folder Include="Database\" />
<Folder Include="Hashing\" />
<Folder Include="BackgroundTask\" />
<Folder Include="Memory\" />
<Folder Include="Compression\" />
<Folder Include="Backup\" />
<Folder Include="Port\" />
<Folder Include="Random\" />
<Folder Include="Time\" />
<Folder Include="WebRequest\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.17" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
Binary file added ArcherCore/Assets/Images/aclogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions ArcherCore/Class1.cs

This file was deleted.

15 changes: 15 additions & 0 deletions ArcherCore/ElipticCurve/Base.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ArcherCore.EllipticCurve
{
public static class Base64
{
public static byte[] decode(string base64String)
{
return Convert.FromBase64String(base64String);
}

public static string encode(byte[] bytes)
{
return Convert.ToBase64String(bytes);
}
}
}
Loading

0 comments on commit 0a85da4

Please sign in to comment.