Skip to content

Commit

Permalink
Worked on reducing the memory consumption of the ingest app by conver…
Browse files Browse the repository at this point in the history
…ting classes to readonly record structs.
  • Loading branch information
uncheckederror committed Nov 1, 2024
1 parent fbd295a commit 0595508
Show file tree
Hide file tree
Showing 19 changed files with 350 additions and 357 deletions.
2 changes: 1 addition & 1 deletion FirstCom/Connected Services/ServiceReference1/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public string text
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="https://api.1pcom.net/")]
public partial class SMSLongcodeRoute
public partial struct SMSLongcodeRoute
{

private string routeField;
Expand Down
4 changes: 2 additions & 2 deletions FirstCom/FirstCom/FirstCom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class FirstPointCom
/// <param name="username"> The FirstPointCom username. </param>
/// <param name="password"> The FirstPointCom password. </param>
/// <returns></returns>
public static async Task<PhoneNumber[]> GetValidNumbersByNPAAsync(string username, string password, int[] areaCodes)
public static async Task<PhoneNumber[]> GetValidNumbersByNPAAsync(ReadOnlyMemory<char> username, ReadOnlyMemory<char> password, int[] areaCodes)
{
var numbers = new List<PhoneNumber>();

foreach (var code in areaCodes)
{
try
{
numbers.AddRange(await NpaNxxFirstPointCom.GetAsync(code.ToString().AsMemory(), string.Empty.AsMemory(), string.Empty.AsMemory(), username.AsMemory(), password.AsMemory()));
numbers.AddRange(await NpaNxxFirstPointCom.GetAsync(code.ToString().AsMemory(), string.Empty.AsMemory(), string.Empty.AsMemory(), username, password));
Log.Information($"[FirstPointCom] Found {numbers.Count} Phone Numbers");
}
catch (Exception ex)
Expand Down
9 changes: 5 additions & 4 deletions FirstCom/FirstCom/FirstPointComOwnedPhoneNumber.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using ServiceReference1;

using System;
using System.Threading.Tasks;

namespace FirstCom
{
public class FirstPointComOwnedPhoneNumber
{
public static async Task<DIDOrderInfoArray> GetAsync(string npa, string username, string password)
public static async Task<DIDOrderInfoArray> GetAsync(ReadOnlyMemory<char> npa, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var Auth = new Credentials
{
Username = username,
Password = password
Username = username.ToString(),
Password = password.ToString()
};

var DIDSearch = new DIDOrderQuery
{
DID = string.Empty,
NPA = npa,
NPA = npa.ToString(),
NXX = string.Empty,
RateCenter = string.Empty
};
Expand Down
9 changes: 5 additions & 4 deletions FirstCom/FirstCom/FirstPointComSMS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ServiceReference1;

using System;
using System.Threading.Tasks;

namespace FirstCom
Expand All @@ -13,17 +14,17 @@ public class FirstPointComSMS
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
public static async Task<SMSLongcodeRoute> GetSMSRoutingByDialedNumberAsync(string dialedNumber, string username, string password)
public static async Task<SMSLongcodeRoute> GetSMSRoutingByDialedNumberAsync(ReadOnlyMemory<char> dialedNumber, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var Auth = new Credentials
{
Username = username,
Password = password
Username = username.ToString(),
Password = password.ToString()
};

using var client = new DIDManagementSoapClient(DIDManagementSoapClient.EndpointConfiguration.DIDManagementSoap);

return await client.LongCodeShowRoutingAsync(Auth, dialedNumber).ConfigureAwait(false);
return await client.LongCodeShowRoutingAsync(Auth, dialedNumber.ToString());
}

public static async Task<QueryResult> EnableSMSByDialedNumberAsync(string dialedNumber, string username, string password)
Expand Down
3 changes: 2 additions & 1 deletion FirstCom/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using ServiceReference;

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down Expand Up @@ -49,7 +50,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
var numbers = new List<DIDOrderInfo>();
var results = await FirstPointComOwnedPhoneNumber.GetAsync("206", username, password).ConfigureAwait(false);
var results = await FirstPointComOwnedPhoneNumber.GetAsync("206".AsMemory(), username.AsMemory(), password.AsMemory()).ConfigureAwait(false);
await Task.Delay(1000);
});
Expand Down
8 changes: 4 additions & 4 deletions Messaging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ public static async Task<Results<Ok<RegistrationResponse>, BadRequest<Registrati
try
{
// Verify that this number is routed through our upstream provider.
var checkRouted = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber, appSettings.ConnectionStrings.PComNetUsername, appSettings.ConnectionStrings.PComNetPassword);
var checkRouted = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber.AsMemory(), appSettings.ConnectionStrings.PComNetUsername.AsMemory(), appSettings.ConnectionStrings.PComNetPassword.AsMemory());
Log.Information(System.Text.Json.JsonSerializer.Serialize(checkRouted));
registeredUpstream = checkRouted.QueryResult.code is 0 && checkRouted.epid is 265;
upstreamStatusDescription = checkRouted.QueryResult.text;
Expand All @@ -985,7 +985,7 @@ public static async Task<Results<Ok<RegistrationResponse>, BadRequest<Registrati
Log.Information(System.Text.Json.JsonSerializer.Serialize(enableSMS));
var setRouting = await FirstPointComSMS.RouteSMSToEPIDByDialedNumberAsync(dialedNumber, 265, appSettings.ConnectionStrings.PComNetUsername, appSettings.ConnectionStrings.PComNetPassword);
Log.Information(System.Text.Json.JsonSerializer.Serialize(setRouting));
var checkRoutedAgain = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber, appSettings.ConnectionStrings.PComNetUsername, appSettings.ConnectionStrings.PComNetPassword);
var checkRoutedAgain = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber.AsMemory(), appSettings.ConnectionStrings.PComNetUsername.AsMemory(), appSettings.ConnectionStrings.PComNetPassword.AsMemory());
Log.Information(System.Text.Json.JsonSerializer.Serialize(checkRouted));
registeredUpstream = checkRouted.QueryResult.code is 0 && checkRouted.epid is 265;
upstreamStatusDescription = checkRouted.QueryResult.text;
Expand Down Expand Up @@ -2005,9 +2005,9 @@ public static async Task<Results<Ok<ClientRegistration>, BadRequest<string>, Not
registration.AsDialed = dialedNumber;

// Verify that this number is routed through our upstream provider.
var checkRouted = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber, appSettings.ConnectionStrings.PComNetUsername, appSettings.ConnectionStrings.PComNetPassword);
var checkRouted = await FirstPointComSMS.GetSMSRoutingByDialedNumberAsync(dialedNumber.AsMemory(), appSettings.ConnectionStrings.PComNetUsername.AsMemory(), appSettings.ConnectionStrings.PComNetPassword.AsMemory());
registration.RegisteredUpstream = checkRouted.QueryResult.code is 0 && checkRouted.epid is 265;
registration.UpstreamStatusDescription = $"{checkRouted?.eptype} {checkRouted?.additional} {checkRouted?.QueryResult.text}".Trim();
registration.UpstreamStatusDescription = $"{checkRouted.eptype} {checkRouted.additional} {checkRouted.QueryResult.text}".Trim();

