/// <summary>
        /// Initializes a new instance of the <see cref="SearchService"/> class.
        /// </summary>
        /// <param name="loggerFactory">Logger factory for this service</param>
        /// <param name="configuration">Application configuration</param>
        public SearchService(ILoggerFactory loggerFactory, IConfiguration configuration)
            : base(loggerFactory, configuration)
        {
            this.Logger.LogTrace("Construction of Search Service beginning");

            // Build configurations
            var cosmosConfiguration = CosmosConfiguration.BuildFromConfiguration(this.Configuration);
            var searchConfiguration = AzureSearchConfiguration.BuildFromConfiguration(this.Configuration);

            this.userRepository   = new CosmosUserRepository <ReadByAllUser>(cosmosConfiguration, loggerFactory);
            this.searchRepository = new AzureSearchRepository(searchConfiguration, loggerFactory);

            this.Logger.LogTrace("Construction of Search Service complete");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AzureSearchRepository"/> class.
        /// </summary>
        /// <param name="configuration">Azure Blob Storage Configuration for this application.</param>
        /// <param name="loggerFactory">Logger factory for logging</param>
        public AzureSearchRepository(AzureSearchConfiguration configuration, ILoggerFactory loggerFactory)
            : base(loggerFactory)
        {
            this.Logger.LogTrace("Beginning construction of Azure Blob Repository Base");

            // Sanity check input arguments
            configuration = Ensure.IsNotNull(() => configuration);
            configuration.Validate();

            this.searchClient = new SearchClient(configuration.Endpoint, configuration.IndexName, configuration.AzureKeyCredential);

            this.CanSuggest    = configuration.CanSuggest ?? false;
            this.suggesterName = configuration.SuggesterName;

            this.Logger.LogTrace("Construction of Azure Blob Repository Base Complete");
        }
Exemplo n.º 3
0
            public Facts(ITestOutputHelper output)
            {
                CloudBlobClient    = new Mock <ICloudBlobClient>();
                CloudBlobContainer = new Mock <ICloudBlobContainer>();
                CloudBlob          = new Mock <ISimpleCloudBlob>();
                Options            = new Mock <IOptionsSnapshot <AzureSearchConfiguration> >();
                TelemetryService   = new Mock <IAzureSearchTelemetryService>();
                Logger             = output.GetLogger <VerifiedPackagesDataClient>();
                Config             = new AzureSearchConfiguration
                {
                    StorageContainer = "unit-test-container",
                };

                ETag            = "\"some-etag\"";
                AccessCondition = new Mock <IAccessCondition>();
                StringCache     = new StringCache();

                Options
                .Setup(x => x.Value)
                .Returns(() => Config);
                CloudBlobClient
                .Setup(x => x.GetContainerReference(It.IsAny <string>()))
                .Returns(() => CloudBlobContainer.Object);
                CloudBlobContainer
                .Setup(x => x.GetBlobReference(It.IsAny <string>()))
                .Returns(() => CloudBlob.Object)
                .Callback <string>(x => BlobNames.Add(x));
                CloudBlob
                .Setup(x => x.ETag)
                .Returns(ETag);
                CloudBlob
                .Setup(x => x.OpenWriteAsync(It.IsAny <AccessCondition>()))
                .ReturnsAsync(() => new RecordingStream(bytes =>
                {
                    SavedBytes.Add(bytes);
                    SavedStrings.Add(Encoding.UTF8.GetString(bytes));
                }));
                CloudBlob
                .Setup(x => x.Properties)
                .Returns(new CloudBlockBlob(new Uri("https://example/blob")).Properties);

                Target = new VerifiedPackagesDataClient(
                    CloudBlobClient.Object,
                    Options.Object,
                    TelemetryService.Object,
                    Logger);
            }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            azureSearchConfiguration = new AzureSearchConfiguration("{Search Service Admin Key}", "{Search Service Query Key}", "{Search Service Name}");
            documentService          = new DocumentService(azureSearchConfiguration);
            indexService             = new IndexService(azureSearchConfiguration);

            CheckIndex().GetAwaiter().GetResult();
            CreateIndex().GetAwaiter().GetResult();
            GetIndex().GetAwaiter().GetResult();
            PopulateIndex().GetAwaiter().GetResult();
            DeleteDocument().GetAwaiter().GetResult();
            UpdateDocument().GetAwaiter().GetResult();
            UpsertDocument().GetAwaiter().GetResult();
            GetIndexById().GetAwaiter().GetResult();
            SearchIndex().GetAwaiter().GetResult();
            DeleteIndex().GetAwaiter().GetResult();

            Console.ReadLine();
        }
 private SearchIndexClient CreateSearchIndexClient(string indexName, AzureSearchConfiguration configuration)
 {
     return(new SearchIndexClient(configuration.Name, indexName, new SearchCredentials(configuration.QueryApiKey)));
 }
 private SearchServiceClient CreateSearchServiceClient(AzureSearchConfiguration configuration)
 {
     return(new SearchServiceClient(configuration.Name, new SearchCredentials(configuration.AdminApiKey)));
 }
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddMvc();
            services.AddControllersWithViews();

            services.AddMemoryCache();

            //Configure Redis distributed cache
            var redisConnectionString = Configuration["RedisConnectionString"];

            services.AddStackExchangeRedisCache(options => {
                options.Configuration = redisConnectionString;
                options.InstanceName  = "";
            });

            services.AddTransient <IDataGenerator, BogusDataGenerator>();

            services.AddHttpClient <ILocationService, LocationService>();

            //Configure CosmosDB
            var cosmosConfig = new CosmosDbConfiguration();

            Configuration.Bind("CosmosConfig", cosmosConfig);
            services.AddSingleton(cosmosConfig);

            try
            {
                services.AddHttpClient <ICosmosDbService, CosmosDbService>();
                services.AddSingleton <ICosmosDbService>(
                    InitializeCosmosClientInstanceAsync(cosmosConfig)
                    .GetAwaiter().GetResult());
            }
            catch (Exception ex)
            {
                LogException(ex, "Could not start CosmosDB services");
            }

            //Configure PostgresSQL
            services.AddTransient <IPostgresSqlRepository, PostgresSqlRepository>();
            services.AddTransient <IPostgresSqlService, PostgresSqlService>();

            //Configure SQL Server
            var sqlConnectionString = Configuration["SqlConnectionString"];

            services.AddDbContext <LocationDbContext>(options =>
                                                      options.UseSqlServer(sqlConnectionString, builder => builder
                                                                           .UseNetTopologySuite()
                                                                           .EnableRetryOnFailure()),
                                                      ServiceLifetime.Transient);

            //Configure PostgresSql
            var pgConnectionString = Configuration["PostgreSql:ConnectionString"];
            var pgPassword         = Configuration["PostgreSql:DbPassword"];
            var pgBuilder          = new NpgsqlConnectionStringBuilder(pgConnectionString)
            {
                Password = pgPassword
            };

            services.AddDbContext <StudentDbContext>(options =>
                                                     options.UseNpgsql(pgBuilder.ConnectionString));

            //Configure Azure Search
            //AzureSearchConfiguration

            var azureConfig = new AzureSearchConfiguration();

            Configuration.Bind("AzureSearchConfiguration", azureConfig);
            services.AddSingleton(azureConfig);
            //var azureConfig = Configuration["AzureSearchConfiguration"];
        }