Ejemplo n.º 1
0
        private async Task UpdateIndexingStatisticsAsync()
        {
            await Task.Run(() =>
            {
                using (var conn = this.factory.GetConnection())
                {
                    try
                    {
                        IndexingStatistic lastFileCountStatistic        = conn.Table <IndexingStatistic>().Select((t) => t).Where((t) => t.Key.Equals("LastFileCount")).FirstOrDefault();
                        IndexingStatistic lastDateFileModifiedStatistic = conn.Table <IndexingStatistic>().Select((t) => t).Where((t) => t.Key.Equals("LastDateFileModified")).FirstOrDefault();

                        long currentDateFileModified = this.allDiskPaths.Select(t => t.Item3).OrderByDescending(t => t).FirstOrDefault();
                        currentDateFileModified      = currentDateFileModified > 0 ? currentDateFileModified : 0;

                        long currentFileCount = this.allDiskPaths.Count;

                        if (lastFileCountStatistic != null)
                        {
                            lastFileCountStatistic.Value = currentFileCount.ToString();
                            conn.Update(lastFileCountStatistic);
                        }
                        else
                        {
                            conn.Insert(new IndexingStatistic {
                                Key = "LastFileCount", Value = currentFileCount.ToString()
                            });
                        }

                        if (lastDateFileModifiedStatistic != null)
                        {
                            lastDateFileModifiedStatistic.Value = currentDateFileModified.ToString();
                            conn.Update(lastDateFileModifiedStatistic);
                        }
                        else
                        {
                            conn.Insert(new IndexingStatistic {
                                Key = "LastDateFileModified", Value = currentDateFileModified.ToString()
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        LogClient.Info("An error occurred while updating indexing statistics. Exception: {0}", ex.Message);
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public async Task CheckCollectionAsync(bool ignoreRemovedFiles, bool artworkOnly)
        {
            if (this.IsIndexing | !this.needsIndexing)
            {
                return;
            }
            else
            {
                this.needsIndexing = false;
            }

            await this.InitializeAsync();

            try
            {
                using (var conn = this.factory.GetConnection())
                {
                    IndexingStatistic lastFileCountStatistic        = conn.Table <IndexingStatistic>().Select((t) => t).Where((t) => t.Key.Equals("LastFileCount")).FirstOrDefault();
                    IndexingStatistic lastDateFileModifiedStatistic = conn.Table <IndexingStatistic>().Select((t) => t).Where((t) => t.Key.Equals("LastDateFileModified")).FirstOrDefault();
                    long needsIndexingCount = conn.Table <Track>().Select(t => t).Where(t => t.NeedsIndexing == 1).ToList().LongCount();

                    long lastFileCount        = 0;
                    long lastDateFileModified = 0;

                    if (lastFileCountStatistic != null)
                    {
                        long.TryParse(lastFileCountStatistic.Value, out lastFileCount);
                    }
                    if (lastDateFileModifiedStatistic != null)
                    {
                        long.TryParse(lastDateFileModifiedStatistic.Value, out lastDateFileModified);
                    }

                    if (needsIndexingCount > 0 | lastFileCount != this.allDiskPaths.Count | (this.allDiskPaths.Count > 0 && (lastDateFileModified < this.allDiskPaths.Select((t) => t.Item3).OrderByDescending((t) => t).First())))
                    {
                        this.needsIndexing = true;
                        await this.IndexCollectionAsync(ignoreRemovedFiles, artworkOnly, true);
                    }
                }
            }
            catch (Exception ex)
            {
                LogClient.Error("Could not get indexing statistics from database. Exception: {0}", ex.Message);
            }
        }