public MainWindow()
 {
     InitializeComponent();
     vkApi = VKAPI.Instance;
     data = new DownloadData()
     {
         UserID = "1"
     };
     imgData = new ImageData();
     tr = TranslationManager.Instance;
     this.albumURL.DataContext = data;
     this.saveDir.DataContext = data;
     this.languageSelector.DataContext = tr;
     tr.CurrentLanguage = tr.Languages.First(a => a.TwoLetterISOLanguageName == tr.CurrentLanguage.TwoLetterISOLanguageName);
 }
示例#2
0
        public override ValidationResults <DownloadStateOccurance> ValidateData(ProcessedDataPackage package)
        {
            ValidationResults <DownloadStateOccurance> results = new ValidationResults <DownloadStateOccurance>();

            results.Score = -1;

            DownloadData data = package.GetData <DownloadData>();

            if (data == null || data.Count == 0)
            {
                return(results);
            }

            results.Score = 100;

            foreach (DownloadState ds in data)
            {
                if (regex.IsMatch(ds.URL) == false)
                {
                    results.Add(new DownloadStateOccurance(ds));
                }
            }

            results.Score -= Math.Min(results.Count, 4) * 10;

            if (results.Count > 0)
            {
                if (results.Count == 1)
                {
                    results.ResultsExplenation = message_single;
                }
                else
                {
                    results.ResultsExplenation = String.Format(message_more, results.Count);
                }
            }

            return(results);
        }
示例#3
0
        public SortedDictionary <string, long> UpdateDownloadTransfers(
            DownloadData downloads,
            SortedDictionary <string, long> downloadChanges,
            PopularityTransferData oldTransfers,
            PopularityTransferData newTransfers)
        {
            Guard.Assert(
                downloadChanges.Comparer == StringComparer.OrdinalIgnoreCase,
                $"Download changes should have comparer {nameof(StringComparer.OrdinalIgnoreCase)}");

            Guard.Assert(
                downloadChanges.All(x => downloads.GetDownloadCount(x.Key) == x.Value),
                "The download changes should match the latest downloads");

            // Downloads are transferred from a "from" package to one or more "to" packages.
            // The "oldTransfers" and "newTransfers" maps "from" packages to their corresponding "to" packages.
            // The "incomingTransfers" maps "to" packages to their corresponding "from" packages.
            var incomingTransfers = GetIncomingTransfers(newTransfers);

            _logger.LogInformation("Detecting changes in popularity transfers.");
            var transferChanges = _dataComparer.ComparePopularityTransfers(oldTransfers, newTransfers);

            _logger.LogInformation("{Count} popularity transfers have changed.", transferChanges.Count);

            // Get the transfer changes for packages affected by the download and transfer changes.
            var affectedPackages = GetPackagesAffectedByChanges(
                oldTransfers,
                newTransfers,
                incomingTransfers,
                transferChanges,
                downloadChanges);

            return(ApplyDownloadTransfers(
                       downloads,
                       newTransfers,
                       incomingTransfers,
                       affectedPackages));
        }
        public override async Task <RopDocument[]> FillDate()
        {
            var dd        = new DownloadData();
            var dataBytes = await dd.Data(rdBase.PathDocument);

            var str  = Encoding.UTF8.GetString(dataBytes);
            var list = new List <RopData>();

            var lines = str.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                var arr = line.Split(new[] { ";" }, StringSplitOptions.None);
                if (string.IsNullOrWhiteSpace(arr[0]))
                {
                    continue;
                }

                if (arr[0].Contains("Jude"))
                {
                    continue;
                }

                var rd = new RopData();
                rd.Judet   = judetFinder.Find(arr[0]);
                rd.Valoare = int.Parse(arr[3]);
                list.Add(rd);
            }
            list = list.GroupBy(it => it.Judet).Select(group =>
                                                       new RopData()
            {
                Judet   = group.Key,
                Valoare = group.Sum(it => it.Valoare)
            }
                                                       ).ToList();
            rdBase.Data = list.ToArray();
            return(new[] { rdBase });
        }
示例#5
0
        private async Task <RopData> CreateFarmacie(Uri uri)
        {
            var rd           = new RopData();
            var numeFarmacie = uri.Segments.Last().Replace(".xls", "");

            switch (numeFarmacie)
            {
            case "bucuresti---sector-1":
            case "bucuresti---sector-2":
            case "bucuresti---sector-3":
            case "bucuresti---sector-4":
            case "bucuresti---sector-5":
            case "bucuresti---sector-6":
                rd.Judet = judetFinder.Find("Bucuresti");
                break;

            case "farmacii-circuit-inchis324112670-1":
                //TODO: take this into consideration
                return(null);

            default:
                rd.Judet = judetFinder.Find(numeFarmacie);
                break;
            }



            var dd        = new DownloadData();
            var dataBytes = await dd.Data(uri);

            var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".xls");

            File.WriteAllBytes(path, dataBytes);
            var nr = await ExcelHelpers.NrRows(path);

            rd.Valoare = nr;
            return(rd);
        }
            public void DetectsDecreaseDueToMissingId()
            {
                var oldData = new DownloadData();

                oldData.SetDownloadCount(IdA, V1, 7);
                oldData.SetDownloadCount(IdA, V2, 1);
                oldData.SetDownloadCount(IdB, V1, 1);
                var newData = new DownloadData();

                newData.SetDownloadCount(IdB, V1, 1);

                var delta = Target.Compare(oldData, newData);

                Assert.Equal(KeyValuePair.Create(IdA, 0L), Assert.Single(delta));
                VerifyDecreaseTelemetry(Times.Exactly(2));
                TelemetryService.Verify(
                    x => x.TrackDownloadCountDecrease(
                        IdA,
                        V1,
                        true,
                        true,
                        7,
                        false,
                        false,
                        0),
                    Times.Once);
                TelemetryService.Verify(
                    x => x.TrackDownloadCountDecrease(
                        IdA,
                        V2,
                        true,
                        true,
                        1,
                        false,
                        false,
                        0),
                    Times.Once);
            }
            public void RejectsCyclicalPopularityTransfers()
            {
                PopularityTransfer = 1;

                DownloadData.SetDownloadCount("A", "1.0.0", 100);
                DownloadData.SetDownloadCount("B", "1.0.0", 100);

                DownloadChanges["A"] = 100;
                DownloadChanges["B"] = 100;

                PopularityTransfers.AddTransfer("A", "B");
                PopularityTransfers.AddTransfer("B", "A");

                var result = Target.UpdateDownloadTransfers(
                    DownloadData,
                    DownloadChanges,
                    OldTransfers,
                    PopularityTransfers);

                Assert.Equal(new[] { "A", "B" }, result.Keys);
                Assert.Equal(0, result["A"]);
                Assert.Equal(0, result["B"]);
            }
            public void IncomingTransfersAddedToNewDownloads()
            {
                PopularityTransfer = 1;

                DownloadData.SetDownloadCount("A", "1.0.0", 100);
                DownloadData.SetDownloadCount("B", "1.0.0", 5);
                DownloadData.SetDownloadCount("C", "1.0.0", 0);

                DownloadChanges["B"] = 5;

                PopularityTransfers.AddTransfer("A", "B");
                PopularityTransfers.AddTransfer("A", "C");

                var result = Target.UpdateDownloadTransfers(
                    DownloadData,
                    DownloadChanges,
                    OldTransfers,
                    PopularityTransfers);

                // B has new downloads and receives downloads from A.
                Assert.Equal(new[] { "B" }, result.Keys);
                Assert.Equal(55, result["B"]);
            }
            public void PopularityTransfersAreNotTransitive()
            {
                PopularityTransfer = 1;

                DownloadData.SetDownloadCount("A", "1.0.0", 100);
                DownloadData.SetDownloadCount("B", "1.0.0", 100);
                DownloadData.SetDownloadCount("C", "1.0.0", 100);

                PopularityTransfers.AddTransfer("A", "B");
                PopularityTransfers.AddTransfer("B", "C");

                var result = Target.InitializeDownloadTransfers(
                    DownloadData,
                    PopularityTransfers);

                // A transfers downloads to B.
                // B transfers downloads to C.
                // B and C should reject downloads from A.
                Assert.Equal(new[] { "A", "B", "C" }, result.Keys);
                Assert.Equal(0, result["A"]);
                Assert.Equal(0, result["B"]);
                Assert.Equal(200, result["C"]);
            }
        public static int DownloadedBookAdd(BookDataContext bookdb, DownloadData dd, ExistHandling handling)
        {
            int retval = 0;

            NQueries++;
            var book = BookGet(bookdb, dd.BookId);

            if (book == null)
            {
                return(retval);
            }
            switch (handling)
            {
            case ExistHandling.IfNotExists:
                if (book.DownloadData == null)
                {
                    book.DownloadData = dd;
                    retval++;
                }
                break;
            }
            return(retval);
        }
        private void ApplyDownloadTransfers(
            DownloadData newData,
            PopularityTransferData oldTransfers,
            PopularityTransferData newTransfers,
            SortedDictionary <string, long> downloadChanges)
        {
            _logger.LogInformation("Finding download changes from popularity transfers.");
            var transferChanges = _downloadTransferrer.UpdateDownloadTransfers(
                newData,
                downloadChanges,
                oldTransfers,
                newTransfers);

            _logger.LogInformation(
                "{Count} package IDs have download count changes from popularity transfers.",
                transferChanges.Count);

            // Apply the transfer changes to the overall download changes.
            foreach (var transferChange in transferChanges)
            {
                downloadChanges[transferChange.Key] = transferChange.Value;
            }
        }
