Пример #1
0
        private void dataGridViewMain_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (IsSearchResultDisplay)
            {
                labelDisplayTitle.Text = "Downloading files:";
                textBoxFileName.Text   = "";
                IsSearchResultDisplay  = false;

                SearchFileDisplay file = dataGridViewMain.Rows[e.RowIndex].DataBoundItem as SearchFileDisplay;
                manager.Download(file.GetParent());

                DownloadFileDisplay temp = new DownloadFileDisplay(file.GetParent());

                downloadingFiles.Add(temp);
                dataGridViewMain.DataSource = downloadingFiles;
            }
        }
Пример #2
0
        private void manager_FilePartDownloaded(object sender, DataContainerEventArg <Manager.FilePartData> e)
        {
            // find a previous list that contains downloading information of this file
            List <Tuple <Manager.DownloadParameter, Byte[]> > prevData = downloadingData.FirstOrDefault(d =>
                                                                                                        d.First().Item1.File.FileName == e.Data.DownloadParameter.File.FileName &&
                                                                                                        d.First().Item1.File.FileHash == e.Data.DownloadParameter.File.FileHash);

            if (prevData == null)
            {
                // if no list before create a new one
                prevData = new List <Tuple <Manager.DownloadParameter, Byte[]> >();
                prevData.Add(new Tuple <Manager.DownloadParameter, Byte[]>(e.Data.DownloadParameter, e.Data.FileBytes));
                downloadingData.Add(prevData);
            }
            else
            {
                downloadingData.FirstOrDefault(d =>
                                               d.First().Item1.File.FileName == e.Data.DownloadParameter.File.FileName &&
                                               d.First().Item1.File.FileHash == e.Data.DownloadParameter.File.FileHash).
                Add(new Tuple <Manager.DownloadParameter, Byte[]>(e.Data.DownloadParameter, e.Data.FileBytes));
            }

            // find the number of downloaded parts by counting tuples in the list that contains downloading information of this file
            int numDownParts = downloadingData.FirstOrDefault(d =>
                                                              d.First().Item1.File.FileName == e.Data.DownloadParameter.File.FileName &&
                                                              d.First().Item1.File.FileHash == e.Data.DownloadParameter.File.FileHash).Count;

            // find the file that shows downloading information of this file
            DownloadFileDisplay file = downloadingFiles.FirstOrDefault(f =>
                                                                       f.FileName == e.Data.DownloadParameter.File.FileName && f.FileHash == e.Data.DownloadParameter.File.FileHash);

            // increment the percently
            file.Perecent += (numDownParts / e.Data.DownloadParameter.AllPartsCount) * 100;

            if (numDownParts == e.Data.DownloadParameter.AllPartsCount)
            {
                downloadingFiles.RemoveAll(f =>
                                           f.FileName == e.Data.DownloadParameter.File.FileName && f.FileHash == e.Data.DownloadParameter.File.FileHash);
                SaveFile(e.Data.DownloadParameter);
            }

            dataGridViewMain.DataSource = downloadingFiles;
        }