* 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>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<Version>1.0.7</Version>
|
<Version>1.0.8</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -5,13 +5,26 @@ using Telegrator.Configuration;
|
|||||||
|
|
||||||
namespace Telegrator.Hosting
|
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
|
public class HostedTelegramBotInfo(ITelegramBotClient client, IServiceProvider services, IConfigurationManager configuration) : ITelegramBotInfo
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public User User { get; } = client.GetMe().Result;
|
public User User { get; } = client.GetMe().Result;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides access to services of this Hosted telegram bot
|
||||||
|
/// </summary>
|
||||||
public IServiceProvider Services { get; } = services;
|
public IServiceProvider Services { get; } = services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides access to configuration of this Hosted telegram bot
|
||||||
|
/// </summary>
|
||||||
public IConfigurationManager Configuration { get; } = configuration;
|
public IConfigurationManager Configuration { get; } = configuration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<Version>1.0.7</Version>
|
<Version>1.0.8</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
+20
-9
@@ -8,12 +8,12 @@ namespace Telegrator
|
|||||||
public static class Alligator
|
public static class Alligator
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets flags of what debug messages to write
|
/// Gets or sets flags of what trace messages to write
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static DebugLevel Allowed { get; set; } = DebugLevel.None;
|
public static DebugLevel Allowed { get; set; } = DebugLevel.None;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Router flag
|
/// Writes trace message if Indent level has Router flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
public static void RouterWriteLine(string message)
|
public static void RouterWriteLine(string message)
|
||||||
@@ -34,7 +34,7 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Providers flag
|
/// Writes trace message if Indent level has Providers flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
public static void ProviderWriteLine(string message)
|
public static void ProviderWriteLine(string message)
|
||||||
@@ -44,7 +44,7 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Providers flag
|
/// Writes trace message if Indent level has Providers flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
@@ -55,7 +55,7 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Filters flag
|
/// Writes trace message if Indent level has Filters flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
public static void FilterWriteLine(string message)
|
public static void FilterWriteLine(string message)
|
||||||
@@ -65,7 +65,7 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Filters flag
|
/// Writes trace message if Indent level has Filters flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
@@ -76,7 +76,7 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Pool flag
|
/// Writes trace message if Indent level has Pool flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
public static void PoolWriteLine(string message)
|
public static void PoolWriteLine(string message)
|
||||||
@@ -86,7 +86,7 @@ namespace Telegrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes debug message if Indent level has Pool flag
|
/// Writes trace message if Indent level has Pool flag
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message"></param>
|
/// <param name="message"></param>
|
||||||
/// <param name="args"></param>
|
/// <param name="args"></param>
|
||||||
@@ -95,13 +95,24 @@ namespace Telegrator
|
|||||||
if (Allowed.HasFlag(DebugLevel.HandlersPool))
|
if (Allowed.HasFlag(DebugLevel.HandlersPool))
|
||||||
Trace.WriteLine(string.Format(message, args));
|
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)
|
public static void WriteLine(DebugLevel level, string message)
|
||||||
{
|
{
|
||||||
if (Allowed.HasFlag(level))
|
if (Allowed.HasFlag(level))
|
||||||
Trace.WriteLine(message);
|
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)
|
public static void WriteLine(DebugLevel level, string message, params object[] args)
|
||||||
{
|
{
|
||||||
if (Allowed.HasFlag(level))
|
if (Allowed.HasFlag(level))
|
||||||
|
|||||||
@@ -9,8 +9,16 @@ using Telegrator.Handlers.Components;
|
|||||||
|
|
||||||
namespace Telegrator.MadiatorCore.Descriptors
|
namespace Telegrator.MadiatorCore.Descriptors
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Descriptor for creating handlers from methods
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TUpdate"></typeparam>
|
||||||
public class MethodHandlerDescriptor<TUpdate> : HandlerDescriptor where TUpdate : class
|
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)
|
public MethodHandlerDescriptor(AbstractHandlerAction<TUpdate> action) : base(DescriptorType.General)
|
||||||
{
|
{
|
||||||
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(action.Method);
|
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(action.Method);
|
||||||
|
|||||||
@@ -420,6 +420,12 @@ namespace Telegrator.MadiatorCore.Descriptors
|
|||||||
InstanceFactory = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
|
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)
|
public void SetInstance(UpdateHandlerBase instance)
|
||||||
{
|
{
|
||||||
if (SingletonInstance != null)
|
if (SingletonInstance != null)
|
||||||
@@ -428,6 +434,20 @@ namespace Telegrator.MadiatorCore.Descriptors
|
|||||||
SingletonInstance = instance;
|
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/>
|
/// <inheritdoc/>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
=> DisplayString ?? HandlerType.Name;
|
=> DisplayString ?? HandlerType.Name;
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ namespace Telegrator.Providers
|
|||||||
return descriptor.SingletonInstance;
|
return descriptor.SingletonInstance;
|
||||||
|
|
||||||
UpdateHandlerBase instance = GetHandlerInstanceInternal(descriptor);
|
UpdateHandlerBase instance = GetHandlerInstanceInternal(descriptor);
|
||||||
descriptor.SingletonInstance = useSingleton ? instance : null;
|
if (useSingleton)
|
||||||
|
descriptor.TrySetInstance(instance);
|
||||||
|
|
||||||
descriptor.LazyInitialization?.Invoke(instance);
|
descriptor.LazyInitialization?.Invoke(instance);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
<Version>1.0.7</Version>
|
<Version>1.0.8</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user