private async Task WriteLibraryMetaData(LibraryItem libraryItem)
        {
            using (var transaction = this.Database.BeginTransaction(this.Database.PreferredIsolationLevel))
            {
                await this.Database.ExecuteAsync(this.Database.Queries.ClearLibraryMetaDataItems, (parameters, phase) =>
                {
                    switch (phase)
                    {
                    case DatabaseParameterPhase.Fetch:
                        parameters["itemId"] = libraryItem.Id;
                        parameters["type"]   = META_DATA_TYPE;
                        break;
                    }
                }, transaction).ConfigureAwait(false);

                using (var writer = new MetaDataWriter(this.Database, this.Database.Queries.AddLibraryMetaDataItem, transaction))
                {
                    await writer.Write(
                        libraryItem.Id,
                        libraryItem.MetaDatas,
                        metaDataItem => META_DATA_TYPE.HasFlag(metaDataItem.Type)
                        ).ConfigureAwait(false);
                }

                libraryItem.ImportDate = DateTimeHelper.ToString(DateTime.UtcNow.AddSeconds(30));
                await LibraryTaskBase.UpdateLibraryItem(this.Database, libraryItem, transaction).ConfigureAwait(false);

                if (transaction.HasTransaction)
                {
                    transaction.Commit();
                }
            }
        }
        private async Task WriteLibraryMetaData(PlaylistItem playlistItem)
        {
            using (var transaction = this.Database.BeginTransaction(this.Database.PreferredIsolationLevel))
            {
                await this.Database.ExecuteAsync(this.Database.Queries.ClearLibraryMetaDataItems, (parameters, phase) =>
                {
                    switch (phase)
                    {
                    case DatabaseParameterPhase.Fetch:
                        parameters["itemId"] = playlistItem.LibraryItem_Id.Value;
                        parameters["type"]   = META_DATA_TYPE;
                        break;
                    }
                }, transaction).ConfigureAwait(false);

                using (var writer = new MetaDataWriter(this.Database, this.Database.Queries.AddLibraryMetaDataItem, transaction))
                {
                    await writer.Write(
                        playlistItem.LibraryItem_Id.Value,
                        playlistItem.MetaDatas,
                        metaDataItem => META_DATA_TYPE.HasFlag(metaDataItem.Type)
                        ).ConfigureAwait(false);
                }

                if (transaction.HasTransaction)
                {
                    transaction.Commit();
                }
            }
        }
Example #3
0
            private async Task AddOrUpdateMetaData()
            {
                Logger.Write(this, LogLevel.Debug, "Fetching meta data for new playlist items.");
                using (var transaction = this.Database.BeginTransaction(this.Database.PreferredIsolationLevel))
                {
                    var query = this.Database
                                .AsQueryable <PlaylistItem>(this.Database.Source(new DatabaseQueryComposer <PlaylistItem>(this.Database), transaction))
                                .Where(playlistItem => playlistItem.Status == PlaylistItemStatus.Import);
                    var info = default(CDInfo);
                    BassUtils.OK(BassCd.GetInfo(this.Drive, out info));
                    using (var writer = new MetaDataWriter(this.Database, this.Database.Queries.AddPlaylistMetaDataItem, transaction))
                    {
                        foreach (var playlistItem in query)
                        {
                            var metaData = await this.MetaDataSource.GetMetaData(playlistItem.FileName).ConfigureAwait(false);

                            foreach (var metaDataItem in metaData)
                            {
                                await writer.Write(playlistItem.Id, metaDataItem).ConfigureAwait(false);
                            }
                        }
                    }
                    transaction.Commit();
                }
            }