Skip to content

Commit

Permalink
Add XML comment documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
arenekosreal committed May 10, 2024
1 parent 49fad0e commit d62d0aa
Show file tree
Hide file tree
Showing 34 changed files with 453 additions and 232 deletions.
3 changes: 3 additions & 0 deletions Constraints.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace E5Renewer
{
/// <summary>Constraints container.</summary>
public static class Constraints
{
/// <value>The time format in log.</value>
public const string loggingTimeFormat = "yyyy-MM-dd HH:mm:ss ";
/// <value>The log level.</value>
public static LogLevel loggingLevel = LogLevel.Information;
}
}
26 changes: 25 additions & 1 deletion E5Renewer.Config/Config.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
namespace E5Renewer.Config
{
/// <summary>Runtime used Config.</summary>
public class RuntimeConfig : ICheckable
{
/// <value>Enable debug mode.</value>
public bool debug { get; set; }
/// <value>Authentication token.</value>
public string authToken { get; set; }
/// <value>HTTP json api listen address.</value>
public string listenAddr { get; set; }
/// <value>HTTP json api listen port.</value>
public uint listenPort { get; set; }
/// <value><br/>
/// Use Unix Domain Socket instead TCP for HTTP json api.<br/>
/// <remarks>
/// Only available when HTTP listen failed and your plaform supports Unix Domain Socket.
/// </remarks>
/// </value>
public string listenSocket { get; set; }
/// <value><br/>
/// The permission of Unix Domain Socket. <br/>
/// <remarks>
/// In octal number like 777 or 644.
/// </remarks>
/// </value>
public uint listenSocketPermission { get; set; }
/// <value>The list of users to access msgraph apis.</value>
/// <seealso cref="GraphUser"/>
public List<GraphUser> users { get; set; }
/// <value>If this object is valid.</value>
/// <seealso cref="ICheckable"/>
public bool check
{
get
{
return this.authToken != "" &&
return !string.IsNullOrEmpty(this.authToken) &&
users.All(
(GraphUser user) => user.check
);
}
}
/// <summary>
/// Default constructor of <c>RuntimeConfig</c>
/// </summary>
public RuntimeConfig()
{
this.debug = false;
Expand Down
4 changes: 4 additions & 0 deletions E5Renewer.Config/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@

namespace E5Renewer.Config
{
/// <summary>Utils for parsing config.</summary>
public static class ConfigParser
{
private static readonly List<IConfigParser> parsers = ModulesLoader.GetRegisteredModules<IConfigParser>();
private static RuntimeConfig? parsedConfig;
/// <summary>Parse config.</summary>
/// <param name="fileInfo">The config path in <c>FileInfo</c> object.</param>
/// <returns>The result of parsed config.</returns>
public static async Task<RuntimeConfig> ParseConfig(FileInfo fileInfo)
{
if (ConfigParser.parsedConfig != null)
Expand Down
16 changes: 16 additions & 0 deletions E5Renewer.Config/GraphUser.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
namespace E5Renewer.Config
{
/// <summary>The class stores info to access msgraph apis.</summary>
public class GraphUser : ICheckable
{
private const uint calmDownMinMilliSeconds = 300000;
private const uint calmDownMaxMilliSeconds = 500000;
private readonly TimeOnly[] privateTimes = new TimeOnly[2];
/// <value>The name of user.</value>
public string name { get; set; }
/// <value>The tenant id of user.</value>
public string tenantId { get; set; }
/// <value>The client id of user.</value>
public string clientId { get; set; }
/// <value>The secret of user.</value>
public string secret { get; set; }
/// <value>When to start the user.</value>
public TimeOnly fromTime
{
get
Expand All @@ -23,6 +29,7 @@ public TimeOnly fromTime
}
}
}
/// <value>When to stop the user.</value>
public TimeOnly toTime
{
get
Expand All @@ -37,7 +44,9 @@ public TimeOnly toTime
}
}
}
/// <value>Which days are allowed to start the user.</value>
public List<DayOfWeek> days { get; set; }
/// <value>If the user is allowed to start.</value>
public bool enabled
{
get
Expand All @@ -59,6 +68,8 @@ public bool enabled
now.CompareTo(toTime) < 0;
}
}
/// <value>Check if <c>GraphUser</c> is valid.</value>
/// <seealso cref="ICheckable"/>
public bool check
{
get
Expand All @@ -69,6 +80,8 @@ public bool check
this.secret != "";
}
}
/// <value>How many milliseconds until next call.</value>
/// <remarks>If is allowed to start, will give the user a rest.</remarks>
public int milliSecondsUntilNextStarting
{
get
Expand Down Expand Up @@ -103,6 +116,9 @@ public int milliSecondsUntilNextStarting

}
}
/// <summary>
/// Default constructor of <c>GraphUser</c>
/// </summary>
public GraphUser()
{
this.name = "";
Expand Down
5 changes: 5 additions & 0 deletions E5Renewer.Config/ICheckable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace E5Renewer.Config
{
/// <summary>The interface of object has a bool property named <c>check</c>.</summary>
public interface ICheckable
{
/// <value><br/>
/// The <c>check</c> property.<br/>
/// It shows that if this object is correct.
/// </value>
public bool check { get; }
}
}
8 changes: 8 additions & 0 deletions E5Renewer.Config/IConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

namespace E5Renewer.Config
{
/// <summary>The api interface of <c>ConfigParser</c>.</summary>
/// <seealso cref="IModule"/>
public interface IConfigParser : IModule
{
/// <summary>If <paramref name="path"/> given is supported by the parser.</summary>
/// <param name="path">The path of config file.</param>
/// <returns>If the path given is supported.</returns>
public bool IsSupported(string path);
/// <summary>Parse <paramref name="path"/> and returns parsed result.</summary>
/// <param name="path">The path of config file.</param>
/// <returns>The parsed result.</returns>
public Task<RuntimeConfig> ParseConfig(string path);
}
}
6 changes: 6 additions & 0 deletions E5Renewer.Config/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
using E5Renewer.Config;
namespace E5Renewer.Modules.ConfigParsers
{
/// <summary> Json config parser.</summary>
[Module]
public class JsonParser : IConfigParser
{
/// <inheritdoc/>
public string name { get => "JsonParser"; }
/// <inheritdoc/>
public string author { get => "E5Renewer"; }
/// <inheritdoc/>
public SemVer apiVersion { get => new(0, 1, 0); }
/// <inheritdoc/>
public bool IsSupported(string path) => path.EndsWith(".json");

/// <inheritdoc/>
public async Task<RuntimeConfig> ParseConfig(string path)
{
RuntimeConfig? runtimeConfig;
Expand Down
6 changes: 6 additions & 0 deletions E5Renewer.Config/TomlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

namespace E5Renewer.Modules.ConfigParsers
{
/// <summary>Toml config parser.</summary>
[Module]
public class TomlParser : IConfigParser
{
/// <inheritdoc/>
public string name { get => "TomlParser"; }
/// <inheritdoc/>
public string author { get => "E5Renewer"; }
/// <inheritdoc/>
public SemVer apiVersion { get => new(0, 1, 0); }
/// <inheritdoc/>
public bool IsSupported(string path) => path.EndsWith(".toml");
/// <inheritdoc/>
public async Task<RuntimeConfig> ParseConfig(string path)
{
RuntimeConfig runtimeConfig;
Expand Down
6 changes: 6 additions & 0 deletions E5Renewer.Config/YamlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

namespace E5Renewer.Modules.ConfigParsers
{
/// <summary>Yaml config parser.</summary>
[Module]
public class YamlParser : IConfigParser
{
/// <inheritdoc/>
public string name { get => "YamlParser"; }
/// <inheritdoc/>
public string author { get => "E5Renewer"; }
/// <inheritdoc/>
public SemVer apiVersion { get => new(0, 1, 0); }
/// <inheritdoc/>
public bool IsSupported(string path) => path.EndsWith(".yaml") || path.EndsWith(".yml");
/// <inheritdoc/>
public async Task<RuntimeConfig> ParseConfig(string path)
{
RuntimeConfig runtimeConfig;
Expand Down
2 changes: 2 additions & 0 deletions E5Renewer.Exceptions/InvalidConfigException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace E5Renewer.Exceptions
{
/// <summary>The Exception that is thown when config is invalid.</summary>
public class InvalidConfigException : ArgumentException
{
/// <summary>Initialize <c>InvalidConfigException</c> by using message.</summary>
public InvalidConfigException(string msg) : base(msg) { }
}
}
2 changes: 2 additions & 0 deletions E5Renewer.Exceptions/NoParserFoundException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace E5Renewer.Exceptions
{
/// <summary>The Exception is thown when no <c>ConfigParser</c> is found for config path given.</summary>
public class NoParserFoundException : Exception
{
/// <summary>Initialize <c>NoParserFoundException</c> from config path.</summary>
public NoParserFoundException(string configName) : base(string.Format("No Parser found for config {0}", configName)) { }
}
}
2 changes: 2 additions & 0 deletions E5Renewer.Exceptions/RuntimeException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace E5Renewer.Exceptions
{
/// <summary>The Exception is thown when generic runtime error happend.</summary>
public class RuntimeException : Exception
{
/// <summary>Initialize <c>RuntimeException</c> from message.</summary>
public RuntimeException(string msg) : base(msg) { }
}
}
13 changes: 9 additions & 4 deletions E5Renewer.Modules/IModule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
namespace E5Renewer.Modules
{
/// <summary>The api interface of loadable module.</summary>
public interface IModule
{
private readonly static SemVer targetSemVer = new SemVer(0,1,0);
public string name{ get; }
public string author{ get; }
private readonly static SemVer targetSemVer = new SemVer(0, 1, 0);
/// <value>The name of the module.</value>
public string name { get; }
/// <value>The author of the module.</value>
public string author { get; }
/// <value>The api version of the module.</value>
public SemVer apiVersion { get; }
public bool IsDeprecated { get => apiVersion < targetSemVer; }
/// <value> If the module is deprecated.</value>
public bool isDeprecated { get => !apiVersion.IsCompatibleTo(targetSemVer); }
}
}
3 changes: 2 additions & 1 deletion E5Renewer.Modules/ModuleAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace E5Renewer.Modules
{
/// <summary>The attribute to mark module class.</summary>
[AttributeUsage(AttributeTargets.Class)]
public class ModuleAttribute : Attribute {}
public class ModuleAttribute : Attribute { }
}
7 changes: 6 additions & 1 deletion E5Renewer.Modules/ModulesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace E5Renewer.Modules
{
/// <summary>Utils to load modules.</summary>
public static class ModulesLoader
{
private static readonly ILogger logger = LoggerFactory.Create(
Expand Down Expand Up @@ -36,7 +37,7 @@ private static List<T> GetModulesInAssembly<T>(Assembly assembly)
{
modules.Add(module);
logger.LogInformation("Loaded module {0} by {1}", module.name, module.author);
if (module.IsDeprecated)
if (module.isDeprecated)
{
logger.LogWarning("You are using a deprecated module!");
}
Expand All @@ -51,6 +52,7 @@ private static List<T> GetModulesInAssembly<T>(Assembly assembly)
}
return modules;
}
/// <summary>Load all modules.</summary>
public static void LoadModules()
{
modules.AddRange(GetModulesInAssembly<IModule>(Assembly.GetExecutingAssembly()));
Expand All @@ -61,6 +63,9 @@ public static void LoadModules()
modules.AddRange(GetModulesInAssembly<IModule>(Assembly.Load(Path.GetFileNameWithoutExtension(fileInfo.FullName))));
}
}
/// <summary>Get registered modules.</summary>
/// <returns>The modules of type <typeparamref name="T">T</typeparamref> in a <c>List</c>.</returns>
/// <typeparam name="T">The type to filter modules.</typeparam>
public static List<T> GetRegisteredModules<T>()
where T : class, IModule
{
Expand Down
Loading

0 comments on commit d62d0aa

Please sign in to comment.