Exemplo n.º 1
0
        protected int doCompare(ListViewItem listViewItemA, ListViewItem listViewItemB)
        {
            // sorting by checked
            if (0 == sortColumn)
            {
                return(listViewItemA.Checked.CompareTo(listViewItemB.Checked));
            }

            // sorting by name, type, or location
            if (1 == sortColumn || 2 == sortColumn || 4 == sortColumn)
            {
                return(caseInsensitiveComparer.Compare(listViewItemA.SubItems[sortColumn].Text, listViewItemB.SubItems[sortColumn].Text));
            }

            // sorting by size
            if (3 == sortColumn)
            {
                IDownloadableResourceFile downloadableResourceFileA = listViewItemA.Tag as IDownloadableResourceFile;
                IDownloadableResourceFile downloadableResourceFileB = listViewItemB.Tag as IDownloadableResourceFile;
                long fileSizeA = null == downloadableResourceFileA ? 0 : downloadableResourceFileA.size;
                long fileSizeB = null == downloadableResourceFileB ? 0 : downloadableResourceFileB.size;
                return(fileSizeA.CompareTo(fileSizeB));
            }

            return(0);
        }
Exemplo n.º 2
0
        public override Boolean download(IDownloadableResourceFile downloadableResourceFile, String filePath)
        {
            Boolean downloaded = base.download(downloadableResourceFile, filePath);

            Thread.Sleep(downloadDuration);
            return(downloaded);
        }
Exemplo n.º 3
0
        public void display(IEnumerable <Tuple <String, IEnumerable <KeyValuePair <String, List <IDownloadableResourceFile> > > > > downloadMappings)
        {
            using (new ListViewUpdate(this)) {
                Groups.Clear();
                Items.Clear();
                foreach (Tuple <String, IEnumerable <KeyValuePair <String, List <IDownloadableResourceFile> > > > grouping in downloadMappings)
                {
                    ListViewGroup listViewGroup = new ListViewGroup(grouping.Item1, HorizontalAlignment.Left)
                    {
                        Tag = grouping
                    };
                    Groups.Add(listViewGroup);
                    foreach (KeyValuePair <String, List <IDownloadableResourceFile> > kvp in grouping.Item2)
                    {
                        // TODO: allow user to select what to do in case of conflict

                        IDownloadableResourceFile downloadableResourceFile = kvp.Value[0];

                        Items.Add(
                            new ListViewItem()
                        {
                            Tag = kvp, Checked = true, Group = listViewGroup
                        }.withSubItems(
                                new ListViewItem.ListViewSubItem()
                        {
                            Text = downloadableResourceFile.name
                        },
                                new ListViewItem.ListViewSubItem()
                        {
                            Text = downloadableResourceFile.type
                        },
                                new ListViewItem.ListViewSubItem()
                        {
                            Text = IecByteMultiples.format(downloadableResourceFile.size)
                        },
                                new ListViewItem.ListViewSubItem()
                        {
                            Text = downloadableResourceFile.location
                        }
                                )
                            );
                    }
                }
                AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
        }
Exemplo n.º 4
0
 public virtual Boolean download(IDownloadableResourceFile downloadableResourceFile, String filePath)
 {
     Debug.WriteLine("Downloading: {0} to {1}", downloadableResourceFile.downloadUri, filePath);
     using (File.Create(filePath)) {}
     return(true);
 }
Exemplo n.º 5
0
 public Boolean download(IDownloadableResourceFile downloadableResourceFile, String filePath)
 {
     return(ouSignedInWebSession.downloadFile(downloadableResourceFile.downloadUri, filePath));
 }
Exemplo n.º 6
0
        internal void downloadAllNotDownloadedWith(IDownloader downloader, String downloadsDirectoryPath)
        {
            IEnumerable <IDownloadableResourceFileCollection> available = null;

            IndefiniteProcessingForm.process(
                (cancellationRequestedChecker, log) => {
                log.WriteLine("Searching for new content...");

                // TODO: consider re-writing enumerateResourceFileCollections to be lazily consumable, could perhaps avert the need for a cancellation checker?

                available = downloader.enumerateResourceFileCollections(cancellationRequestedChecker, log);
                return(false);
            },
                "Searching...",
                this
                );
            if (available.isNullOrEmpty())
            {
                return;
            }

            IEnumerable <KeyValuePair <String, List <IDownloadableResourceFile> > > notDownloaded = available.map().enumerateNotDownloaded(downloadsDirectoryPath);

            if (!notDownloaded.Any())
            {
                this.inform("All files checked are up-to-date.", "Downloads");
                return;
            }
            IList <Tuple <IDownloadableResourceFile, String> > picks = DownloadPicker.pickDownloads(notDownloaded, this);

            if (picks.isNullOrEmpty())
            {
                return;
            }

            long downloadedByteCount = 0;
            long totalByteCount      = picks.Select(t => t.Item1.size).Sum();

            BatchProcessingForm <Tuple <IDownloadableResourceFile, String> > .process(
                picks,
                (tuple, log) => {
                IDownloadableResourceFile downloadableResourceFile = tuple.Item1;
                String relativeFilePath = tuple.Item2;
                log.WriteLine("Downloading: \"{0}\"", downloadableResourceFile.name);
                FileInfo fileInfo = new FileInfo(Path.Combine(downloadsDirectoryPath, relativeFilePath));
                fileInfo.Directory.Create();
                if (!downloader.download(downloadableResourceFile, fileInfo.FullName))
                {
                    Console.Error.WriteLine("Downloading of uri: {0} failed", downloadableResourceFile);
                    if (fileInfo.Exists)
                    {
                        Console.Error.WriteLine("Deleting partially downloaded file: {0}", fileInfo.FullName);
                        fileInfo.Delete();
                    }
                    return(-1);
                }
                downloadedByteCount += downloadableResourceFile.size;
                return((int)(Math.Ceiling((Double)(downloadedByteCount) / (Double)(totalByteCount) * 100d)));
            },
                "Downloading...",
                "{0}% downloaded",
                this
                );
        }