Esempio n. 1
0
        public void Update()
        {
            switch (State)
            {
            case WorkState.Populating:
            {
                if (m_populateSearchTask != null && m_populateSearchTask.IsCompleted)
                {
                    m_populateSearchTask = null;
                }

                if (m_populateTask != null && m_populateTask.IsCompleted)
                {
                    m_populateTask = null;
                }

                if (m_populateQueue.Count > 0 && m_populateTask == null)
                {
                    Debug.Assert(m_currentTaskCancellation != null);
                    m_populateTask = Task.Run(() => RunPopulate(m_currentTaskCancellation !.Token));
                }

                if (m_populateSearchTask == null && m_populateQueue.Count == 0)
                {
                    SetToIdle();
                }
            } break;

            case WorkState.CleanSearching:
            {
                foreach (var set in ChartDatabaseService.ChartSets)
                {
                    string dirPath = Path.Combine(ChartDatabaseService.ChartsDirectory, set.FilePath);
                    if (!Directory.Exists(dirPath))
                    {
                        ChartDatabaseService.RemoveSet(set);
                    }
                }

                Logger.Log("Setting database worker to Clean");
                State = WorkState.Cleaning;
            }
            break;

            case WorkState.Cleaning:
            {
                SetToIdle();
            }
            break;
            }
        }
Esempio n. 2
0
        private void RunPopulate(CancellationToken ct)
        {
            while (m_populateQueue !.TryDequeue(out var info))
            {
                if (ct.IsCancellationRequested)
                {
                    ct.ThrowIfCancellationRequested();
                }

                Logger.Log($"Adding { info.FilePath } to the database");
                //if (ChartDatabaseService.ContainsSet(info)) continue;
                ChartDatabaseService.AddSet(info);
            }
        }
Esempio n. 3
0
        private void AddSetFileRelative(string relPath)
        {
            if (PathL.IsFullPath(relPath))
            {
                throw new ArgumentException($"{ nameof(AddSetFileRelative) } expects a relative path.");
            }

            string setDir  = Directory.GetParent(relPath).FullName;
            string setFile = Path.GetFileName(relPath);

            Debug.Assert(Path.Combine(setDir, setFile) == relPath);

            var setSerializer = new ChartSetSerializer(ChartDatabaseService.ChartsDirectory);
            var setInfo       = setSerializer.LoadFromFile(setDir, setFile);

            ChartDatabaseService.AddSet(setInfo);
        }
Esempio n. 4
0
        private void RunPopulateSearch(CancellationToken ct)
        {
            string chartsDirectory = ChartDatabaseService.ChartsDirectory;

            Logger.Log($"Attempt to populate from chart directory `{Path.GetFullPath(chartsDirectory)}`");
            if (!Directory.Exists(chartsDirectory))
            {
                Logger.Log($"Charts directory ot found.");
                return;
            }

            var setSerializer = new ChartSetSerializer(chartsDirectory);

            SearchDirectory(chartsDirectory, null);

            void SearchDirectory(string directory, string?currentSubDirectory)
            {
                //Logger.Log($"Searching directory `{directory}` for charts...");
                foreach (string entry in Directory.EnumerateDirectories(directory))
                {
                    if (ct.IsCancellationRequested)
                    {
                        Logger.Log("Chart search canceled");
                        ct.ThrowIfCancellationRequested();
                    }

                    string entrySubDirectory = currentSubDirectory == null?Path.GetFileName(entry) : Path.Combine(currentSubDirectory, Path.GetFileName(entry));

                    // TODO(local): check for anything with any .theori-set extension
                    var sets = new DirectoryInfo(entry).GetFiles("*.theori-set");
                    foreach (var setFile in sets)
                    {
                        // TODO(local): see if this can be updated rather than just skipped
                        if (ChartDatabaseService.ContainsSetAtLocation(Path.Combine(entrySubDirectory, setFile.Name)))
                        {
                            continue;
                        }
                        //Logger.Log($"Adding set file `{setFile}`");
                        EnqueuePopulateEntry(setSerializer.LoadFromFile(entrySubDirectory, setFile.Name));
                    }

                    SearchDirectory(entry, entrySubDirectory);
                }
            }
        }
Esempio n. 5
0
 public IEnumerable <ChartInfo> GetChartsInCollection(string collectionName) => ChartDatabaseService.GetChartsInCollection(collectionName);
Esempio n. 6
0
 public void RemoveChartFromCollection(string collectionName, ChartInfo chart) => ChartDatabaseService.RemoveFromCollection(collectionName, chart);
Esempio n. 7
0
 public void AddChartToCollection(string collectionName, ChartInfo chart) => ChartDatabaseService.AddToCollection(collectionName, chart);
Esempio n. 8
0
 public void CreateCollection(string collectionName) => ChartDatabaseService.CreateCollection(collectionName);