/// <summary>
        /// 非同期処理
        /// </summary>
        /// <param name="directoryName"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Photo> > ExecuteAsync(string folderPath)
        {
            var files          = _photoFileService.FindAllPhotoFilesFromDirectory(folderPath);
            var photosInFolder = new List <Photo>();

            if (files == null)
            {
                return(null);
            }

            var photos            = _photoRepository.Find(allPhoto => allPhoto);
            var photosInDirectory = await Task.Run(() =>
            {
                var photosList = new List <Photo>();
                foreach (var file in files)
                {
                    var searchedPhoto = photos.SingleOrDefault(photo => photo.File.FilePath == file.FilePath);

                    if (searchedPhoto != null)
                    {
                        photosInFolder.Add(searchedPhoto);
                    }
                    else
                    {
                        var photo = Photo.CreateFromFile(file, GetDateTime(file.FilePath));
                        photosInFolder.Add(photo);
                        _photoRepository.Store(photo);
                    }
                }

                return(photosList);
            });

            return(photosInDirectory);
        }
Exemple #2
0
        /// <summary>
        /// アルバム新規作成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_CreateAlbum_Click(object sender, EventArgs e)
        {
            string albumName = textBox_SearchAlbum.Text;

            if (Directory.Exists(albumName))
            {
                IEnumerable <Album> result = albumRepository.Find((IQueryable <Album> albums) => (from p in albums where p.Name == albumName select p));

                // 登録済みのアルバム名でない場合はアルバムを作成
                if (result == null || result.Count() == 0)
                {
                    Album album = Album.Create(albumName);
                    albumRepository.Store(album);

                    string[] path_list = Directory.GetFiles(albumName, "*.*", SearchOption.AllDirectories);

                    foreach (string filePath in path_list)
                    {
                        PhotoFrame.Domain.Model.File file = new PhotoFrame.Domain.Model.File(filePath);

                        if (file.IsPhoto)
                        {
                            Photo photo = Photo.CreateFromFile(file);
                            photo.IsAssignedTo(album);

                            photoRepository.Store(photo);
                        }
                    }

                    // アルバム変更用のアルバム名リストの更新
                    comboBox_ChangeAlbum.Items.Add(album.Name);
                }
            }
        }
Exemple #3
0
        public async Task <IEnumerable <Photo> > ExecuteAsync(string directoryName)
        {
            IEnumerable <Domain.Model.File> files = photoFileService.FindAllPhotoFilesFromDirectory(directoryName);
            List <Photo> photosInDirectory        = new List <Photo>();

            foreach (File file in files)
            {
                Func <IQueryable <Photo>, Photo> query = allPhotos =>
                {
                    foreach (Photo photo in allPhotos)
                    {
                        if (photo.File.FilePath == file.FilePath)
                        {
                            return(photo);
                        }
                    }

                    return(Photo.CreateFromFile(file));
                };

                Photo hitPhoto = await Task.Run(() => photoRepository.Find(query));

                if (hitPhoto != null)
                {
                    photosInDirectory.Add(hitPhoto);
                }
                else
                {
                    photosInDirectory.Add(Photo.CreateFromFile(file));
                }
            }

            return(photosInDirectory);
        }
Exemple #4
0
        [TestMethod]//テスト8
        public void 写真を追加できること()
        {
            var firstPhoto  = Photo.CreateFromFile(new File("dummy1.bmp"), new DateTime(1993, 05, 15, 15, 00, 00));
            var secondPhoto = Photo.CreateFromFile(new File("dummy2.bmp"), new DateTime(2018, 07, 18, 15, 00, 00));

            photoRepository.Store(firstPhoto);
            photoRepository.Store(secondPhoto);
        }
Exemple #5
0
        public void 写真を追加できること()
        {
            var photo = Photo.CreateFromFile(new File("dummy.bmp"));

            photoRepository.Store(photo);

            var result = photoRepository.FindBy(photo.Id);

            Assert.AreNotEqual(null, result);
        }
        /// <summary>
        /// 指定したディレクトリ直下のフォトのリストを返す
        /// </summary>
        /// <param name="dirpath"></param>
        /// <returns></returns>
        public List <Photo> Execute(string dirpath)
        {
            //ディレクトリパスが入力されていない場合
            if (dirpath.Length == 0 || dirpath == null)
            {
                throw new ArgumentNullException("ディレクトリパスが入力されていません");
            }

            //ディレクトリ内に存在する写真ファイルの一覧を取得(Fileインスタンス)
            IEnumerable <Domain.Model.File> files = photoFileService.FindAllPhotoFilesFromDirectory(dirpath);

            List <Photo> photosInDirectory = new List <Photo>();

            foreach (File file in files)
            {
                //クエリ
                Func <IQueryable <Photo>, IQueryable <Photo> > query = allPhotos =>
                {
                    List <Photo> photos = new List <Photo>();
                    foreach (Photo photo in allPhotos)
                    {
                        if (photo.File.FilePath == file.FilePath)
                        {
                            photos.Add(photo);
                        }
                    }
                    if (photos.Count() == 0)
                    {
                        photos.Add(Photo.CreateFromFile(file));
                    }
                    return(photos.AsQueryable());
                };

                //既にDBに写真データが登録されているか
                Photo hitPhoto = photoRepository.Find(query).First();

                //登録されていたら
                if (hitPhoto != null)
                {
                    photosInDirectory.Add(hitPhoto);
                }
                //登録されていなかったら
                else
                {
                    photosInDirectory.Add(Photo.CreateFromFile(file));
                }
            }
            //写真ファイルが存在しなかった場合
            if (photosInDirectory == null)
            {
                return(null);
            }
            return(photosInDirectory);
        }
