示例#1
0
        private void ContinueDownloadsFromPreviousTimeSlot()
        {
            //copy and clear out the download sections in progress
            Dictionary <User, DownloadingFrom> previousDownloadSectionsInProgress = new Dictionary <User, DownloadingFrom>();

            foreach (User user in _downloadSectionsInProgress.Keys)
            {
                previousDownloadSectionsInProgress[user] = _downloadSectionsInProgress[user];
            }
            _downloadSectionsInProgress = new Dictionary <User, DownloadingFrom>();

            if (previousDownloadSectionsInProgress.Count > 0)
            {
                for (int i = previousDownloadSectionsInProgress.Count - 1; i >= 0; i--)
                {
                    if (ConsumedDownloadBandwidth < DownloadBandwidth)
                    {
                        User            user            = previousDownloadSectionsInProgress.Keys.ElementAt(i);
                        DownloadingFrom downloadingFrom = previousDownloadSectionsInProgress[user];
                        double          percentage      = DownloadSectionFromContact(
                            user,
                            downloadingFrom.FileSection.SectionNumber,
                            1 - downloadingFrom.PercentageDownloaded
                            );
                        if (percentage != 1 - downloadingFrom.PercentageDownloaded)
                        {
                            downloadingFrom.PercentageDownloaded += percentage;
                            _downloadSectionsInProgress[user]     = downloadingFrom;
                        }
                    }
                }
            }
        }
示例#2
0
        private double DownloadSectionFromContact(User contactToDownloadFrom, int section, double percentage)
        {
            DownloadingFrom downloadingFrom = contactToDownloadFrom.RequestSection(this, section, percentage, VideoRate);

            if (downloadingFrom == null)
            {
                return(0);
            }

            if (downloadingFrom.PercentageDownloaded == percentage)
            {
                ConsumedDownloadBandwidth += Functions.BandwidthNeededPerSection(VideoRate) * percentage;
                _sectionsToInsert.Add(downloadingFrom.FileSection);
                return(percentage);
            }
            else
            {
                ConsumedDownloadBandwidth += Functions.BandwidthNeededPerSection(VideoRate) * downloadingFrom.PercentageDownloaded;
                _downloadSectionsInProgress[contactToDownloadFrom] = downloadingFrom;
                return(downloadingFrom.PercentageDownloaded);
            }
        }