Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

ログファイルの送受信に関する変更 #32

Merged
merged 8 commits into from
Jun 19, 2021
Merged
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
12 changes: 11 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
# かっこの設定
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_other_operators = always_for_clarity
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity

# 修飾子設定
Expand All @@ -53,6 +53,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true:silent
dotnet_style_explicit_tuple_names = true:silent
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true
dotnet_style_object_initializer = true:silent
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand All @@ -75,6 +76,10 @@ dotnet_code_quality_unused_parameters = all:silent
# 抑制の設定
dotnet_remove_unnecessary_suppression_exclusions = none

# 改行設定
dotnet_style_allow_multiple_blank_lines_experimental = true
dotnet_style_allow_statement_immediately_after_block_experimental = true

#### C# コーディング規則 ####

# var を優先
Expand Down Expand Up @@ -125,6 +130,11 @@ csharp_style_unused_value_expression_statement_preference = discard_variable
# 'using' ディレクティブの基本設定
csharp_using_directive_placement = outside_namespace:suggestion

# 改行設定
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
csharp_style_allow_embedded_statements_on_same_line_experimental = true

#### C# 書式ルール ####

# 改行設定
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Copyright (C) 2020-2021 Takym.
* 個人情報を含むメッセージの強調表示
* 一部メッセージの翻訳
* 詳細情報のコピー/Markdown へ変換
* ログファイルを外部と送受信

## 注意事項
このソフトウェアは厚生労働省とは関係ありません。
Expand Down Expand Up @@ -82,6 +83,14 @@ Copyright (C) 2020-2021 Takym.
### その他の機能
* **個人情報を含むメッセージの強調表示**
* ログメッセージに個人情報が含まれている可能性がある場合、そのメッセージの背景は薄い桃色になります。
* **ログファイルを外部と送受信**
* ランチャーから起動した場合、ログファイルを外部と送受信する事ができます。
* ログファイルを受信する場合は「**機能(T)**」メニュー内の「**外部から動作情報ファイルを受信する(R)...**」をクリックします。
* IPアドレス(LAN内専用)とポート番号が表示されます。
* 受信を停止する場合はウィンドウを閉じます。
* 受信したログファイルは即座に表示されます。
* ログファイルを送信する場合は「**機能(T)**」メニュー内の「**外部へ動作情報ファイルを送信する(S)...**」をクリックします。
* 送信先のアドレスとポート番号と送信するログファイルを指定します。

## 更新履歴

Expand Down
14 changes: 11 additions & 3 deletions src/Covid19Radar.LogViewer.Globalization.English/English.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ public class English : LanguageData
public override string MainWindow_OFD_Filter_All => "All files";
public override string MainWindow_OFD_Error => "An error occurred.";
public override string MainWindow_OFD_Error_Message => "The specified file is not a log file, or the application cannot access the file.";
public override string FormMain_FeaturesMenu => "&Tools";
public override string FormMain_FeaturesMenu_ShowReceiver => "&Receive log files from external...";
public override string FormMain_FeaturesMenu_ShowSender => "&Send log files to external...";
public override string FormMain_ButtonOpen => "&Open a log file";
public override string FormMain_Menu_ShowReceiver => "&Receive log files from COCOA";
public override string FormMain_CheckBoxAllowEscape => "Convert escape characters.";
public override string FormMain_CheckBoxAllowEscape => "&Convert escape characters.";
public override string FormMain_FormClosing => "Are you sure to close all COCOA log file viewers?";
public override string FormReceiver_Title => "Receive log files from COCOA";
public override string FormReceiver_Title => "Receive log files from external";
public override string FormReceiver_Description => "Now receiving . . .";
public override string FormSender_Title => "Send log files to external";
public override string FormSender_Label_Address => "The IP address or hostname";
public override string FormSender_Label_Port => "The port number";
public override string FormSender_Label_File => "The path to a log file to send";
public override string FormSender_Button_Cancel => "&Cancel";
public override string FormSender_Button_Send => "&Send";
public override string ModuleLoader_Failed_Title => "Extension loading error";
public override string ModuleLoader_Failed_Message => "Failed to load the extension \"{0}\". {1}";
public override string ControllerView_Refresh => "Reload logs";
Expand Down
82 changes: 54 additions & 28 deletions src/Covid19Radar.LogViewer.Launcher/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 26 additions & 15 deletions src/Covid19Radar.LogViewer.Launcher/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class FormMain : Form
private readonly ModuleInitializationContext _context;
private App? _app;
private FormReceiver? _receiver;
private FormSender? _sender;

