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