// Don't pollute the registrations with 1 prefixed numbers.
registration.AsDialed = asDialedNumber.DialedNumber;
Expand Down
8 changes: 4 additions & 4 deletions NumberSearch.DataAccess/BulkVS/OrderTn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class OrderTn
public string Mrc { get; set; } = string.Empty;
public string Nrc { get; set; } = string.Empty;

public static async Task<OrderTn[]> GetRawAsync(string npa, string nxx, string username, string password)
public static async Task<OrderTn[]> GetRawAsync(string npa, string nxx, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
string baseUrl = "https://portal.bulkvs.com/api/v1.0/";
string endpoint = "orderTn";
Expand All @@ -35,7 +35,7 @@ public static async Task<OrderTn[]> GetRawAsync(string npa, string nxx, string u
string route = $"{baseUrl}{endpoint}{npaParameter}{nxxParameter}";
try
{
return await route.WithBasicAuth(username, password).GetJsonAsync<OrderTn[]>().ConfigureAwait(false);
return await route.WithBasicAuth(username.ToString(), password.ToString()).GetJsonAsync<OrderTn[]>().ConfigureAwait(false);
}
catch (FlurlHttpException ex)
{
Expand All @@ -45,7 +45,7 @@ public static async Task<OrderTn[]> GetRawAsync(string npa, string nxx, string u
}
}

public static async Task<PhoneNumber[]> GetAsync(int inNpa, string username, string password)
public static async Task<PhoneNumber[]> GetAsync(int inNpa, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var results = await GetRawAsync(inNpa.ToString("000"), string.Empty, username, password).ConfigureAwait(false);
var output = new List<PhoneNumber>();
Expand Down Expand Up @@ -82,7 +82,7 @@ public static async Task<PhoneNumber[]> GetAsync(int inNpa, string username, str
return [.. output];
}

public static async Task<PhoneNumber[]> GetAsync(int inNpa, int inNxx, string username, string password)
public static async Task<PhoneNumber[]> GetAsync(int inNpa, int inNxx, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var results = await GetRawAsync(inNpa.ToString("000"), inNxx.ToString("000"), username, password).ConfigureAwait(false);
var output = new List<PhoneNumber>();
Expand Down
31 changes: 16 additions & 15 deletions NumberSearch.DataAccess/BulkVS/PortTn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Serilog;

using System;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

Expand All @@ -24,15 +25,15 @@ public class PortTn
public PortTnNote[] Notes { get; set; } = [];


public static async Task<PortTn> GetAsync(string orderId, string username, string password)
public static async Task<PortTn> GetAsync(ReadOnlyMemory<char> orderId, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
string baseUrl = "https://portal.bulkvs.com/api/v1.0/";
string endpoint = "portTn";
string orderIdParameter = $"?OrderId={orderId}";
string route = $"{baseUrl}{endpoint}{orderIdParameter}";
try
{
return await route.WithBasicAuth(username, password).GetJsonAsync<PortTn>().ConfigureAwait(false);
return await route.WithBasicAuth(username.ToString(), password.ToString()).GetJsonAsync<PortTn>();
}
catch (FlurlHttpException ex)
{
Expand All @@ -43,14 +44,14 @@ public static async Task<PortTn> GetAsync(string orderId, string username, strin
}
}

public static async Task<TNList[]> GetAllAsync(string username, string password)
public static async Task<TNList[]> GetAllAsync(ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
string baseUrl = "https://portal.bulkvs.com/api/v1.0/";
string endpoint = "portTn";
string route = $"{baseUrl}{endpoint}";
try
{
return await route.WithBasicAuth(username, password).GetJsonAsync<TNList[]>().ConfigureAwait(false);
return await route.WithBasicAuth(username.ToString(), password.ToString()).GetJsonAsync<TNList[]>();
}
catch (FlurlHttpException ex)
{
Expand Down Expand Up @@ -92,17 +93,17 @@ public class EndUserInfo
public string Pin { get; set; } = string.Empty;
}

public class TNList
{
public string OrderId { get; set; } = string.Empty;
public string ReferenceId { get; set; } = string.Empty;
public string TN { get; set; } = string.Empty;
[JsonPropertyName("LNP Status")]
[JsonProperty("LNP Status")]
public string LNPStatus { get; set; } = string.Empty;
public string RDD { get; set; } = string.Empty;
public string Reason { get; set; } = string.Empty;
}
public readonly record struct TNList
(
string OrderId,
string ReferenceId,
string TN,
[property: JsonPropertyName("LNP Status")]
[property: JsonProperty("LNP Status")]
string LNPStatus,
string RDD,
string Reason
);

public class PortTnAttachment
{
Expand Down
98 changes: 47 additions & 51 deletions NumberSearch.DataAccess/BulkVS/TnRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,56 @@

namespace NumberSearch.DataAccess.BulkVS
{
public class TnRecord
public readonly record struct TnRecord
(
string TN,
string Status,
string Lidb,
[property: JsonPropertyName("Portout Pin")]
[property: JsonProperty("Portout Pin")]
string PortoutPin,
TnRecord.TnRecordRouting Routing,
TnRecord.TnRecordMessaging Messaging,
[property: JsonPropertyName("TN Details")]
[property: JsonProperty("TN Details")]
TnRecord.TnRecordTNDetails TNDetails
)
{
public string TN { get; set; } = string.Empty;
public string Status { get; set; } = string.Empty;
public string Lidb { get; set; } = string.Empty;
[JsonPropertyName("Portout Pin")]
[JsonProperty("Portout Pin")]
public string PortoutPin { get; set; } = string.Empty;
public TnRecordRouting Routing { get; set; } = new();
public TnRecordMessaging Messaging { get; set; } = new();
[JsonPropertyName("TN Details")]
[JsonProperty("TN Details")]
public TnRecordTNDetails TNDetails { get; set; } = new();

public class TnRecordRouting
{
[JsonPropertyName("Trunk Group")]
[JsonProperty("Trunk Group")]
public string TrunkGroup { get; set; } = string.Empty;
[JsonPropertyName("Custom URI")]
[JsonProperty("Custom URI")]
public string CustomURI { get; set; } = string.Empty;
[JsonPropertyName("Call Forward")]
[JsonProperty("Call Forward")]
public object CallForward { get; set; } = new();
}

public class TnRecordMessaging
{
public bool Sms { get; set; }
public bool Mms { get; set; }
}

public class TnRecordTNDetails
{
[JsonPropertyName("Rate Center")]
[JsonProperty("Rate Center")]
public string RateCenter { get; set; } = string.Empty;
public string State { get; set; } = string.Empty;
public string Tier { get; set; } = string.Empty;
public bool Cnam { get; set; }
[JsonPropertyName("Activation Date")]
[JsonProperty("Activation Date")]
public string ActivationDate { get; set; } = string.Empty;
}

public static async Task<TnRecord[]> GetRawAsync(string username, string password)
public readonly record struct TnRecordRouting
(
[property: JsonPropertyName("Trunk Group")]
[property: JsonProperty("Trunk Group")]
string TrunkGroup,
[property: JsonPropertyName("Custom URI")]
[property: JsonProperty("Custom URI")]
string CustomURI,
[property: JsonPropertyName("Call Forward")]
[property: JsonProperty("Call Forward")]
object CallForward);


public readonly record struct TnRecordMessaging(bool Sms, bool Mms);

public readonly record struct TnRecordTNDetails(
[property: JsonPropertyName("Rate Center")]
[property: JsonProperty("Rate Center")]
string RateCenter,
string State,
string Tier,
bool Cnam,
[property: JsonPropertyName("Activation Date")]
[property: JsonProperty("Activation Date")]
string ActivationDate);

public static async Task<TnRecord[]> GetRawAsync(ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
string baseUrl = "https://portal.bulkvs.com/api/v1.0/";
string endpoint = "tnRecord";
string route = $"{baseUrl}{endpoint}";
try
{
return await route.WithBasicAuth(username, password).GetJsonAsync<TnRecord[]>().ConfigureAwait(false);
return await route.WithBasicAuth(username.ToString(), password.ToString()).GetJsonAsync<TnRecord[]>();
}
catch (FlurlHttpException ex)
{
Expand All @@ -77,16 +73,16 @@ public static async Task<TnRecord[]> GetRawAsync(string username, string passwor
}
}

public static async Task<TnRecord> GetByDialedNumberAsync(string dialedNumber, string username, string password)
public static async Task<TnRecord> GetByDialedNumberAsync(ReadOnlyMemory<char> dialedNumber, ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
string baseUrl = "https://portal.bulkvs.com/api/v1.0/";
string endpoint = "tnRecord";
string numberParameter = $"?Number=1{dialedNumber}";
string route = $"{baseUrl}{endpoint}{numberParameter}";
try
{
var results = await route.WithBasicAuth(username, password).GetJsonAsync<TnRecord[]>().ConfigureAwait(false);
return results.FirstOrDefault() ?? new();
var results = await route.WithBasicAuth(username.ToString(), password.ToString()).GetJsonAsync<TnRecord[]>();
return results.FirstOrDefault();
}
catch (FlurlHttpException ex)
{
Expand All @@ -96,7 +92,7 @@ public static async Task<TnRecord> GetByDialedNumberAsync(string dialedNumber, s
}
}

public static async Task<PhoneNumber[]> GetAsync(string username, string password)
public static async Task<PhoneNumber[]> GetAsync(ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var results = await GetRawAsync(username, password).ConfigureAwait(false);
var output = new List<PhoneNumber>();
Expand Down Expand Up @@ -134,7 +130,7 @@ public static async Task<PhoneNumber[]> GetAsync(string username, string passwor
return [.. output];
}

public static async Task<OwnedPhoneNumber[]> GetOwnedAsync(string username, string password)
public static async Task<OwnedPhoneNumber[]> GetOwnedAsync(ReadOnlyMemory<char> username, ReadOnlyMemory<char> password)
{
var results = await GetRawAsync(username, password).ConfigureAwait(false);
var output = new List<OwnedPhoneNumber>();
Expand Down
Loading

0 comments on commit 0595508

Please sign in to comment.