Example #1
0
        /// <summary>
        /// 全フォトリストを格納
        /// </summary>
        /// <returns></returns>
        private IQueryable <Photo> FindAll()
        {
            // CSVファイルを読み込む
            List <Photo> photos = new List <Photo>();

            if (System.IO.File.Exists(this.CsvFilePath))
            {
                using (StreamReader sr = new StreamReader(CsvFilePath))
                {
                    // 行末まで読み込む
                    while (sr.Peek() > -1)
                    {
                        string            line      = sr.ReadLine();
                        string[]          photoData = line.Split(',');
                        Domain.Model.File file      = new Domain.Model.File(photoData[1]);
                        Album             album     = albumRepository.FindBy(photoData[3]);
                        photos.Add(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album));
                    }
                }
                // IQueryable型に変換してReturn
                return(photos.AsQueryable());
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        public IEnumerable <Domain.Model.File> FindAllPhotoFilesFromDirectory(string directory)
        {
            // TODO: コレクション講座で実装予定
            List <Domain.Model.File> file_list = new List <Domain.Model.File>();

            // directoryが存在する場合
            if (Directory.Exists(directory))
            {
                List <string> path_list = Enumerate(directory);
                foreach (string filePath in path_list)
                {
                    Domain.Model.File file = new Domain.Model.File(filePath);
                    if (file.IsPhoto)
                    {
                        using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(filePath))
                        {
                            foreach (System.Drawing.Imaging.PropertyItem item in bmp.PropertyItems)
                            {
                                //Exif情報から撮影時間を取得する
                                if (item.Id == 0x9003 && item.Type == 2)
                                {
                                    //文字列に変換する
                                    string val = System.Text.Encoding.ASCII.GetString(item.Value);
                                    val = val.Trim(new char[] { '\0' });
                                    //DateTimeに変換
                                    file.AddDateTime(DateTime.ParseExact(val, "yyyy:MM:dd HH:mm:ss", null));
                                }
                            }
                            file_list.Add(file);
                        }
                    }
                }
            }
            return(file_list);
        }
        public IEnumerable <Domain.Model.File> FindAllPhotoFilesFromDirectory(string directory)
        {
            // TODO: コレクション講座で実装予定
            List <Domain.Model.File> file_list = new List <Domain.Model.File>();

            // directoryが存在する場合
            if (Directory.Exists(directory))
            {
                List <string> path_list = Enumerate(directory);

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

                    if (file.IsPhoto)
                    {
                        file_list.Add(file);
                    }
                }
            }
            //else
            //{
            //    throw new IOException("指定したディレクトリが存在しません");
            //}

            return(file_list);
        }
Example #4
0
        public List <Photo> FindFav(Photo entity)
        {
            // TODO: ファイルIO講座で実装
            // 保存したcsvからidを検索
            using (StreamReader sr = new StreamReader(CsvFilePath))
            {
                List <Photo> favlist = new List <Photo>();
                while (sr.Peek() > -1)
                {
                    string   line      = sr.ReadLine();
                    string[] photoData = line.Split(',');
                    if (photoData[2] == "true")
                    {
                        // あったよ
                        Domain.Model.File  file  = new Domain.Model.File(photoData[1]);
                        Domain.Model.Album album = albumRepository.FindBy(photoData[3]);

                        //favlistに該当する写真の情報を出力する
                        favlist.Add(entity);

                        return(favlist);
                    }
                }
                return(null);
            }
        }
Example #5
0
        public Photo FindFT(string filePath)
        {
            // TODO: ファイルIO講座で実装
            // 保存したcsvからidを検索
            //string ext = Path.GetExtension(filePath).ToLower();
            //return photoFileExtensions.Any(x => x == ext);
            using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8))
            {
                while (sr.Peek() > -1)
                {
                    string   line      = sr.ReadLine();
                    string[] photoData = line.Split(',');
                    if (photoData[1] == filePath)
                    {
                        // あったよ
                        Domain.Model.File file = new Domain.Model.File(photoData[1]);
                        //Domain.Model.Album album = new Domain.Model.Album(photoData[3]);
                        Domain.Model.Album album = albumRepository.FindBy(photoData[3]);

                        return(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album));
                    }
                }
                return(null);
            }
        }
