Пример #1
0
        public async Task Populate <T>(IEnumerable <T> fileDatas, CancellationToken cancellationToken) where T : IFileData
        {
            Logger.Write(this, LogLevel.Debug, "Begin populating meta data.");

            if (this.ReportProgress)
            {
                await this.SetName("Populating meta data").ConfigureAwait(false);

                await this.SetPosition(0).ConfigureAwait(false);

                await this.SetCount(fileDatas.Count()).ConfigureAwait(false);

                if (this.Count <= 100)
                {
                    this.Timer.Interval = FAST_INTERVAL;
                }
                else if (this.Count < 1000)
                {
                    this.Timer.Interval = NORMAL_INTERVAL;
                }
                else
                {
                    this.Timer.Interval = LONG_INTERVAL;
                }
                this.Timer.Start();
            }

            var metaDataSource = this.MetaDataSourceFactory.Create();

            await AsyncParallel.ForEach(fileDatas, async fileData =>
            {
                Logger.Write(this, LogLevel.Debug, "Populating meta data for file: {0} => {1}", fileData.Id, fileData.FileName);

                var metaData = await metaDataSource.GetMetaData(fileData.FileName).ConfigureAwait(false);

#if NET40
                this.Semaphore.Wait();
#else
                await this.Semaphore.WaitAsync().ConfigureAwait(false);
#endif

                try
                {
                    foreach (var metaDataItem in metaData)
                    {
                        await this.Writer.Write(fileData.Id, metaDataItem).ConfigureAwait(false);
                    }
                }
                finally
                {
                    this.Semaphore.Release();
                }

                if (this.ReportProgress)
                {
                    this.Current = fileData;
                    Interlocked.Increment(ref this.position);
                }
            }, cancellationToken, this.ParallelOptions).ConfigureAwait(false);
        }
Пример #2
0
        public async Task Populate(LibraryItemStatus?status, CancellationToken cancellationToken)
        {
            var libraryHierarchies = this.GetHierarchies(this.Transaction);

            if (libraryHierarchies.Length == 0)
            {
                Logger.Write(this, LogLevel.Warn, "No library hierarchies are defined (or enabled).");
                return;
            }

            var libraryHierarchyLevels = this.GetLevels(libraryHierarchies);
            var libraryItems           = this.GetItems(status, this.Transaction);

            if (this.ReportProgress)
            {
                this.Name     = "Populating library hierarchies";
                this.Position = 0;
                this.Count    = libraryItems.Count();
                if (this.Count <= 100)
                {
                    this.Timer.Interval = FAST_INTERVAL;
                }
                else if (this.Count < 1000)
                {
                    this.Timer.Interval = NORMAL_INTERVAL;
                }
                else
                {
                    this.Timer.Interval = LONG_INTERVAL;
                }
                this.Timer.Start();
            }

            await AsyncParallel.ForEach(libraryItems, async libraryItem =>
            {
                foreach (var libraryHierarchy in libraryHierarchies)
                {
                    await this.Populate(libraryItem, libraryHierarchy, libraryHierarchyLevels[libraryHierarchy]).ConfigureAwait(false);
                }

                if (this.ReportProgress)
                {
                    this.Current = libraryItem.FileName;
                    Interlocked.Increment(ref this.position);
                }
            }, cancellationToken, this.ParallelOptions).ConfigureAwait(false);
        }
Пример #3
0
        public async Task Populate(LibraryItemStatus?status, CancellationToken cancellationToken)
        {
            var libraryHierarchies     = this.GetHierarchies(this.Transaction);
            var libraryHierarchyLevels = this.GetLevels(libraryHierarchies);
            var libraryItems           = this.GetItems(status, this.Transaction);

            if (this.ReportProgress)
            {
                await this.SetName("Populating library hierarchies").ConfigureAwait(false);

                await this.SetPosition(0).ConfigureAwait(false);

                await this.SetCount(libraryItems.Count()).ConfigureAwait(false);

                if (this.Count <= 100)
                {
                    this.Timer.Interval = FAST_INTERVAL;
                }
                else if (this.Count < 1000)
                {
                    this.Timer.Interval = NORMAL_INTERVAL;
                }
                else
                {
                    this.Timer.Interval = LONG_INTERVAL;
                }
                this.Timer.Start();
            }

            await AsyncParallel.ForEach(libraryItems, async libraryItem =>
            {
                foreach (var libraryHierarchy in libraryHierarchies)
                {
                    await this.Populate(libraryItem, libraryHierarchy, libraryHierarchyLevels[libraryHierarchy]).ConfigureAwait(false);
                }

                if (this.ReportProgress)
                {
                    this.Current = libraryItem.FileName;
                    Interlocked.Increment(ref this.position);
                }
            }, cancellationToken, this.ParallelOptions).ConfigureAwait(false);
        }
