Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/mstest-372
Browse files Browse the repository at this point in the history
  • Loading branch information
artempushkin authored Jan 30, 2025
2 parents 406f91c + a2d5b36 commit 9ca4c3e
Show file tree
Hide file tree
Showing 37 changed files with 34 additions and 1,795 deletions.
60 changes: 0 additions & 60 deletions src/Abstractions/EventSources/EventSourcesEventIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,6 @@ namespace Microsoft.Omex.Extensions.Abstractions.EventSources
/// </remarks>
public enum EventSourcesEventIds
{
/// <summary>
/// Event Id for logging general info message
/// </summary>
LogInfo = 1,

/// <summary>
/// Event Id for logging error message
/// </summary>
LogError = 2,

/// <summary>
/// Event Id for logging warning message
/// </summary>
LogWarning = 3,

/// <summary>
/// Event Id for logging verbose message
/// </summary>
LogVerbose = 4,

/// <summary>
/// Event Id for logging spam message
/// </summary>
LogSpam = 5,

/// <summary>
/// Event Id for logging activities
/// </summary>
Expand All @@ -45,40 +20,5 @@ public enum EventSourcesEventIds
/// Event Id for logging test activities
/// </summary>
LogActivityTestContext = 7,

/// <summary>
/// Event Id for service type registered
/// </summary>
ServiceTypeRegistered = 11,

/// <summary>
/// Event Id for service host initialization failed
/// </summary>
ServiceHostInitializationFailed = 12,

/// <summary>
/// Event Id for actor type registered
/// </summary>
ActorTypeRegistered = 13,

/// <summary>
/// Event Id for actor host initialization failed
/// </summary>
ActorHostInitializationFailed = 14,

/// <summary>
/// Event Id for logging Analytics information
/// </summary>
LogAnalytics = 15,

/// <summary>
/// Event Id for generic host build succeded
/// </summary>
GenericHostBuildSucceeded = 16,

/// <summary>
/// Event Id for generic host build failed
/// </summary>
GenericHostFailed = 17
}
}
72 changes: 25 additions & 47 deletions src/Hosting.Services/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Omex.Extensions.Abstractions;
using Microsoft.Omex.Extensions.Abstractions.Accessors;
using Microsoft.Omex.Extensions.Abstractions.ExecutionContext;
using Microsoft.Omex.Extensions.Logging;
using Microsoft.ServiceFabric.Data;

namespace Microsoft.Omex.Extensions.Hosting.Services
Expand Down Expand Up @@ -58,8 +56,6 @@ public static IServiceCollection AddOmexServiceFabricDependencies<TContext>(this
}

collection.TryAddAccessor<TContext, ServiceContext>();

collection.TryAddSingleton<IServiceContext, OmexServiceFabricContext>();
collection.TryAddSingleton<IExecutionContext, ServiceFabricExecutionContext>();

return collection.AddOmexServices();
Expand All @@ -75,53 +71,35 @@ private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
{
string serviceNameForLogging = serviceName;

try
if (string.IsNullOrWhiteSpace(serviceName))
{
if (string.IsNullOrWhiteSpace(serviceName))
{
// use executing assembly name for logging since application name not available
serviceNameForLogging = Assembly.GetExecutingAssembly().GetName().FullName;
throw new ArgumentException("Service type name is null of whitespace", nameof(serviceName));
}

builderAction(new ServiceFabricHostBuilder<TService, TContext>(builder));

IHost host = builder
.ConfigureServices((context, collection) =>
{
collection
.Configure<ServiceRegistratorOptions>(options =>
{
options.ServiceTypeName = serviceName;
})
.AddOmexServiceFabricDependencies<TContext>()
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
})
.UseDefaultServiceProvider(options =>
{
options.ValidateOnBuild = true;
options.ValidateScopes = true;
})
#pragma warning disable OMEX188 // AddOmexLogging using OmexLogger is obsolete. DiagnosticId = "OMEX188"
.ConfigureLogging(builder => builder.AddOmexLogging())
#pragma warning restore OMEX188 // AddOmexLogging using OmexLogger is obsolete. DiagnosticId = "OMEX188"
.Build();
// use executing assembly name for logging since application name not available
serviceNameForLogging = Assembly.GetExecutingAssembly().GetName().FullName;
throw new ArgumentException("Service type name is null of whitespace", nameof(serviceName));
}

#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"
InitializationLogger.LogInitializationSucceed(serviceNameForLogging);
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"
builderAction(new ServiceFabricHostBuilder<TService, TContext>(builder));

return host;
}
catch (Exception e)
{
#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"
InitializationLogger.LogInitializationFail(serviceNameForLogging, e);
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete. DiagnosticId = "OMEX188"
IHost host = builder
.ConfigureServices((context, collection) =>
{
collection
.Configure<ServiceRegistratorOptions>(options =>
{
options.ServiceTypeName = serviceName;
})
.AddOmexServiceFabricDependencies<TContext>()
.AddSingleton<IOmexServiceRegistrator, TRunner>()
.AddHostedService<OmexHostedService>();
})
.UseDefaultServiceProvider(options =>
{
options.ValidateOnBuild = true;
options.ValidateScopes = true;
})
.Build();

throw;
}
return host;
}

