Ejemplo n.º 1
0
        /// <summary>
        /// Cancels the async.
        /// </summary>
        /// <returns>A function delegate that returns the future result to be available through the Task.</returns>
        public Task CancelAsync()
        {
            if (string.IsNullOrWhiteSpace(this.Id))
            {
                // The job was not submitted yet.
                throw new InvalidOperationException(StringTable.InvalidOperationCancelForNotSubmittedJob);
            }

            Uri uri = new Uri(
                string.Format(CultureInfo.InvariantCulture, "/CancelJob?jobid='{0}'", HttpUtility.UrlEncode(Id)),
                UriKind.Relative);

            IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext();

            dataContext.IgnoreResourceNotFoundException = false;
            dataContext.AttachTo(JobBaseCollection.JobSet, this);

            return(dataContext
                   .ExecuteAsync <string>(uri, this)
                   .ContinueWith(
                       t =>
            {
                t.ThrowIfFaulted();

                JobData data = (JobData)t.AsyncState;
                data.Refresh();
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the Key Delivery Uri Asynchronously
        /// </summary>
        public Task <Uri> GetKeyDeliveryUrlAsync(ContentKeyDeliveryType contentKeyDeliveryType)
        {
            return(Task.Factory.StartNew <Uri>(() =>
            {
                Uri returnValue = null;
                if (this.GetMediaContext() != null)
                {
                    IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext();

                    MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter);

                    Uri uriGetKeyDeliveryUrl = new Uri(string.Format(CultureInfo.InvariantCulture, "/ContentKeys('{0}')/GetKeyDeliveryUrl", this.Id), UriKind.Relative);

                    BodyOperationParameter keyDeliveryTypeParameter = new BodyOperationParameter("keyDeliveryType", (int)contentKeyDeliveryType);

                    try
                    {
                        IEnumerable <string> results = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.ExecuteAsync(uriGetKeyDeliveryUrl, "POST", true, keyDeliveryTypeParameter).Result);

                        if (results != null)
                        {
                            // We specified only one result above so take the first result
                            string uriString = results.FirstOrDefault();

                            if (uriString != null)
                            {
                                returnValue = new Uri(uriString);
                            }
                        }
                    }
                    catch (AggregateException exception)
                    {
                        throw exception.Flatten().InnerException;
                    }
                }

                return returnValue;
            }));
        }