예제 #1
0
        public static bool TryHandleDownload(DcBot connection, DownloadItem item, Source source)
        {
            if (item != null && source != null)
            {
                string fileType = item.ContentInfo.Get(ContentInfo.FILELIST);
                string func = item.ContentInfo.Get("FUNC");
                string path = item.ContentInfo.Get(ContentInfo.STORAGEPATH);
                string usrId = item.ContentInfo.Get("USR");

                byte[] data = null;

                BaseFilelist filelist = null;

                int i = 0;
                while (i < 10)
                {
                    try
                    {
                        data = File.ReadAllBytes(path);
                        break;
                    }
                    catch (Exception)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    finally
                    {
                        i++;
                    }

                }

                if (data == null)
                    return false;

                switch (fileType)
                {
                    case BaseFilelist.XMLBZ:
                        filelist = new FilelistXmlBz2(data, true);
                        break;
                    case BaseFilelist.XML:
                        filelist = new FilelistXmlBz2(data, false);
                        break;
                    case BaseFilelist.BZ:
                        filelist = new FilelistMyList(data, true);
                        break;
                    default:
                        connection.SendMessage(Actions.PrivateMessage, usrId, "Unrecognized filelist.");
                        return false;
                }

                LogMsg("CreateShare");
                filelist.CreateShare();
                LogMsg("/CreateShare");
                Share share = filelist.Share as Share;

                File.Delete(path);

                if (share != null)
                {
                    switch (func)
                    {
                        case "new":
                            FuncListShare(connection, share, usrId, FunctionTypes.ListNewEpisodes); break;
                        case "list":
                            FuncListShare(connection, share, usrId, FunctionTypes.ListAllEpisodes); break;
                        case "debug":
                            FuncListShare(connection, share, usrId, FunctionTypes.ListDebugInfoOnEpisodes); break;
                        case "countdown":
                        case "cd":
                            FuncCountDownShare(connection, share, usrId); break;
                    }
                }
            }

            return false;
        }
예제 #2
0
파일: UiHub.cs 프로젝트: musakasim/flowlib
        void DownloadManager_DownloadCompleted(object sender, FmdcEventArgs e)
        {
            DownloadItem di = sender as DownloadItem;
            if (di == null)
                return;
            if (di.ContentInfo.IsFilelist)
            {
                byte[] data = System.IO.File.ReadAllBytes(di.ContentInfo.Get(ContentInfo.STORAGEPATH));
                BaseFilelist filelist = null;
                switch (di.ContentInfo.Get(ContentInfo.FILELIST))
                {
                    case BaseFilelist.XMLBZ:
                        filelist = new FilelistXmlBz2(data, true);
                        break;
                    case BaseFilelist.BZ:
                        filelist = new FilelistMyList(data, true);
                        break;
                }

                if (filelist != null)
                {
                    filelist.CreateShare();
                    Share userShare = filelist.Share;

                    if (user != null)
                    {
                        foreach (System.Collections.Generic.KeyValuePair<string, ContentInfo> var in userShare)
                        {
                            var.Value.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\Download\" + var.Value.Get(ContentInfo.NAME));
                            DownloadItem di2 = new DownloadItem(var.Value);
                            // Uncomment below if you want to disable segment downloading.
                            //di2.SegmentSize = di2.ContentInfo.Size;
                            downloadManager.AddDownload(di2, new Source(null, user.ID));
                        }
                    }
                }
            }
        }
예제 #3
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;
        }