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