/// <summary>
 /// Sets current stream active
 /// </summary>
 /// <param name="active">Flag to set stream active</param>
 public void SetCurrentStreamActive(bool active)
 {
     if (this.currentRecordIndex >= 0)
     {
         PriorityRecord pr = this.streamList[this.currentRecordIndex];
         pr.StreamActive = active;
         this.streamList[this.currentRecordIndex] = pr;
     }
 }
        /// <summary>
        /// Sets stream to open status
        /// </summary>
        /// <param name="name">Name of original file</param>
        /// <param name="streamId">Stream Id</param>
        public void StartStream(string name, int streamId)
        {
            int result = this.streamList.BinarySearch(new PriorityRecord(name), new PriorityComparer(PrioritySortField.NAME));

            if (result >= 0)
            {
                PriorityRecord pr = this.streamList[result];
                pr.StreamId             = streamId;
                pr.StreamOpened         = true;
                this.streamList[result] = pr;
                this.openStreamCount++;
            }
        }
        /// <summary>
        /// Sets stream to closed status if it can find such stream
        /// </summary>
        /// <param name="name">Name of original file</param>
        public void CloseStream(string name)
        {
            int result = this.streamList.BinarySearch(new PriorityRecord(name), new PriorityComparer(PrioritySortField.NAME));

            if (result >= 0)
            {
                PriorityRecord pr = this.streamList[result];
                pr.StreamOpened         = false;
                this.streamList[result] = pr;
                this.openStreamCount--;
                this.completedStreamCount++;
            }
        }
        /// <summary>
        /// Create download list for contents of HTML document
        /// </summary>
        /// <param name="origdir">Original path</param>
        /// <param name="document">The document</param>
        private static void MakeDownloadList(string origdir, XHtmlDocument document)
        {
            foreach (var script in document.Scripts)
            {
                PriorityRecord pr = new PriorityRecord(PriorityLevel.HighPriority, string.Format("{0}/{1}", origdir.ToLower(), script.ToLower()));
                currentStreams.Add(pr);
            }

            foreach (var link in document.Links)
            {
                PriorityRecord pr = new PriorityRecord(PriorityLevel.MediumPriority, string.Format("{0}/{1}", origdir.ToLower(), link.ToLower()));
                currentStreams.Add(pr);
            }

            foreach (var image in document.Images)
            {
                PriorityRecord pr = new PriorityRecord(PriorityLevel.LowPriority, string.Format("{0}/{1}", origdir.ToLower(), image.ToLower()));
                currentStreams.Add(pr);
            }

            // sort by priority, name
            currentStreams.SortByPriority();
        }
        /// <summary>
        /// File download. Called from command processor for top of the file tree
        /// </summary>
        /// <param name="fileName">The file name</param>
        private static void DownloadRootFile(string fileName)
        {
            if (protocolMonitor != null)
            {
                // set title of HTTP2 dowload
                protocolMonitor.Totals.LogTitle = "HTTP2 " + fileName;
                protocolMonitor.LastStartDate = DateTime.Now;

                // clear previous HTTP download
                protocolMonitor.LastHTTPLog = null;
            }

            // event will be set in OnDataReceived event handler
            rootDownloadEvent.Reset();
            rootFileName = fileName;

            // add first stream to list of streams
            PriorityRecord pr = new PriorityRecord(PriorityLevel.HighPriority, rootFileName);
            currentStreams.Add(pr);

            if (true == DownloadPath(fileName))
            {
                // if session state not "Opened" we got server side error and there is no connection
                if (session.State == ProtocolSessionState.Opened)
                {
                    // wait until all streams are closed
                    timeoutStreamMonitor = false;
                    streamMonitorEvent.Reset();
                    ThreadPool.QueueUserWorkItem(new WaitCallback(StreamListMonitorProc), 0);

                    streamMonitorEvent.WaitOne(1000);
                    timeoutStreamMonitor = true;
                }
            }
        }
 /// <summary>
 /// Add stream priority record
 /// </summary>
 /// <param name="rec">Record to find</param>
 public void Add(PriorityRecord rec)
 {
     this.streamList.Add(rec);
 }
 /// <summary>
 /// Add stream priority record
 /// </summary>
 /// <param name="rec">Record to find</param>
 public void Add(PriorityRecord rec)
 {
     this.streamList.Add(rec);
 }