public FormMain(IEnumerable<CocoaLogViewerModule> modules, ModuleInitializationContext context)
{
Expand All @@ -36,11 +37,13 @@ private async void FormMain_Load(object sender, EventArgs e)
{
foreach (var _ in _modules) ;

this .Text = LanguageData.Current.MainWindow_Title;
btnOpen .Text = LanguageData.Current.FormMain_ButtonOpen;
menuItem_showReceiver.Text = LanguageData.Current.FormMain_Menu_ShowReceiver;
cboxAllowEscape .Text = LanguageData.Current.FormMain_CheckBoxAllowEscape;
labelVersion .Text = VersionInfo.GetCaption();
this .Text = LanguageData.Current.MainWindow_Title;
btnOpen .Text = LanguageData.Current.FormMain_ButtonOpen;
menuFeatures .Text = LanguageData.Current.FormMain_FeaturesMenu;
menuFeatures_showReceiver.Text = LanguageData.Current.FormMain_FeaturesMenu_ShowReceiver;
menuFeatures_showSender .Text = LanguageData.Current.FormMain_FeaturesMenu_ShowSender;
cboxAllowEscape .Text = LanguageData.Current.FormMain_CheckBoxAllowEscape;
labelVersion .Text = VersionInfo.GetCaption() + "\r\n" + VersionInfo.GetCopyright();

_app = new App();
_app.OpenWindow = false;
Expand All @@ -58,19 +61,27 @@ private async void FormMain_Load(object sender, EventArgs e)
}
}

private async void btnOpen_Click(object sender, EventArgs e)
private void menuFeatures_showReceiver_Click(object sender, EventArgs e)
{
var mwnd = this.CreateMainWindow();
if (await mwnd.ShowOpenFileDialogAsync(cboxAllowEscape.Checked)) {
this.ShowMainWindow(mwnd);
if (_receiver is null || _receiver.IsDisposed) {
_receiver = new(this);
_receiver.ShowReceiver();
}
}

private void menuItem_showReceiver_Click(object sender, EventArgs e)
private void menuFeatures_showSender_Click(object sender, EventArgs e)
{
if (_receiver is null || _receiver.IsDisposed) {
_receiver = new(this);
_receiver.ShowReceiver();
if (_sender is null || _sender.IsDisposed) {
_sender = new();
_sender.Show(this);
}
}

private async void btnOpen_Click(object sender, EventArgs e)
{
var mwnd = this.CreateMainWindow();
if (await mwnd.ShowOpenFileDialogAsync(cboxAllowEscape.Checked)) {
this.ShowMainWindow(mwnd);
}
}

Expand Down Expand Up @@ -109,10 +120,10 @@ private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
}
}

internal async ValueTask OpenFileAsync(string filename)
internal async ValueTask OpenFileAsync(string filename, bool? allowEscape = null)
{
var mwnd = this.CreateMainWindow();
if (await mwnd.OpenFile(filename, cboxAllowEscape.Checked)) {
if (await mwnd.OpenFile(filename, allowEscape ?? cboxAllowEscape.Checked)) {
this.ShowMainWindow(mwnd);
}
}
Expand Down
26 changes: 19 additions & 7 deletions src/Covid19Radar.LogViewer.Launcher/FormReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,38 @@ private async void FormReceiver_Load(object sender, EventArgs e)
}

try {
bool allowEscape;

while (!_cts.IsCancellationRequested) {
string temp = Path.GetTempFileName();
byte[] buf = new byte[1024];

using (var client = await Task.Run(listener.AcceptTcpClientAsync, _cts.Token)) {
var ns = client.GetStream();
await using (ns.ConfigureAwait(false)) {
var fs = new FileStream(temp, FileMode.Create, FileAccess.Write, FileShare.None);
await using (fs.ConfigureAwait(false)) {
while (ns.DataAvailable) {
int bytes = await ns.ReadAsync(buf.AsMemory(), _cts.Token);
if (bytes > 0) {
await fs.WriteAsync(buf.AsMemory(0..bytes), _cts.Token);
using (var br = new BinaryReader(ns)) {
while (!ns.DataAvailable) {
await Task.Yield();
}
allowEscape = br.ReadBoolean();
long len = br.ReadInt64();
var fs = new FileStream(temp, FileMode.Create, FileAccess.Write, FileShare.None);
await using (fs.ConfigureAwait(false)) {
while (fs.Length < len) {
while (!ns.DataAvailable) {
await Task.Yield();
}
int bytes = await ns.ReadAsync(buf.AsMemory(), _cts.Token);
if (bytes > 0) {
await fs.WriteAsync(buf.AsMemory(0..bytes), _cts.Token);
}
}
}
}
}
}

await _owner.OpenFileAsync(temp);
await _owner.OpenFileAsync(temp, allowEscape);
}
} finally {
listener.Stop();
Expand Down
Loading