protected async Task <bool> EnsureWebAPIsessionStarted()
        {
            if (webAPIsessionStarted)
            {
                return(true);
            }

            string url = new Uri(base_webAPI_uri).Append("exec?command=start&webapi_client_id=" + guid).AbsoluteUri;

#if DEBUG
            Console.WriteLine("btnStartWebAPIsession_onClick: HTTP GET");
            Console.WriteLine("URL = " + url);
#endif
            HttpClient http    = new HttpClient();
            string     strRepl = await http.GetStringAsync(url);

            WebAPI_response resp = null;
            try
            {
                resp = JsonConvert.DeserializeObject <WebAPI_response>(strRepl, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                });
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine(e);
#endif
                throw;
            }

            if (resp == null)
            {
#if DEBUG
                Console.WriteLine("ERROR: failed deserializing WebAPI response");
#endif
                return(false);
            }

            if (resp.ResponseCode == ResponseCodes.Error)
            {
#if DEBUG
                Console.WriteLine("ERROR : failed starting a WebAPI session:");
                Console.WriteLine("Error code: " + resp.Error.ErrorCode);
                Console.WriteLine("Error message: " + resp.Error.ErrorDescription);
#endif
                return(false);
            }
            else if (resp.ResponseCode == ResponseCodes.OK)
            {
                Console.WriteLine("OK : WebAPI session started successfully!");
                webAPIsessionStarted = true;
                return(true);
            }

            return(false);
        }
        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);
        }
        protected async Task <bool> RequestImageURL(string request_type = "get_next_image")
        {
            string url = new Uri(base_webAPI_uri).Append("images?command=" + request_type + "&webapi_client_id=" + guid).AbsoluteUri;

#if DEBUG
            Console.WriteLine("URL = " + url);
#endif

            string strRepl = await http.GetStringAsync(url);

            WebAPI_response resp = null;
            try
            {
                resp = JsonConvert.DeserializeObject <WebAPI_response>(strRepl, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                });
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine(e);
#endif
                throw;
            }

            if (resp == null)
            {
#if DEBUG
                Console.WriteLine("ERROR: failed deserializing WebAPI response");
#endif
                return(false);
            }


            if (resp.ResponseCode == ResponseCodes.Error)
            {
                WebAPI_error currError = resp.Error;
#if DEBUG
                Console.WriteLine("WebAPI ERROR code : " + currError.ErrorCode);
                Console.WriteLine("WebAPI ERROR description : " + currError.ErrorDescription);
                Console.WriteLine("Response JSON: ");
                Console.Write(resp.ToJSON());
#endif
            }
            else
            {
                try
                {
                    CurrentBackgroundImageURI = resp.StringAttributes["imageURL"];
#if DEBUG
                    Console.WriteLine("got CurrentBackgroundImageURI value: " + CurrentBackgroundImageURI);
#endif
                    CurrentBackgroundImageURI = new Uri(MyNavigationManager.Uri).Append(CurrentBackgroundImageURI).AbsoluteUri;
#if DEBUG
                    Console.WriteLine("now CurrentBackgroundImageURI: " + CurrentBackgroundImageURI);
#endif
                    CurrentImageBasename = resp.StringAttributes["imgBaseName"];

                    StateHasChanged();
                }
                catch (Exception e)
                {
#if DEBUG
                    Console.WriteLine("ERROR : failed extracting CurrentBackgroundImageURI 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);
        }