Files
VDownload/VDownload.Core/Services/TaskId.cs

57 lines
1.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
namespace VDownload.Core.Services
{
public class TaskId
{
2022-03-02 22:13:28 +01:00
#region CONSTANTS
// RANDOM
private static readonly Random Random = new Random();
2022-03-02 22:13:28 +01:00
// ID SETTINGS
private static readonly char[] IDChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
private static readonly int IDLength = 10;
#endregion
#region PROPERTIES
// USED IDS LIST
private static readonly List<string> UsedIDs = new List<string>();
2022-03-02 22:13:28 +01:00
#endregion
#region METHODS
// GET TASK ID
public static string Get()
{
string id;
do
{
id = "";
2022-03-02 22:13:28 +01:00
while (id.Length < IDLength)
{
2022-03-02 22:13:28 +01:00
id += IDChars[Random.Next(0, IDChars.Length)];
}
} while (UsedIDs.Contains(id));
UsedIDs.Add(id);
return id;
}
2022-03-02 22:13:28 +01:00
// DISPOSE TASK ID
public static void Dispose(string id)
{
UsedIDs.Remove(id);
}
2022-03-02 22:13:28 +01:00
#endregion
}
}