public static void UploadImage()
        {
            Properties.Settings.Default.message = "Uploading file.";

            Task <string> responseContent = UploadImage(ImgHelper.GetImgPath());

            if (responseContent == null)
            {
                return;
            }

            responseContent.Wait();

            string json = responseContent.Result;

            ResponseJson responseObj = JsonConvert.DeserializeObject <ResponseJson>(json);

            if (responseObj.Status == "success")
            {
                bool parsed = Int32.TryParse(responseObj.SubId, out int parseResult);

                if (parsed)
                {
                    ApiHelper.SubId = parseResult;
                }
            }
        }
示例#2
0
        private static void SaveSession(Task <string> sessionStatus)
        {
            string json = sessionStatus.Result;

            ResponseJson responseObj = JsonConvert.DeserializeObject <ResponseJson>(json);

            if (responseObj.Status == "success")
            {
                SessionKey = responseObj.Session;
            }
        }
        public static bool GeJobStatus()
        {
            string url = $"jobs/" + ApiHelper.JobId;

            Properties.Settings.Default.message = "Getting job status...";

            Task <string> task = SendRequest(url);

            task.Wait();

            ResponseJson responseObj
                = JsonConvert.DeserializeObject <ResponseJson>(task.Result);

            if (responseObj.Status == "success")
            {
                Properties.Settings.Default.message = "Job succesfull";

                return(true);
            }

            return(false);
        }
        public static bool GetSubmissionStatus()
        {
            //int time = 0;
            //int sleep = 10000;

            DateTime time = DateTime.UtcNow;

            if (ApiHelper.SubId == 0)
            {
                return(false);
            }

            string url = $"submissions/" + ApiHelper.SubId;

            DateTime waitTime = DateTime.UtcNow;

            while (true)
            {
                if (DateTime.UtcNow - waitTime < TimeSpan.FromSeconds(10))
                {
                    continue;
                }

                Properties.Settings.Default.message = DateTime.UtcNow.ToString("HH:mm:ss")
                                                      + " Asking for submission results...";


                try
                {
                    Task <string> task = SendRequest(url);

                    task.Wait();

                    string jsonString = task.Result;

                    //Console.WriteLine(jsonString);


                    ResponseJson responseObj
                        = JsonConvert.DeserializeObject <ResponseJson>(jsonString);

                    if (responseObj.job_calibrations.Count() != 0)
                    {
                        Properties.Settings.Default.message = "Submission succesfull";
                        ApiHelper.JobId = responseObj.jobs[0].ToString();
                        return(true);
                    }
                }
                catch
                {
                    Properties.Settings.Default.message = "Connection error. Retrying...";
                    //Thread.Sleep(2000);
                }

                if (DateTime.UtcNow - time > TimeSpan.FromMinutes(30))
                {
                    return(false);
                }

                waitTime = DateTime.UtcNow;
            }
        }