* version incremented
* Added XML summaries to new members * Added TrySetInstance to HandlerDescriptor. Exception-free version of SetInstance method * Changed singleton ionstance setting in HandlersProvidedr
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Version>1.0.7</Version>
|
||||
<Version>1.0.8</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -5,13 +5,26 @@ using Telegrator.Configuration;
|
||||
|
||||
namespace Telegrator.Hosting
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="ITelegramBotInfo"/> that provides bot information.
|
||||
/// Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public class HostedTelegramBotInfo(ITelegramBotClient client, IServiceProvider services, IConfigurationManager configuration) : ITelegramBotInfo
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public User User { get; } = client.GetMe().Result;
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to services of this Hosted telegram bot
|
||||
/// </summary>
|
||||
public IServiceProvider Services { get; } = services;
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to configuration of this Hosted telegram bot
|
||||
/// </summary>
|
||||
public IConfigurationManager Configuration { get; } = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Version>1.0.7</Version>
|
||||
<Version>1.0.8</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+19
-8
@@ -8,12 +8,12 @@ namespace Telegrator
|
||||
public static class Alligator
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets flags of what debug messages to write
|
||||
/// Gets or sets flags of what trace messages to write
|
||||
/// </summary>
|
||||
public static DebugLevel Allowed { get; set; } = DebugLevel.None;
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Router flag
|
||||
/// Writes trace message if Indent level has Router flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void RouterWriteLine(string message)
|
||||
@@ -34,7 +34,7 @@ namespace Telegrator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Providers flag
|
||||
/// Writes trace message if Indent level has Providers flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void ProviderWriteLine(string message)
|
||||
@@ -44,7 +44,7 @@ namespace Telegrator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Providers flag
|
||||
/// Writes trace message if Indent level has Providers flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
@@ -55,7 +55,7 @@ namespace Telegrator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Filters flag
|
||||
/// Writes trace message if Indent level has Filters flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void FilterWriteLine(string message)
|
||||
@@ -65,7 +65,7 @@ namespace Telegrator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Filters flag
|
||||
/// Writes trace message if Indent level has Filters flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
@@ -76,7 +76,7 @@ namespace Telegrator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Pool flag
|
||||
/// Writes trace message if Indent level has Pool flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public static void PoolWriteLine(string message)
|
||||
@@ -86,7 +86,7 @@ namespace Telegrator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes debug message if Indent level has Pool flag
|
||||
/// Writes trace message if Indent level has Pool flag
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
@@ -96,12 +96,23 @@ namespace Telegrator
|
||||
Trace.WriteLine(string.Format(message, args));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes trace message if flag was set
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
/// <param name="message"></param>
|
||||
public static void WriteLine(DebugLevel level, string message)
|
||||
{
|
||||
if (Allowed.HasFlag(level))
|
||||
Trace.WriteLine(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes trace message if flag was set
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
public static void WriteLine(DebugLevel level, string message, params object[] args)
|
||||
{
|
||||
if (Allowed.HasFlag(level))
|
||||
|
||||
@@ -9,8 +9,16 @@ using Telegrator.Handlers.Components;
|
||||
|
||||
namespace Telegrator.MadiatorCore.Descriptors
|
||||
{
|
||||
/// <summary>
|
||||
/// Descriptor for creating handlers from methods
|
||||
/// </summary>
|
||||
/// <typeparam name="TUpdate"></typeparam>
|
||||
public class MethodHandlerDescriptor<TUpdate> : HandlerDescriptor where TUpdate : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes new instance of <see cref="MethodHandlerDescriptor{TUpdate}"/>
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
public MethodHandlerDescriptor(AbstractHandlerAction<TUpdate> action) : base(DescriptorType.General)
|
||||
{
|
||||
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(action.Method);
|
||||
|
||||
@@ -420,6 +420,12 @@ namespace Telegrator.MadiatorCore.Descriptors
|
||||
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets singleton instance of this descriptor
|
||||
/// Throws exception if instance already set
|
||||
/// </summary>
|
||||
/// <param name="instance"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void SetInstance(UpdateHandlerBase instance)
|
||||
{
|
||||
if (SingletonInstance != null)
|
||||
@@ -428,6 +434,20 @@ namespace Telegrator.MadiatorCore.Descriptors
|
||||
SingletonInstance = instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to set singleton instance of this descriptor
|
||||
/// </summary>
|
||||
/// <param name="instance"></param>
|
||||
/// <returns></returns>
|
||||
public bool TrySetInstance(UpdateHandlerBase instance)
|
||||
{
|
||||
if (SingletonInstance != null)
|
||||
return false;
|
||||
|
||||
SingletonInstance = instance;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
=> DisplayString ?? HandlerType.Name;
|
||||
|
||||
@@ -70,7 +70,9 @@ namespace Telegrator.Providers
|
||||
return descriptor.SingletonInstance;
|
||||
|
||||
UpdateHandlerBase instance = GetHandlerInstanceInternal(descriptor);
|
||||
descriptor.SingletonInstance = useSingleton ? instance : null;
|
||||
if (useSingleton)
|
||||
descriptor.TrySetInstance(instance);
|
||||
|
||||
descriptor.LazyInitialization?.Invoke(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<Version>1.0.7</Version>
|
||||
<Version>1.0.8</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user