<commit_before>﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Elfie.Model;
using Microsoft.CodeAnalysis.Elfie.Model.Structures;
using Microsoft.CodeAnalysis.Elfie.Model.Tree;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.SymbolSearch
{
    /// <summary>
    /// A service which enables searching for packages matching certain criteria.
    /// It works against a <see cref="Microsoft.CodeAnalysis.Elfie"/> database to find results.
    /// 
    /// This implementation also spawns a task which will attempt to keep that database up to
    /// date by downloading patches on a daily basis.
    /// </summary>
    internal partial class SymbolSearchUpdateEngine : ISymbolSearchUpdateEngine
    {
        private readonly ConcurrentDictionary<string, IAddReferenceDatabaseWrapper> _sourceToDatabase =
            new ConcurrentDictionary<string, IAddReferenceDatabaseWrapper>();

        public SymbolSearchUpdateEngine(
            ISymbolSearchLogService logService,
            ISymbolSearchProgressService progressService)
            : this(logService, progressService, CancellationToken.None)
        {
        }

        public SymbolSearchUpdateEngine(
            ISymbolSearchLogService logService,
            ISymbolSearchProgressService progressService,
            CancellationToken updateCancellationToken)
            : this(logService,
                   progressService,
                   new RemoteControlService(),
                   new DelayService(),
                   new IOService(),
                   new PatchService(),
                   new DatabaseFactoryService(),
                   // Report all exceptions we encounter, but don't crash on them.
                   FatalError.ReportWithoutCrash,
                   updateCancellationToken)
        {
        }

        /// <summary>
        /// For testing purposes only.
        /// </summary>
        internal SymbolSearchUpdateEngine(
            ISymbolSearchLogService logService,
            ISymbolSearchProgressService progressService,
            IRemoteControlService remoteControlService,
            IDelayService delayService,
            IIOService ioService,
            IPatchService patchService,
            IDatabaseFactoryService databaseFactoryService,<commit_msg>Simplify<commit_after>﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Elfie.Model;
using Microsoft.CodeAnalysis.Elfie.Model.Structures;
using Microsoft.CodeAnalysis.Elfie.Model.Tree;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.SymbolSearch
{
    /// <summary>
    /// A service which enables searching for packages matching certain criteria.
    /// It works against a <see cref="Microsoft.CodeAnalysis.Elfie"/> database to find results.
    /// 
    /// This implementation also spawns a task which will attempt to keep that database up to
    /// date by downloading patches on a daily basis.
    /// </summary>
    internal partial class SymbolSearchUpdateEngine : ISymbolSearchUpdateEngine
    {
        private readonly ConcurrentDictionary<string, IAddReferenceDatabaseWrapper> _sourceToDatabase =
            new ConcurrentDictionary<string, IAddReferenceDatabaseWrapper>();

        public SymbolSearchUpdateEngine(
            ISymbolSearchLogService logService,
            ISymbolSearchProgressService progressService)
            : this(logService,
                   progressService,
                   new RemoteControlService(),
                   new DelayService(),
                   new IOService(),
                   new PatchService(),
                   new DatabaseFactoryService(),
                   // Report all exceptions we encounter, but don't crash on them.
                   FatalError.ReportWithoutCrash,
                   // In non-test scenarios, we're not cancellable.  Our lifetime will simply be
                   // that of the OOP process itself.  i.e. when it goes away, it will just tear
                   // down our update-loop itself.  So we don't need any additional controls over
                   // it.
                   testCancellationToken: CancellationToken.None)
        {
        }

        /// <summary>
        /// For testing purposes only.
        /// </summary>
        internal SymbolSearchUpdateEngine(
            ISymbolSearchLogService logService,
            ISymbolSearchProgressService progressService,
            IRemoteControlService remoteControlService,
            IDelayService delayService,
            IIOService ioService,
            IPatchService patchService,
            IDatabaseFactoryService databaseFactoryService,
{'fraction_non_alphanumeric': 0.06524926686217009, 'fraction_numerical': 0.0007331378299120235, 'mean_word_length': 2.4869009584664536, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615413', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1214, 'n_words': 372}