Skip to content

Commit

Permalink
Upgrade to .NET8
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslieu committed May 11, 2024
1 parent 3ddfabc commit e6cc39a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
6 changes: 4 additions & 2 deletions AnagramSolver/AnagramSolver/AnagramSolver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Data.SQLite" Version="1.0.109.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
</ItemGroup>

</Project>
40 changes: 22 additions & 18 deletions AnagramSolver/AnagramSolver/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace AnagramSolver
{
public class Program
{
private static DataTable dataTable = new DataTable();
private static List<string> permutations = new List<string>();
private static readonly DataTable dataTable = new();
private static List<string> permutations = [];
private static int resultCount;
private static SQLiteConnection sqlite = new SQLiteConnection("Data Source=" + System.IO.Path.GetFullPath(@"..\..\..\db\Dictionary.db"));
private static List<Thread> workerThreads = new List<Thread>();
private static readonly SQLiteConnection sqlite = new("Data Source=" + System.IO.Path.GetFullPath(@"..\..\..\db\Dictionary.db"));
private static readonly List<Thread> workerThreads = [];

public static void Main()
{
Expand All @@ -36,7 +36,8 @@ private static void HandleEntry(string entry)
{
Console.WriteLine("You cannot enter fewer than 2 characters. Press enter to exit");
}
else if (entry.Length > 9) {
else if (entry.Length > 9)
{
Console.WriteLine("You cannot enter more than 9 characters. Press enter to exit");
}
else
Expand All @@ -45,7 +46,7 @@ private static void HandleEntry(string entry)
Console.WriteLine();

// Run anagram solver
RunAnagramSolver(entry.ToLower());
RunAnagramSolver(entry.ToLower());
if (resultCount == 0)
{
Console.WriteLine("There were no anagrams for that word or phrase");
Expand All @@ -54,13 +55,11 @@ private static void HandleEntry(string entry)
Console.WriteLine();
Console.WriteLine("Done");
Console.WriteLine("Press enter to exit.");
}

}
}

private static void RunAnagramSolver(string entry)
{

{
char[] entryLetters = entry.ToCharArray();
permutations = Permutation.GetPermutations(entryLetters, 0, entryLetters.Length - 1);

Expand All @@ -79,11 +78,12 @@ private static void FillDataTable(char[] entryLetters, string entry)

foreach (char entryLetter in uniqueEntryLetters)
{
Thread thread = new Thread(() => {
Thread thread = new(() =>
{
lock (dataTable)
{
SQLiteCommand sqliteCommand = GetWordsByLetter(entryLetter, entry);
SQLiteDataAdapter sqliteDataAdapter = new SQLiteDataAdapter(sqliteCommand);
SQLiteDataAdapter sqliteDataAdapter = new(sqliteCommand);
sqliteDataAdapter.Fill(dataTable); //fill the datasource
}
});
Expand All @@ -105,7 +105,7 @@ private static void OutputResults()
for (int i = 0; i < dataTable.Rows.Count; i++)
{
var word = (string)dataTable.Rows[i]["word"];
var lowerCaseWord = Char.ToLowerInvariant(word[0]) + word.Substring(1);
var lowerCaseWord = char.ToLowerInvariant(word[0]) + word[1..];

for (int j = 0; j < permutations.Count; j++)
{
Expand Down Expand Up @@ -138,12 +138,16 @@ SELECT DISTINCT
AND
LENGTH(word) > 1";

SQLiteParameter letterParam = new SQLiteParameter();
letterParam.Value = letter + "%";
SQLiteParameter letterParam = new()
{
Value = letter + "%"
};
sqliteCommand.Parameters.Add(letterParam);

SQLiteParameter lengthParam = new SQLiteParameter();
lengthParam.Value = entry.Length;
SQLiteParameter lengthParam = new()
{
Value = entry.Length
};
sqliteCommand.Parameters.Add(lengthParam);
}
catch (SQLiteException ex)
Expand All @@ -154,4 +158,4 @@ SELECT DISTINCT
return sqliteCommand;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit e6cc39a

Please sign in to comment.