Example #6
0
        public Photo FindBy(string id)
        {
            // TODO: ファイルIO講座で実装
            // 保存したcsvからidを検索
            using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8))
            {
                while (sr.Peek() > -1)
                {
                    string   line      = sr.ReadLine();
                    string[] photoData = line.Split(',');
                    if (photoData[0] == id)
                    {
                        // あったよ
                        Domain.Model.File file = new Domain.Model.File(photoData[1]);
                        //Domain.Model.Album album = new Domain.Model.Album(photoData[3]);

                        Domain.Model.Album album = albumRepository.FindBy(photoData[3]);

                        return(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album));
                    }
                }

                // なかったよ
                return(null);
                //throw new NotImplementedException();
            }
        }
Example #7
0
        /// <summary>
        /// Csvファイル内のすべてのフォトの取得
        /// (引数にフォトを渡した場合はそのフォトと同じIDのフォトをリストから除く)
        /// </summary>
        /// <returns></returns>
        IQueryable <Photo> FindAll(Photo photo = null)
        {
            List <Photo> photos = new List <Photo>();

            if (System.IO.File.Exists(CsvFilePath))
            {
                using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8))
                {
                    while (sr.Peek() > -1)
                    {
                        string   line      = sr.ReadLine();
                        string[] photoData = line.Split(',');

                        Domain.Model.File  file  = new Domain.Model.File(photoData[1]);
                        Domain.Model.Album album = albumRepository.FindBy(photoData[3]);

                        if (photo == null || photo.Id != photoData[0])
                        {
                            photos.Add(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album));
                        }
                    }
                }

                return(photos.AsQueryable());
            }
            else
            {
                // なかったよ
                return(null);
            }
        }
        public Photo Find(Func <IQueryable <Photo>, Photo> query)
        {
            // TODO: イベント・デリゲート講座で実装予定
            List <Photo> photos = new List <Photo>();

            if (System.IO.File.Exists(CsvFilePath))
            {
                using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8))
                {
                    while (sr.Peek() > -1)
                    {
                        string   line      = sr.ReadLine();
                        string[] photoData = line.Split(',');

                        Domain.Model.File  file  = new Domain.Model.File(photoData[1]);
                        Domain.Model.Album album = albumRepository.FindBy(photoData[3]);

                        photos.Add(new Photo(photoData[0], file, Convert.ToBoolean(photoData[2]), photoData[3], album));
                    }
                }

                return(query(photos.AsQueryable <Photo>()));
            }
            else
            {
                // なかったよ
                return(null);
            }
        }
        public IEnumerable <Photo> FindByIsFavorite()
        {
            List <Photo> photo_list = new List <Photo>();

            if (System.IO.File.Exists(CsvFilePath))
            {
                using (StreamReader sr = new StreamReader(CsvFilePath, Encoding.UTF8))
                {
                    while (sr.Peek() > -1)
                    {
                        string   line       = sr.ReadLine();
                        string[] photoData  = line.Split(',');
                        bool     isFavorite = Convert.ToBoolean(photoData[2]);

                        if (isFavorite == true)
                        {
                            // あったよ
                            Domain.Model.File file = new Domain.Model.File(photoData[1]);

                            Domain.Model.Album album = albumRepository.FindBy(photoData[3]);

                            photo_list.Add(new Photo(photoData[0], file, isFavorite, photoData[3], album));
                        }
                    }
                }
            }

            // なかったよ
            return(photo_list);
        }
        // CSVの1行をKeyword型のデータに変換する(=デシリアライズ)
        private Photo Deserialize(string csvRow)
        {
            var split    = csvRow.Split(',');
            var file     = new Domain.Model.File(split[1]);
            var keyword  = keywordRepository.FindBy(split[3]);
            var dateTime = new DateTime(1993, 05, 15, 15, 00, 00);

            return(new Photo(split[0], file, dateTime, Convert.ToBoolean(split[2]), split[3], keyword));
        }
        public IEnumerable <Domain.Model.File> FindAllPhotoFilesFromDirectory(string directory)
        {
            // TODO: コレクション講座で実装予定
            List <Domain.Model.File> file_list = null;

            // directoryが存在する場合
            if (Directory.Exists(directory))
            {
                file_list = new List <Domain.Model.File>();
                List <string> path_list = Enumerate(directory);

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

                    if (file.IsPhoto)
                    {
                        file_list.Add(file);
                    }
                }
            }

            return(file_list);
        }
 public DownloadProcessor(File file, IDownloadListner downloadListner) : base(file, downloadListner)
 {
     _file = new FileEntity(file.Url, file.Location, file.FileType);
 }