1.0-dev10 (Code cleaning)
This commit is contained in:
@@ -1,38 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Core.Services
|
||||
{
|
||||
public class TaskId
|
||||
{
|
||||
// VARIABLES
|
||||
#region CONSTANTS
|
||||
|
||||
// RANDOM
|
||||
private static readonly Random Random = new Random();
|
||||
private static readonly char[] CharsID = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
|
||||
private static readonly int LengthID = 10;
|
||||
|
||||
// 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>();
|
||||
|
||||
// METHOD
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region METHODS
|
||||
|
||||
// GET TASK ID
|
||||
public static string Get()
|
||||
{
|
||||
string id;
|
||||
do
|
||||
{
|
||||
id = "";
|
||||
while (id.Length < LengthID)
|
||||
while (id.Length < IDLength)
|
||||
{
|
||||
id += CharsID[Random.Next(0, CharsID.Length)];
|
||||
id += IDChars[Random.Next(0, IDChars.Length)];
|
||||
}
|
||||
} while (UsedIDs.Contains(id));
|
||||
UsedIDs.Add(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
// DISPOSE TASK ID
|
||||
public static void Dispose(string id)
|
||||
{
|
||||
UsedIDs.Remove(id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user