code cleanup
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Telegram.Bot.Types;
|
||||
using Telegrator.Filters.Components;
|
||||
using Telegrator.Handlers.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.Attributes.Components
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Attributes.Components;
|
||||
using Telegrator.Filters.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.Attributes
|
||||
|
||||
@@ -5,7 +5,6 @@ using Telegrator.Filters.Components;
|
||||
using Telegrator.Handlers.Components;
|
||||
using Telegrator.MadiatorCore;
|
||||
using Telegrator.MadiatorCore.Descriptors;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.Handlers.Building.Components
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Telegram.Bot.Types;
|
||||
using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Filters.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.Handlers.Building.Components
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Filters;
|
||||
using Telegrator.Filters.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.Handlers.Building.Components
|
||||
|
||||
@@ -3,7 +3,6 @@ using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Filters.Components;
|
||||
using Telegrator.Handlers.Building.Components;
|
||||
using Telegrator.StateKeeping;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.Handlers.Building
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Telegrator.Polling
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a dictionayr with limited number of slots, if trying to overflow, will block calling thread until one of slots will be free
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
public class LimitedDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable
|
||||
{
|
||||
private readonly int? _maximum;
|
||||
private readonly SemaphoreSlim _semaphore = null!;
|
||||
private readonly ConcurrentDictionary<TKey, TValue> _dict = [];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes new instance of <see cref="LimitedDictionary{TKey, TValue}"/>
|
||||
/// </summary>
|
||||
/// <param name="maximum"></param>
|
||||
public LimitedDictionary(int? maximum)
|
||||
{
|
||||
_maximum = maximum;
|
||||
if (maximum != null)
|
||||
{
|
||||
int value = maximum.Value;
|
||||
_semaphore = new SemaphoreSlim(value, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to add new element to dictioanry.
|
||||
/// If all slots are occupied, blocks calling thread.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> Add(TKey key, TValue value, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_semaphore != null)
|
||||
await _semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return _dict.TryAdd(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to remove element from dictionay.
|
||||
/// Frees slot on success.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="result"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(TKey key, out TValue result)
|
||||
{
|
||||
if (_dict.TryRemove(key, out result))
|
||||
{
|
||||
_semaphore?.Release(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => _dict.GetEnumerator();
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator() => _dict.GetEnumerator();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
_semaphore.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Telegrator.Polling
|
||||
{
|
||||
/*
|
||||
public class LimitedQueue<T>
|
||||
{
|
||||
private readonly int? _maximum;
|
||||
private readonly ConcurrentQueue<T> _queue = [];
|
||||
private readonly SemaphoreSlim _semaphore = null!;
|
||||
|
||||
public LimitedQueue(int? maximum)
|
||||
{
|
||||
_maximum = maximum;
|
||||
if (maximum != null)
|
||||
{
|
||||
int value = maximum.Value;
|
||||
_semaphore = new SemaphoreSlim(value, value);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Enqueue(T item, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_maximum.HasValue)
|
||||
await _semaphore.WaitAsync(cancellationToken);
|
||||
|
||||
_queue.Enqueue(item);
|
||||
}
|
||||
|
||||
public bool Dequeue(out T result)
|
||||
{
|
||||
if (_queue.TryDequeue(out result))
|
||||
{
|
||||
if (_maximum.HasValue)
|
||||
_semaphore?.Release(1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Telegrator.StateKeeping.Abstracts
|
||||
{
|
||||
/*
|
||||
public class UpdateBasedStateKeeperBase
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
namespace Telegrator.StateKeeping.Abstracts
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.StateKeeping
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract base class for state keepers that manage state transitions using an array of predefined states.
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Telegrator.StateKeeping.Components
|
||||
{
|
||||
/*
|
||||
public interface IStateKeepingFacility
|
||||
{
|
||||
public void SetState(object key, object value);
|
||||
|
||||
public object GetState(object key);
|
||||
}
|
||||
*/
|
||||
}
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
using Telegram.Bot.Types;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.StateKeeping.Abstracts
|
||||
namespace Telegrator.StateKeeping.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for managing state associated with updates and keys.
|
||||
@@ -1,6 +1,5 @@
|
||||
using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Handlers.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
|
||||
namespace Telegrator.StateKeeping
|
||||
{
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Telegrator.StateKeeping.Facilities
|
||||
{
|
||||
/*
|
||||
public class JsonStateKeepingFacility : IStateKeepingFacility
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Handlers.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.StateKeeping
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Telegrator.Annotations.StateKeeping;
|
||||
using Telegrator.Handlers.Components;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator.StateKeeping
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ using Telegrator.MadiatorCore;
|
||||
using Telegrator.MadiatorCore.Descriptors;
|
||||
using Telegrator.Providers;
|
||||
using Telegrator.StateKeeping;
|
||||
using Telegrator.StateKeeping.Abstracts;
|
||||
using Telegrator.StateKeeping.Components;
|
||||
|
||||
namespace Telegrator
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user