Пример #4
0
        public async Task Populate(CancellationToken cancellationToken)
        {
            //Using source without relations.
            //TODO: Add this kind of thing to FoxDb, we're actually performing some schema queries to create this structure.
            var source = this.Database.Source(
                this.Database.Config.Transient.Table <LibraryItem>(TableFlags.AutoColumns),
                this.Transaction
                );
            var set = this.Database.Set <LibraryItem>(source);

            if (this.ReportProgress)
            {
                await this.SetName("Updating library").ConfigureAwait(false);

                await this.SetPosition(0).ConfigureAwait(false);

                if (this.Items != null && this.Items.Any())
                {
                    await this.SetCount(this.Items.Count()).ConfigureAwait(false);
                }
                else
                {
                    await this.SetCount(set.Count).ConfigureAwait(false);
                }
                if (this.Count <= 100)
                {
                    this.Timer.Interval = FAST_INTERVAL;
                }
                else if (this.Count < 1000)
                {
                    this.Timer.Interval = NORMAL_INTERVAL;
                }
                else
                {
                    this.Timer.Interval = LONG_INTERVAL;
                }
                this.Timer.Start();
            }

            var sequence = default(IEnumerable <LibraryItem>);

            if (this.Items != null && this.Items.Any())
            {
                sequence = this.Items;
            }
            else
            {
                sequence = set;
            }
            await AsyncParallel.ForEach(sequence, async libraryItem =>
            {
                if (this.Predicate(libraryItem))
                {
                    await this.Task(set, libraryItem).ConfigureAwait(false);
                }

                if (this.ReportProgress)
                {
                    this.Current = libraryItem;
                    Interlocked.Increment(ref this.position);
                }
            }, cancellationToken, this.ParallelOptions).ConfigureAwait(false);
        }
Пример #5
0
        public async Task Populate <T>(IEnumerable <T> fileDatas, CancellationToken cancellationToken) where T : IFileData
        {
            Logger.Write(this, LogLevel.Debug, "Begin populating meta data.");

            if (this.ReportProgress)
            {
                this.Name     = "Populating meta data";
                this.Position = 0;
                this.Count    = fileDatas.Count();
                if (this.Count <= 100)
                {
                    this.Timer.Interval = FAST_INTERVAL;
                }
                else if (this.Count < 1000)
                {
                    this.Timer.Interval = NORMAL_INTERVAL;
                }
                else
                {
                    this.Timer.Interval = LONG_INTERVAL;
                }
                this.Timer.Start();
            }

            var metaDataSource = this.MetaDataSourceFactory.Create();

            await AsyncParallel.ForEach(fileDatas, async fileData =>
            {
                Logger.Write(this, LogLevel.Debug, "Reading meta data from file \"{0}\".", fileData.FileName);
                try
                {
                    var metaData = await metaDataSource.GetMetaData(fileData.FileName).ConfigureAwait(false);

                    foreach (var warning in metaDataSource.GetWarnings(fileData.FileName))
                    {
                        this.AddWarning(fileData, warning);
                    }

#if NET40
                    this.Semaphore.Wait();
#else
                    await this.Semaphore.WaitAsync().ConfigureAwait(false);
#endif

                    try
                    {
                        foreach (var metaDataItem in metaData)
                        {
                            try
                            {
                                await this.Writer.Write(fileData.Id, metaDataItem).ConfigureAwait(false);
                            }
                            catch (Exception e)
                            {
                                Logger.Write(this, LogLevel.Debug, "Failed to write meta data entry from file \"{0}\" with name \"{1}\": {2}", fileData.FileName, metaDataItem.Name, e.Message);
                                this.AddWarning(fileData, e.Message);
                            }
                        }
                    }
                    finally
                    {
                        this.Semaphore.Release();
                    }

                    if (this.ReportProgress)
                    {
                        this.Current = fileData;
                        Interlocked.Increment(ref this.position);
                    }
                }
                catch (Exception e)
                {
                    Logger.Write(this, LogLevel.Debug, "Failed to read meta data from file \"{0}\": {1}", fileData.FileName, e.Message);
                    this.AddWarning(fileData, e.Message);
                }
            }, cancellationToken, this.ParallelOptions).ConfigureAwait(false);
        }