Ejemplo n.º 1
0
 private void NavigateToURL(MarkStringContent linkMark)
 {
     try
     {
         Uri targetUri = new Uri(linkMark.content);
         WebViewControl.Navigate(targetUri);
     }
     catch (UriFormatException)
     {
         System.Diagnostics.Debug.WriteLine("Address is invalid, try again.");
     }
 }
Ejemplo n.º 2
0
        private void GetRequest(string url)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    System.Diagnostics.Debug.WriteLine(Globals.selectedMark.id);

                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders
                    .Accept
                    .Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "relativeAddress");

                    using (var response = client.GetAsync("/mark/" + Globals.selectedMark.id).Result)
                    {
                        string responseString = response.Content.ReadAsStringAsync().Result;
                        System.Diagnostics.Debug.WriteLine(responseString);

                        var resultObject = JObject.Parse(responseString);
                        var newMark      = resultObject.ToObject <Mark>();

                        Globals.selectedMark.id    = newMark.id;
                        Globals.selectedMark.label = newMark.label;
                        Globals.selectedMark.type  = newMark.type;

                        if (newMark.type == "link")
                        {
                            MarkStringContent linkMark = resultObject.ToObject <MarkStringContent>();
                            if (linkMark.content != previousLink)
                            {
                                previousLink = linkMark.content;
                                NavigateToURL(linkMark);
                            }
                        }
                        else
                        {
                            previousLink = "";
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine("CAUGHT EXCEPTION:");
                System.Diagnostics.Debug.WriteLine(exception);
            }
        }
Ejemplo n.º 3
0
        async private void PostRequest(string url, string newLabel)
        {
            string newId = GetId(url);

            if (newId == "")
            {
                return;
            }

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);

                    var mark = new MarkStringContent();
                    mark.id      = newId;
                    mark.label   = newLabel;
                    mark.type    = "undefined";
                    mark.content = "";

                    Globals.selectedMark = mark;
                    Globals.selectedMarksOnView[Globals.tileId] = mark;

                    var json        = JsonConvert.SerializeObject(mark);
                    var httpContent = new StringContent(json, Encoding.UTF8, "application/json");

                    var httpResponse = await client.PostAsync("/mark/", httpContent);

                    if (httpResponse.Content != null)
                    {
                        var responseContent = await httpResponse.Content.ReadAsStringAsync();

                        System.Diagnostics.Debug.WriteLine(responseContent);
                    }
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine("CAUGHT EXCEPTION:");
                System.Diagnostics.Debug.WriteLine(exception);
            }
        }