Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to dotnet core 3.1 #28

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: .NET Core

on: [push]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Build
run: dotnet build --configuration Release
35 changes: 24 additions & 11 deletions SmartHunter/Core/Config/ConfigContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SmartHunter.Ui.Windows;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;

namespace SmartHunter.Core.Config
Expand All @@ -28,15 +29,15 @@ public void HandleDeserializationError(object sender, ErrorEventArgs args)
Log.WriteException(args.ErrorContext.Error);
args.ErrorContext.Handled = true;
}

override protected void OnChanged()
{
Load();
}

void Load()
{
if (File.Exists(FullPathFileName))// && FileName.Equals("Config.json"))
if (File.Exists(FullPathFileName))
{
try
{
Expand All @@ -49,10 +50,12 @@ void Load()
}
}

var settings = new JsonSerializerSettings();
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new ContractResolver();
settings.Error = HandleDeserializationError;
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ContractResolver = new ContractResolver(),
Error = HandleDeserializationError
};

// Solves dictionary/lists being added to instead of overwritten but causes problems elsewhere
// https://stackoverflow.com/questions/29113063/json-net-why-does-it-add-to-list-instead-of-overwriting
Expand Down Expand Up @@ -88,17 +91,27 @@ public void Save()

try
{
var settings = new JsonSerializerSettings();
settings.Formatting = Formatting.Indented;
settings.NullValueHandling = NullValueHandling.Ignore;
settings.ContractResolver = new ContractResolver();
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new ContractResolver()
};

settings.Converters.Add(new StringEnumConverter());
settings.Converters.Add(new StringFloatConverter());

var jsonString = JsonConvert.SerializeObject(Values, settings);

File.WriteAllText(FullPathFileName, jsonString);
using (var fileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write, 4096, FileOptions.None))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that it fails to resolve the file stream correctly. So we need to explicitly grab it rather than relying on File.WriteAllText to auto resolve it for us

{
using var streamWriter = new StreamWriter(fileStream)
{
AutoFlush = true
};

streamWriter.Write(jsonString);
}

Log.WriteLine($"{FileName} saved");
}
Expand Down
5 changes: 5 additions & 0 deletions SmartHunter/Core/Helpers/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class Updater

public bool CheckForUpdates(bool forceCheck = false)
{
#if DEBUG

return false;
#endif

if (_needUpdates.Count == 0 || forceCheck == true)
{
try
Expand Down
12 changes: 4 additions & 8 deletions SmartHunter/Core/Log.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System;
using System.ComponentModel;
using System.IO;
using System.Security.AccessControl;

namespace SmartHunter.Core
{
Expand All @@ -16,17 +15,14 @@ public static void WriteLine(string message)
string line = String.Format("[{0:yyyy-MM-dd HH:mm:ss}] {1}", DateTimeOffset.Now.ToUniversalTime(), message);
Console.WriteLine(line);

if (LineReceived != null)
{
LineReceived(null, new GenericEventArgs<string>(line));
}
LineReceived?.Invoke(null, new GenericEventArgs<string>(line));

bool isDesignInstance = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
if (!isDesignInstance)
{
try
{
using (FileStream fileStream = new FileStream(s_FileName, FileMode.OpenOrCreate, FileSystemRights.AppendData, FileShare.Write, 4096, FileOptions.None))
using (FileStream fileStream = new FileStream(s_FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write, 4096, FileOptions.None))
{
using (StreamWriter streamWriter = new StreamWriter(fileStream))
{
Expand All @@ -44,4 +40,4 @@ public static void WriteException(Exception exception)
WriteLine($"{exception.GetType().Name}: {exception.Message}\r\n{exception.StackTrace}");
}
}
}
}
79 changes: 37 additions & 42 deletions SmartHunter/SmartHunter.csproj
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<ProjectGuid>{F5F99CEF-1C16-48E6-A88B-1A66D3B53998}</ProjectGuid>
<OutputType>WinExe</OutputType>
<TargetFramework>net461</TargetFramework>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>false</Deterministic>
<LangVersion>latest</LangVersion>
<AssemblyTitle>SmartHunter</AssemblyTitle>
<Deterministic>false</Deterministic>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<OutputPath>bin\$(Configuration)</OutputPath>
<UseWPF>true</UseWPF>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<Target Name="PostBuild" BeforeTargets="PostBuildEvent">
<Exec Command="xcopy /E /Y &quot;$(ProjectDir)Ui\Resources&quot; &quot;$(TargetDir)&quot;" />
</Target>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Resource Include="Ui\Fonts\Roboto-Bold.ttf" />
<Resource Include="Ui\Fonts\Roboto-Medium.ttf" />
</ItemGroup>
</Project>
<PropertyGroup>
<ProjectGuid>{F5F99CEF-1C16-48E6-A88B-1A66D3B53998}</ProjectGuid>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>false</Deterministic>
<LangVersion>latest</LangVersion>
<AssemblyTitle>SmartHunter</AssemblyTitle>
<Deterministic>false</Deterministic>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<OutputPath>bin\$(Configuration)</OutputPath>
<UseWPF>true</UseWPF>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<Target Name="PostBuild" BeforeTargets="PostBuildEvent">
<Exec Command="xcopy /E /Y &quot;$(ProjectDir)Ui\Resources&quot; &quot;$(TargetDir)&quot;"/>
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.0"/>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
</ItemGroup>
<ItemGroup>
<Resource Include="Ui\Fonts\Roboto-Bold.ttf"/>
<Resource Include="Ui\Fonts\Roboto-Medium.ttf"/>
</ItemGroup>
</Project>