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
|
|
|
|
|
|
|
|
|
|
|
|
// ID SETTINGS
|
|
|
|
|
|
private static readonly char[] IDChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
|
|
|
|
|
|
private static readonly int IDLength = 10;
|
|
|
|
|
|
|
2022-03-07 14:59:11 +01:00
|
|
|
|
// IDS LIST
|
|
|
|
|
|
private static readonly List<string> IDList = new List<string>();
|
2022-03-02 01:36:26 +01:00
|
|
|
|
|
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-07 14:59:11 +01:00
|
|
|
|
id += IDChars[new Random().Next(0, IDChars.Length)];
|
2022-03-02 01:36:26 +01:00
|
|
|
|
}
|
2022-03-07 14:59:11 +01:00
|
|
|
|
} while (IDList.Contains(id));
|
|
|
|
|
|
IDList.Add(id);
|
2022-03-02 01:36:26 +01:00
|
|
|
|
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)
|
|
|
|
|
|
{
|
2022-03-07 14:59:11 +01:00
|
|
|
|
IDList.Remove(id);
|
2022-03-02 01:36:26 +01:00
|
|
|
|
}
|
2022-03-02 22:13:28 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2022-03-02 01:36:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|