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

デバッグ版COCOA本体からログファイルを受信できる様にする #29

Open
Takym opened this issue Jun 17, 2021 · 7 comments · Fixed by #32
Open

デバッグ版COCOA本体からログファイルを受信できる様にする #29

Takym opened this issue Jun 17, 2021 · 7 comments · Fixed by #32
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@Takym
Copy link
Member

Takym commented Jun 17, 2021

TcpListener を使う

@Takym Takym added enhancement New feature or request help wanted Extra attention is needed labels Jun 17, 2021
@Takym Takym self-assigned this Jun 17, 2021
@Takym
Copy link
Member Author

Takym commented Jun 17, 2021

ランチャーの「開く」ボタンを右クリックし、コンテキストメニューから受信できる様にする。

@Takym
Copy link
Member Author

Takym commented Jun 17, 2021

#30 にて実装は完了。あとは動作実験のみ。

@Takym
Copy link
Member Author

Takym commented Jun 19, 2021

送受信処理は正しく動作している。
後はデバッグ版COCOA本体にログファイルの送信処理を実装するだけ。

@Takym
Copy link
Member Author

Takym commented Jun 19, 2021

この Issue はデバッグ版COCOA本体に CocoaLogViewer へログファイルを送信する仕組みが実装されてから閉じる。
cocoa-mhlw/cocoa#232

@Takym
Copy link
Member Author

Takym commented Jun 21, 2021

送信処理:

using (var client = new TcpClient(tboxAddress.Text, ((int)(nudPort.Value)))) {
var ns = client.GetStream();
await using (ns.ConfigureAwait(false)) {
var bw = new BinaryWriter(ns);
await using (bw.ConfigureAwait(false)) {
bw.Write(cboxAllowEscape.Checked);
var fs = new FileStream(tboxFile.Text, FileMode.Open, FileAccess.Read, FileShare.Read);
await using (fs.ConfigureAwait(false)) {
bw.Write(fs.Length);
await fs.CopyToAsync(ns);
}
}
}
}

受信処理:

using (var client = await Task.Run(listener.AcceptTcpClientAsync, _cts.Token)) {
var ns = client.GetStream();
await using (ns.ConfigureAwait(false)) {
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);
}
}
}
}
}
}

@Takym Takym added this to the 0.2 milestone Jul 3, 2021
@Takym
Copy link
Member Author

Takym commented Jul 3, 2021

v0.1.0.0 現在の送信処理:

private async void btnSend_Click(object sender, EventArgs e)
{
using (var client = new TcpClient(tboxAddress.Text, ((int)(nudPort.Value)))) {
var ns = client.GetStream();
await using (ns.ConfigureAwait(false)) {
var bw = new BinaryWriter(ns);
await using (bw.ConfigureAwait(false)) {
bw.Write(cboxAllowEscape.Checked);
var fs = new FileStream(tboxFile.Text, FileMode.Open, FileAccess.Read, FileShare.Read);
await using (fs.ConfigureAwait(false)) {
bw.Write(fs.Length);
await fs.CopyToAsync(ns);
}
}
}
}
this.Invoke(new Action(this.Close));
}

@Takym
Copy link
Member Author

Takym commented Jul 3, 2021

cocoa-mhlw/cocoa#271 にて機能提案を行った。

@Takym Takym modified the milestones: 0.2, 0.1 Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant