コード例 #1
0
        public IEnumerable <MediaItem> GetMediaItems(MediaFolder folder, string[] mediaExtensions)
        {
            DirectoryInfo dir = new DirectoryInfo(folder.Url);

            if (!dir.Exists)
            {
                throw new InvalidUrlException(folder.Url);
            }

            List <MediaAnnotation> annotations = LoadAnnotations(folder.Url);

            foreach (FileInfo file in dir.GetFiles())
            {
                if (Array.Exists(mediaExtensions, ext => ext.ToLower() == file.Extension.ToLower()))
                {
                    MediaAnnotation ma  = annotations.Find(a => a.MediaName == file.Name);
                    string          ann = ma == null ? null : ma.Annotation;
                    DateTime        ct  = ma == null ? file.CreationTime : ma.CreationTime;

                    MediaItem mediaItem = new MediaItem
                    {
                        Name         = file.Name,
                        Url          = file.FullName,
                        Annotation   = ann,
                        CreationTime = ct
                    };

                    #if SLOW
                    System.Threading.Thread.Sleep(100);
                    #endif

                    yield return(mediaItem);
                }
            }
        }
コード例 #2
0
        private static void MergeAnnotation(List <MediaAnnotation> annotationList, MediaAnnotation annotation)
        {
            int aIdx = annotationList.FindIndex(a => a.MediaName == annotation.MediaName);

            if (aIdx >= 0)
            {
                annotationList[aIdx] = annotation;
            }
            else
            {
                annotationList.Add(annotation);
            }
        }