Exemple #1
0
        /// <summary>
        /// Posts a Delete request to a given <paramref name="location"/>
        /// </summary>
        /// <returns>The Result if any, shouldn't return anything.</returns>
        /// <param name="location">The url sub-address like "http://192.168.1.2/<paramref name="location"/>"</param>
        internal override string Delete(string location)
        {
            string strResponseValue = string.Empty;

            Debug.WriteLine("This was deleted:");
            Debug.WriteLine(EndPoint + location + "?apikey=" + ApiKey);

            //Create an HTTP client object
            Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
            var headers = httpClient.DefaultRequestHeaders;

            headers.Add("X-Api-Key", ApiKey);
            Uri requestUri = new Uri(EndPoint + location);

            //Send the GET request asynchronously and retrieve the response as a string.
            Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
            string httpResponseBody = "";

            try
            {
                //Send the GET request
                httpResponse = httpClient.DeleteAsync(requestUri).AsTask().GetAwaiter().GetResult();
                //httpResponse.EnsureSuccessStatusCode();
                httpResponseBody = httpResponse.Content.ReadAsStringAsync().AsTask().GetAwaiter().GetResult();
                strResponseValue = httpResponseBody;
            }
            catch (Exception ex)
            {
                httpResponseBody = "Error: " + ex.HResult.ToString("X") + " Message: " + ex.Message;
            }
            return(strResponseValue);
        }
Exemple #2
0
        public static async Task <bool> DeleteQuizAsync(Quiz quiz)
        {
            Uri uri    = new Uri(quizzesBaseUri + quiz.QuizId.ToString(CultureInfo.InvariantCulture));
            var result = await httpClient.DeleteAsync(uri);

            return(result.IsSuccessStatusCode);
        }
        public async System.Threading.Tasks.Task RemoveItem(Item item)
        {
            var        itemIdJson = JsonConvert.SerializeObject(item.Id);
            HttpClient httpClient = new HttpClient();
            var        url        = $"http://localhost:5001/api/Category/DeleteItem/{item.Id}";
            var        res        = await httpClient.DeleteAsync(new Uri(url));

            if (res.IsSuccessStatusCode)
            {
                Category cat = null;
                foreach (Category c in Categories)
                {
                    if (c.Items.Contains(item))
                    {
                        cat = c;
                    }
                }
                if (cat != null)
                {
                    cat.Items.Remove(item);
                    Category tCat = Travellist.Categories.SingleOrDefault(c => c.Id == cat.Id);
                    tCat.Items.Remove(item);
                }
            }
        }
