protected async void btnSaveCurrExampleLabels_onClick() { bool webAPIsessionStarted = await EnsureWebAPIsessionStarted(); if (!webAPIsessionStarted) { return; } string url = new Uri(base_webAPI_uri).Append("labels?command=post_current_example_labels&webapi_client_id=" + guid).AbsoluteUri; #if DEBUG Console.WriteLine("URL = " + url); #endif ExampleLabels labelsPackage = new ExampleLabels(CurrentImageBasename, ObjectsList, PaintAreaSize); string currExampleLabelsJSONstring = JsonConvert.SerializeObject(labelsPackage, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); #if DEBUG Console.WriteLine("currExampleLabelsJSONstring: "); Console.WriteLine(currExampleLabelsJSONstring); #endif HttpResponseMessage response = await http.PostAsync(url, new StringContent(currExampleLabelsJSONstring), CancellationToken.None); HttpStatusCode respCode = response.StatusCode; #if DEBUG Console.WriteLine("response status code: " + respCode); #endif if (respCode != HttpStatusCode.OK) { } StateHasChanged(); }
protected async Task <bool> RequestExistingLabels() { WebAPI_response resp = null; string url = new Uri(base_webAPI_uri).Append("labels?command=get_current_example_labels&webapi_client_id=" + guid + "&img_basename=" + CurrentImageBasename).AbsoluteUri; #if DEBUG Console.WriteLine("URL = " + url); #endif string strRepl = await http.GetStringAsync(url); try { resp = JsonConvert.DeserializeObject <WebAPI_response>(strRepl, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); } catch (Exception e) { #if DEBUG Console.WriteLine(e); Console.WriteLine("ERROR: failed deserializing WebAPI response"); return(false); #endif } if (resp != null) { if (resp.ResponseCode == ResponseCodes.Error) { #if DEBUG WebAPI_error currError = resp.Error; Console.WriteLine("WebAPI ERROR code : " + currError.ErrorCode); Console.WriteLine("WebAPI ERROR description : " + currError.ErrorDescription); Console.WriteLine("Response JSON: "); return(false); #endif } else { try { ExampleLabels received_labels = JsonConvert.DeserializeObject <ExampleLabels>(resp.StringAttributes["found_example_labels"], new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); #if DEBUG Console.WriteLine("got received_labels: " + received_labels.ToJSON()); #endif foreach (BPaintObject bpobj in received_labels.LabelsList) { try { #if DEBUG Console.WriteLine("post-processing BPaintObject"); #endif bpobj.PostJsonDeserializationCleaning(); } catch (Exception e) { Console.WriteLine(e); } ObjectsList.Add(bpobj); if (ObjectsList.Any()) { bpobj.ObjectID = ObjectsList.Max(x => x.ObjectID) + 1; cmd_Clear_Selection(); cmd_Clear_Editing(); } else { bpobj.ObjectID = 1; } foreach (BPaintVertex v in bpobj.VerticesList) { #if DEBUG Console.WriteLine("Adding " + bpobj.VerticesList.Count.ToString() + " vertices to this frame"); #endif VerticesList.Add(v); } } cmd_RefreshSVG(); return(true); } catch (Exception e) { #if DEBUG Console.WriteLine("ERROR : failed extracting found_example_labels from JSON response."); Console.WriteLine("got JSON response:"); Console.Write(strRepl); Console.WriteLine("converted it to the WebAPI_response instance:"); Console.Write(resp.ToJSON()); Console.WriteLine(e); #endif return(false); } } } return(true); }