mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 23:31:13 -05:00
More cleanup
project renaming moved PluginImporter to SharedLibrary config writer abstracted for plugins
This commit is contained in:
52
SharedLibrary/Helpers/AsyncStatus.cs
Normal file
52
SharedLibrary/Helpers/AsyncStatus.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public sealed class AsyncStatus
|
||||
{
|
||||
CancellationToken Token;
|
||||
DateTime StartTime;
|
||||
int TimesRun;
|
||||
int UpdateFrequency;
|
||||
public double RunAverage { get; private set; }
|
||||
public object Dependant { get; private set; }
|
||||
public Task RequestedTask { get; private set; }
|
||||
|
||||
public AsyncStatus(object dependant, int frequency)
|
||||
{
|
||||
Token = new CancellationToken();
|
||||
StartTime = DateTime.Now;
|
||||
Dependant = dependant;
|
||||
UpdateFrequency = frequency;
|
||||
// technically 0 but it's faster than checking for division by 0
|
||||
TimesRun = 1;
|
||||
}
|
||||
|
||||
public CancellationToken GetToken()
|
||||
{
|
||||
return Token;
|
||||
}
|
||||
|
||||
public double ElapsedMillisecondsTime()
|
||||
{
|
||||
return (DateTime.Now - StartTime).TotalMilliseconds;
|
||||
}
|
||||
|
||||
public void Update(Task T)
|
||||
{
|
||||
RequestedTask = T;
|
||||
RequestedTask.Start();
|
||||
|
||||
if (TimesRun > 25)
|
||||
TimesRun = 1;
|
||||
|
||||
RunAverage = RunAverage + ((DateTime.Now - StartTime).TotalMilliseconds - RunAverage - UpdateFrequency) / TimesRun;
|
||||
StartTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
50
SharedLibrary/Helpers/Configuration.cs
Normal file
50
SharedLibrary/Helpers/Configuration.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class Configuration<T> : Interfaces.Serialize<T>
|
||||
{
|
||||
string FilePostfix;
|
||||
public Configuration(Server S)
|
||||
{
|
||||
FilePostfix = $"_{S.GetIP()}_{S.GetPort()}.cfg";
|
||||
}
|
||||
|
||||
public T Read()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Read();
|
||||
}
|
||||
|
||||
catch (Exceptions.SerializeException)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Write(T Data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Write(Filename(), Data);
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(Exceptions.SerializeException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Filename()
|
||||
{
|
||||
return $"config/{typeof(T).ToString()}_{FilePostfix}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
20
SharedLibrary/Helpers/MessageToken.cs
Normal file
20
SharedLibrary/Helpers/MessageToken.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class MessageToken
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
Func<string> Value;
|
||||
public MessageToken(string Name, Func<string> Value)
|
||||
{
|
||||
this.Name = Name;
|
||||
this.Value = Value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value().ToString();
|
||||
}
|
||||
}
|
||||
}
|
15
SharedLibrary/Helpers/PlayerHistory.cs
Normal file
15
SharedLibrary/Helpers/PlayerHistory.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class PlayerHistory
|
||||
{
|
||||
public PlayerHistory(DateTime w, int cNum)
|
||||
{
|
||||
When = w;
|
||||
Players = cNum;
|
||||
}
|
||||
public DateTime When { get; private set; }
|
||||
public int Players { get; private set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user