Exemple #7
0
        public void 写真を更新できること()
        {
            var photo = Photo.CreateFromFile(new File("dummy.bmp"));

            photoRepository.Store(photo);

            photo.MarkAsFavorite();
            photoRepository.Store(photo);

            var result = photoRepository.FindBy(photo.Id);

            Assert.AreEqual(true, result.IsFavorite);
        }
Exemple #8
0
        public void 写真の検索ができること()
        {
            for (int i = 0; i < 5; i++)
            {
                Photo photo = Photo.CreateFromFile(new File("dummy.bmp"));


                if (i % 2 == 1)
                {
                    photo.MarkAsFavorite();
                }

                photoRepository.Store(photo);
            }


            Func <IQueryable <Photo>, IQueryable <Photo> > query = (IQueryable <Photo> photos) =>
            {
                List <Photo> new_photos = new List <Photo>();

                //var q = from p in photos where p.IsFavorite == true select p;
                //new_photos = q.ToList();

                foreach (Photo photo in photos)
                {
                    if (photo.IsFavorite)
                    {
                        new_photos.Add(photo);
                    }
                }

                return(new_photos.AsQueryable <Photo>());
            };


            IEnumerable <Photo> result0 = photoRepository.Find(photos => from p in photos where p.IsFavorite == true select p);


            IEnumerable <Photo> result = photoRepository.Find(query);

            int photo_num = 0;

            foreach (Photo photo in result0)
            {
                Assert.IsTrue(photo.IsFavorite);
                photo_num++;
            }
            Assert.AreEqual(photo_num, 2);
        }
Exemple #9
0
        public void 既存の写真をアルバムに追加できること()
        {
            var album = Album.Create("Album1");

            albumRepository.Store(album);
            var photo = Photo.CreateFromFile(new File("dummy.bmp"));

            photoRepository.Store(photo);

            photo.IsAssignedTo(album);
            photoRepository.Store(photo);

            var result = photoRepository.FindBy(photo.Id);

            Assert.AreEqual(album.Id, result.Album.Id);
        }
        public Photo Execute(string photoTitle, string albumTitle)
        {
            // フォトが存在するか検索する
            Func <IQueryable <Photo>, Photo> func = allPhotos =>
            {
                foreach (var p in allPhotos)
                {
                    if (p.File.FilePath == photoTitle)
                    {
                        return(p);
                    }
                }
                ;
                return(null);
            };

            // アルバム名からアルバムを取得する
            Func <IQueryable <Album>, Album> func2 = allAlbums =>
            {
                foreach (var p in allAlbums)
                {
                    if (p.Name == albumTitle)
                    {
                        return(p);
                    }
                }
                ;
                return(null);
            };

            // フォトが存在するか検索する
            var targetPhoto = photoRepository.Find(func) ?? Photo.CreateFromFile(new File(photoTitle));

            // 所属アルバムを変更する
            targetPhoto.IsAssignedTo(albumRepository.Find(func2));

            // 更新済みのフォトを保存する
            photoRepository.Store(targetPhoto);

            return(targetPhoto);
        }
Exemple #11
0
        public async Task <IEnumerable <Photo> > Execute(string directory)
        {
            // 画像ファイルリスト生成
            var          photoFileList = service.FindAllPhotoFilesFromDirectory(directory);
            List <Photo> photos        = new List <Photo>();

            // ファイルパスからFindをして、既にcsvに存在するかどうかも調べたほうがよい?

            // フォトデータ生成
            foreach (var p in photoFileList)
            {
                var photo = Photo.CreateFromFile(p);
                await Task.Run(() =>
                {
                    photoRepository.Store(photo);
                });

                photos.Add(photo);
            }
            return(photos);
        }