Skip to content

Commit

Permalink
Merge pull request #110 from dotnet-campus/t/lindexi/SyncTool
Browse files Browse the repository at this point in the history
同步工具的使用优化
  • Loading branch information
kkwpsv authored Mar 12, 2024
2 parents 3a8dd2c + 0bfbf62 commit dc38998
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 12 additions & 1 deletion SyncTool/Client/SyncOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ public async Task Run()
{
if (string.IsNullOrEmpty(Address))
{
Console.WriteLine($"找不到同步地址,请确保传入 Address 参数");
Console.WriteLine($@"找不到同步地址,请确保传入正确参数。
参数列表:
- `-a` 或 `--Address` : 【必填】同步服务的地址,如 http://127.0.0.1:56621
- `-f` 或 `--Folder` : 【选填】本地同步的文件夹,不填默认为工作路径
参数例子:
SyncTool -a http://127.0.0.1:56621 -f lindexi");
return;
}

Expand All @@ -37,8 +44,11 @@ public async Task Run()
syncFolder = Environment.CurrentDirectory;
}

syncFolder = Path.GetFullPath(syncFolder);
Directory.CreateDirectory(syncFolder);

Console.WriteLine($"开始执行文件夹同步。同步地址:{Address} 同步文件夹{syncFolder}");

using var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(Address);

Expand Down Expand Up @@ -135,6 +145,7 @@ async Task SyncFolderAsync(List<SyncFileInfo> remote, ulong version)
await RemoveRedundantFile(remote, version);

Console.WriteLine($"[{version}] 同步完成");
Console.WriteLine($"同步地址:{Address} 同步文件夹{syncFolder}");
Console.WriteLine("==========");
}

Expand Down
22 changes: 20 additions & 2 deletions SyncTool/Server/ServeOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net;
using System.Net.Mime;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using dotnetCampus.Cli;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -35,15 +36,32 @@ public async Task Run()
syncFolder = Environment.CurrentDirectory;
}

syncFolder = Path.GetFullPath(syncFolder);

var syncFolderManager = new SyncFolderManager();
syncFolderManager.Run(syncFolder);

var port = Port ?? GetAvailablePort(IPAddress.Any);

Console.WriteLine($"Listening on: http://0.0.0.0:{port} SyncFolder: {syncFolder}");
Console.WriteLine($"Listening on: http://0.0.0.0:{port}");
try
{
foreach (var networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (var unicastIpAddressInformation in networkInterface.GetIPProperties().UnicastAddresses)
{
Console.WriteLine($"Listening on: http://{unicastIpAddressInformation.Address.ToString()}:{port}");
}
}
}
catch
{
// 忽略异常,只是为了方便开发者了解当前的网络信息,不用每次都去看自己内网地址
}
Console.WriteLine($"SyncFolder: {syncFolder}");

var builder = WebApplication.CreateBuilder();
builder.WebHost.UseUrls($"http://0.0.0.0:{port}");
builder.WebHost.UseUrls($"http://*:{port}");

builder.Configuration["Logging:LogLevel:Microsoft.AspNetCore"] = "Debug";
builder.Configuration["Logging:LogLevel:Microsoft.AspNetCore.Routing.EndpointMiddleware"] = "Warning";
Expand Down

0 comments on commit dc38998

Please sign in to comment.