Ejemplo n.º 1
0
        List <OdFileInfo> SelectFiles(SourceConfiguration sourceConfig, IMediaQueue mediaQueue)
        {
            mediaQueue.ReportProgress("Selecting files");

            // Determine the "after" threshold from SelectAfter and SelectIncremental
            var after = sourceConfig.GetBookmarkOrAfter(m_bookmarkPath);

            if (after.HasValue)
            {
                mediaQueue.ReportProgress($"  Filter: Created after {after.Value}");
            }

            // Retrieve file info and enqueue
            var queue = new List <OdFileInfo>();
            int count = 0;

            // This is a Kludge. Need a way to either detect the correct folder or to
            // configure it when setting up a new named source. And, with the named
            // source, we need to clean up the circumstance when credentials expire.
            string nextUrl = m_sourceName.Equals("BrandtOneDrive")
                ? c_oneDriveSamsungCameraUrl : c_oneDriveCameraRollUrl;

            do
            {
                var fileList = FetchJson(nextUrl);
                var root     = fileList.CreateNavigator();
                nextUrl = root.XPVal("/root/a:item[@item='@odata.nextLink']");

                foreach (XPathNavigator node in fileList.CreateNavigator().Select("/root/value/item"))
                {
                    ++count;
                    var odfi = new OdFileInfo(node);

                    if (!after.HasValue ||
                        (odfi.BookmarkDate.HasValue && odfi.BookmarkDate > after.Value))
                    {
                        queue.Add(odfi);
                    }
                }

                mediaQueue.ReportStatus($"  Selected {queue.Count} Skipped {count - queue.Count}");
            }while (!string.IsNullOrEmpty(nextUrl));
            mediaQueue.ReportStatus(null);
            mediaQueue.ReportProgress($"Selected {queue.Count} Skipped {count - queue.Count}");

            if (queue.Count > c_maxBatch)
            {
                // Sort so that we'll keep the oldest ones.
                queue.Sort((a, b) => DateCompare(a.BookmarkDate, b.BookmarkDate));
                queue.RemoveRange(c_maxBatch, queue.Count - c_maxBatch);
                mediaQueue.RequestAnotherBatch = true;
                mediaQueue.ReportProgress($"Batch limited to {queue.Count}");
            }

            return(queue);
        }
Ejemplo n.º 2
0
        private List <ProcessFileInfo> SelectFiles(SourceConfiguration sourceConfig, IMediaQueue mediaQueue)
        {
            mediaQueue.ReportProgress($"Selecting {(m_recursive ? "from" : "tree")}: {m_path}");

            // Determine the "after" threshold from SelectAfter and SelectIncremental
            var after = sourceConfig.GetBookmarkOrAfter(m_path);

            m_newestSelection = after ?? DateTime.MinValue;
            var queue        = new List <ProcessFileInfo>();
            int skippedFiles = 0;

            try
            {
                DirectoryInfo di = new DirectoryInfo(m_directory);
                foreach (var fi in di.EnumerateFiles(m_pattern, m_recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
                {
                    if (((queue.Count + skippedFiles) % 100) == 0)
                    {
                        string message = (skippedFiles == 0)
                            ? $"Selected: {queue.Count}"
                            : $"Selected: {queue.Count} Not Selected: {skippedFiles}";
                        mediaQueue.ReportStatus(message);
                    }

                    if (MediaFile.IsSupportedMediaType(fi.Extension))
                    {
                        // Limit date window of files to be selected
                        if (after.HasValue)
                        {
                            var date = MediaFile.GetBookmarkDate(fi.FullName);
                            if (!date.HasValue || date.Value <= after.Value)
                            {
                                ++skippedFiles;
                                continue;
                            }

                            // For this operation, we do everything in localtime because photo
                            // DateTaken metadata is in localtime.
                            // This is after-the-fact but since it's a debugging test that's OK.
                            Debug.Assert(date.Value.Kind == DateTimeKind.Local);

                            if (m_newestSelection < date.Value)
                            {
                                m_newestSelection = date.Value;
                            }
                        }

                        queue.Add(new ProcessFileInfo(fi));
                    }
                }
            }
            catch (Exception err)
            {
                throw new ArgumentException($"Source '{m_path}' not found. ({err.Message})", err);
            }
            mediaQueue.ReportStatus(null);
            mediaQueue.ReportProgress(skippedFiles == 0
                ? $"   Selected: {queue.Count}"
                : $"   Selected: {queue.Count} Not Selected: {skippedFiles}");

            // If SelectIncremental, report the new bookmark
            if (sourceConfig.SelectIncremental && queue.Count > 0)
            {
                Debug.Assert(m_newestSelection > DateTime.MinValue);
                mediaQueue.ReportProgress($"   Newest: {m_newestSelection:yyyy'-'MM'-'dd' 'HH':'mm':'ss}");
            }

            return(queue);
        }