示例#12
0
        private void UserSigninProcess()
        {
            if (chkRememberMe.IsChecked == true)
            {
                SaveData();
            }
            Uploader u = new Uploader();
            Farm     f = new Farm();

            u.SetRole(DownloadData.GetUserRole(txtUsername.Text));
            try
            {
                f = DownloadData.GetUserFarm(txtUsername.Text);
                u.SetFarm(f);
            }
            catch
            {
                MessageBox.Show("An error occured when attempting to load your farm details.");
            }

            this.Close();
            u.ShowDialog();
        }
示例#13
0
        private SortedDictionary <string, long> ApplyDownloadTransfers(
            DownloadData downloads,
            PopularityTransferData outgoingTransfers,
            SortedDictionary <string, SortedSet <string> > incomingTransfers,
            HashSet <string> packageIds)
        {
            _logger.LogInformation(
                "{Count} package IDs have download changes due to popularity transfers.",
                packageIds.Count);

            var result = new SortedDictionary <string, long>(StringComparer.OrdinalIgnoreCase);

            foreach (var packageId in packageIds)
            {
                result[packageId] = TransferPackageDownloads(
                    packageId,
                    outgoingTransfers,
                    incomingTransfers,
                    downloads);
            }

            return(result);
        }
示例#14
0
    public static int CreateNewDownload(SqlConnection oConnData, string downloadName, string filetype, int studyID, int inclREL, string mlist, string tplist, string grplist, string sslist)
    {
        //!!!!!!!!!!!!!!!!!!!!!!!!
        //LOG THE NEW DOWNLOAD

        int new_downloadPK = DownloadData.NewDownload_INSERT(oConnData, downloadName, filetype, studyID, inclREL, mlist, tplist, grplist, sslist);
        int new_ddversPK   = DownloadData.NewDownload_vers_INSERT(oConnData, new_downloadPK);

        //The vers should always be 1 for new downloads
        SqlCommand cmdVers = new SqlCommand("select vers from datDownload_vers   where ddversPK =" + new_ddversPK.ToString(), oConnData);
        int        vers    = (int)cmdVers.ExecuteScalar();


///        string[] measnames = mlist_names.Split('|');

        //RETRIEVE THE DATA
        DataTable[] myDT = DownloadData.DownloadDataArray2(oConnData, Convert.ToInt16(new_ddversPK));

        string filename = "zipdata_" + new_downloadPK.ToString() + "_v" + vers.ToString();

        //string info_msg = "";
        //string data_msg = "";

        if (filetype == "Excel XML")
        {
            CreateExcel(myDT, filename);
        }

        else if (filetype == "TAB zip")
        {
            CreateTABzip(myDT, filename);
        }
        // Handle other file types here...

        ///!!!!!!!!!!!!!!!!!!!!!!!!!!
        return(new_ddversPK);
    }
        private async void ReloadDownload_Click(object sender, RoutedEventArgs e)
        {
            using (var FolderDialog = new System.Windows.Forms.OpenFileDialog())
            {
                FolderDialog.InitialDirectory = (Properties.Settings.Default.CustomTempDownloadFolder) ? Properties.Settings.Default.DownloadFolder : Properties.Settings.Default.DEFAULT_TempDownloadFolder;
                FolderDialog.Filter           = "Pdi files (*.dtemp.pdi;*.pdi)|*.dtemp.pdi;*.pdi";
                FolderDialog.Multiselect      = true;

                var result = FolderDialog.ShowDialog();

                if (result != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                foreach (String file in FolderDialog.FileNames)
                {
                    var temp = DownloadData.DeserializeDownloadData(file);
                    /** Prepare download **/
                    var listItem = new StreamDownloaderControls.UserControls.DownloadListItem()
                    {
                        Filename       = temp.FileName,
                        DownloadFolder = temp.DownloadDestination,
                        DownloadURL    = temp.RawURL
                    };

                    listBox.Items.Add(listItem);

                    var downloadContainer = new DownloadContainer(listItem, temp);

                    /** Start **/
                    await downloadContainer.Initialize();

                    downloadContainer.Start();
                }
            }
        }
示例#16
0
        /// <summary>
        /// Open a new download settings dialog.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static async Task <DownloadData> OpenDialog(Window owner, DownloadData data)
        {
            //Initialize window
            var temp = new DownlaodSettings()
            {
                Owner              = owner,
                _host              = data.FileHost,
                HostIcon           = data.FileHost.HostIcon,
                HostName           = data.FileHost.HostName,
                DownloadURL        = data.RawURL,
                DownloadFolder     = data.DownloadDestination,
                Filename           = data.FileName,
                AdditionalSettigns = (data.FileHost.CustomSettings == null) ? null : new DefaultSettings()
            };

            //Load file extensions
            var sfe = new List <FileExtensionListItem>();

            if (data.FileHost.SupportedFileExtensions != null)
            {
                foreach (var extension in data.FileHost.SupportedFileExtensions)
                {
                    sfe.Add(new FileExtensionListItem(extension.Extension, extension));
                }
            }

            temp.FileExtensions = sfe; //Apply file extensions
            temp.Show();

            temp.Owner.IsEnabled = false; //Lock main window
            await WaitToContinue(temp);   //Await Submit or cancel click

            temp.Close();
            temp.Owner.IsEnabled = true; //Unlock main window

            return(temp._downloadData);  //return result
        }
示例#17
0
        private async Task StartOneDownload(string fileName, Uri uri, DownloadData dd)
        {
            StorageFile destinationFile = null;

            try
            {
                var acFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("ACFUNVideo", CreationCollisionOption.OpenIfExists);

                destinationFile = await acFolder.CreateFileAsync(fileName,
                                                                 CreationCollisionOption.ReplaceExisting);
            }
            catch (Exception ex)
            {
                return;
            }

            BackgroundDownloader downloader = new BackgroundDownloader();
            DownloadOperation    download   = downloader.CreateDownload(uri, destinationFile);

            dd.DownloadGuid.Add(download.Guid.ToString());
            SaveDB();
            download.Priority = BackgroundTransferPriority.Default;
            await download.StartAsync();
        }
            public void NewOrUpdatedSplitsPopularityTransfer()
            {
                PopularityTransfer = 1;

                DownloadData.SetDownloadCount("A", "1.0.0", 100);
                DownloadData.SetDownloadCount("B", "1.0.0", 5);
                DownloadData.SetDownloadCount("C", "1.0.0", 0);

                PopularityTransfers.AddTransfer("A", "B");
                PopularityTransfers.AddTransfer("A", "C");

                TransferChanges["A"] = new[] { "B", "C" };

                var result = Target.UpdateDownloadTransfers(
                    DownloadData,
                    DownloadChanges,
                    OldTransfers,
                    PopularityTransfers);

                Assert.Equal(new[] { "A", "B", "C" }, result.Keys);
                Assert.Equal(0, result["A"]);
                Assert.Equal(55, result["B"]);
                Assert.Equal(50, result["C"]);
            }
            public void RemovePopularityTransfer()
            {
                // A used to transfer to both B and C.
                PopularityTransfer = 1;

                DownloadData.SetDownloadCount("A", "1.0.0", 100);
                DownloadData.SetDownloadCount("B", "1.0.0", 5);
                DownloadData.SetDownloadCount("C", "1.0.0", 0);

                TransferChanges["A"] = new string[0];
                OldTransfers.AddTransfer("A", "B");
                OldTransfers.AddTransfer("A", "C");

                var result = Target.UpdateDownloadTransfers(
                    DownloadData,
                    DownloadChanges,
                    OldTransfers,
                    PopularityTransfers);

                Assert.Equal(new[] { "A", "B", "C" }, result.Keys);
                Assert.Equal(100, result["A"]);
                Assert.Equal(5, result["B"]);
                Assert.Equal(0, result["C"]);
            }
示例#20
0
        public static List <DownloadData> Uliza(string json, string domain)
        {
            var       list = new List <DownloadData>();
            ULIZAINFO info = JsonConvert.DeserializeObject <ULIZAINFO>(json);

            string url   = info.NET_CONN;
            string title = info.TITLE;
            string dir   = info.STORAGESUBDIR;

            foreach (var item in info.PLAYLIST)
            {
                string filename = item.NAME;
                string ext      = Util.GetExtension(filename);

                string T = url;
                string Y = String.Format("{0}:{1}/{2}", ext, dir, filename);


                DownloadData data = new DownloadData
                {
                    URL       = url,
                    Title     = title,
                    Folder    = domain,
                    Protocol  = "RTMP",
                    Extension = "",

                    RTMP_T = T,
                    RTMP_Y = Y,
                };

                list.Add(data);
            }
            //rtmpdump -r "rtmp://flv.nhk.or.jp/ondemand/flv/mp4:nhk-mov/7b1527cb9377660aa81d869c284e73dd-1_multi_464000_v1.mp4"  -s "https://aka-secure-img.uliza.jp/Player/2417/player.swf?d=20150416" -t "rtmp://flv.nhk.or.jp/ondemand/flv/" -y "mp4:nhk-mov/7b1527cb9377660aa81d869c284e73dd-1_multi_464000_v1.mp4" -o filename.mp4

            return(list);
        }
示例#21
0
        private static List <DownloadData> ParseSite(ShowData showData, string url, out string nextpageurl, out string firstcover, UploadCache uploadCache)
        {
            nextpageurl = "";
            firstcover  = "";

            HttpWebRequest req = HttpWebRequest.CreateHttp(url);

            req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            var            resp       = req.GetResponse();
            BufferedStream buffStream = new BufferedStream(req.GetResponse().GetResponseStream());

            url = resp.ResponseUri.ToString();
            StreamReader reader = new StreamReader(buffStream);

            bool inContent           = false;
            bool inPost              = false;
            bool inPostContent       = false;
            List <DownloadData> list = new List <DownloadData>();
            Match      m;
            SeasonData seasonData = null;
            UploadData uploadData = null;

            while (!reader.EndOfStream)
            {
                String line = reader.ReadLine();
                if (line.Contains("line-height") && line.Contains("&nbsp;")) //detect: <div style="line-height:5px;height:5px;background-color:lightgrey;">&nbsp;</div>
                {
                    continue;                                                //I can only hope this will never occour in any other case..
                }
                if (inContent)
                {
                    if (inPost)
                    {
                        if (inPostContent)
                        {
                            //Debug.Assert(seasonData!=null);
                            if (seasonData == null)
                            {
                                Console.WriteLine("Warning: Invalid Html received while parsing " + showData.Name + ". Trying to continue");
                                continue;
                            }
                            if ((m = new Regex("<p>\\s*<strong>\\s*(.+?)\\s*</strong>\\s*[^/]*\\s*<br\\s?/>").Match(line)).Success)
                            {
                                //Debug.Assert(uploadData != null);
                                if (uploadData == null)
                                {
                                    Console.WriteLine("Warning: Invalid Html received while parsing " + showData.Name + ". Trying to continue");
                                    continue;
                                }
                                string title = WebUtility.HtmlDecode(m.Groups[1].Value);

                                var   downloads = new Dictionary <string, string>();
                                Regex r         = new Regex("<a\\s+href\\s*=\"([^\"]+)\".+\\s+(.+?)\\s*<");
                                while (true)
                                {
                                    line = reader.ReadLine();
                                    Match m2 = r.Match(line);
                                    if (m2.Success)
                                    {
                                        String keyOrg = WebUtility.HtmlDecode(m2.Groups[2].Value);
                                        String key    = keyOrg;
                                        while (downloads.ContainsKey(key))
                                        {
                                            Match mx  = new Regex("\\((\\d+)\\)$").Match(key);
                                            int   num = 1;
                                            if (mx.Success)
                                            {
                                                num = int.Parse(mx.Groups[1].Value);
                                            }

                                            key = keyOrg + "(" + ++num + ")";
                                        }
                                        String val = m2.Groups[1].Value;
                                        if (val != null && !String.IsNullOrWhiteSpace(val) && val.Trim().StartsWith("http://"))
                                        {
                                            downloads.Add(key, val);
                                        }
                                        else
                                        {
                                            Console.WriteLine("Warning: Invalid Download received while parsing " + showData.Name + ". Ignoring link");
                                            //ignoring invalid download
                                        }
                                    }
                                    if (line.Contains("</p>"))
                                    {
                                        break;
                                    }
                                }

                                if (title.Contains("720p"))
                                {
                                    uploadData.Format = "720p";
                                }
                                else if (title.Contains("1080p"))
                                {
                                    uploadData.Format = "1080p";
                                }
                                else if (title.Contains("720i"))
                                {
                                    uploadData.Format = "720i";
                                }
                                else if (title.Contains("1080i"))
                                {
                                    uploadData.Format = "1080i";
                                }

                                DownloadData dd = new DownloadData();
                                dd.Upload = uploadCache == null ? uploadData : uploadCache.GetUniqueUploadData(uploadData);
                                dd.Title  = title;

                                if (title.ToLower().Contains("subbed"))
                                {
                                    dd.Upload.Subbed = true;
                                }

                                foreach (var download in downloads)
                                {
                                    dd.Links.Add(download.Key, download.Value);
                                }

                                list.Add(dd);
                            }
                            else if ((m = new Regex("(?:(?:<p(?:\\s+style\\s*\\=\\s*\\\"[^\\\"]+\\\"\\s*)?>)|(?:<div\\s+class\\s*=\\s*\"info\">))\\s*(.*?(?:Dauer|Größe|Sprache|Format|Uploader).*?)\\s*(?:(?:</p>)|(?:</div>))").Match(line)).Success ||
                                     ((m = new Regex("<p\\s+style\\s*\\=\\s*\\\"[^\\\"]+\\\"\\s*>").Match(line)).Success && ((line = reader.ReadLine()) != "") && (m = new Regex("\\s*(.*?(?:Dauer|Größe|Sprache|Format|Uploader).*?)\\s*</p>").Match(line)).Success))
                            {
                                /*
                                 * Nice case:
                                 * <p><strong>Dauer:</strong> 20:00 | <strong>Größe:</strong> 175 MB | <strong>Sprache:</strong> Englisch &amp; deutsche Untertitel | <strong>Format:</strong> XviD | <strong>HQ-Cover:</strong> <a href="http://justpic.info/?s=cover&amp;id=&amp;name=&amp;keyword=VGhlIEJpZyBCYW5nIFRoZW9yeQ,,">Download</a> | <strong>Uploader:</strong> block06</p>
                                 *
                                 * Bad case: (note newline!!)
                                 * <p style="background-color: #f0f0f0;">
                                 *  <strong>Dauer:</strong> 20:00 | <strong>Größe:</strong> 175 MB | <strong>Sprache:</strong> Englisch | <strong>Format:</strong> XviD | <strong>HQ-Cover:</strong> <a href="http://justpic.info/?s=cover&#038;id=&#038;name=&#038;keyword=VGhlIEJpZyBCYW5nIFRoZW9yeQ,,">Download</a> | <strong>Uploader:</strong> block06</p>
                                 */

                                uploadData        = new UploadData();
                                uploadData.Season = seasonData;

                                String          c  = WebUtility.HtmlDecode(m.Groups[1].Value);
                                MatchCollection mc = new Regex("<strong>\\s*(.+?)\\s*</strong>\\s*(.+?)\\s*(?:\\||$)").Matches(c);
                                foreach (Match match in mc)
                                {
                                    String key   = match.Groups[1].Value.ToLower();
                                    String value = match.Groups[2].Value;
                                    if (key.Contains("dauer") || key.Contains("runtime") || key.Contains("duration"))
                                    {
                                        uploadData.Runtime = value;
                                    }
                                    else if (key.Contains("grösse") || key.Contains("größe") || key.Contains("size"))
                                    {
                                        uploadData.Size = value;
                                    }
                                    else if (key.Contains("uploader"))
                                    {
                                        uploadData.Uploader = value;
                                    }
                                    else if (key.Contains("format"))
                                    {
                                        uploadData.Format = value;
                                    }
                                    else if (key.Contains("sprache") || key.Contains("language"))
                                    {
                                        value = value.ToLower();
                                        if (value.Contains("deutsch") || value.Contains("german"))
                                        {
                                            uploadData.Language |= UploadLanguage.German;
                                        }
                                        if (value.Contains("englisch") || value.Contains("english"))
                                        {
                                            uploadData.Language |= UploadLanguage.English;
                                        }
                                        if (value.Contains("subbed"))
                                        {
                                            uploadData.Subbed = true;
                                        }
                                    }
                                }
                            }
                            else if ((m = new Regex("<p>\\s*([^<]+)\\s*</p>").Match(line)).Success)
                            {
                                if (seasonData.Description == "")
                                {
                                    seasonData.Description = WebUtility.HtmlDecode(m.Groups[1].Value);
                                }
                            }
                            else if ((m = new Regex("<p>\\s*<img\\s+src\\s*=\"([^\"]+)\".*?/>\\s*</p>").Match(line)).Success)
                            {
                                seasonData.CoverUrl = m.Groups[1].Value;
                                if (firstcover == "")
                                {
                                    firstcover = seasonData.CoverUrl;
                                }
                            }
                            else if (new Regex("</div>").Match(line).Success)
                            {
                                inPostContent = false;
                                seasonData    = null;
                                uploadData    = null;
                            }
                        }
                        else if ((m = new Regex("<h2>\\s*<a\\s+href\\s*=\"([^\"]+)\".*?>(.+?)</a>\\s*</h2>").Match(line)).Success)
                        {
                            seasonData      = new SeasonData();
                            seasonData.Show = showData;

                            seasonData.Url   = m.Groups[1].Value;
                            seasonData.Title = WebUtility.HtmlDecode(m.Groups[2].Value);
                        }
                        else if (new Regex("<div\\s+class\\s*=\\s*\"post-content\"\\s*>").Match(line).Success)
                        {
                            inPostContent = true;
                        }
                        else if (new Regex("</div>").Match(line).Success)
                        {
                            inPost = false;
                        }
                    }
                    else if (new Regex("<div\\s+class\\s*=\\s*\"post\"\\s*>").Match(line).Success)
                    {
                        inPost = true;
                    }
                    else
                    {
                        if ((m = new Regex("<span\\s+class\\s*=\\s*'page\\s+current'>\\s*(\\d+)\\s*</span>").Match(line)).Success)
                        {
                            int currentPage = int.Parse(m.Groups[1].Value);
                            int nextPage    = currentPage + 1;
                            if (new Regex("title\\s*='" + nextPage + "'").Match(line).Success)
                            {
                                if (new Regex("/page/" + currentPage + "/?$").Match(url).Success)
                                {
                                    nextpageurl = url.Replace("page/" + currentPage, "page/" + nextPage);
                                }
                                else
                                {
                                    nextpageurl = url;
                                    if (!nextpageurl.EndsWith("/"))
                                    {
                                        nextpageurl += "/";
                                    }
                                    nextpageurl += "page/" + nextPage + "/";
                                }
                            }
                        }
                        if (new Regex("</div>").Match(line).Success)
                        {
                            inContent = false;
                        }
                    }
                }
                else if (new Regex("<div\\s+id\\s*=\\s*\"content\"\\s*>").Match(line).Success)
                {
                    inContent = true;
                }
            }
            reader.Close();
            return(list);
        }
示例#22
0
    bool DownMultiFiles(DownloadData dd)
    {
        MultiFileDownData    mfdd       = (MultiFileDownData)dd.Data;
        List <DownChunkData> chunkList  = new List <DownChunkData>();
        List <DownChunkData> waitList   = new List <DownChunkData>();
        List <DownChunkData> retryList  = new List <DownChunkData>();
        List <CheckServerIP> serverList = new List <CheckServerIP>();
        bool bHasNoYD = false;

        for (byte i = 0; i < mfdd.FTPIPList.Count; ++i)
        {
            CheckServerIP ssi = new CheckServerIP(i);
            if (mfdd.FTPIPList[i].ISP == (byte)ISPType.ISP_YD)
            {
                ssi.FailedCount = (uint)(MAX_CHUNK_COUNT * 2);
            }
            serverList.Add(ssi);
            if (mfdd.FTPIPList[i].ISP != (byte)ISPType.ISP_YD)
            {
                bHasNoYD = true;
            }
        }
        //1.划分Chunk
        //================================
        uint tick        = Utility.GetTickCount();
        byte ipidx       = 0;
        int  CHUNK_SIZE2 = CHUNK_SIZE << 1;
        uint chunkIdx    = 0;

        for (byte i = 0; i < mfdd.FileList.Count; ++i)
        {
            int resSize   = (int)mfdd.FileList[i].ResSize;
            int resOffset = 0;
            while (resSize > 0)
            {
                DownChunkData dcd = new DownChunkData();
                dcd.FileIdx = i;
                if (resSize >= CHUNK_SIZE2)
                {
                    dcd.Length = CHUNK_SIZE;
                }
                else
                {
                    dcd.Length = resSize;
                }
                dcd.ChunkIdx = chunkIdx++;
                dcd.Offset   = resOffset;
                dcd.RecvSize = 0;
                dcd.RecvTick = 0;
                resOffset   += dcd.Length;
                resSize     -= dcd.Length;
                if (chunkList.Count < MAX_CHUNK_COUNT)
                {
                    do
                    {
                        ipidx = (byte)((ipidx + 1) % serverList.Count);
                    } while (bHasNoYD && mfdd.FTPIPList[ipidx].ISP == (byte)ISPType.ISP_YD);
                    dcd.checkServer = serverList[ipidx];
                    dcd.checkServer.BeginUse();
                    if (!InitChunk(dd, dcd, mfdd.FTPIPList[ipidx]))
                    {
                        return(false);
                    }
                    dcd.RecvTick = tick;
                    chunkList.Add(dcd);
                }
                else
                {
                    waitList.Add(dcd);
                }
            }
        }
        //1.接收Chunk
        //================================
        while (true)
        {
            tick = Utility.GetTickCount();
            for (int i = 0; i < chunkList.Count;)
            {
                DownChunkData chunk = chunkList[i];
                if (!DownChunk(dd, chunk, tick))
                {
                    CloseSocket(chunk);
                    chunk.checkServer.EndUse(chunk.State != ChunkState.CHUNK_CONNECT && chunk.RecvSize != 0);
                    if (chunk.State == ChunkState.CHUNK_RECV_DATA)
                    {
                        //将接收的数据coy到data
                        CopyBuffToData(mfdd, chunk);
                        chunk.Offset  += chunk.RecvSize;
                        chunk.Length  -= chunk.RecvSize;
                        chunk.RecvSize = 0;
                        ++chunk.RetryCount;
                        chunk.SendCmdData = null;
                    }
                    if (chunk.RetryCount >= MAX_RETRY_COUNT)
                    {
                        //split
                        if ((chunk.Length > MAX_XOR_SIZE || chunk.XOR == 1) && chunk.Length > 16)
                        {
                            DownChunkData dcd1, dcd2;
                            SplitChunk(ref chunkIdx, chunk, out dcd1, out dcd2);
                            waitList.Add(dcd1);
                            waitList.Add(dcd2);
                        }
                        else
                        {
                            chunk.RetryCount  = 0;
                            chunk.XOR         = 1;
                            chunk.SendCmdData = null;
                            retryList.Add(chunk);
                        }
                    }
                    else
                    {
                        retryList.Add(chunk);
                    }
                    Utility.ListRemoveAt(chunkList, i);
                    continue;
                }
                else if (chunk.State == ChunkState.CHUNK_COMPLETION)
                {
                    CopyBuffToData(mfdd, chunk);
                    CloseSocket(chunk);
                    chunk.checkServer.EndUse(true);
                    RecvFileDataFlag cfd = mfdd.RecvFileList[chunk.FileIdx];
                    if (cfd.RecvSize == cfd.FileData.Length)
                    {
                        //完成
                        MultiFileOK mfo = new MultiFileOK();
                        mfo.Data = cfd.FileData;
                        mfo.Drd  = mfdd.FileList[chunk.FileIdx];
                        mfdd.CompletionList[mfdd.RecvCount] = mfo;
                        if (++mfdd.RecvCount == mfdd.FileList.Count)
                        {
                            Debug.Log("所有文件完成!");
                            return(true);
                        }
                    }
                    Utility.ListRemoveAt(chunkList, i);
                    continue;
                }
                ++i;
            }//end for

            if (chunkList.Count < MAX_CHUNK_COUNT)
            {
                tick = Utility.GetTickCount();
                DownChunkData dcd = null;
                if (waitList.Count > 0)
                {
                    dcd = waitList[0];
                    waitList.RemoveAt(0);
                }
                else if (retryList.Count > 0)
                {
                    dcd = retryList[0];
                    retryList.RemoveAt(0);
                }
                if (dcd != null)
                {
                    serverList.Sort(SortCheckServer);
                    serverList[0].BeginUse();
                    dcd.checkServer = serverList[0];
                    if (!InitChunk(dd, dcd, mfdd.FTPIPList[dcd.checkServer.ServerIdx]))
                    {
                        return(false);
                    }
                    dcd.RecvTick = Utility.GetTickCount();
                    chunkList.Add(dcd);
                }
            }
            if (mfdd.RecvCount == mfdd.FileList.Count)
            {
                break;
            }
            Thread.Sleep(1);
        }
        ; //end while
        return(true);
    }
示例#23
0
        public void DownloadSubtitle(SubtitleItem subtitleItem, BasicMediaDetail mediaDetail, FolderSelectionItem folderSelectionItem, SubtitlesSearchType searchType, bool skipDefaults)
        {
            if (IsCanceled())
                Kill();
            if (_subtitlesDownloaderThread != null && _subtitlesDownloaderThread.IsAlive)
                return;

            _isCanceled = false;
            _status = ThreadStatus.StatusEnded;

            DownloadData downloadData = new DownloadData {
                SubtitleItem = subtitleItem,
                MediaDetail = mediaDetail,
                FolderSelectionItem = folderSelectionItem,
                SearchType = searchType,
                SkipDefaults = skipDefaults,
                StatusList = new List<SubtitleDownloadStatus>()
            };

            _subtitlesDownloaderThread = new Thread(DownloadSubtitleAsync);
            _subtitlesDownloaderThread.IsBackground = true;
            _subtitlesDownloaderThread.Name = "Subtitles Downloader Thread";
            _subtitlesDownloaderThread.Start(downloadData);
        }
示例#24
0
    void DownMultiFile_OldFTP(DownloadData dd)
    {
        byte[]            buffer = new byte[65536];
        MultiFileDownData mfdd   = (MultiFileDownData)dd.Data;

        for (int i = 0; i < mfdd.FTPIPList.Count; ++i)
        {
            ServerIPData sid = mfdd.FTPIPList[i];
            if (sid.ISP == (int)ISPType.ISP_DX)
            {
                LogMgr.Log("<电信FTP:" + sid.IP + ">");
            }
            else if (sid.ISP == (int)ISPType.ISP_LT)
            {
                LogMgr.Log("<联通FTP:" + sid.IP + ">");
            }
            else
            {
                LogMgr.Log("<移动FTP:" + sid.IP + ">");
            }
            int retryCount = 0;
            while (mfdd.RecvCount < mfdd.FileList.Count)
            {
                DownResData drd      = mfdd.FileList[mfdd.RecvCount];
                string      url      = "ftp://" + sid.IP + "/" + drd.ResUrl;
                int         readSize = 0;
                try
                {
                    FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(url);
                    if (ftpRequest == null)
                    {
                        if (retryCount >= MAX_RETRY_COUNT)
                        {
                            break;
                        }
                        else
                        {
                            ++retryCount;
                            Thread.Sleep(500);
                            continue;
                        }
                    }
                    ftpRequest.Method    = WebRequestMethods.Ftp.DownloadFile;
                    ftpRequest.UseBinary = true;
                    ftpRequest.KeepAlive = false;
                    FtpWebResponse response  = (FtpWebResponse)ftpRequest.GetResponse();
                    Stream         ftpStream = null;
                    if (response == null || (ftpStream = response.GetResponseStream()) == null)
                    {
                        if (retryCount >= MAX_RETRY_COUNT)
                        {
                            break;
                        }
                        else
                        {
                            ++retryCount;
                            Thread.Sleep(500);
                            continue;
                        }
                    }
                    MemoryStream ms = new MemoryStream();
                    while (true)
                    {
                        int s = ftpStream.Read(buffer, 0, buffer.Length);
                        if (s <= 0)
                        {
                            break;
                        }
                        ms.Write(buffer, 0, s);
                        readSize             += s;
                        mfdd.CurrentRecvSize += s;
                        dd.DownloadBytes     += (uint)s;
                    }
                    try
                    {
                        ftpStream.Close();
                        response.Close();
                    }
                    catch
                    {
                    }
                    if (mfdd.CurrentRecvSize == drd.ResSize)
                    {
                        MultiFileOK mfo = new MultiFileOK();
                        mfo.Data = ms.ToArray();
                        mfo.Drd  = mfdd.FileList[mfdd.RecvCount];
                        mfdd.CompletionList[mfdd.RecvCount] = mfo;
                        ++mfdd.RecvCount;
                        if (mfdd.RecvCount == mfdd.FileList.Count)
                        {
                            dd.DownState = DownloadState.DS_DOWNLOADED_OK;
                            if (dd.Type != DownloadType.DOWNLOAD_DEFAULT)
                            {
                                m_CompletionList.AddItem(dd);
                            }
                            return;
                        }
                        else
                        {
                            mfdd.CurrentRecvSize = 0;
                        }
                    }
                }
                catch (System.Exception e)
                {
                    dd.DownloadBytes -= (uint)readSize;
                    LogMgr.Log("OLD_FTP下载失败:" + e.ToString());
                    if (retryCount >= MAX_RETRY_COUNT)
                    {
                        break;
                    }
                    else
                    {
                        ++retryCount;
                        Thread.Sleep(500);
                        continue;
                    }
                }
            }
        }
        dd.DownState = DownloadState.DS_DOWNLOADED_ERROR;
        if (dd.Type != DownloadType.DOWNLOAD_DEFAULT)
        {
            m_CompletionList.AddItem(dd);
        }
    }
示例#25
0
    bool DownChunk(DownloadData dd, DownChunkData dcd, uint tick)
    {
        int ret = 0;

        switch (dcd.State)
        {
        case ChunkState.CHUNK_CONNECT:
            if (dcd.Fcd.connected)
            {
                dcd.Fcd.socket.Blocking = false;
                dcd.State    = ChunkState.CHUNK_SEND_CMD;
                dcd.RecvTick = tick;
                return(true);
            }
            return(tick - dcd.RecvTick < 3000);

            break;

        case ChunkState.CHUNK_SEND_CMD:
            try
            {
                ret = dcd.Fcd.socket.Send(dcd.SendCmdData, SocketFlags.None);
                if (ret == dcd.SendCmdData.Length)
                {
                    dcd.State       = ChunkState.CHUNK_RECV_SIZE;
                    dcd.SendCmdData = null;
                    dcd.RecvTick    = tick;

                    return(true);
                }
            }
            catch
            {
                if (dcd.Fcd.socket.Connected == false)
                {
                    return(false);
                }
            }
            return(tick - dcd.RecvTick < TIME_OUT);

            break;

        case ChunkState.CHUNK_RECV_SIZE:
            try
            {
                ret = dcd.Fcd.socket.Receive(dcd.RecvData, dcd.RecvSize, dcd.RecvData.Length - dcd.RecvSize, SocketFlags.None);
            }
            catch
            {
                if (dcd.Fcd.socket.Connected == false)
                {
                    return(false);
                }
            }
            if (ret <= 0)
            {
                return(tick - dcd.RecvTick < TIME_OUT);
            }
            dcd.RecvTick  = tick;
            dcd.RecvSize += ret;
            int retIdx = 0;
            while (dcd.RecvSize >= 4)
            {
                uint recvID = System.BitConverter.ToUInt32(dcd.RecvData, retIdx);
                retIdx       += 4;
                dcd.RecvSize -= 4;
                if (recvID == 0xEFFFFFFF)
                {
                    //正在等待打开文件中
                }
                else if ((recvID & 0xF0000000) == 0xF0000000)
                {
                    //文件大小
                    recvID &= 0x0fffffff;
                    if (dcd.Length == 0)
                    {
                        dcd.Length = (int)recvID;
                    }
                    else if (dcd.Length != recvID)
                    {
                        throw new System.Exception("Recv FileSize Error:ServerSize:" + recvID + ", LocalSize:" + dcd.Length);
                        return(false);
                    }
                    if (dcd.RecvData.Length < dcd.Length)
                    {
                        byte[] recvdata = new byte[dcd.Length];
                        CopyXorData(dcd.RecvData, retIdx, recvdata, dcd.RecvSize, dcd.XOR == 1);
                        retIdx       = 0;
                        dcd.RecvData = recvdata;
                    }
                    //接收完成
                    dd.Queue          = 0xffffffff;
                    dcd.State         = ChunkState.CHUNK_RECV_DATA;
                    dcd.RecvTick      = tick;
                    dd.DownloadBytes += (uint)dcd.RecvSize;
                    break;
                }
                else if ((recvID & 0xC0000000) == 0xC0000000)
                {
                    //文件个数
                    byte isp = (byte)((recvID >> 28) & 0x3);
                    if (dd.Type == DownloadType.DOWNLOAD_CHECK_VER)
                    {
                        ISP_TYPE = isp;
                        // LogMgr.Log("<ISP:" + ((ISPType)ISP_TYPE) + ">");
                    }
                    recvID &= 0xff;
                    if (recvID != 1)
                    {
                        throw new System.Exception("File Count Error,ServerCount:" + recvID + ", LocalCount:1");
                        return(false);
                    }
                }
                else if ((recvID & 0x80000000) != 0)
                {
                    //排队中
                    dd.Queue = (recvID) & 0x7fffffff;
                }
                else
                {
                    throw new System.Exception("未知的RecvSize数据:" + recvID);
                    return(false);
                }
            }
            //移动数据到最开始
            if (retIdx != 0)
            {
                CopyXorData(dcd.RecvData, retIdx, dcd.RecvData, dcd.RecvSize, (dcd.XOR == 1 && dcd.State == ChunkState.CHUNK_RECV_DATA));
            }
            if (dcd.State == ChunkState.CHUNK_RECV_DATA && dcd.RecvSize == dcd.Length)
            {
                dcd.State = ChunkState.CHUNK_COMPLETION;
            }
            return(true);

            break;

        case ChunkState.CHUNK_RECV_DATA:
            try
            {
                ret = dcd.Fcd.socket.Receive(dcd.RecvData, dcd.RecvSize, dcd.Length - dcd.RecvSize, SocketFlags.None);
            }
            catch (SocketException e)
            {
                if (dcd.Fcd.socket.Connected == false)
                {
                    return(false);
                }
            }
            if (ret <= 0)
            {
                if (tick - dcd.RecvTick < TIME_OUT)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (dcd.XOR == 1)
            {
                int endsize = dcd.RecvSize + ret;
                for (int i = dcd.RecvSize; i < endsize; ++i)
                {
                    dcd.RecvData[i] ^= XOR_MASK;
                }
            }
            dcd.RecvTick      = tick;
            dcd.RecvSize     += ret;
            dd.DownloadBytes += (uint)ret;
            if (dcd.RecvSize == dcd.Length)
            {
                dcd.State = ChunkState.CHUNK_COMPLETION;
            }
            return(true);

        default:
            throw new System.Exception("未知的Recv状态:" + dcd.State);
            return(false);
        }
        return(false);
    }
示例#26
0
        private void btnDownloadStock_Click(object sender, EventArgs e)
        {
            string OrginalDataDate = dateTimePicker1.Value.Date.ToString("yyyy-MM-dd");
            string ConvertDataDate = dateTimePicker1.Value.Date.ToString("yyyyMMdd");
            string DownloadData;
            string Uri = $"https://www.twse.com.tw/exchangeReport/BWIBBU_d?response=csv&date={ConvertDataDate}&selectType=ALL";

            #region HttpWebRequest to get stcok data
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri);
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            try
            {
                using (HttpWebResponse aHttpWebResponse =
                           (HttpWebResponse)request.GetResponse())
                {
                    using Stream aStream       = aHttpWebResponse.GetResponseStream();
                    using StreamReader aReader = new StreamReader(aStream, Encoding.GetEncoding(950));
                    DownloadData = aReader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            #endregion

            if (DownloadData.Trim().Length == 0)
            {
                MessageBox.Show("No stock data to download!");
                return;
            }

            #region Sql scripts
            StringBuilder UpdateSql              = new StringBuilder();
            string        InitialSQL             = @"INSERT INTO [dbo].[StockInformation]
                                       ([Code],          [Name],          [Yield], 
                                        [DividendYear],  [PeRatio],       [PbRatio],
                                        [FinancialQuarter], [DataDate] )	
                                VALUES (
                                ";
            string        DeleteDuplicateDataSql = $"DELETE FROM StockInformation WHERE DataDate = '{OrginalDataDate}' ; ";
            #endregion

            #region Paser the stock data
            CsvReader Csv      = new CsvReader();
            string[]  LineStrs = DownloadData.Split('\n');
            string    Code;                 // 證券代號
            string    Name;                 // 證券名稱
            string    Yield;                // 殖利率
            string    DividendYear;         // 股利年度
            string    PeRatio;              // 本益比
            string    PbRatio;              // 股價淨值比
            string    FinancialQuarter;     // 財報年/季

            for (int i = 0; i < LineStrs.Length; i++)
            {
                string strline = LineStrs[i];

                // First row or no data
                if (i == 0 || i == 1 || strline.Trim().Length == 0)
                {
                    continue;
                }

                // Exclude the sheet description wording
                if (strline.IndexOf("個股日本益比、殖利率及股價淨值比") > -1 ||
                    strline.IndexOf("說明") > -1 ||
                    strline.IndexOf("本網頁資料僅供研究參考用途") > -1 ||
                    strline.IndexOf("本網頁資料推計基礎如下") > -1)
                {
                    continue;
                }

                ArrayList Result = new ArrayList();
                Csv.ParseCSVData(Result, strline);
                string[] StockDatas = (string[])Result.ToArray(typeof(string));

                if (StockDatas.Count() < 7)
                {
                    continue;
                }

                Code             = StockDatas[0].Trim();    // 證券代號
                Name             = StockDatas[1].Trim();    // 證券名稱
                Yield            = StockDatas[2].Trim();    // 殖利率
                DividendYear     = StockDatas[3].Trim();    // 股利年度
                PeRatio          = StockDatas[4].Trim();    // 本益比
                PbRatio          = StockDatas[5].Trim();    // 股價淨值比
                FinancialQuarter = StockDatas[6].Trim();    // 財報年/季

                UpdateSql.Append(InitialSQL);
                UpdateSql.Append($"'{Code}','{Name}','{Yield}','{DividendYear}','{PeRatio}'," +
                                 $"'{PbRatio}','{FinancialQuarter}','{OrginalDataDate}');");
            }

            #endregion

            #region Insert to db
            try
            {
                using (var Conn = new SqlConnection(CommonSetting.DbSetting.DbConnectionString))
                {
                    using (TransactionScope aTransactionScope = new TransactionScope())
                    {
                        Conn.Execute(DeleteDuplicateDataSql);
                        Conn.Execute(UpdateSql.ToString());
                        aTransactionScope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            #endregion

            MessageBox.Show($"Download the stock data of {OrginalDataDate} successfully!");
        }
示例#27
0
    //资源有带前缀"ftp://"
    public DownloadData AddMultiResDownload(DownloadType dt, List <ServerIPData> serverList, List <DownResData> resList, object obj = null)
    {
        if (m_DownList.HasSpace() == false)
        {
            return(null);
        }
        MultiFileDownData mfdd = new MultiFileDownData();

        mfdd.CompletionList   = new MultiFileOK[resList.Count];
        mfdd.FTPIPList        = new List <ServerIPData>();
        mfdd.FileList         = new List <DownResData>();
        mfdd.OutsideRecvIndex = 0;
        mfdd.RecvCount        = 0;
        mfdd.CurrentRecvSize  = 0;
        mfdd.ExtraData        = obj;
        mfdd.RecvFileList     = new RecvFileDataFlag[resList.Count];
        List <ServerIPData> ipList1 = new List <ServerIPData>();
        List <ServerIPData> ipList2 = new List <ServerIPData>();

        for (int i = 0; i < serverList.Count; ++i)
        {
            if (serverList[i].ISP == ISP_TYPE || serverList[i].ISP == (byte)ISPType.ISP_YD || ISP_TYPE == (byte)ISPType.ISP_YD)
            {
                ipList1.Add(serverList[i]);
            }
            //else
            //  ipList2.Add(sip);
        }
        if (ipList1.Count == 0)
        {
            for (int i = 0; i < serverList.Count; ++i)
            {
                ipList1.Add(serverList[i]);
            }
        }
        for (int i = 0; i < resList.Count; ++i)
        {
            mfdd.RecvFileList[i] = new RecvFileDataFlag();
            DownResData drd = resList[i];
            string      url = drd.ResUrl.ToLower();
            int         idx = url.IndexOf("fishpublish");
            if (idx == -1)
            {
                return(null);
            }
            drd.ResUrl = url.Substring(idx, url.Length - idx);
            mfdd.FileList.Add(drd);
        }
        //将FTP排队
        for (int i = 0; i < ipList1.Count;)
        {
            int idx = Utility.Range(0, ipList1.Count);
            if (idx >= ipList1.Count)
            {
                idx = ipList1.Count - 1;
            }
            mfdd.FTPIPList.Add(ipList1[idx]);
            ipList1.RemoveAt(idx);
        }
        for (int i = 0; i < ipList2.Count;)
        {
            int idx = Utility.Range(0, ipList2.Count);
            if (idx >= ipList2.Count)
            {
                idx = ipList2.Count - 1;
            }
            mfdd.FTPIPList.Add(ipList2[idx]);
            ipList2.RemoveAt(idx);
        }
        DownloadData dd = new DownloadData(null, mfdd, dt);

        dd.DownState = DownloadState.DS_DOWNLOADING;
        m_DownList.AddItem(dd);
        return(dd);
    }
示例#28
0
文件: MapUtil.cs 项目: abdojobs/gccv2
        private bool DownloadOsmTile(string tile_name)
        {
            if (DlList.Count > 2)       //only 2 download threads allowed on osm
                return false;
            DownloadData dld = new DownloadData();
            try
            {
                String forecastAdress = tile_name.Replace(MapsFilesDirectory + "\\", OsmServer);
                forecastAdress = forecastAdress.Replace("\\", "/");

                dld.DLFilename = tile_name;
                dld.httpRequest = (HttpWebRequest)WebRequest.Create(forecastAdress);

                dld.httpRequest.Credentials = CredentialCache.DefaultCredentials;
                dld.httpRequest.Timeout = 30000;          // 10 sec timeouts
                dld.httpRequest.ReadWriteTimeout = 30000;
                dld.httpRequest.UserAgent = "GpsCycleComputer";

                dld.httpRequest.BeginGetResponse(GetResponseCallback, dld);
                DlList.Add(dld);
                return true;
            }
            catch(Exception e)
            {
                DownloadEnd(e, dld);
            }
            return false;
        }
示例#29
0
    public void Update(float delta)
    {
        if (m_bError)
        {
            NativeInterface.ShowMsgAndExit("res_save_error", 109);
            return;
        }
        if (m_ActiveDown != null)
        {
            if (m_ActiveDown.Type == DownloadType.DOWNLOAD_MULTI_FILE && m_ActiveDown.DownloadBytes != 0)
            {
            }
            else
            {
                m_UpdateUI.SetIsQueue(m_ActiveDown.IsQueue, m_ActiveDown.Type == DownloadType.DOWNLOAD_CHECK_VER);
            }
            if (m_ActiveDown.IsQueue)
            {
                m_UpdateTick = Utility.GetTickCount();
            }
        }
        switch (m_State)
        {
        case UpdateState.UPDATE_CHECK_LOCALVER:
            CheckLocalFile();
            break;

        case UpdateState.UPDATE_UNZIPING_FILE:
            CheckUnzipping();
            break;

        case UpdateState.UPDATE_INIT:
            m_UpdateTick = Utility.GetTickCount();
            string ftpurl = RuntimeInfo.GetFTPVersionURL();
            m_ActiveDown = FTPClient.Instance.AddDownload(DownloadType.DOWNLOAD_CHECK_VER, ftpurl, null);
            m_State      = UpdateState.UPDATE_DOWNLOAD_VERSION;
            break;

        case UpdateState.UPDATE_DOWNLOAD_VERSION:
            if (m_ActiveDown.IsOK)
            {
                m_RetryCount = 0;
                string xml = m_ActiveDown.Text;
                m_ActiveDown = null;
                if (!CheckVersion(xml))
                {
                    NativeInterface.ShowMsgAndExit("update_error", 101);
                }
            }
            else if (m_ActiveDown.HasError)
            {
                //出错了
                if (++m_RetryCount > MAX_RETRY_COUNT)
                {
                    NativeInterface.ShowMsgAndExit("res_connect_error", 102);
                }
                else
                {
                    m_State      = UpdateState.UPDATE_INIT;
                    m_ActiveDown = null;
                }
            }
            else
            {
                if (m_ActiveDown.IsQueue == false && Utility.GetTickCount() - m_UpdateTick > UPDATE_VERSION_TIME_OUT)
                {
                    NativeInterface.ShowMsgAndExit("res_connect_error", 103);
                }
            }
            break;

        case UpdateState.UPDATE_DOWNLOAD_RES:
            if (m_ActiveDown == null)
            {
                if (m_DownList.Count > 0)
                {
                    m_DownloadBytes = 0;
                    m_UpdateTick    = Utility.GetTickCount();
                    m_UpdateUI.BeginDown(ResType.FishRes);
                    m_ActiveDown    = FTPClient.Instance.AddMultiResDownload(DownloadType.DOWNLOAD_MULTI_FILE, m_ResFtpList, m_DownList);
                    m_RecvFileCount = m_DownList.Count;
                    m_DownList.Clear();
                }
                else
                {
                    m_State = UpdateState.UPDATE_COMPLETE;
                }
            }
            else if (m_ActiveDown.IsOK)
            {
                m_RetryCount            = 0;
                m_CurrentDownloadBytes += m_ActiveDown.DownloadBytes;
                m_DownloadBytes         = 0;
                //m_ThreadList.AddItem(m_ActiveDown);
                SaveDownloadData(m_ActiveDown);

                m_ActiveDown = null;
            }
            else if (m_ActiveDown.HasError)
            {
                NativeInterface.ShowMsgAndExit("update_error", 105);
            }
            else
            {
                if (m_ActiveDown.IsQueue)
                {
                    //排队中
                }
                else if (m_DownloadBytes != m_ActiveDown.DownloadBytes)
                {
                    m_DownloadBytes = m_ActiveDown.DownloadBytes;
                    m_UpdateTick    = Utility.GetTickCount();
                    MultiFileDownData mfdd = (MultiFileDownData)m_ActiveDown.Data;
                    if (mfdd.OutsideRecvIndex < mfdd.RecvCount)
                    {
                        SaveDownloadData(m_ActiveDown);
                    }
                }
                else if (Utility.GetTickCount() - m_UpdateTick > UPDATE_RES_TIME_OUT)
                {
                    NativeInterface.ShowMsgAndExit("update_error", 106);
                }
            }
            break;

        case UpdateState.UPDATE_COMPLETE:
            //if (m_DownloadCompletionCount != m_DownloadOrgCount)
            //{
            //    m_UpdateUI.SetUnzipping();
            //    return;
            //}
            //更新完成,进入下一个逻辑
            if (m_SaveCount != m_RecvFileCount)
            {
                return;
            }
            if (m_bNewClient)
            {
                if (RuntimeInfo.GetPlatform() == GamePlatformType.Android)
                {
                    NativeInterface.DownNewClientVersion(GetClientPath());
                }
                else if (RuntimeInfo.GetPlatform() == GamePlatformType.Windows)
                {
                    NativeInterface.ShowMsgAndExit("update_restart", 0);
                }
                else
                {
                    NativeInterface.DownNewClientVersion(m_NewClientURL);
                }
            }
            else
            {
                LogicManager.Instance.Forward(null);
            }
            break;

        case UpdateState.UPDATE_NEW_CLIENT:
            LogicManager.Instance.Shutdown();
            break;
        }
    }
示例#30
0
        public override IEnumerable <string> Process(string fileName)
        {
            if (removeOldFile && new FileInfo(fileName).Exists)
            {
                new FileInfo(fileName).Delete();
            }

            using (DownloadData data = DownloadData.Create(url, fileName))
            {
                bool bShowProgress = data.IsProgressKnown;

                if (bShowProgress)
                {
                    Progress.SetRange(0, data.FileSize);
                }

                // send the new download state
                Progress.SetMessage("Downloading ...");

                // create the download buffer
                byte[] buffer = new byte[downloadBlockSize];

                int readCount;

                // update how many bytes have already been read
                long totalDownloaded = data.StartPoint;

                using (FileStream f = File.Open(fileName, FileMode.Create, FileAccess.Write))
                {
                    // read a block of bytes and get the number of bytes read
                    while ((int)(readCount = data.DownloadStream.Read(buffer, 0, downloadBlockSize)) > 0)
                    {
                        // break on cancel
                        if (Progress.IsCancellationPending())
                        {
                            throw new UserTerminatedException();
                        }

                        // update total bytes read
                        totalDownloaded += readCount;

                        // send progress info
                        if (bShowProgress)
                        {
                            Progress.SetPosition(totalDownloaded);
                        }
                        else
                        {
                            Progress.SetMessage("Downloaded " + totalDownloaded + " bytes ...");
                        }

                        // save block to end of file
                        f.Write(buffer, 0, readCount);

                        // break on cancel
                        if (Progress.IsCancellationPending())
                        {
                            throw new UserTerminatedException();
                        }
                    }

                    // send 100% completion if url size is known and user hasn't cancelled
                    if (bShowProgress)
                    {
                        Progress.SetPosition(data.FileSize);
                    }
                    else
                    {
                        Progress.SetMessage("Finished, downloaded " + totalDownloaded + " bytes");
                    }
                }
            }

            return(new string[] { fileName });
        }
示例#31
0
文件: MapUtil.cs 项目: abdojobs/gccv2
 void DownloadEnd(Exception e, DownloadData dld)
 {
     Utils.log.Error (" DownloadOsmTile ", e);
     if (e.Message.IndexOf("404") != -1)
         MapErrors = __MapErrorNotFound;
     else
         MapErrors = __MapErrorDownload;
     try { File.Delete(dld.DLFilename); }
     catch { }
     DlList.Remove(dld);
     dld.Cleanup();
 }
示例#32
0
    public static void Handle(DownloadData dd)
    {
        switch (dd.Type)
        {
        case DownloadType.DOWNLOAD_RANK_INFO:
        {
            //下载普通的排行榜文件
            if (dd.DownState == DownloadState.DS_DOWNLOADED_OK)
            {
                PlayerRole.Instance.RankManager.SaveRankXml(dd.Bytes);
                PlayerRole.Instance.RankManager.DownLoadReadRankXml();
            }
            else if (dd.DownState == DownloadState.DS_DOWNLOADED_ERROR)
            {
                PlayerRole.Instance.RankManager.DownLoadReadRankXml(true);
            }
            return;
        }

        case DownloadType.DOWNLOAD_Month_Rank:
        {
            if (dd.DownState == DownloadState.DS_DOWNLOADED_OK)
            {
                PlayerRole.Instance.MonthManager.SaveMonthRankXml(dd.Bytes, (string)dd.Data);        //保存XML文件
                PlayerRole.Instance.MonthManager.OnDownLoadMonthRankXml((string)dd.Data);
            }
            else if (dd.DownState == DownloadState.DS_DOWNLOADED_ERROR)
            {
                PlayerRole.Instance.MonthManager.OnDownLoadMonthRankXml((string)dd.Data, true);
            }
            return;
        }

        case DownloadType.DOWNLOAD_ANNOUNCEMENT:
        {
            if (dd.DownState == DownloadState.DS_DOWNLOADED_OK)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(dd.Text);
                XmlElement ele   = doc.DocumentElement;
                XmlNode    title = ele.SelectSingleNode("items");
                List <AnnouncementData> annoucesList = new List <AnnouncementData>();
                for (int i = 0; i < title.ChildNodes.Count; ++i)
                {
                    AnnouncementData ad = new AnnouncementData();
                    ad.Title   = title.ChildNodes[i].Attributes["title"].Value;
                    ad.Date    = title.ChildNodes[i].Attributes["date"].Value;
                    ad.Content = title.ChildNodes[i].Attributes["content"].Value;
                    annoucesList.Add(ad);
                }
                //获取公告列表
                LogonRuntime.LogonLogicUI.UpdateNotice(annoucesList);
            }
            else
            {
                //获取公告失败。
                GlobalHallUIMgr.Instance.ShowSystemTipsUI(StringTable.GetString("UOM_Login_GetNoticeError"), 2.0f, false);
            }
            break;
        }
        }
    }
示例#33
0
 public ActiveDownloadJob(ExtractImages.DownloadData downloadData, ProgressBar progressBar, WebClient webClient)
 {
     this.DownloadData = downloadData;
     this.ProgressBar  = progressBar;
     this.WebClient    = webClient;
 }
示例#34
0
        private static List <DownloadData> ParseSite(ShowData showData, string url, out string nextpageurl, out string firstcover, UploadCache uploadCache)
        {
            nextpageurl = "";
            firstcover  = "";

            WebResponse resp = null;

            for (int i = 0; i <= 7; i++)
            {
                try
                {
                    HttpWebRequest req = WebRequest.CreateHttp(url);
                    req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                    req.KeepAlive = false;
                    resp          = req.GetResponse();
                    break;
                }
                catch (WebException ex)
                {
                    if (ex.Status != WebExceptionStatus.Timeout)
                    {
                        throw;
                    }
                }
            }
            if (resp == null)
            {
                throw new TimeoutException();
            }


            HtmlDocument doc = new HtmlDocument();

            doc.OptionDefaultStreamEncoding = Encoding.UTF8;
            doc.Load(resp.GetResponseStream());
            resp.Dispose();
            List <DownloadData> list = new List <DownloadData>();

            HtmlNode content = doc.GetElementbyId("content");

            HtmlNode nextLink = content.SelectSingleNode("//div[@class='navigation']//a[@href][@class='next']");

            if (nextLink != null)
            {
                nextpageurl = nextLink.GetAttributeValue("href", null);
            }

            var posts = content.SelectNodes("div[@class='post']");

            if (posts == null)
            {
                return(list);
            }
            foreach (var post in posts)
            {
                //--------------Season Title-----------------------------------
                var title = post.SelectSingleNode("h2/a[@href]");
                if (title == null)
                {
                    Console.WriteLine("SjInfo Parser: No Title");
                    continue;
                }
                var seasonData = new SeasonData();
                seasonData.Show  = showData;
                seasonData.Url   = title.GetAttributeValue("href", null);
                seasonData.Title = WebUtility.HtmlDecode(title.InnerText);


                var postContent = post.SelectSingleNode("div[@class='post-content']");
                if (postContent == null)
                {
                    Console.WriteLine("SjInfo Parser: No Post content");
                    continue;
                }

                //----------------Season Cover------------------------------------------------
                var cover = postContent.SelectSingleNode(".//p/img[@src]");
                if (cover != null)
                {
                    seasonData.CoverUrl = cover.GetAttributeValue("src", null);
                    if (String.IsNullOrEmpty(firstcover))
                    {
                        firstcover = seasonData.CoverUrl;
                    }
                }

                //----------------Season description-----------------------------------------
                var desc = postContent.SelectSingleNode(".//p[count(node())=1][not(@class='post-info-co')]/text()");
                if (desc != null)
                {
                    seasonData.Description = WebUtility.HtmlDecode(desc.InnerText);
                }

                UploadData uploadData = null;

                var ps = postContent.SelectNodes(".//node()[self::p|self::div][count(strong)>=2]");
                if (ps == null)
                {
                    Console.WriteLine("SjInfo Parser: no uploads/headers");
                    continue;
                }

                foreach (var p in ps)
                {
                    //--------------- Upload Header ------------------------------
                    if (p.SelectSingleNode("self::node()[not(./a[@target])]") != null)
                    {
                        uploadData        = new UploadData();
                        uploadData.Season = seasonData;

                        String          c  = WebUtility.HtmlDecode(p.InnerHtml);
                        MatchCollection mc = new Regex("<strong>\\s*(.+?)\\s*</strong>\\s*(.+?)\\s*(?:\\||$)").Matches(c);
                        foreach (Match match in mc)
                        {
                            String key   = match.Groups[1].Value.ToLower();
                            String value = match.Groups[2].Value;
                            if (key.Contains("dauer") || key.Contains("runtime") || key.Contains("duration"))
                            {
                                uploadData.Runtime = value;
                            }
                            else if (key.Contains("grösse") || key.Contains("größe") || key.Contains("size"))
                            {
                                uploadData.Size = value;
                            }
                            else if (key.Contains("uploader"))
                            {
                                uploadData.Uploader = value;
                            }
                            else if (key.Contains("format"))
                            {
                                uploadData.Format = value;
                            }
                            else if (key.Contains("sprache") || key.Contains("language"))
                            {
                                value = value.ToLower();
                                if (value.Contains("deutsch") || value.Contains("german"))
                                {
                                    uploadData.Language |= UploadLanguage.German;
                                }
                                if (value.Contains("englisch") || value.Contains("english"))
                                {
                                    uploadData.Language |= UploadLanguage.English;
                                }
                                if (value.Contains("subbed"))
                                {
                                    uploadData.Subbed = true;
                                }
                            }
                        }
                    }
                    else if (uploadData != null)
                    {
                        // ------------------ Links -------------------------
                        var ulTitle = p.SelectSingleNode("strong[position()=1][count(node())=1]/text()");
                        if (ulTitle == null)
                        {
                            Console.WriteLine("SjInfo Parser: No title for link? " + p.InnerHtml);
                            continue;
                        }
                        string titleStr = WebUtility.HtmlDecode(ulTitle.InnerText).Trim();

                        var links = p.SelectNodes("a[@href][following-sibling::text()]");
                        if (links == null)
                        {
                            continue;
                        }
                        var downloads = new Dictionary <string, string>();
                        foreach (var link in links)
                        {
                            string ur     = link.GetAttributeValue("href", null);
                            string keyOrg = WebUtility.HtmlDecode(link.NextSibling.InnerText.Trim());
                            if (keyOrg.StartsWith("|"))
                            {
                                keyOrg = keyOrg.Substring(1).Trim();
                            }

                            String key = keyOrg;
                            int    i   = 1;
                            while (downloads.ContainsKey(key))
                            {
                                key = keyOrg + "(" + i++ + ")";
                            }
                            downloads.Add(key, ur);
                        }

                        if (titleStr.Contains("720p"))
                        {
                            uploadData.Format = "720p";
                        }
                        else if (titleStr.Contains("1080p"))
                        {
                            uploadData.Format = "1080p";
                        }
                        else if (titleStr.Contains("720i"))
                        {
                            uploadData.Format = "720i";
                        }
                        else if (titleStr.Contains("1080i"))
                        {
                            uploadData.Format = "1080i";
                        }

                        DownloadData dd = new DownloadData();
                        dd.Upload = uploadCache == null ? uploadData : uploadCache.GetUniqueUploadData(uploadData);
                        dd.Title  = titleStr;

                        if (titleStr.ToLower().Contains("subbed"))
                        {
                            dd.Upload.Subbed = true;
                        }

                        foreach (var download in downloads)
                        {
                            dd.Links.Add(download.Key, download.Value);
                        }

                        list.Add(dd);
                    }
                    else
                    {
                        Console.WriteLine("SjInfo Parser: UploadData was null");
                    }
                }
            }
            return(list);
        }