1
0
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:
RaidMax
2017-06-12 17:47:31 -04:00
parent 0ef306a60c
commit 5d1c9bd218
36 changed files with 303 additions and 330 deletions

View 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;
}
}
}

View 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}";
}
}
}

View 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();
}
}
}

View 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; }
}
}