_view = new ViewImpl();
Build ();
this.ButtonGetDate.Clicked += this.ButtonGetDateClicked;
+ this.SendDataButton.Clicked += this.SendDataButtonClicked;
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
a.RetVal = true;
}
- async private void ButtonGetDateClicked(object sender, EventArgs a)
+ async private void ButtonGetDateClicked(object sender, EventArgs e)
{
try {
this.RemoteDate.Buffer.Text = await _view.GetCurrentDateAsync();
}
- catch (Exception e)
+ catch (Exception exception)
{
- logger.Error("ButtonGetDateClicked error: ", e);
+ logger.ErrorException("ButtonGetDateClicked error: ", exception);
+ }
+ }
+
+ async private void SendDataButtonClicked(object sender, EventArgs e)
+ {
+ try {
+ await _view.SetWriteTextAsync(this.TextToSend.Buffer.Text,
+ this.SpinButtonNumbers.Value);
+ }
+ catch (Exception exception)
+ {
+ logger.ErrorException("SendDataButtonClicked error: ", exception);
}
}
}
<target name="asyncFile" xsi:type="AsyncWrapper">
<target xsi:type="File" name="logfile" fileName="${shortdate}.log"
- layout="${longdate} ${uppercase:${level}} ${callsite} ${message} ${newline}" />
+ layout="${longdate} ${uppercase:${level}} ${callsite} ${message} ${exception:format=ToString,StackTrace} ${newline}" />
</target>
+ <target xsi:type="Console" name="console"
+ layout="${longdate} ${uppercase:${level}} ${callsite} ${message} ${exception:format=ToString,StackTrace} ${newline}" />
+
-->
<target xsi:type="LogReceiverService"
name="remoteLog"
useBinaryEncoding="false"
clientId="remoteagents_wp8"
includeEventProperties="true">
- <parameter layout="${longdate} ${uppercase:${level}} ${callsite} ${message} ${newline}" />
+ <parameter layout="${longdate} ${uppercase:${level}} ${callsite} ${message} ${exception:format=ToString,StackTrace} ${newline}" />
</target>
</targets>
<!--
<logger name="*" minlevel="Info" writeTo="asyncFile" />
+ <logger name="*" minlevel="Info" writeTo="console" />
-->
<logger name="*" minlevel="Info" writeTo="remoteLog" />
{
return await _vm.GetCurrentDateAsync();
}
+
+ async public Task SetWriteTextAsync(params object[] parameters)
+ {
+ await _vm.SetWriteTextAsync(parameters);
+ }
}
}
{
public class ViewModelImpl
{
- private static readonly string uri = "http://127.0.0.1:8080/spring-mainapp/CurrentDateService.json";
+ private static readonly string uriGetCurrentDate = "http://127.0.0.1:8080/spring-mainapp/CurrentDateService.json";
+ private static readonly string uriSetWriteText = "http://127.0.0.1:8080/spring-mainapp/WriteTextService.json";
private readonly JsonRpcHttpAsyncClient _remoteClient = new JsonRpcHttpAsyncClient();
async public Task<string> GetCurrentDateAsync()
{
- return await _remoteClient.PostRemoteServiceAsync<string>(uri, "getCurrentDate");
+ return await _remoteClient.PostRemoteServiceAsync<string>(uriGetCurrentDate, "getCurrentDate");
+ }
+
+ async public Task SetWriteTextAsync(params object[] parameters)
+ {
+ await _remoteClient.PostWithParametersRemoteServiceAsync(uriSetWriteText, "setWriteText", parameters);
}
}
}
{
private global::Gtk.VBox vbox3;
private global::Gtk.TextView RemoteDate;
+ private global::Gtk.HBox hbox1;
+ private global::Gtk.ScrolledWindow GtkScrolledWindow;
+ private global::Gtk.TextView TextToSend;
+ private global::Gtk.SpinButton SpinButtonNumbers;
private global::Gtk.HBox hbox2;
private global::Gtk.Button ButtonGetDate;
- private global::Gtk.Button RetrieveRemoteDateButton;
+ private global::Gtk.Button SendDataButton;
protected virtual void Build ()
{
global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.vbox3 [this.RemoteDate]));
w1.Position = 0;
// Container child vbox3.Gtk.Box+BoxChild
+ this.hbox1 = new global::Gtk.HBox ();
+ this.hbox1.Name = "hbox1";
+ this.hbox1.Spacing = 6;
+ // Container child hbox1.Gtk.Box+BoxChild
+ this.GtkScrolledWindow = new global::Gtk.ScrolledWindow ();
+ this.GtkScrolledWindow.Name = "GtkScrolledWindow";
+ this.GtkScrolledWindow.ShadowType = ((global::Gtk.ShadowType)(1));
+ // Container child GtkScrolledWindow.Gtk.Container+ContainerChild
+ this.TextToSend = new global::Gtk.TextView ();
+ this.TextToSend.CanFocus = true;
+ this.TextToSend.Name = "TextToSend";
+ this.GtkScrolledWindow.Add (this.TextToSend);
+ this.hbox1.Add (this.GtkScrolledWindow);
+ global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.GtkScrolledWindow]));
+ w3.Position = 0;
+ // Container child hbox1.Gtk.Box+BoxChild
+ this.SpinButtonNumbers = new global::Gtk.SpinButton (0, 1000, 10);
+ this.SpinButtonNumbers.CanFocus = true;
+ this.SpinButtonNumbers.Name = "SpinButtonNumbers";
+ this.SpinButtonNumbers.Adjustment.PageIncrement = 10;
+ this.SpinButtonNumbers.ClimbRate = 1;
+ this.SpinButtonNumbers.Numeric = true;
+ this.hbox1.Add (this.SpinButtonNumbers);
+ global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.SpinButtonNumbers]));
+ w4.Position = 1;
+ w4.Fill = false;
+ this.vbox3.Add (this.hbox1);
+ global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox3 [this.hbox1]));
+ w5.Position = 1;
+ w5.Fill = false;
+ // Container child vbox3.Gtk.Box+BoxChild
this.hbox2 = new global::Gtk.HBox ();
this.hbox2.Name = "hbox2";
this.hbox2.Spacing = 6;
this.ButtonGetDate.UseUnderline = true;
this.ButtonGetDate.Label = global::Mono.Unix.Catalog.GetString ("GetRemoteDate");
this.hbox2.Add (this.ButtonGetDate);
- global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox2 [this.ButtonGetDate]));
- w2.Position = 0;
- w2.Expand = false;
- w2.Fill = false;
+ global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.hbox2 [this.ButtonGetDate]));
+ w6.Position = 0;
+ w6.Expand = false;
+ w6.Fill = false;
// Container child hbox2.Gtk.Box+BoxChild
- this.RetrieveRemoteDateButton = new global::Gtk.Button ();
- this.RetrieveRemoteDateButton.CanFocus = true;
- this.RetrieveRemoteDateButton.Name = "RetrieveRemoteDateButton";
- this.RetrieveRemoteDateButton.UseUnderline = true;
- this.RetrieveRemoteDateButton.Label = global::Mono.Unix.Catalog.GetString ("RemoteDate");
- this.hbox2.Add (this.RetrieveRemoteDateButton);
- global::Gtk.Box.BoxChild w3 = ((global::Gtk.Box.BoxChild)(this.hbox2 [this.RetrieveRemoteDateButton]));
- w3.Position = 2;
- w3.Expand = false;
- w3.Fill = false;
+ this.SendDataButton = new global::Gtk.Button ();
+ this.SendDataButton.CanFocus = true;
+ this.SendDataButton.Name = "SendDataButton";
+ this.SendDataButton.UseUnderline = true;
+ this.SendDataButton.Label = global::Mono.Unix.Catalog.GetString ("SendData");
+ this.hbox2.Add (this.SendDataButton);
+ global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.hbox2 [this.SendDataButton]));
+ w7.Position = 2;
+ w7.Expand = false;
+ w7.Fill = false;
this.vbox3.Add (this.hbox2);
- global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.vbox3 [this.hbox2]));
- w4.Position = 2;
- w4.Expand = false;
- w4.Fill = false;
+ global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox3 [this.hbox2]));
+ w8.Position = 2;
+ w8.Expand = false;
+ w8.Fill = false;
this.Add (this.vbox3);
if ((this.Child != null)) {
this.Child.ShowAll ();
</widget>
<packing>
<property name="Position">0</property>
- <property name="AutoSize">False</property>
+ <property name="AutoSize">True</property>
</packing>
</child>
<child>
- <placeholder />
+ <widget class="Gtk.HBox" id="hbox1">
+ <property name="MemberName" />
+ <property name="Spacing">6</property>
+ <child>
+ <widget class="Gtk.ScrolledWindow" id="GtkScrolledWindow">
+ <property name="MemberName" />
+ <property name="ShadowType">In</property>
+ <child>
+ <widget class="Gtk.TextView" id="TextToSend">
+ <property name="MemberName" />
+ <property name="CanFocus">True</property>
+ <property name="ShowScrollbars">True</property>
+ <property name="Text" translatable="yes" />
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="Position">0</property>
+ <property name="AutoSize">True</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="Gtk.SpinButton" id="SpinButtonNumbers">
+ <property name="MemberName" />
+ <property name="CanFocus">True</property>
+ <property name="Upper">1000</property>
+ <property name="PageIncrement">10</property>
+ <property name="StepIncrement">10</property>
+ <property name="ClimbRate">1</property>
+ <property name="Numeric">True</property>
+ </widget>
+ <packing>
+ <property name="Position">1</property>
+ <property name="AutoSize">False</property>
+ <property name="Fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="Position">1</property>
+ <property name="AutoSize">False</property>
+ <property name="Fill">False</property>
+ </packing>
</child>
<child>
<widget class="Gtk.HBox" id="hbox2">
<placeholder />
</child>
<child>
- <widget class="Gtk.Button" id="RetrieveRemoteDateButton">
+ <widget class="Gtk.Button" id="SendDataButton">
<property name="MemberName" />
<property name="CanFocus">True</property>
<property name="Type">TextOnly</property>
- <property name="Label" translatable="yes">RemoteDate</property>
+ <property name="Label" translatable="yes">SendData</property>
<property name="UseUnderline">True</property>
</widget>
<packing>
/// <typeparam name="TResult">The 1st type parameter.</typeparam>
async public Task<TResult> PostRemoteServiceAsync<TResult>(string uri, string method)
{
- POSTResult<TResult> postResult = await this.PostAsync<TResult>(uri, method, CancellationToken.None);
+ var postData = new POST();
+ postData.id = Interlocked.Increment(ref _nextId).ToString();
+ postData.jsonrpc = "2.0";
+ postData.method = method;
+
+ string jsonData = JsonConvert.SerializeObject(postData, _jsonSettings);
+
+ POSTResult<TResult> postResult = await this.PostAsync<TResult>(uri, method, jsonData, CancellationToken.None);
return postResult.result;
}
/// <summary>
- /// Posts the async.
+ /// Posts the remote service async.
/// </summary>
- /// <returns>The async.</returns>
+ /// <returns>The remote service async.</returns>
/// <param name="uri">URI.</param>
/// <param name="method">Method.</param>
- /// <param name="cancellation">Cancellation.</param>
/// <typeparam name="TResult">The 1st type parameter.</typeparam>
- async private Task<POSTResult<TResult>> PostAsync<TResult>(string uri, string method, CancellationToken cancellation)
+ async public Task PostRemoteServiceAsync(string uri, string method)
{
- var postData = new POST();
+ await this.PostRemoteServiceAsync<object>(uri, method);
+ }
+
+ /// <summary>
+ /// Posts the with parameters remote service async.
+ /// </summary>
+ /// <returns>The with parameters remote service async.</returns>
+ /// <param name="uri">URI.</param>
+ /// <param name="method">Method.</param>
+ /// <param name="parameters">Parameters.</param>
+ /// <typeparam name="TResult">The 1st type parameter.</typeparam>
+ async public Task<TResult> PostWithParametersRemoteServiceAsync<TResult>(string uri, string method, params object[] parameters)
+ {
+ var inputParameters = new List<object>(parameters);
+ var postData = new POSTParameters();
postData.id = Interlocked.Increment(ref _nextId).ToString();
postData.jsonrpc = "2.0";
postData.method = method;
+ postData.@params = inputParameters;
+
+ string jsonData = JsonConvert.SerializeObject(postData, _jsonSettings);
+
+ POSTResult<TResult> postResult = await this.PostAsync<TResult>(uri, method, jsonData, CancellationToken.None);
+
+ return postResult.result;
+ }
- string data = JsonConvert.SerializeObject(postData, _jsonSettings);
+ /// <summary>
+ /// Posts the with parameters remote service async.
+ /// </summary>
+ /// <returns>The with parameters remote service async.</returns>
+ /// <param name="uri">URI.</param>
+ /// <param name="method">Method.</param>
+ /// <param name="parameters">Parameters.</param>
+ async public Task PostWithParametersRemoteServiceAsync(string uri, string method, params object[] parameters)
+ {
+ await this.PostWithParametersRemoteServiceAsync<object>(uri, method, parameters);
+ }
+ /// <summary>
+ /// Posts the async.
+ /// </summary>
+ /// <returns>The async.</returns>
+ /// <param name="uri">URI.</param>
+ /// <param name="method">Method.</param>
+ /// <param name="cancellation">Cancellation.</param>
+ /// <typeparam name="TResult">The 1st type parameter.</typeparam>
+ async private Task<POSTResult<TResult>> PostAsync<TResult>(string uri, string method, string jsonData, CancellationToken cancellation)
+ {
// see: http://stackoverflow.com/questions/1329739/nested-using-statements-in-c-sharp
// see: http://stackoverflow.com/questions/5895879/when-do-we-need-to-call-dispose-in-dot-net-c
//TODO: Am I really sure I have to call the Dispose method of HttpContent content? In this case, shouldn't it be stupid?
// For HttpResponseMessage response I am sure I have to do it but I am not for HttpContent content.
- using (HttpContent content = new StringContent(data, System.Text.Encoding.UTF8, "application/json-rpc"))
+ using (HttpContent content = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json-rpc"))
using (HttpResponseMessage response = await this.PostAsync(uri, content, cancellation))
{
public string jsonrpc { get; set; }
public TResult result { get; set; }
}
+
+ private class POSTParameters
+ {
+ public string id { get; set; }
+ public string jsonrpc { get; set; }
+ public string method { get; set; }
+ public List<object> @params { get; set; }
+ }
}
}