public async Task <WorklightResult> RestInvokeAsync() { var result = new WorklightResult(); try { StringBuilder uriBuilder = new StringBuilder() .Append(client.ServerUrl.AbsoluteUri) // Get the server URL .Append("/adapters") .Append("/SampleHTTPAdapter") //Name of the adapter .Append("/getStories"); // Name of the adapter procedure WorklightResourceRequest rr = client.ResourceRequest(new Uri(uriBuilder.ToString()), "GET"); WorklightResponse resp = await rr.Send(); result.Success = resp.Success; result.Message = (resp.Success) ? "Connected" : resp.Message; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> UnprotectedInvokeAsync() { var result = new WorklightResult(); try { StringBuilder uriBuilder = new StringBuilder() .Append("/adapters") .Append("/ResourceAdapter") //Name of the adapter .Append("/publicData"); // Name of the adapter procedure WorklightResourceRequest rr = client.ResourceRequest(new Uri(uriBuilder.ToString(), UriKind.Relative), "GET"); WorklightResponse resp = await rr.Send(); result.Success = resp.Success; //result.Message = (resp.Success) ? "Connected" : resp.Message; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> SendActivityAsync() { var result = new WorklightResult(); try { var resp = await Task.Run <string>(() => { client.Analytics.Send(); client.LogActivity("sample data from Xamarin app"); return("Activity Logged"); }); result.Success = true; result.Message = resp; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public ResultPage(WorklightResult result) : base() { BackgroundColor = Color.XamarinLightGray.ToFormsColor (); var htmlSource = new HtmlWebViewSource (); htmlSource.Html = (String.IsNullOrWhiteSpace(result.Response)) ? result.Message : result.Response; var webView = new WebView() { Source = htmlSource, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; Content = webView; }
public ResultPage(WorklightResult result) : base() { BackgroundColor = Color.XamarinLightGray.ToFormsColor(); var htmlSource = new HtmlWebViewSource(); htmlSource.Html = (String.IsNullOrWhiteSpace(result.Response)) ? result.Message : result.Response; var webView = new WebView() { Source = htmlSource, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; Content = webView; }
/// <summary> /// Invokes the procedured /// </summary> /// <returns>The proc.</returns> private async Task <WorklightResult> InvokeProc() { var result = new WorklightResult(); try { client.Analytics.Log("trying to invoking procedure"); System.Diagnostics.Debug.WriteLine("Trying to invoke proc"); WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("SampleHTTPAdapter", "getStories", new object[] { "technology" }); WorklightResponse task = await client.InvokeProcedure(invocationData); client.Analytics.Log("invoke response : " + task.Success); StringBuilder retval = new StringBuilder(); result.Success = task.Success; if (task.Success) { JsonArray jsonArray = (JsonArray)task.ResponseJSON["rss"]["channel"]["item"]; foreach (JsonObject title in jsonArray) { System.Json.JsonValue titleString; title.TryGetValue("title", out titleString); retval.Append(titleString.ToString()); retval.AppendLine(); } } else { retval.Append("Failure: " + task.Message); } result.Message = retval.ToString(); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> GetTagsAsync() { var result = new WorklightResult(); try { var resp = await GetTags(); result.Success = resp.Success; result.Message = "All tags"; result.Response = (resp.ResponseJSON != null) ? resp.ResponseJSON.ToString() : ""; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> UnSubscribeAsync() { var result = new WorklightResult(); try { var resp = await UnsubscribePush(); result.Success = resp.Success; result.Message = "Unsubscribed"; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> UnregisterAsync() { var result = new WorklightResult(); try { var resp = await push.UnregisterDevice(); result.Success = resp.Success; result.Message = "Unregistered"; result.Response = (resp.ResponseJSON != null) ? resp.ResponseJSON.ToString() : ""; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> ConnectAsync() { var result = new WorklightResult(); try { var resp = await Connect(); result.Success = resp.Success; result.Message = (resp.Success) ? "Connected" : resp.Message; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task<WorklightResult> ConnectAsync() { var result = new WorklightResult(); try { var resp = await Connect(); result.Success = resp.Success; result.Message = (resp.Success) ? "Connected" : resp.Message; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; System.Diagnostics.Debug.WriteLine("ERROR: " + ex.Message); // ERROR LOG } return result; }
public async Task <WorklightResult> SubscribeAsync() { var result = new WorklightResult(); try { var resp = await push.Subscribe(new string[] { "Xamarin" }); push.NotificationReceived += handleNotification; result.Success = resp.Success; result.Message = "Subscribed"; result.Response = (resp.ResponseJSON != null) ? resp.ResponseJSON.ToString() : ""; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public async Task <WorklightResult> InvokeAsync() { var result = new WorklightResult(); try { var conResp = await ConnectAsync(); if (!conResp.Success) { return(conResp); } result = await InvokeProc(); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
private async Task HandleResult(WorklightResult result, String title, bool ShowOnSuccess = false) { Busy = false; if (result.Success) { if (ShowOnSuccess) { await Navigation.PushAsync(new ResultPage(result) { Title = title, }); } else { await DisplayAlert(title, result.Message, "OK"); } } else { await Navigation.PushAsync(new ResultPage(result) { Title = title, }); } }
private async Task HandleResult(WorklightResult result, String title, bool ShowOnSuccess = false) { Busy = false; if (result.Success) { if (ShowOnSuccess) { await Navigation.PushAsync (new ResultPage(result) { Title = title, }); } else { await DisplayAlert(title,result.Message, "OK"); } } else { await Navigation.PushAsync (new ResultPage(result) { Title = title, }); } }
public async Task<WorklightResult> RestInvokeAsync() { var result = new WorklightResult(); try { StringBuilder uriBuilder = new StringBuilder() .Append(client.ServerUrl.AbsoluteUri) // Get the server URL .Append("/adapters") .Append("/SampleHTTPAdapter") //Name of the adapter .Append("/getStories"); // Name of the adapter procedure WorklightResourceRequest rr = client.ResourceRequest(new Uri(uriBuilder.ToString()), "GET" ); WorklightResponse resp = await rr.Send(); result.Success = resp.Success; result.Message = (resp.Success) ? "Connected" : resp.Message; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return result; }
public async Task<WorklightResult> InvokeAsync() { var result = new WorklightResult(); try { var conResp = await ConnectAsync(); if (!conResp.Success) return conResp; result = await InvokeProc(); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return result; }
public async Task<WorklightResult> SendActivityAsync() { var result = new WorklightResult(); try { var resp = await Task.Run<string>(()=> { client.Analytics.Send(); client.LogActivity("sample data from Xamarin app"); return "Activity Logged"; }); result.Success = true; result.Message = resp; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return result; }
public async Task<WorklightResult> UnSubscribeAsync() { var result = new WorklightResult(); try { var resp = await UnsubscribePush(); result.Success = resp.Success; result.Message = "Unsubscribed"; result.Response = resp.ResponseText; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return result; }
/// <summary> /// Invokes the procedured /// </summary> /// <returns>The proc.</returns> private async Task<WorklightResult> InvokeProc() { var result = new WorklightResult(); try { client.Analytics.Log("trying to invoking procedure"); System.Diagnostics.Debug.WriteLine("Trying to invoke proc"); WorklightProcedureInvocationData invocationData = new WorklightProcedureInvocationData("SampleHTTPAdapter", "getFeed", new object[] { "technology" }); // getStories WorklightResponse task = await client.InvokeProcedure(invocationData); client.Analytics.Log("invoke response : " + task.Success); StringBuilder retval = new StringBuilder(); result.Success = task.Success; if (task.Success) { JsonArray jsonArray = (JsonArray)task.ResponseJSON["rss"]["channel"]["item"]; foreach (JsonObject title in jsonArray) { System.Json.JsonValue titleString; title.TryGetValue("title", out titleString); retval.Append(titleString.ToString()); retval.AppendLine(); } } else { retval.Append("Failure: " + task.Message); } result.Message = retval.ToString(); } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return result; }