protected override void BeginRequest(RetryQueueRequest request)
 {
     //Adding an intentional delay here to work around a known timing issue
     //with the SSME.  If this is called too soon after initialization the
     //request will be aborted with no indication raised from the SSME.
     //TODO: Remove this workaround once the SSME has been fixed.
     DispatcherTimer timer = new DispatcherTimer();
     timer.Interval = TimeSpan.FromMilliseconds(250);
     EventHandler tickHandler = null;
     tickHandler = (s, e) =>
         {
             Segment segment = null;
             List<StreamInfo> streams = null;
             var streamSelectionRequest = request as StreamSelectionRequest;
             if (streamSelectionRequest != null)
             {
                 streams = streamSelectionRequest.Streams.Select(i => i.StreamInfo).ToList();
                 segment = streamSelectionRequest.Segment;
             }
             else
             {
                 var streamModifyRequest = request as StreamModifyRequest;
                 if (streamModifyRequest != null)
                 {
                     streams = streamModifyRequest.Streams.Select(i => i.StreamInfo).ToList();
                     segment = streamModifyRequest.Segment;
                 }
             }                    
             segment.SegmentInfo.SelectStreamsAsync(streams, request);
             timer.Tick -= tickHandler;
             timer.Stop();
         };
     timer.Tick += tickHandler;
     timer.Start();
 }
        protected void NotifyRequestSuccessful(RetryQueueRequest request)
        {
            lock (_threadSync)
            {
                if (_activeRequests.Contains(request))
                {
                    _activeRequests.Remove(request);
                }
            }

            OnRequestCompleted(request);
            AttemptToStartRequests();
        }
        protected override void BeginRequest(RetryQueueRequest request)
        {
            var offlineTask = request as OfflineTask;

            if (offlineTask != null)
            {
                switch (offlineTask.Type)
                {
                    case OfflineTaskType.DownloadFile:
                        BeginDownloadFile(offlineTask);
                        break;
                    case OfflineTaskType.ProcessManifest:
                        break;
                    case OfflineTaskType.QueueChunkList:
                        break;
                    default:
                        break;
                }
            }
        }
        protected override void CancelRequest(RetryQueueRequest request)
        {
            base.CancelRequest(request);

            var offlineTask = request as OfflineTask;

            if (offlineTask != null && offlineTask.DownloadWebClient != null)
            {
                offlineTask.DownloadWebClient.CancelAsync();
            }
        }
        protected override void OnRetryingRequest(RetryQueueRequest request)
        {
            base.OnRetryingRequest(request);

            var downloadRequest = request as DownloadRequest;
            if (RetryingDownload != null && downloadRequest != null)
            {
                RetryingDownload(this, downloadRequest.MediaTrack, downloadRequest.ChunkTimestamp);
            }
        }
        protected override void OnRequestExceededMaximumRetryAttempts(RetryQueueRequest request)
        {
            base.OnRequestExceededMaximumRetryAttempts(request);

            var downloadRequest = request as DownloadRequest;
            if (DownloadExceededMaximumRetries != null && downloadRequest != null)
            {
                DownloadExceededMaximumRetries(this, downloadRequest.MediaTrack, downloadRequest.ChunkTimestamp);
            }
        }
        protected override void BeginRequest(RetryQueueRequest request)
        {
            var downloadRequest = request as DownloadRequest;
            if (downloadRequest != null)
            {
                _rateMonitor.UpdateRate();
                if (_rateMonitor.CurrentRate > _maximumRequestRate)
                {
                    var delay = _rateMonitor.RecommendDelay(_maximumRequestRate);
                    var timer = new DispatcherTimer
                    {
                        Interval = delay
                    };

                    EventHandler tickHandler = null;
                    tickHandler = (s, e) =>
                    {
                        timer.Tick -= tickHandler;
                        timer.Stop();
                        downloadRequest.MediaTrack.TrackInfo.BeginGetChunk(
                            downloadRequest.ChunkTimestamp, BeginGetChunk_Completed,
                            downloadRequest);
                    };
                    timer.Tick += tickHandler;
                    timer.Start();
                }
                else
                {
                    downloadRequest.MediaTrack.TrackInfo.BeginGetChunk(downloadRequest.ChunkTimestamp, BeginGetChunk_Completed, downloadRequest);
                }
            }
        }
 protected void AddRequest(RetryQueueRequest request)
 {
     _requestQueue.Enqueue(request);
     NotifyRequestAdded();
 }
 protected virtual void CancelRequest(RetryQueueRequest request) { }
 protected virtual void OnRequestCompleted(RetryQueueRequest request) { }
 protected virtual void OnRequestExceededMaximumRetryAttempts(RetryQueueRequest request) { }
 protected virtual void OnRetryingRequest(RetryQueueRequest request) { }
 protected abstract void BeginRequest(RetryQueueRequest request);
        protected override void OnRequestExceededMaximumRetryAttempts(RetryQueueRequest request)
        {
            base.OnRequestExceededMaximumRetryAttempts(request);

            var streamSelectionRequest = request as IStreamSelectionRequest;
            if (StreamSelectionExceededMaximumRetries != null && streamSelectionRequest != null)
            {
                StreamSelectionExceededMaximumRetries(this, streamSelectionRequest.Segment, streamSelectionRequest.Streams);
            }
        }
        protected override void OnRetryingRequest(RetryQueueRequest request)
        {
            base.OnRetryingRequest(request);

            var streamSelectionRequest = request as IStreamSelectionRequest;
            if (RetryingStreamSelection != null && streamSelectionRequest != null)
            {
                RetryingStreamSelection(this, streamSelectionRequest.Segment, streamSelectionRequest.Streams);
            }
        }