Esempio n. 1
0
        void downloadManager_DownloadCompleted(object sender, FmdcEventArgs e)
        {
            DownloadItem dwnItem = sender as DownloadItem;

            if (dwnItem == null)
            {
                return;
            }

            if (dwnItem.ContentInfo.IsFilelist)
            {
                _gotFilelist = true;
                // Read filelist
                byte[]       data     = System.IO.File.ReadAllBytes(dwnItem.ContentInfo.Get(ContentInfo.STORAGEPATH));
                BaseFilelist filelist = null;
                switch (dwnItem.ContentInfo.Get(ContentInfo.FILELIST))
                {
                case BaseFilelist.XMLBZ:
                    filelist = new FilelistXmlBz2(data, true);
                    break;

                case BaseFilelist.XML:
                    filelist = new FilelistXmlBz2(data, false);
                    break;
                }
                _testTimeoutLength += 10;
                filelist.CreateShare();
                IShare share = filelist.Share;

                // Select one file that is more then 500 MiB of size
                var bigContentItem = share.Where(f => f.Value.Size > BIGSIZE).Select(k => k.Value).FirstOrDefault();
                // Select one file that is less then 100 MiB of size
                var smallContentItem = share.Where(f => f.Value.Size < SMALLSIZE).Select(k => k.Value).FirstOrDefault();

                if (bigContentItem == null)
                {
                    return;
                }
                // Add BIG file for a user
                bigContentItem.Set(ContentInfo.STORAGEPATH, currentDir + "Download" + System.IO.Path.DirectorySeparatorChar + "big" + ".file");
                downloadManager.AddDownload(new DownloadItem(bigContentItem), new Source(dwnItem.ContentInfo.Get("HubStoreId"), dwnItem.ContentInfo.Get(UserInfo.STOREID)));
                _hasBigContent = true;

                if (smallContentItem == null)
                {
                    return;
                }
                // Add SMALL file for a user
                smallContentItem.Set(ContentInfo.STORAGEPATH, currentDir + "Download" + System.IO.Path.DirectorySeparatorChar + "small" + ".file");
                downloadManager.AddDownload(new DownloadItem(smallContentItem), new Source(dwnItem.ContentInfo.Get("HubStoreId"), dwnItem.ContentInfo.Get(UserInfo.STOREID)));
                _hasSmallContent = true;

                _testTimeoutLength += 30;
            }
            else
            {
                // Handle file
                if (dwnItem.ContentInfo.Size > BIGSIZE)
                {
                    _gotBigContent = true;
                }
                else if (dwnItem.ContentInfo.Size < SMALLSIZE)
                {
                    _gotSmallContent = true;
                }
            }

            if (_gotFilelist && _gotBigContent && _gotSmallContent)
            {
                _isFinished = true;
            }
        }