Skip to content

Commit

Permalink
Updated the the new version of PhoneNumberNA.
Browse files Browse the repository at this point in the history
  • Loading branch information
uncheckederror committed Nov 5, 2024
1 parent e513ed6 commit f194257
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Messaging/Messaging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
<PackageReference Include="PhoneNumbersNA" Version="1.0.14" />
<PackageReference Include="PhoneNumbersNA" Version="1.0.15" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
<PackageReference Include="Serilog" Version="4.1.0" />
Expand Down
26 changes: 13 additions & 13 deletions Messaging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
if (!string.IsNullOrWhiteSpace(msisdn))
{
bool checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(msisdn, out var fromPhoneNumber);
if (checkFrom && fromPhoneNumber is not null && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
if (checkFrom && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
{
if (fromPhoneNumber.Type is not PhoneNumbersNA.NumberType.ShortCode)
{
Expand Down Expand Up @@ -404,7 +404,7 @@
{
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(number, out var toPhoneNumber);
if (checkTo && toPhoneNumber is not null)
if (checkTo)
{
var formattedNumber = toPhoneNumber.Type is PhoneNumbersNA.NumberType.ShortCode ? $"{toPhoneNumber.DialedNumber}" : $"1{toPhoneNumber.DialedNumber}";
// Prevent the duplicates from being included in the the recipients list.
Expand All @@ -419,7 +419,7 @@
{
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(number, out var toPhoneNumber);
if (checkTo && toPhoneNumber is not null)
if (checkTo)
{
var formattedNumber = toPhoneNumber.Type is PhoneNumbersNA.NumberType.ShortCode ? $"{toPhoneNumber.DialedNumber}" : $"1{toPhoneNumber.DialedNumber}";
// Prevent the duplicates from being included in the the recipients list.
Expand Down Expand Up @@ -1177,7 +1177,7 @@ public static async Task<Results<Ok<string>, NotFound<string>, BadRequest<string
try
{
bool checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(asDialed, out var asDialedNumber);
if (checkFrom && asDialedNumber is not null && !string.IsNullOrWhiteSpace(asDialedNumber.DialedNumber))
if (checkFrom && !string.IsNullOrWhiteSpace(asDialedNumber.DialedNumber))
{
string dialedNumber = asDialedNumber.Type is not PhoneNumbersNA.NumberType.ShortCode ? $"1{asDialedNumber.DialedNumber}" : asDialedNumber.DialedNumber;

Expand Down Expand Up @@ -1275,7 +1275,7 @@ public static async Task<Results<Ok<MessageRecord[]>, NotFound<string>, BadReque
try
{
bool checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(asDialed, out var fromPhoneNumber);
if (checkFrom && fromPhoneNumber is not null && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
if (checkFrom && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
{
if (fromPhoneNumber.Type is not PhoneNumbersNA.NumberType.ShortCode)
{
Expand Down Expand Up @@ -1449,7 +1449,7 @@ public static async Task<Results<Ok<SendMessageResponse>, BadRequest<SendMessage
if (message is not null && !string.IsNullOrWhiteSpace(message.MSISDN))
{
bool checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(message.MSISDN, out var fromPhoneNumber);
if (checkFrom && fromPhoneNumber is not null && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
if (checkFrom && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
{
if (fromPhoneNumber.Type is not PhoneNumbersNA.NumberType.ShortCode)
{
Expand Down Expand Up @@ -1499,7 +1499,7 @@ public static async Task<Results<Ok<SendMessageResponse>, BadRequest<SendMessage
{
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(number, out var toPhoneNumber);

if (checkTo && toPhoneNumber is not null)
if (checkTo)
{
var formattedNumber = toPhoneNumber.Type is PhoneNumbersNA.NumberType.ShortCode ? $"{toPhoneNumber.DialedNumber}" : $"1{toPhoneNumber.DialedNumber}";
// Prevent the MSISDN from being included in the the recipients list. But allow circular messages where the MSISDN and To are the same to support testing.
Expand Down Expand Up @@ -1805,7 +1805,7 @@ public static async Task<Results<Ok<string>, BadRequest<string>, Ok<ForwardedMes
if (!string.IsNullOrWhiteSpace(msisdn))
{
bool checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(msisdn, out var fromPhoneNumber);
if (checkFrom && fromPhoneNumber is not null && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
if (checkFrom && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
{
if (fromPhoneNumber.Type is not PhoneNumbersNA.NumberType.ShortCode)
{
Expand Down Expand Up @@ -1834,7 +1834,7 @@ public static async Task<Results<Ok<string>, BadRequest<string>, Ok<ForwardedMes
{
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(number, out var toPhoneNumber);

if (checkTo && toPhoneNumber is not null)
if (checkTo)
{
var formattedNumber = toPhoneNumber.Type is PhoneNumbersNA.NumberType.ShortCode ? $"{toPhoneNumber.DialedNumber}" : $"1{toPhoneNumber.DialedNumber}";
// Prevent the duplicates from being included in the the recipients list.
Expand All @@ -1849,7 +1849,7 @@ public static async Task<Results<Ok<string>, BadRequest<string>, Ok<ForwardedMes
{
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(number, out var toPhoneNumber);

if (checkTo && toPhoneNumber is not null)
if (checkTo)
{
var formattedNumber = toPhoneNumber.Type is PhoneNumbersNA.NumberType.ShortCode ? $"{toPhoneNumber.DialedNumber}" : $"1{toPhoneNumber.DialedNumber}";
// Prevent the duplicates from being included in the the recipients list.
Expand Down Expand Up @@ -2243,7 +2243,7 @@ public bool RegularizeAndValidate()
if (!string.IsNullOrWhiteSpace(ani))
{
var checkFrom = PhoneNumbersNA.PhoneNumber.TryParse(ani, out var fromPhoneNumber);
if (checkFrom && fromPhoneNumber is not null && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
if (checkFrom && !string.IsNullOrWhiteSpace(fromPhoneNumber.DialedNumber))
{
FromPhoneNumber = fromPhoneNumber;
ani = $"1{fromPhoneNumber.DialedNumber}";
Expand All @@ -2260,14 +2260,14 @@ public bool RegularizeAndValidate()
{
var checkTo = PhoneNumbersNA.PhoneNumber.TryParse(number, out var toPhoneNumber);

if (checkTo && toPhoneNumber is not null)
if (checkTo)
{
ToPhoneNumbers.Add(toPhoneNumber);
}
}

// This will drop the numbers that couldn't be parsed.
recip = ToPhoneNumbers is not null && ToPhoneNumbers.Count != 0 ? ToPhoneNumbers.Count > 1 ? string.Join(",", ToPhoneNumbers.Select(x => $"1{x.DialedNumber!}")) : $"1{ToPhoneNumbers?.FirstOrDefault()?.DialedNumber}" ?? string.Empty : string.Empty;
recip = ToPhoneNumbers is not null && ToPhoneNumbers.Count != 0 ? ToPhoneNumbers.Count > 1 ? string.Join(",", ToPhoneNumbers.Select(x => $"1{x.DialedNumber!}")) : $"1{ToPhoneNumbers?.FirstOrDefault().DialedNumber}" ?? string.Empty : string.Empty;
ToParsed = true;
}

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 @@ -54,14 +54,14 @@ public static async Task<PhoneNumber[]> GetAsync(int inNpa, ReadOnlyMemory<char>
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item.TN, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
output.Add(new PhoneNumber
{
NPA = phoneNumber.NPA,
NXX = phoneNumber.NXX,
XXXX = phoneNumber.XXXX,
DialedNumber = phoneNumber?.DialedNumber ?? string.Empty,
DialedNumber = phoneNumber.DialedNumber ?? string.Empty,
City = string.IsNullOrWhiteSpace(item.RateCenter) ? "Unknown City" : item.RateCenter,
State = string.IsNullOrWhiteSpace(item.State) ? "Unknown State" : item.State,
DateIngested = DateTime.Now,
Expand All @@ -88,14 +88,14 @@ public static async Task<PhoneNumber[]> GetAsync(int inNpa, int inNxx, ReadOnlyM
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item.TN, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
output.Add(new PhoneNumber
{
NPA = phoneNumber.NPA,
NXX = phoneNumber.NXX,
XXXX = phoneNumber.XXXX,
DialedNumber = phoneNumber?.DialedNumber ?? string.Empty,
DialedNumber = phoneNumber.DialedNumber ?? string.Empty,
City = string.IsNullOrWhiteSpace(item.RateCenter) ? "Unknown City" : item.RateCenter,
State = string.IsNullOrWhiteSpace(item.State) ? "Unknown State" : item.State,
DateIngested = DateTime.Now,
Expand Down
8 changes: 4 additions & 4 deletions NumberSearch.DataAccess/BulkVS/TnRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public static async Task<PhoneNumber[]> GetAsync(ReadOnlyMemory<char> username,

var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item.TN, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
output.Add(new PhoneNumber
{
NPA = phoneNumber.NPA,
NXX = phoneNumber.NXX,
XXXX = phoneNumber.XXXX,
DialedNumber = phoneNumber?.DialedNumber ?? string.Empty,
DialedNumber = phoneNumber.DialedNumber ?? string.Empty,
City = string.IsNullOrWhiteSpace(item.TNDetails.RateCenter) ? "Unknown City" : item.TNDetails.RateCenter,
State = string.IsNullOrWhiteSpace(item.TNDetails.State) ? "Unknown State" : item.TNDetails.State,
DateIngested = DateTime.Now,
Expand Down Expand Up @@ -145,11 +145,11 @@ public static async Task<OwnedPhoneNumber[]> GetOwnedAsync(ReadOnlyMemory<char>
{
var checkParsed = PhoneNumbersNA.PhoneNumber.TryParse(item.TN, out var phoneNumber);

if (checkParsed && phoneNumber is not null)
if (checkParsed)
{
output.Add(new OwnedPhoneNumber
{
DialedNumber = phoneNumber?.DialedNumber ?? string.Empty,
DialedNumber = phoneNumber.DialedNumber ?? string.Empty,
IngestedFrom = "BulkVS",
TrunkGroup = item.Routing.TrunkGroup ?? string.Empty,
Active = true,
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.DataAccess/NumberSearch.DataAccess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="MimeKit" Version="4.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="8.0.5" />
<PackageReference Include="PhoneNumbersNA" Version="1.0.14" />
<PackageReference Include="PhoneNumbersNA" Version="1.0.15" />
<PackageReference Include="Serilog" Version="4.1.0" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions NumberSearch.Ingest/Owned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public static async Task<IEnumerable<OwnedPhoneNumber>> FirstPointComAsync(ReadO
{
List<OwnedPhoneNumber> numbers = [];

foreach (int npa in AreaCode.All)
foreach (int npa in AreaCodes.All)
{
try
{
Expand All @@ -346,7 +346,7 @@ public static async Task<IEnumerable<OwnedPhoneNumber>> FirstPointComAsync(ReadO
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item.DID, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
numbers.Add(new OwnedPhoneNumber
{
Expand Down Expand Up @@ -551,7 +551,7 @@ public static async Task<IngestStatistics> OfferUnassignedNumberForSaleAsync(Rea
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(item?.DialedNumber ?? string.Empty, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
number = new DataAccess.Models.PhoneNumber
{
Expand Down Expand Up @@ -717,7 +717,7 @@ public static async Task<ServiceProviderChanged[]> VerifyServiceProvidersAsync(R
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(number.DialedNumber, out var phoneNumber);

if (checkParse && phoneNumber is not null && !string.IsNullOrWhiteSpace(phoneNumber.DialedNumber))
if (checkParse && !string.IsNullOrWhiteSpace(phoneNumber.DialedNumber))
{
if (phoneNumber.DialedNumber.IsTollfree())
{
Expand Down
4 changes: 2 additions & 2 deletions NumberSearch.Ingest/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static async Task<IngestStatistics> BulkVSCompleteAsync(TimeSpan cycle, I
Log.Information("Ingesting data from BulkVS");
// Breaking this into chunks to limit peak memory consumption.
List<IngestStatistics> allStats = [];
var groups = PhoneNumbersNA.AreaCode.All.Chunk(50);
var groups = PhoneNumbersNA.AreaCodes.All.Chunk(50);
foreach (var group in groups)
{
var BulkVSStats = await Provider.BulkVSAsync(appConfig.BulkVSUsername, appConfig.BulkVSPassword, group, appConfig.Postgresql);
Expand Down Expand Up @@ -266,7 +266,7 @@ public static async Task<IngestStatistics> FirstPointComCompleteAsync(TimeSpan c

// Ingest all available numbers in the FirsPointCom API.
Log.Information("[FirstPointCom] Ingesting data from FirstPointCom");
var FirstPointComStats = await Provider.FirstPointComAsync(appConfig.PComNetUsername, appConfig.PComNetPassword, PhoneNumbersNA.AreaCode.All, appConfig.Postgresql);
var FirstPointComStats = await Provider.FirstPointComAsync(appConfig.PComNetUsername, appConfig.PComNetPassword, PhoneNumbersNA.AreaCodes.All, appConfig.Postgresql);

// Remove the lock from the database to prevent it from getting cluttered with blank entries.
var lockEntry = await IngestStatistics.GetLockAsync("FirstPointCom", appConfig.Postgresql.ToString());
Expand Down
8 changes: 4 additions & 4 deletions NumberSearch.Mvc/Controllers/CartAPIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public async Task<IActionResult> NumberSearchBulkAsync(string token, string dial
// Add portable numbers to cart in bulk
if (!string.IsNullOrWhiteSpace(dialedNumber))
{
var parsedNumbers = dialedNumber.ExtractDialedNumbers();
var parsedNumbers = dialedNumber.ExtractDialedNumbers().ToArray();

if (!parsedNumbers.Any())
if (parsedNumbers.Length == 0)
{
return BadRequest("No dialed phone numbers found. Please try a different query. 🥺👉👈");
}
Expand Down Expand Up @@ -812,7 +812,7 @@ public async Task<IActionResult> PortPhoneNumberAsync(string dialedPhoneNumber)

var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(dialedPhoneNumber, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
// Determine if the number is a wireless number.
var lrnLookup = await LrnBulkCnam.GetAsync(phoneNumber.DialedNumber.AsMemory(), _apiKey.AsMemory());
Expand Down Expand Up @@ -908,7 +908,7 @@ public async Task<IActionResult> VerifyPhoneNumberAsync(string dialedPhoneNumber

var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(dialedPhoneNumber, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
try
{
Expand Down
10 changes: 5 additions & 5 deletions NumberSearch.Mvc/Controllers/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public async Task<IActionResult> BulkPortAsync([Bind("dialedNumber")] string dia
// Add portable numbers to cart in bulk
if (!string.IsNullOrWhiteSpace(dialedNumber))
{
var parsedNumbers = dialedNumber.ExtractDialedNumbers();
var parsedNumbers = dialedNumber.ExtractDialedNumbers().ToArray();

if (!parsedNumbers.Any())
if (parsedNumbers.Length == 0)
{
return View("Index", new LookupResults
{
Expand Down Expand Up @@ -134,9 +134,9 @@ public async Task<IActionResult> ToCSVAsync([Bind("dialedNumber")] string dialed
// Add portable numbers to cart in bulk
if (!string.IsNullOrWhiteSpace(dialedNumber))
{
var parsedNumbers = dialedNumber.ExtractDialedNumbers();
var parsedNumbers = dialedNumber.ExtractDialedNumbers().ToArray();

if (!parsedNumbers.Any())
if (parsedNumbers.Length == 0)
{
return View("Index", new LookupResults
{
Expand Down Expand Up @@ -188,7 +188,7 @@ public async Task<PortedPhoneNumber> VerifyPortabilityAsync(string dialedNumber)
{
var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(dialedNumber, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Mvc/Controllers/PortNotifierController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<IActionResult> IndexAsync(string Query)

var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(Query, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
try
{
Expand Down
4 changes: 2 additions & 2 deletions NumberSearch.Mvc/Controllers/PortingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<IActionResult> CheckPortabilityAsync(string Query)

var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(Query, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
try
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task<IActionResult> RequestPortAsync(string Query)

var checkParse = PhoneNumbersNA.PhoneNumber.TryParse(Query, out var phoneNumber);

if (checkParse && phoneNumber is not null)
if (checkParse)
{
var portable = await ValidatePortability.GetAsync(phoneNumber.DialedNumber.AsMemory(), _bulkVSAPIUsername.AsMemory(), _bulkVSAPIPassword.AsMemory());

Expand Down
2 changes: 1 addition & 1 deletion NumberSearch.Mvc/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<IActionResult> SearchAsync(string query, string city, string f
{
var checkConvert = int.TryParse(cleanedQuery, out var code);

if (checkConvert && PhoneNumbersNA.AreaCode.All.Contains(code))
if (checkConvert && PhoneNumbersNA.AreaCodes.All.Contains(code))
{
cleanedQuery += "*******";
}
Expand Down
Loading

0 comments on commit f194257

Please sign in to comment.