Skip to content

Commit

Permalink
Add redis playground as well as launchsettings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeline committed Nov 5, 2024
1 parent 7749940 commit c0ff3c1
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Azure/RedisPlayground/RedisPlayground.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedisPlayground", "RedisPlayground\RedisPlayground.csproj", "{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20A28F41-5F94-4030-B2B2-2E4AB2243DB2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions Azure/RedisPlayground/RedisPlayground/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.IO.Compression;
using System.Text;

namespace RedisPlayground;

public static class Extensions
{
public static string Decompress(string s)
{
var bytes = Convert.FromBase64String(s);
using var memoryStreamInput = new MemoryStream(bytes);
using var memoryStreamOutput = new MemoryStream();
using var gzipStream = new GZipStream(memoryStreamInput, CompressionMode.Decompress);
gzipStream.CopyTo(memoryStreamOutput);
return Encoding.Unicode.GetString(memoryStreamOutput.ToArray());
}
}
44 changes: 44 additions & 0 deletions Azure/RedisPlayground/RedisPlayground/Models/AccountLoanSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Text.Json.Serialization;

namespace RedisPlayground.Models;

public class AccountLoanSummary
{
public decimal? PrincipalAmount { get; set; }
public decimal? InterestAmount { get; set; }
public decimal? TotalLateFeeAmount { get; set; }
public decimal? TotalNSFFeeAmount { get; set; }
public decimal? PerDiem { get; set; }
public decimal? PayOffAmount { get; set; }
public decimal? APRRate { get; set; }
public DateTime? CurrentMaturityDate { get; set; }
public int? NumberOfPaymentsRemaining { get; set; }
public decimal? InsuranceAmountDelinquent { get; set; }
public DateTime? PastDueSinceDate { get; set; }
public decimal? AmountToRoll { get; set; }
public int? NumberOfPaymentsMade { get; set; }
public DateTime? NextPaymentDueDate { get; set; }
public decimal? PastDueAmount { get; set; }
public int NumberOfDaysPastDue { get; set; }
public decimal TotalAmountDue { get; set; }
public decimal NextAmountDue { get; set; }
public decimal AmountDueNow { get; set; }
public DateTime? StatusChangeEffectiveDate { get; set; }
public int? StatusReasonCode { get; set; }
public string StatusReasonDescription { get; set; }
public string ReportLot { get; set; }
public DateTime? SaleDate { get; set; }
public decimal? PaymentAmount { get; set; }
public decimal? OriginalLoanBalance { get; set; }
public short? TotalNumberOfPayments { get; set; }
[JsonConverter(typeof(NullConverter))]
public short? PaymentDueDayOne { get; set; }
[JsonConverter(typeof(NullConverter))]
public short? PaymentDueDayTwo { get; set; }
public DateTime? OriginalMaturityDate { get; set; }
public string PaymentFrequencyName { get; set; }
public decimal? OriginalAPR { get; set; }
public char AccountStatusKey { get; set; }
public bool IsDisplayReason { get; set; }
public int CurrentPoolNumber { get; set; }
}
18 changes: 18 additions & 0 deletions Azure/RedisPlayground/RedisPlayground/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// See https://aka.ms/new-console-template for more information

using RedisPlayground;


// var devRedisHost = "localhost";
// var devRedisPort = 6380;
// var devRedisConnection = "localhost:6379";
// var devRedisConnection = "";
var testRedisConnection = "";
var testRedisHost = "";

var redisExtensions = new RedisExtensions(testRedisConnection, testRedisHost);

var keys = TimerExtensions.TimeIt(redisExtensions.GetAllKeys);
var results = await TimerExtensions.TimeItAsync(() => redisExtensions.GetAllRecords(keys));

Console.WriteLine($"Got back {results.Count} results");
76 changes: 76 additions & 0 deletions Azure/RedisPlayground/RedisPlayground/RedisExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using Newtonsoft.Json;
using RedisPlayground.Models;
using StackExchange.Redis;

namespace RedisPlayground;

public class RedisExtensions
{
private readonly ConnectionMultiplexer _redis;
private readonly string _redisHost;

public RedisExtensions(string redisConnection, string redisHost)
{
Console.WriteLine($"host: {redisHost}: connecting to {redisConnection}");
_redisHost = redisHost;
_redis = ConnectionMultiplexer.Connect(redisConnection);
}

public List<string> GetAllKeys()
{
var listKeys = new List<string>();
var keys = _redis.GetServer(_redisHost, 6380).Keys(pattern: "AccountLoanSummary").ToList();
listKeys.AddRange(keys.Select(key => (string) key).ToList());
return listKeys;
}

public async Task<List<AccountLoanSummary>> GetAllRecords(List<string> keys)
{
var db = _redis.GetDatabase();
var results = new List<AccountLoanSummary>();
var totalKeys = keys.Count;
var count = 1;
var errorCount = 0;
foreach (var key in keys)
{
var redisValue = (await db.StringGetAsync(key)).ToString();
// var accountLoanSummary = new AccountLoanSummary
// {
//
// }
try
{
var decompressedResult = Extensions.Decompress(redisValue);
var result = JsonConvert.DeserializeObject<AccountLoanSummary>(decompressedResult);

results.Add(result);
Console.WriteLine($"Grabbed {count}/{totalKeys} - {errorCount}");
count++;
}
catch (Exception ex)
{
errorCount++;
}
}

return results;
}
}

public class NullConverter: JsonConverter
{
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
throw new NotImplementedException();
}

public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
return existingValue;
}