Exemple #4
0
        private async void GetHoloPoints(object sender, object e)
        {
            var uri = new System.Uri("https://holotest-6cd6b.firebaseio.com/HoloPoints.json");

            using (var httpClient = new Windows.Web.Http.HttpClient())
            {
                // Always catch network exceptions for async methods
                try
                {
                    //string result = "{\"FarBottomLeftX\":\" - 0.53\",\"FarBottomLeftY\":\" - 0.30\",\"FarBottomLeftZ\":\"2.08\",\"FarBottomRightX\":\"0.53\",\"FarBottomRightY\":\" - 0.30\",\"FarBottomRightZ\":\"2.08\",\"FarTopLeftX\":\" - 0.53\",\"FarTopLeftY\":\"0.30\",\"FarTopLeftZ\":\"2.08\",\"FarTopRightX\":\"0.53\",\"FarTopRightY\":\"0.30\",\"FarTopRightZ\":\"2.08\",\"NearBottomLeftX\":\" - 0.53\",\"NearBottomLeftY\":\" - 0.30\",\"NearBottomLeftZ\":\"0.00\",\"NearBottomRightX\":\"0.53\",\"NearBottomRightY\":\" - 0.30\",\"NearBottomRightZ\":\"0.00\",\"NearTopLeftX\":\" - 0.53\",\"NearTopLeftY\":\"0.30\",\"NearTopLeftZ\":\"0.00\",\"NearTopRightX\":\"0.53\",\"NearTopRightY\":\"0.30\",\"NearTopRightZ\":\"0.00\"}";//await httpClient.GetStringAsync(uri);
                    string result = await httpClient.GetStringAsync(uri);

                    Dictionary <string, Dictionary <string, string> > parentDict = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(result);

                    Dictionary <string, string> childDict = parentDict.Values.First();

                    WebServiceTxt.Text = childDict["FarBottomLeftX"];

                    Point3D topLeftpt = new Point3D();
                    topLeftpt.x = float.Parse(childDict["NearTopLeftX"]);
                    topLeftpt.y = float.Parse(childDict["NearTopLeftY"]);
                    topLeftpt.z = float.Parse(childDict["NearTopLeftZ"]);

                    Point3D topRightpt = new Point3D();
                    topRightpt.x = float.Parse(childDict["NearTopRightX"]);
                    topRightpt.y = float.Parse(childDict["NearTopRightY"]);
                    topRightpt.z = float.Parse(childDict["NearTopRightZ"]);

                    Point3D bottomLeftpt = new Point3D();
                    bottomLeftpt.x = float.Parse(childDict["NearBottomLeftX"]);
                    bottomLeftpt.y = float.Parse(childDict["NearBottomLeftY"]);
                    bottomLeftpt.z = float.Parse(childDict["NearBottomLeftZ"]);

                    Point3D bottomRightpt = new Point3D();
                    bottomRightpt.x = float.Parse(childDict["NearBottomRightX"]);
                    bottomRightpt.y = float.Parse(childDict["NearBottomRightY"]);
                    bottomRightpt.z = float.Parse(childDict["NearBottomRightZ"]);

                    DebugTxt.Text += " topLeftpt.x:  " + topLeftpt.x + " topLeftpt.y:   " + topLeftpt.y + " topLeftpt.z:   " + topLeftpt.z + "  " +
                                     " topRightpt.x:  " + topRightpt.x + " topRightpt.y:  " + topRightpt.y + " topRightpt.z:  " + topRightpt.z + "  " +
                                     " bottomLeftpt.x:  " + bottomLeftpt.x + " bottomLeftpt.y:  " + bottomLeftpt.y + " bottomLeftpt.z:  " + bottomLeftpt.z + "  " +
                                     " bottomRightpt.x:  " + bottomRightpt.x + " bottomRightpt.y:  " + bottomRightpt.y + " bottomRightpt.z:  " + bottomRightpt.z;



                    HoloPoints.Instance.topLeftpt     = topLeftpt;
                    HoloPoints.Instance.topRightpt    = topRightpt;
                    HoloPoints.Instance.bottomLeftpt  = bottomLeftpt;
                    HoloPoints.Instance.bottomRightpt = bottomRightpt;


                    Windows.Web.Http.HttpResponseMessage response = await httpClient.DeleteAsync(uri);
                }
                catch (Exception ex)
                {
                    WebServiceTxt.Text = ex.Message;
                }
            }
        }
Exemple #5
0
        // Delete A Travellist
        public async System.Threading.Tasks.Task DeleteSelectedTravellist(int id)
        {
            var        taskIdJson = JsonConvert.SerializeObject(id);
            HttpClient httpClient = new HttpClient();
            var        url        = $"http://localhost:5001/api/Travellist/{id}";
            var        res        = await httpClient.DeleteAsync(new Uri(url));

            if (res.IsSuccessStatusCode)
            {
                var deletedTravellist = Travellists.SingleOrDefault((t) => t.Id == id);
                if (deletedTravellist != null)
                {
                    Travellists.Remove(deletedTravellist);
                }
            }
        }
        public async System.Threading.Tasks.Task RemoveCat(Category cat)
        {
            var        catIdJson  = JsonConvert.SerializeObject(cat.Id);
            HttpClient httpClient = new HttpClient();
            var        url        = $"http://localhost:5001/api/Category/{cat.Id}";
            var        res        = await httpClient.DeleteAsync(new Uri(url));

            if (res.IsSuccessStatusCode)
            {
                var deletedCat = Categories.SingleOrDefault((t) => t.Id == cat.Id);
                if (deletedCat != null)
                {
                    Categories.Remove(deletedCat);
                    CategoryNames.Remove(deletedCat.Name);
                    Travellist.Categories.Remove(deletedCat);
                }
            }
        }