示例#1
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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;
        }
示例#5
0
        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;
        }
示例#6
0
        /// <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);
        }
示例#8
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
		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);
        }
示例#13
0
        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);
        }
示例#14
0
        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,
                });
            }
        }
示例#15
0
		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,
				});
			}
		}
示例#16
0
		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;
		}
示例#17
0
		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;
		}
示例#18
0
		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;
		}
示例#19
0
		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;
		}
示例#20
0
		/// <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;
		
		}