bc9d341bd58dadc3377227fd6411dbff878482bc
[CSharpForFun/.git] / Mono / RemoteAgents / GTKLinux / MainWindow.cs
1 using System;
2 using Gtk;
3 using System.Threading.Tasks;
4 using Example.RemoteAgents.GTKLinux.View;
5 using NLog;
6
7 namespace Example.RemoteAgents.GTKLinux
8 {
9     public partial class MainWindow: Gtk.Window
10     {
11         private readonly ViewImpl _view;
12         private static readonly Logger logger = LogManager.GetCurrentClassLogger();
13
14             public MainWindow () : base (Gtk.WindowType.Toplevel)
15             {
16             _view = new ViewImpl();
17                     Build ();
18             this.ButtonGetDate.Clicked += this.ButtonGetDateClicked;
19             this.SendDataButton.Clicked += this.SendDataButtonClicked;
20             }
21
22             protected void OnDeleteEvent (object sender, DeleteEventArgs a)
23             {
24                     Application.Quit ();
25                     a.RetVal = true;
26             }
27
28         async private void ButtonGetDateClicked(object sender, EventArgs e)
29         {
30             try {
31                 this.RemoteDate.Buffer.Text = await _view.GetCurrentDateAsync();
32             }
33             catch (Exception exception)
34             {
35                 logger.ErrorException("ButtonGetDateClicked error: ", exception);
36             }
37         }
38
39         async private void SendDataButtonClicked(object sender, EventArgs e)
40         {
41             try {
42                 await _view.SetWriteTextAsync(this.TextToSend.Buffer.Text,
43                                               this.SpinButtonNumbers.Value);
44             }
45             catch (Exception exception)
46             {
47                 logger.ErrorException("SendDataButtonClicked error: ", exception);
48             }
49         }
50     }
51 }