Exemplo n.º 1
0
        public void RetrieveMediaFiles(SourceConfiguration sourceConfig, IMediaQueue mediaQueue)
        {
            var queue = SelectFiles(sourceConfig, mediaQueue);

            // if a destination directory was specified, copy or move the files
            if (sourceConfig.DestinationDirectory != null)
            {
                FileMover.CopyOrMoveFiles(queue, sourceConfig, mediaQueue);
            }

            // Else, simply put them in the mediaQueue
            else
            {
                FileMover.EnqueueFiles(queue, mediaQueue);
            }

            // Save the bookmark
            if (m_newestSelection > DateTime.MinValue)
            {
                // Only sets a bookmark if incremental is on.
                sourceConfig.SetBookmark(m_path, m_newestSelection);
            }
        }
Exemplo n.º 2
0
        void DownloadMediaFiles(List <OdFileInfo> queue, SourceConfiguration sourceConfig, IMediaQueue mediaQueue)
        {
            mediaQueue.ReportProgress($"Downloading media files from OneDrive to working folder: {sourceConfig.DestinationDirectory}.");
            DateTime newestSelection = DateTime.MinValue;

            // Sum up the size of the files to be downloaded
            long selectedFilesSize = 0;

            foreach (var fi in queue)
            {
                selectedFilesSize += fi.Size;
            }

            uint startTicks      = (uint)Environment.TickCount;
            long bytesDownloaded = 0;

            int n = 0;

            foreach (var fi in queue)
            {
                if (bytesDownloaded == 0)
                {
                    mediaQueue.ReportStatus($"Downloading file {n + 1} of {queue.Count}");
                }
                else
                {
                    uint ticksElapsed;
                    unchecked
                    {
                        ticksElapsed = (uint)Environment.TickCount - startTicks;
                    }

                    double   bps    = ((double)bytesDownloaded * 8000.0) / (double)ticksElapsed;
                    TimeSpan remain = new TimeSpan(((long)((selectedFilesSize - bytesDownloaded) / (bps / 8))) * 10000000L);

                    mediaQueue.ReportStatus($"Downloading file {n + 1} of {queue.Count}. Time remaining: {remain.FmtCustom()} Mbps: {(bps / (1024 * 1024)):#,###.###}");
                }

                string dstFilepath = Path.Combine(sourceConfig.DestinationDirectory, fi.OriginalFilename);
                MediaFile.MakeFilepathUnique(ref dstFilepath);

                FetchFile(fi.Url, dstFilepath);
                bytesDownloaded += fi.Size;
                ++n;

                // Add to the destination queue
                mediaQueue.Add(new ProcessFileInfo(
                                   dstFilepath,
                                   fi.Size,
                                   fi.OriginalFilename,
                                   fi.OriginalDateCreated ?? DateTime.MinValue,
                                   fi.OriginalDateModified ?? DateTime.MinValue));

                if (fi.BookmarkDate.HasValue && newestSelection < fi.BookmarkDate)
                {
                    newestSelection = fi.BookmarkDate.Value;
                }
            }

            TimeSpan elapsed;

            unchecked
            {
                uint ticksElapsed = (uint)Environment.TickCount - startTicks;
                elapsed = new TimeSpan(ticksElapsed * 10000L);
            }

            mediaQueue.ReportStatus(null);
            mediaQueue.ReportProgress($"Download complete. {queue.Count} files, {bytesDownloaded / (1024.0 * 1024.0): #,##0.0} MB, {elapsed.FmtCustom()} elapsed");
            if (newestSelection > DateTime.MinValue)
            {
                if (sourceConfig.SetBookmark(m_bookmarkPath, newestSelection))
                {
                    mediaQueue.ReportProgress($"Bookmark Set to {newestSelection}");
                }
            }
        }