Exemple #1
0
        public static void AddDownload(Search.Result result, string subFolder)
        {
            if (result == null)
                throw new ArgumentNullException("result");

            try
            {
                m_DownloadsAndQueue.Lock();
                if (m_DownloadsAndQueue.ContainsKey(ByteArrayToString(result.FileHash), DownloadCollection.KeyAccess.FileHash))
                    return;
                Download download = new Download(result);
                if (m_DownloadsAndQueue.Count >= Constants.MaximumDownloadsCount)
                {
                    download.SetSubFolderAndTime(subFolder, null);
                    download.RemoveSources();
                    if (bool.Parse(Settings.Instance["NewDownloadsToBeginngingOfQueue"]))
                        m_DownloadsAndQueue.Insert(Constants.MaximumDownloadsCount, download);
                    else
                        m_DownloadsAndQueue.Add(download);
                }
                else
                {
                    download.SetSubFolderAndTime(subFolder, DateTime.Now);
                    m_DownloadsAndQueue.Add(download);
                }
            }
            finally
            {
                m_DownloadsAndQueue.Unlock();
            }
            DownloadsXmlWriter.Write(m_DownloadsFilePath, m_DownloadsAndQueue);
        }
Exemple #2
0
        public static void AddDownload(byte[] fileHash, string fileName, long fileSize, string subFolder)
        {
            if (fileHash == null)
                throw new ArgumentNullException("fileHash");
            if (fileHash.Length != 64)
                throw new ArgumentException();
            if (fileName == null)
                throw new ArgumentNullException("fileName");
            if (fileSize < 0)
                throw new ArgumentOutOfRangeException("fileSize");

            try
            {
                m_DownloadsAndQueue.Lock();
                if (m_DownloadsAndQueue.ContainsKey(ByteArrayToString(fileHash), DownloadCollection.KeyAccess.FileHash))
                    return;
                Download download = new Download(fileHash, fileName, fileSize);
                if (m_DownloadsAndQueue.Count >= Constants.MaximumDownloadsCount)
                {
                    download.SetSubFolderAndTime(subFolder, null);
                    download.RemoveSources();
                    if (bool.Parse(Settings.Instance["NewDownloadsToBeginngingOfQueue"]))
                        m_DownloadsAndQueue.Insert(Constants.MaximumDownloadsCount, download);
                    else
                        m_DownloadsAndQueue.Add(download);
                }
                else
                {
                    download.SetSubFolderAndTime(subFolder, DateTime.Now);
                    m_DownloadsAndQueue.Add(download);
                }
            }
            finally
            {
                m_DownloadsAndQueue.Unlock();
            }
            DownloadsXmlWriter.Write(m_DownloadsFilePath, m_DownloadsAndQueue);
        }