-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInteraction.cs
59 lines (53 loc) · 1.66 KB
/
Interaction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Threading;
using System.Threading.Tasks;
using WpfCalculator;
namespace Host.Core
{
/// <summary>
/// WPFを使用して計算の入出力を処理するクラスです。
/// </summary>
public class Interaction : IDisposable
{
private volatile MainWindow mainWindow;
/// <summary>
/// コンストラクタです。
/// </summary>
public Interaction()
{
this.mainWindow = new MainWindow();
this.mainWindow.Show();
}
/// <summary>
/// Disposeメソッドです。
/// </summary>
public void Dispose()
{
var mainWindow = Interlocked.Exchange(ref this.mainWindow, null);
if (mainWindow != null)
{
mainWindow.Close();
}
}
/// <summary>
/// ホストに対して指定された書式で文字列を出力します。
/// </summary>
/// <param name="format">書式</param>
/// <param name="args">追加引数群</param>
/// <returns>タスク</returns>
public Task<string> ReadLineAsync()
{
// ウインドウにバイパスする
return this.mainWindow.ReadLineAsync();
}
/// <summary>
/// ホストから文字列を入力します。
/// </summary>
/// <returns>取得した文字列</returns>
public Task WriteLineAsync(string format, params object[] args)
{
// ウインドウにバイパスする
return this.mainWindow.WriteLineAsync(string.Format(format, args));
}
}
}