Example #1
0
        /// <summary>
        /// Get the status of an asynchronous operation
        /// </summary>
        /// <param name="link">Url asynchronous operation</param>
        /// <returns>The status of an asynchronous operation</returns>
        private StatusAsync GetAsyncStatus(string link)
        {
            const string success  = "success";     // The completion status of the asynchronous operation 'completed successfully'
            const string progress = "in-progress"; // The execution status of the asynchronous operation 'in progress'

            string      content;
            string      status;
            StatusAsync statusAsync = StatusAsync.Failed;
            Param       param       = new Param();

            param.Link = link;

            content = CommandDisk(Oauth, YandexDiskAsk.Asynchronous_operation, param);

            if (content != null)
            {
                JObject json = JObject.Parse(content);
                status = (string)json.SelectToken("status");
                if (status == success)
                {
                    statusAsync = StatusAsync.Success;
                }
                else if (status == progress)
                {
                    statusAsync = StatusAsync.InProgress;
                }
                else
                {
                    statusAsync = StatusAsync.Failed;
                }
            }

            return(statusAsync);
        }
Example #2
0
        /// <summary>
        /// Await asynchronous operation complete
        /// </summary>
        /// <param name="content">String json for deserialization</param>
        private void AwaitAsyncComplete(string content)
        {
            string      link;
            StatusAsync status = StatusAsync.InProgress;

            JObject json = JObject.Parse(content);

            link = (string)json.SelectToken("href");

            if (link != null)
            {
                while (status == StatusAsync.InProgress)
                {
                    Thread.Sleep(1000);
                    status = GetAsyncStatus(link);
                    if (status != StatusAsync.InProgress)
                    {
                        break;
                    }
                }
            }
        }