Initial .net 6 upgrades
This commit is contained in:
@ -6,12 +6,41 @@ namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
public class BuildNumber : IComparable
|
||||
{
|
||||
private BuildNumber()
|
||||
{
|
||||
}
|
||||
|
||||
public int Major { get; private set; }
|
||||
public int Minor { get; private set; }
|
||||
public int Build { get; private set; }
|
||||
public int Revision { get; private set; }
|
||||
|
||||
private BuildNumber() { }
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var buildNumber = obj as BuildNumber;
|
||||
if (buildNumber == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ReferenceEquals(this, buildNumber))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Major == buildNumber.Major
|
||||
? Minor == buildNumber.Minor
|
||||
? Build == buildNumber.Build
|
||||
? Revision.CompareTo(buildNumber.Revision)
|
||||
: Build.CompareTo(buildNumber.Build)
|
||||
: Minor.CompareTo(buildNumber.Minor)
|
||||
: Major.CompareTo(buildNumber.Major);
|
||||
}
|
||||
|
||||
public static bool TryParse(string input, out BuildNumber buildNumber)
|
||||
{
|
||||
@ -28,23 +57,32 @@ namespace SharedLibraryCore.Helpers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a build number string into a BuildNumber class
|
||||
/// Parses a build number string into a BuildNumber class
|
||||
/// </summary>
|
||||
/// <param name="buildNumber">The build number string to parse</param>
|
||||
/// <returns>A new BuildNumber class set from the buildNumber string</returns>
|
||||
/// <exception cref="ArgumentException">Thrown if there are less than 2 or
|
||||
/// more than 4 version parts to the build number</exception>
|
||||
/// <exception cref="FormatException">Thrown if string cannot be parsed
|
||||
/// to a series of integers</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if any version
|
||||
/// integer is less than zero</exception>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// Thrown if there are less than 2 or
|
||||
/// more than 4 version parts to the build number
|
||||
/// </exception>
|
||||
/// <exception cref="FormatException">
|
||||
/// Thrown if string cannot be parsed
|
||||
/// to a series of integers
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// Thrown if any version
|
||||
/// integer is less than zero
|
||||
/// </exception>
|
||||
public static BuildNumber Parse(string buildNumber)
|
||||
{
|
||||
if (buildNumber == null) throw new ArgumentNullException("buildNumber");
|
||||
if (buildNumber == null)
|
||||
{
|
||||
throw new ArgumentNullException("buildNumber");
|
||||
}
|
||||
|
||||
var versions = buildNumber
|
||||
.Split(new[] { '.' },
|
||||
StringSplitOptions.RemoveEmptyEntries)
|
||||
StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(v => v.Trim())
|
||||
.ToList();
|
||||
|
||||
@ -90,39 +128,23 @@ namespace SharedLibraryCore.Helpers
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0}.{1}{2}{3}", Major, Minor,
|
||||
Build < 0 ? "" : "." + Build,
|
||||
Revision < 0 ? "" : "." + Revision);
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
if (obj == null) return 1;
|
||||
var buildNumber = obj as BuildNumber;
|
||||
if (buildNumber == null) return 1;
|
||||
if (ReferenceEquals(this, buildNumber)) return 0;
|
||||
|
||||
return (Major == buildNumber.Major)
|
||||
? (Minor == buildNumber.Minor)
|
||||
? (Build == buildNumber.Build)
|
||||
? Revision.CompareTo(buildNumber.Revision)
|
||||
: Build.CompareTo(buildNumber.Build)
|
||||
: Minor.CompareTo(buildNumber.Minor)
|
||||
: Major.CompareTo(buildNumber.Major);
|
||||
Build < 0 ? "" : "." + Build,
|
||||
Revision < 0 ? "" : "." + Revision);
|
||||
}
|
||||
|
||||
public static bool operator >(BuildNumber first, BuildNumber second)
|
||||
{
|
||||
return (first.CompareTo(second) > 0);
|
||||
return first.CompareTo(second) > 0;
|
||||
}
|
||||
|
||||
public static bool operator <(BuildNumber first, BuildNumber second)
|
||||
{
|
||||
return (first.CompareTo(second) < 0);
|
||||
return first.CompareTo(second) < 0;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (CompareTo(obj) == 0);
|
||||
return CompareTo(obj) == 0;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@ -138,4 +160,4 @@ namespace SharedLibraryCore.Helpers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// JSON converter for the build number
|
||||
/// JSON converter for the build number
|
||||
/// </summary>
|
||||
public class BuildNumberJsonConverter : JsonConverter
|
||||
{
|
||||
@ -13,7 +13,8 @@ namespace SharedLibraryCore.Helpers
|
||||
return objectType == typeof(string);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
return BuildNumber.Parse(reader.Value.ToString());
|
||||
}
|
||||
@ -23,4 +24,4 @@ namespace SharedLibraryCore.Helpers
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +1,36 @@
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// This class provides a way to keep track of changes to an entity
|
||||
/// This class provides a way to keep track of changes to an entity
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of entity to keep track of changes to</typeparam>
|
||||
public class ChangeTracking<T>
|
||||
{
|
||||
ConcurrentQueue<T> Values;
|
||||
private readonly ConcurrentQueue<T> Values;
|
||||
|
||||
public ChangeTracking()
|
||||
{
|
||||
Values = new ConcurrentQueue<T>();
|
||||
}
|
||||
|
||||
public bool HasChanges => Values.Count > 0;
|
||||
|
||||
public void OnChange(T value)
|
||||
{
|
||||
if (Values.Count > 30)
|
||||
Values.TryDequeue(out T throwAway);
|
||||
{
|
||||
Values.TryDequeue(out var throwAway);
|
||||
}
|
||||
|
||||
Values.Enqueue(value);
|
||||
}
|
||||
|
||||
public T GetNextChange()
|
||||
{
|
||||
bool itemDequeued = Values.TryDequeue(out T val);
|
||||
return itemDequeued ? val : default(T);
|
||||
var itemDequeued = Values.TryDequeue(out var val);
|
||||
return itemDequeued ? val : default;
|
||||
}
|
||||
|
||||
public bool HasChanges => Values.Count > 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,13 +5,12 @@ namespace SharedLibraryCore.Helpers
|
||||
public class Hashing
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate password hash and salt
|
||||
/// Generate password hash and salt
|
||||
/// </summary>
|
||||
/// <param name="password">plaintext password</param>
|
||||
/// <returns></returns>
|
||||
public static string[] Hash(string password, string saltStr = null)
|
||||
{
|
||||
|
||||
string hash;
|
||||
string salt;
|
||||
var CryptoSvc = new PBKDF2();
|
||||
@ -21,22 +20,19 @@ namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
hash = CryptoSvc.Compute(password);
|
||||
salt = CryptoSvc.Salt;
|
||||
return new string[]
|
||||
return new[]
|
||||
{
|
||||
hash,
|
||||
salt
|
||||
};
|
||||
}
|
||||
|
||||
else
|
||||
hash = CryptoSvc.Compute(password, saltStr);
|
||||
return new[]
|
||||
{
|
||||
hash = CryptoSvc.Compute(password, saltStr);
|
||||
return new string[]
|
||||
{
|
||||
hash,
|
||||
""
|
||||
};
|
||||
}
|
||||
hash,
|
||||
""
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
public class MessageToken
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
private readonly Func<Server, Task<string>> _asyncValue;
|
||||
|
||||
|
||||
@ -16,10 +14,12 @@ namespace SharedLibraryCore.Helpers
|
||||
_asyncValue = Value;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public async Task<string> ProcessAsync(Server server)
|
||||
{
|
||||
string result = await _asyncValue(server);
|
||||
var result = await _asyncValue(server);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,8 +13,8 @@ namespace SharedLibraryCore.Helpers
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
return (T)(Enum.GetValues(type).GetValue(0));
|
||||
return (T)Enum.GetValues(type).GetValue(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,8 +6,8 @@ namespace SharedLibraryCore.Interfaces
|
||||
public sealed class ParserRegex
|
||||
{
|
||||
/// <summary>
|
||||
/// represents the logical mapping of information provided by
|
||||
/// game logs, get status, and get dvar information
|
||||
/// represents the logical mapping of information provided by
|
||||
/// game logs, get status, and get dvar information
|
||||
/// </summary>
|
||||
public enum GroupType
|
||||
{
|
||||
@ -43,11 +43,18 @@ namespace SharedLibraryCore.Interfaces
|
||||
AdditionalGroup = 200
|
||||
}
|
||||
|
||||
public IParserPatternMatcher PatternMatcher { get; private set; }
|
||||
|
||||
private string pattern;
|
||||
|
||||
public ParserRegex(IParserPatternMatcher pattern)
|
||||
{
|
||||
GroupMapping = new Dictionary<GroupType, int>();
|
||||
PatternMatcher = pattern;
|
||||
}
|
||||
|
||||
public IParserPatternMatcher PatternMatcher { get; }
|
||||
|
||||
/// <summary>
|
||||
/// stores the regular expression groups that will be mapped to group types
|
||||
/// stores the regular expression groups that will be mapped to group types
|
||||
/// </summary>
|
||||
public string Pattern
|
||||
{
|
||||
@ -60,20 +67,20 @@ namespace SharedLibraryCore.Interfaces
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// stores the mapping from group type to group index in the regular expression
|
||||
/// stores the mapping from group type to group index in the regular expression
|
||||
/// </summary>
|
||||
public Dictionary<GroupType, int> GroupMapping { get; private set; }
|
||||
public Dictionary<GroupType, int> GroupMapping { get; }
|
||||
|
||||
/// <summary>
|
||||
/// helper method to enable script parsers to app regex mapping
|
||||
/// the first parameter specifies the group type contained in the regex pattern
|
||||
/// the second parameter specifies the group index to retrieve in the matched regex pattern
|
||||
/// helper method to enable script parsers to app regex mapping
|
||||
/// the first parameter specifies the group type contained in the regex pattern
|
||||
/// the second parameter specifies the group index to retrieve in the matched regex pattern
|
||||
/// </summary>
|
||||
/// <param name="mapKey">group type</param>
|
||||
/// <param name="mapValue">group index</param>
|
||||
public void AddMapping(object mapKey, object mapValue)
|
||||
{
|
||||
if (int.TryParse(mapKey.ToString(), out int key) && int.TryParse(mapValue.ToString(), out int value))
|
||||
if (int.TryParse(mapKey.ToString(), out var key) && int.TryParse(mapValue.ToString(), out var value))
|
||||
{
|
||||
if (GroupMapping.ContainsKey((GroupType)key))
|
||||
{
|
||||
@ -88,8 +95,8 @@ namespace SharedLibraryCore.Interfaces
|
||||
|
||||
if (mapKey.GetType() == typeof(GroupType) && mapValue.GetType().ToString() == "System.Int32")
|
||||
{
|
||||
GroupType k = (GroupType)Enum.Parse(typeof(GroupType), mapKey.ToString());
|
||||
int v = int.Parse(mapValue.ToString());
|
||||
var k = (GroupType)Enum.Parse(typeof(GroupType), mapKey.ToString());
|
||||
var v = int.Parse(mapValue.ToString());
|
||||
|
||||
if (GroupMapping.ContainsKey(k))
|
||||
{
|
||||
@ -102,11 +109,5 @@ namespace SharedLibraryCore.Interfaces
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ParserRegex(IParserPatternMatcher pattern)
|
||||
{
|
||||
GroupMapping = new Dictionary<GroupType, int>();
|
||||
PatternMatcher = pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,28 +8,23 @@ namespace SharedLibraryCore.Helpers
|
||||
// how many minutes between updates
|
||||
public static readonly int UpdateInterval = 5;
|
||||
|
||||
private readonly DateTime When;
|
||||
|
||||
public PlayerHistory(int cNum)
|
||||
{
|
||||
DateTime t = DateTime.UtcNow;
|
||||
When = new DateTime(t.Year, t.Month, t.Day, t.Hour, Math.Min(59, UpdateInterval * (int)Math.Round(t.Minute / (float)UpdateInterval)), 0);
|
||||
var t = DateTime.UtcNow;
|
||||
When = new DateTime(t.Year, t.Month, t.Day, t.Hour,
|
||||
Math.Min(59, UpdateInterval * (int)Math.Round(t.Minute / (float)UpdateInterval)), 0);
|
||||
y = cNum;
|
||||
}
|
||||
|
||||
private DateTime When;
|
||||
|
||||
/// <summary>
|
||||
/// Used by CanvasJS as a point on the x axis
|
||||
/// Used by CanvasJS as a point on the x axis
|
||||
/// </summary>
|
||||
public string x
|
||||
{
|
||||
get
|
||||
{
|
||||
return When.ToString("yyyy-MM-ddTHH:mm:ssZ");
|
||||
}
|
||||
}
|
||||
public string x => When.ToString("yyyy-MM-ddTHH:mm:ssZ");
|
||||
|
||||
/// <summary>
|
||||
/// Used by CanvasJS as a point on the y axis
|
||||
/// Used by CanvasJS as a point on the y axis
|
||||
/// </summary>
|
||||
public int y { get; }
|
||||
|
||||
@ -42,4 +37,4 @@ namespace SharedLibraryCore.Helpers
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using SharedLibraryCore.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
@ -11,6 +6,6 @@ namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
public EFClient Target { get; set; }
|
||||
public EFClient Origin { get; set; }
|
||||
public string Reason { get; set; }
|
||||
public string Reason { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SharedLibraryCore.Dtos.Meta.Responses;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// generic class for passing information about a resource query
|
||||
/// generic class for passing information about a resource query
|
||||
/// </summary>
|
||||
/// <typeparam name="QueryResultType">Type of query result</typeparam>
|
||||
public class ResourceQueryHelperResult<QueryResultType>
|
||||
{
|
||||
/// <summary>
|
||||
/// indicates the total number of results found
|
||||
/// indicates the total number of results found
|
||||
/// </summary>
|
||||
public long TotalResultCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// indicates the total number of results retrieved
|
||||
/// indicates the total number of results retrieved
|
||||
/// </summary>
|
||||
public int RetrievedResultCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// collection of results
|
||||
/// collection of results
|
||||
/// </summary>
|
||||
public IEnumerable<QueryResultType> Results { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
@ -10,6 +8,8 @@ namespace SharedLibraryCore.Helpers
|
||||
public DateTime RequestTime { get; set; } = DateTime.Now;
|
||||
public TimeSpan TokenDuration { get; set; }
|
||||
public string Token { get; set; }
|
||||
public string RemainingTime => Math.Round(-(DateTime.Now - RequestTime).Subtract(TokenDuration).TotalMinutes, 1).ToString();
|
||||
|
||||
public string RemainingTime => Math.Round(-(DateTime.Now - RequestTime).Subtract(TokenDuration).TotalMinutes, 1)
|
||||
.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user