Code cleanup

This commit is contained in:
Andriy
2023-07-29 15:03:45 +03:00
parent 5e4183acfa
commit a24332370d
36 changed files with 46 additions and 111 deletions
+1 -3
View File
@@ -1,6 +1,4 @@
using System;
namespace Kruzya.TelegramBot.Core.Cache
namespace Kruzya.TelegramBot.Core.Cache
{
public interface ICacheStorage<TKey, TValue>
{
+7 -9
View File
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using SQLitePCL;
namespace Kruzya.TelegramBot.Core.Cache
{
@@ -32,7 +30,7 @@ namespace Kruzya.TelegramBot.Core.Cache
/// <summary>
///
/// </summary>
private Dictionary<TKey, CacheEntry<TValue>> dict = new Dictionary<TKey, CacheEntry<TValue>>();
private readonly Dictionary<TKey, CacheEntry<TValue>> _dict = new();
/// <summary>
/// The TTL for all entries if not set.
@@ -51,20 +49,20 @@ namespace Kruzya.TelegramBot.Core.Cache
public bool TryGetValue(TKey key, out TValue value)
{
value = default;
if (!dict.ContainsKey(key))
if (!_dict.ContainsKey(key))
{
return false;
}
CacheEntry<TValue> temp;
if (!dict.TryGetValue(key, out temp))
if (!_dict.TryGetValue(key, out temp))
{
return false;
}
if (temp.IsExpired())
{
dict.Remove(key);
_dict.Remove(key);
return false;
}
@@ -90,12 +88,12 @@ namespace Kruzya.TelegramBot.Core.Cache
public void SetValue(TKey key, TValue value, int timeToLive)
{
if (dict.ContainsKey(key))
if (_dict.ContainsKey(key))
{
dict.Remove(key);
_dict.Remove(key);
}
dict.Add(key, new CacheEntry<TValue>()
_dict.Add(key, new CacheEntry<TValue>()
{
Created = DateTime.Now,
ExpiresAt = timeToLive,
-1
View File
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Kruzya.TelegramBot.Core.Data
-4
View File
@@ -1,12 +1,8 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
namespace Kruzya.TelegramBot.Core.Data
{
+1 -2
View File
@@ -1,5 +1,4 @@
using System;
using Telegram.Bot.Types;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace Kruzya.TelegramBot.Core.Extensions;
+1 -4
View File
@@ -1,7 +1,4 @@
using System.Threading.Tasks;
using Kruzya.TelegramBot.Core.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace Kruzya.TelegramBot.Core.Extensions
{
@@ -1,14 +1,9 @@
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BotFramework;
using BotFramework.Abstractions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Telegram.Bot;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Types;
namespace Kruzya.TelegramBot.Core.Service
{
-1
View File
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;