public override bool CanConvert(Type objectType)
{
throw new NotImplementedException();
}
}
15 changes: 15 additions & 0 deletions Azure/RedisPlayground/RedisPlayground/RedisPlayground.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.70" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions Azure/RedisPlayground/RedisPlayground/TimerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Diagnostics;

namespace RedisPlayground;

public static class TimerExtensions
{
public static TOutput TimeIt<TOutput>(Func<TOutput> func)
{
var stopwatch = Stopwatch.StartNew();
var output = func();
stopwatch.Stop();
var ts = stopwatch.Elapsed;
Console.WriteLine($"Took: {ts.Minutes}Minutes, {ts.Seconds} seconds to execute");
return output;
}

public static async Task<List<TOutput>> TimeItAsync<TOutput>(Func<Task<List<TOutput>>> func)
{
var stopwatch = Stopwatch.StartNew();
var output = await func();
stopwatch.Stop();
var ts = stopwatch.Elapsed;
Console.WriteLine($"Took: {ts.Minutes}Minutes, {ts.Seconds} seconds to execute");
return output;
}
}
31 changes: 31 additions & 0 deletions Azure/ServiceBusExample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53626",
"sslPort": 44318
}
},
"profiles": {
"ServiceBusExample": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7152;http://localhost:5260",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
9 changes: 9 additions & 0 deletions Azure/WeatherDataProcessor/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
"WeatherDataProcessor": {
"commandName": "Project",
"commandLineArgs": "--port 7076",
"launchBrowser": false
}
}
}
6 changes: 6 additions & 0 deletions BlazorApp1/BlazorApp1.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication2", "WebAppli
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorApp2", "BlazorApp2\BlazorApp2.csproj", "{93F8BECC-119B-483F-AC07-5376E9579523}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorApp3", "BlazorApp3\BlazorApp3.csproj", "{B08117F6-B9F5-4C31-A97E-DA1AFE5A289B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,5 +32,9 @@ Global
{93F8BECC-119B-483F-AC07-5376E9579523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93F8BECC-119B-483F-AC07-5376E9579523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93F8BECC-119B-483F-AC07-5376E9579523}.Release|Any CPU.Build.0 = Release|Any CPU
{B08117F6-B9F5-4C31-A97E-DA1AFE5A289B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B08117F6-B9F5-4C31-A97E-DA1AFE5A289B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B08117F6-B9F5-4C31-A97E-DA1AFE5A289B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B08117F6-B9F5-4C31-A97E-DA1AFE5A289B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
38 changes: 38 additions & 0 deletions BlazorApp1/BlazorApp3/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61702",
"sslPort": 44373
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5236",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7199;http://localhost:5236",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");

0 comments on commit c0ff3c1

Please sign in to comment.