Beispiel #1
0
        public async Task <PhotoUser> CreatePhotoUserAsync(Photo photo, User user)
        {
            var photoUser = new PhotoUser
            {
                Photo = photo,
                User  = user
            };

            await _context.PhotoUsers.AddAsync(photoUser);

            return(photoUser);
        }
Beispiel #2
0
        public PhotoUser CreatePhotoUser(Photo photo, User user)
        {
            var photoUser = new PhotoUser
            {
                Photo = photo,
                User  = user
            };

            _context.PhotoUsers.Add(photoUser);

            return(photoUser);
        }
Beispiel #3
0
        public async Task CreateDBCacheIfNeededAsync(IEnumerable <string> filePaths)
        {
            // DBに存在しないものだけキャッシュ作成を行う
            foreach (var filePath in filePaths.Except(await _context.Photos.Select(p => p.FilePath).ToListAsync().ConfigureAwait(true)))
            {
                var photo = new Photo
                {
                    FilePath = filePath
                };

                // サムネイル作成
                // サムネイルは初表示時に作成する
                //photo.Thumbnail = await ImageHelper.CreateThumbnailAsync(filePath);

                // metaデータ読み込み
                if (!VrcMetaDataReader.TryRead(filePath, out VrcMetaData meta))
                {
                    // ファイル名から日付を取得
                    photo.Date = MetaDataHelper.GetDateTimeFromPhotoName(filePath);
                }
                else
                {
                    // 日付情報設定
                    photo.Date = meta.Date;

                    // ワールド情報設定
                    if (string.IsNullOrEmpty(meta.World))
                    {
                        photo.World = null;
                    }
                    else
                    {
                        if (!ExistsWorldByWorldName(meta.World, out var world))
                        {
                            photo.World = CreateWorld(meta.World);
                        }
                        else
                        {
                            photo.World = world;
                        }
                    }

                    // 撮影者情報設定
                    if (string.IsNullOrEmpty(meta.Photographer))
                    {
                        photo.Photographer = null;
                    }
                    else
                    {
                        var(exists, photographer) = await ExistsUserByUserNameAsync(meta.Photographer).ConfigureAwait(true);

                        if (!exists)
                        {
                            photo.Photographer = await CreateUserAsync(meta.Photographer).ConfigureAwait(true);
                        }
                        else
                        {
                            photo.Photographer = photographer;
                        }
                    }

                    // ユーザ情報設定
                    if (meta.Users.Any())
                    {
                        foreach (var metaUser in meta.Users)
                        {
                            var(exists, user) = await ExistsUserByUserNameAsync(metaUser.UserName).ConfigureAwait(true);

                            // TODO:TwitterのDisplaynameを入れていない
                            if (!exists)
                            {
                                user = await CreateUserAsync(metaUser.UserName).ConfigureAwait(true);
                            }

                            var photoUser = CreatePhotoUser(photo, user);

                            photo.PhotoUsers.Add(photoUser);
                        }
                    }
                }

                await _context.Photos.AddAsync(photo);

                await _context.SaveChangesAsync().ConfigureAwait(true);
            }
        }
Beispiel #4
0
        public Task InsertAsync(string filePath, VrcMetaData metaData, CancellationToken cancelToken)
        {
            return(Task.Run(async() =>
            {
                var photo = new Photo
                {
                    FilePath = filePath
                };

                photo.Date = metaData.Date;

                using (await asyncLock.LockAsync())
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (metaData.Photographer != null)
                    {
                        if (!ExistsUserByUserName(metaData.Photographer, out User user))
                        {
                            user = CreateUser(metaData.Photographer);
                        }
                        photo.Photographer = user;
                    }

                    if (metaData.World != null)
                    {
                        if (!ExistsWorldByWorldName(metaData.World, out World world))
                        {
                            world = CreateWorld(metaData.World);
                        }
                        photo.World = world;
                    }

                    if (metaData.Users != null && metaData.Users.Any())
                    {
                        foreach (var metaUser in metaData.Users)
                        {
                            if (!ExistsUserByUserName(metaUser.UserName, out User user))
                            {
                                user = CreateUser(metaUser.UserName);
                            }

                            var photoUser = CreatePhotoUser(photo, user);
                            photo.PhotoUsers.Add(photoUser);
                        }
                    }

                    _context.Photos.Add(photo);
                    count++;

                    if (count >= 100)
                    {
                        _context.SaveChanges();
                        count = 0;
                    }
                }
            }, cancelToken));
        }