private async Task InitializeFiltersAsync()
        {
            try
            {
                if (MatureIndexFileManager.Exists())
                {
                    using var sr = MatureIndexFileManager.OpenText();
                    if (!sr.EndOfStream)
                    {
                        var    lineTask = sr.ReadLineAsync();
                        string line     = null;
                        while (lineTask != null)
                        {
                            if (line is null)
                            {
                                line = await lineTask.ConfigureAwait(false);
                            }

                            lineTask = sr.EndOfStream ? null : sr.ReadLineAsync();

                            ProcessLine(line, enqueue: false);

                            line = null;
                        }
                    }
                }
            }
            catch
            {
                // We found a corrupted entry. Stop here.
                // Delete the currupted file.
                // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events.
                Logger.LogError("Mature index got corrupted. Deleting both mature and immature index...");
                MatureIndexFileManager.DeleteMe();
                ImmatureIndexFileManager.DeleteMe();
                throw;
            }

            try
            {
                if (ImmatureIndexFileManager.Exists())
                {
                    foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync().ConfigureAwait(false))                     // We can load ImmatureIndexFileManager to the memory, no problem.
                    {
                        ProcessLine(line, enqueue: true);
                    }
                }
            }
            catch
            {
                // We found a corrupted entry. Stop here.
                // Delete the currupted file.
                // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events.
                Logger.LogError("Immature index got corrupted. Deleting it...");
                ImmatureIndexFileManager.DeleteMe();
                throw;
            }
        }
示例#2
0
        private async Task InitializeFiltersAsync()
        {
            try
            {
                Height height = StartingHeight;

                if (MatureIndexFileManager.Exists())
                {
                    using (var sr = MatureIndexFileManager.OpenText())
                    {
                        if (!sr.EndOfStream)
                        {
                            var    lineTask = sr.ReadLineAsync();
                            string line     = null;
                            while (lineTask != null)
                            {
                                if (line is null)
                                {
                                    line = await lineTask;
                                }

                                lineTask = sr.EndOfStream ? null : sr.ReadLineAsync();

                                ProcessLine(height, line, enqueue: false);
                                height++;

                                line = null;
                            }
                        }
                    }
                }

                if (ImmatureIndexFileManager.Exists())
                {
                    foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync())                     // We can load ImmatureIndexFileManager to the memory, no problem.
                    {
                        ProcessLine(height, line, enqueue: true);
                        height++;
                    }
                }
            }
            catch
            {
                // We found a corrupted entry. Stop here.
                // Delete the currupted file.
                // Don't try to autocorrect, because the internal data structures are throwing events those may confuse the consumers of those events.
                Logger.LogError <IndexStore>("An index file got corrupted. Deleting index files...");
                MatureIndexFileManager.DeleteMe();
                ImmatureIndexFileManager.DeleteMe();
                throw;
            }
        }
示例#3
0
    private async Task InitializeFiltersAsync(CancellationToken cancel)
    {
        try
        {
            if (MatureIndexFileManager.Exists())
            {
                using (BenchmarkLogger.Measure(LogLevel.Debug, "MatureIndexFileManager loading"))
                {
                    int i = 0;
                    using StreamReader sr = MatureIndexFileManager.OpenText();
                    if (!sr.EndOfStream)
                    {
                        while (true)
                        {
                            i++;
                            cancel.ThrowIfCancellationRequested();
                            string?line = await sr.ReadLineAsync().ConfigureAwait(false);

                            if (line is null)
                            {
                                break;
                            }

                            ProcessLine(line, enqueue: false);
                        }
                    }

                    Logger.LogDebug($"Loaded {i} lines from the mature index file.");
                }
            }
        }
        catch (Exception ex) when(ex is not OperationCanceledException)
        {
            // We found a corrupted entry. Stop here.
            // Delete the corrupted file.
            // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events.
            Logger.LogError("Mature index got corrupted. Deleting both mature and immature index...");
            MatureIndexFileManager.DeleteMe();
            ImmatureIndexFileManager.DeleteMe();
            throw;
        }
        cancel.ThrowIfCancellationRequested();

        try
        {
            if (ImmatureIndexFileManager.Exists())
            {
                foreach (var line in await ImmatureIndexFileManager.ReadAllLinesAsync(cancel).ConfigureAwait(false))                 // We can load ImmatureIndexFileManager to the memory, no problem.
                {
                    ProcessLine(line, enqueue: true);
                    cancel.ThrowIfCancellationRequested();
                }
            }
        }
        catch (Exception ex) when(ex is not OperationCanceledException)
        {
            // We found a corrupted entry. Stop here.
            // Delete the corrupted file.
            // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events.
            Logger.LogError("Immature index got corrupted. Deleting it...");
            ImmatureIndexFileManager.DeleteMe();
            throw;
        }
    }