Skip to content

Commit

Permalink
.NET 6.0 (neo-project#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Nov 17, 2021
1 parent 963ccac commit 5c2edbf
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: .NET Core Test
on: pull_request

env:
DOTNET_VERSION: 5.0.100
DOTNET_VERSION: 6.0.x

jobs:

Expand All @@ -21,9 +21,7 @@ jobs:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Check format
if: runner.os == 'Linux'
run: |
dotnet tool install --version 5.0.142902 --tool-path ./ dotnet-format --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
./dotnet-format --check -v diagnostic
run: dotnet format --no-restore --verify-no-changes --verbosity diagnostic
- name: Build CLI
if: runner.os == 'Linux'
run: |
Expand Down
3 changes: 2 additions & 1 deletion Neo.ConsoleService/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ private bool OnCommand(string commandLine)
case 1:
{
var (command, arguments) = availableCommands[0];
command.Method.Invoke(command.Instance, arguments);
object result = command.Method.Invoke(command.Instance, arguments);
if (result is Task task) task.Wait();
return true;
}
default:
Expand Down
6 changes: 3 additions & 3 deletions Neo.ConsoleService/Neo.ConsoleService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<Copyright>2015-2021 The Neo Project</Copyright>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
<Authors>The Neo Project</Authors>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<PackageProjectUrl>https://github.com/neo-project/neo-node</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
Expand All @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="5.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" />
</ItemGroup>

</Project>
31 changes: 14 additions & 17 deletions neo-cli/CLI/MainService.Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace Neo.CLI
{
Expand All @@ -26,23 +28,19 @@ partial class MainService
/// </summary>
/// <param name="pluginName">Plugin name</param>
[ConsoleCommand("install", Category = "Plugin Commands")]
private void OnInstallCommand(string pluginName)
private async Task OnInstallCommandAsync(string pluginName)
{
HttpWebRequest request = WebRequest.CreateHttp($"https://github.com/neo-project/neo-modules/releases/download/v{typeof(Plugin).Assembly.GetVersion()}/{pluginName}.zip");
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex) when (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
using HttpClient http = new();
HttpResponseMessage response = await http.GetAsync($"https://github.com/neo-project/neo-modules/releases/download/v{typeof(Plugin).Assembly.GetVersion()}/{pluginName}.zip");
if (response.StatusCode == HttpStatusCode.NotFound)
{
response.Dispose();
Version version_core = typeof(Plugin).Assembly.GetName().Version;
request = WebRequest.CreateHttp($"https://api.github.com/repos/neo-project/neo-modules/releases");
request.UserAgent = $"{GetType().Assembly.GetName().Name}/{GetType().Assembly.GetVersion()}";
using HttpWebResponse response_api = (HttpWebResponse)request.GetResponse();
using Stream stream = response_api.GetResponseStream();
using StreamReader reader = new(stream);
JObject releases = JObject.Parse(reader.ReadToEnd());
HttpRequestMessage request = new(HttpMethod.Get, "https://api.github.com/repos/neo-project/neo-modules/releases");
request.Headers.UserAgent.ParseAdd($"{GetType().Assembly.GetName().Name}/{GetType().Assembly.GetVersion()}");
using HttpResponseMessage response_api = await http.SendAsync(request);
byte[] buffer = await response_api.Content.ReadAsByteArrayAsync();
JObject releases = JObject.Parse(buffer);
JObject asset = releases.GetArray()
.Where(p => !p["tag_name"].GetString().Contains('-'))
.Select(p => new
Expand All @@ -54,12 +52,11 @@ private void OnInstallCommand(string pluginName)
.First(p => p.Version <= version_core).Assets
.FirstOrDefault(p => p["name"].GetString() == $"{pluginName}.zip");
if (asset is null) throw new Exception("Plugin doesn't exist.");
request = WebRequest.CreateHttp(asset["browser_download_url"].GetString());
response = (HttpWebResponse)request.GetResponse();
response = await http.GetAsync(asset["browser_download_url"].GetString());
}
using (response)
{
using Stream stream = response.GetResponseStream();
using Stream stream = await response.Content.ReadAsStreamAsync();
using ZipArchive zip = new(stream, ZipArchiveMode.Read);
try
{
Expand Down
6 changes: 3 additions & 3 deletions neo-cli/neo-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<Copyright>2016-2021 The Neo Project</Copyright>
<AssemblyTitle>Neo.CLI</AssemblyTitle>
<Version>3.0.3</Version>
<Version>3.1.0</Version>
<Authors>The Neo Project</Authors>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>neo-cli</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Neo.CLI</PackageId>
Expand All @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.0.3" />
<PackageReference Include="Neo" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
49 changes: 20 additions & 29 deletions neo-gui/GUI/UpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@

using Neo.Properties;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Neo.GUI
{
internal partial class UpdateDialog : Form
{
private readonly WebClient web = new WebClient();
private readonly HttpClient http = new();
private readonly string download_url;
private string download_path;

Expand All @@ -35,26 +34,36 @@ public UpdateDialog(XDocument xdoc)
XElement release = xdoc.Element("update").Elements("release").First(p => p.Attribute("version").Value == latest.ToString());
textBox2.Text = release.Element("changes").Value.Replace("\n", Environment.NewLine);
download_url = release.Attribute("file").Value;
web.DownloadProgressChanged += Web_DownloadProgressChanged;
web.DownloadFileCompleted += Web_DownloadFileCompleted;
}

private void Web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
Process.Start("https://neo.org/");
}

private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(download_url);
}

private void Web_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
private async void button2_Click(object sender, EventArgs e)
{
if (e.Cancelled || e.Error != null) return;
button1.Enabled = false;
button2.Enabled = false;
download_path = "update.zip";
using (Stream responseStream = await http.GetStreamAsync(download_url))
using (FileStream fileStream = new(download_path, FileMode.Create, FileAccess.Write, FileShare.None))
{
await responseStream.CopyToAsync(fileStream);
}
DirectoryInfo di = new DirectoryInfo("update");
if (di.Exists) di.Delete(true);
di.Create();
ZipFile.ExtractToDirectory(download_path, di.Name);
FileSystemInfo[] fs = di.GetFileSystemInfos();
if (fs.Length == 1 && fs[0] is DirectoryInfo)
if (fs.Length == 1 && fs[0] is DirectoryInfo directory)
{
((DirectoryInfo)fs[0]).MoveTo("update2");
directory.MoveTo("update2");
di.Delete();
Directory.Move("update2", di.Name);
}
Expand All @@ -63,23 +72,5 @@ private void Web_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
if (Program.MainForm != null) Program.MainForm.Close();
Process.Start("update.bat");
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://neo.org/");
}

private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(download_url);
}

private void button2_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
download_path = "update.zip";
web.DownloadFileAsync(new Uri(download_url), download_path);
}
}
}
4 changes: 2 additions & 2 deletions neo-gui/neo-gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<Copyright>2016-2021 The Neo Project</Copyright>
<AssemblyTitle>Neo.GUI</AssemblyTitle>
<Version>3.0.3</Version>
<Version>3.1.0</Version>
<Authors>The Neo Project</Authors>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<RootNamespace>Neo</RootNamespace>
<UseWindowsForms>true</UseWindowsForms>
<Company>The Neo Project</Company>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>neo_cli.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
</ItemGroup>
Expand Down

0 comments on commit 5c2edbf

Please sign in to comment.