internal static IServiceCollection TryAddAccessor<TValue, TBase>(this IServiceCollection collection)
Expand Down
35 changes: 0 additions & 35 deletions src/Hosting.Services/Internal/OmexServiceFabricContext.cs

This file was deleted.

33 changes: 1 addition & 32 deletions src/Hosting/Certificates/CertificateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ namespace Microsoft.Omex.Extensions.Hosting.Certificates
internal class CertificateReader : ICertificateReader
{
private readonly ICertificateStore m_certificateStore;
private readonly ILogger m_logger;
private readonly ConcurrentDictionary<StoreName, CertificateInformation[]> m_certificatesCache;

public CertificateReader(ICertificateStore certificateStore, ILogger<CertificateReader> logger) : this(certificateStore, logger as ILogger)
{
}

internal CertificateReader(ICertificateStore certificateStore, ILogger logger)
public CertificateReader(ICertificateStore certificateStore)
{
m_certificateStore = certificateStore;
m_logger = logger;
m_certificatesCache = new ConcurrentDictionary<StoreName, CertificateInformation[]>();
}

Expand All @@ -42,40 +36,20 @@ internal CertificateReader(ICertificateStore certificateStore, ILogger logger)
}
}

if (matchingCertificate == null)
{
m_logger.LogError(Tag.Create(), "Could not find certificate with {0} thumbprint.", thumbprint);
}
else
{
m_logger.LogDebug(Tag.Create(), "Found certificate with {0} thumbprint.", thumbprint);
}

return matchingCertificate;
}

public IEnumerable<X509Certificate2> GetCertificatesByCommonName(string commonName, bool refreshCache, StoreName storeName)
{
Validation.ThrowIfNullOrWhiteSpace(commonName, nameof(commonName));

bool certFound = false;
foreach (CertificateInformation info in LoadCertificates(storeName, refreshCache))
{
if (string.Equals(info.CommonName, commonName, StringComparison.Ordinal))
{
certFound = true;
yield return info.Certificate;
}
}

if (certFound)
{
m_logger.LogDebug(Tag.Create(), "Found at least one certificate with {0} as common name.", commonName);
}
else
{
m_logger.LogError(Tag.Create(), "Could not find certificate with {0} as common name.", commonName);
}
}

public X509Certificate2? GetCertificateByCommonName(string commonName, bool refreshCache, StoreName storeName) =>
Expand All @@ -86,12 +60,7 @@ private CertificateInformation[] LoadCertificates(StoreName storeName, bool refr
CertificateInformation[]? certificates;
if (refreshCache || !m_certificatesCache.TryGetValue(storeName, out certificates))
{
m_logger.LogInformation(Tag.Create(), "Updating certificates cache for store '{0}'.", storeName);

certificates = m_certificateStore.GetAllCertificates(storeName, StoreLocation.LocalMachine).ToArray();

m_logger.LogInformation(Tag.Create(), "Inserting '{0}' certificates to certificates cache for store '{1}'.", certificates.Length, storeName);

m_certificatesCache[storeName] = certificates;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Hosting/Certificates/InitializationCertificateReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public static class InitializationCertificateReader
/// <summary>
/// Instance of CertificateReader
/// </summary>
#pragma warning disable OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024.
public static ICertificateReader Instance { get; } = new CertificateReader(new CertificateStore(), InitializationLogger.Instance);
#pragma warning restore OMEX188 // InitializationLogger using OmexLogger is obsolete and is pending for removal by 1 July 2024.
public static ICertificateReader Instance { get; } = new CertificateReader(new CertificateStore());
}
}
8 changes: 1 addition & 7 deletions src/Hosting/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Omex.Extensions.Hosting.Certificates;
using Microsoft.Omex.Extensions.Logging;

namespace Microsoft.Omex.Extensions.Hosting
{
Expand All @@ -26,11 +24,7 @@ public static IHostBuilder AddOmexServices(this IHostBuilder builder) =>
/// Add Omex Logging and ActivitySource dependencies
/// </summary>
public static IServiceCollection AddOmexServices(this IServiceCollection collection) =>
#pragma warning disable OMEX188 // OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.
collection
.AddOmexLogging()
#pragma warning restore OMEX188 // OmexLogger and OmexLogEventSource are obsolete and pending for removal by 1 July 2024. Please consider using a different Logger.
.AddOmexActivitySource();
collection.AddOmexActivitySource();

/// <summary>
/// Add Omex Logging and ActivitySource dependencies
Expand Down
32 changes: 0 additions & 32 deletions src/Logging/ILogEventSender.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/Logging/IServiceContext.cs

This file was deleted.

Loading

0 comments on commit 9ca4c3e

Please sign in to comment.