private async Task <ODAsyncTask> AsyncTaskResultForRequest(Http.IHttpRequest request, Uri requestUri)
        {
            var response = await GetHttpResponseAsync(request);

            if (response.StatusCode == HttpStatusCode.Accepted)
            {
                var sourceUrl = new Uri(response.Headers[ApiConstants.LocationHeaderName]);
                var jobStatus = new ODAsyncTask {
                    StatusUri = sourceUrl, RequestUri = requestUri
                };
                await RefreshAsyncTaskStatus(jobStatus);

                return(jobStatus);
            }
            else
            {
                var exception = await response.ToException();

                throw exception;
            }
        }
        internal async Task RefreshAsyncTaskStatus(ODAsyncTask task)
        {
            if (null == task)
            {
                throw new ArgumentNullException("task");
            }
            if (null == task.StatusUri)
            {
                throw new ArgumentException("task cannot have a null source URL");
            }

            var request = await CreateHttpRequestAsync(task.StatusUri, ApiConstants.HttpGet);

            var response = await GetHttpResponseAsync(request);

            if (response.ContentType != null)
            {
                var newStatus = await response.ConvertToDataModel <ODAsyncTaskStatus>();

                task.Status = newStatus;
            }
            else if (response.StatusCode == HttpStatusCode.SeeOther)
            {
                if (task.Status != null)
                {
                    task.Status.PercentComplete = 100;
                    task.Status.Status          = AsyncJobStatus.Complete;
                }

                // Create a request to get the new item
                Uri newUrl      = new Uri(response.Headers[ApiConstants.LocationHeaderName]);
                var itemRequest = await CreateHttpRequestAsync(newUrl, ApiConstants.HttpGet);

                task.FinishedItem = await DataModelForRequest <ODItem>(itemRequest);
            }
        }
        void UpdateListViewItem(ListViewItem item, ODAsyncTask task, bool forceUpdate = false)
        {
            if (!forceUpdate && !this.IsHandleCreated)
                return;

            var updateAction = new Action<ListViewItem, ODAsyncTask>((lvitem, lvtask) =>
                {
                    lvitem.SubItems.Clear();
                    lvitem.Text = lvtask.Status.Operation.ToString();
                    lvitem.SubItems.Add(lvtask.Status.PercentComplete.ToString());
                    lvitem.SubItems.Add(lvtask.Status.Status.ToString());
                    lvitem.SubItems.Add(lvtask.RequestUri.ToString());
                    lvitem.Tag = lvtask;
                });

            if (this.InvokeRequired)
            {
                Invoke(new MethodInvoker(() => updateAction(item, task)));
            }
            else
            {
                updateAction(item, task);
            }
        }
Esempio n. 4
0
 public static async Task Refresh(this ODAsyncTask pendingTask, ODConnection connection)
 {
     await connection.RefreshAsyncTaskStatus(pendingTask);
 }
 ListViewItem ListViewItemForTask(ODAsyncTask task)
 {
     var item = new ListViewItem();
     UpdateListViewItem(item, task, true);
     return item;
 }