Compare commits
2 Commits
4c4d1d657e
...
e19fdbf11e
Author | SHA1 | Date |
---|---|---|
Tudor Stanciu | e19fdbf11e | |
Tudor Stanciu | c84b4e2157 |
|
@ -1,6 +1,6 @@
|
||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.0.2</Version>
|
<Version>1.0.3</Version>
|
||||||
<Authors>Tudor Stanciu</Authors>
|
<Authors>Tudor Stanciu</Authors>
|
||||||
<Company>STA</Company>
|
<Company>STA</Company>
|
||||||
<PackageTags>GoDaddyDDNS</PackageTags>
|
<PackageTags>GoDaddyDDNS</PackageTags>
|
||||||
|
|
|
@ -21,3 +21,9 @@ To make this worker functional, a minimum configuration is required:
|
||||||
## Stack
|
## Stack
|
||||||
* .NET (C#)
|
* .NET (C#)
|
||||||
* Docker
|
* Docker
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
**1.0.0** - The first release version of the service.
|
||||||
|
**1.0.1** - ConfigureAwait(false) was set for the http client get async calls.
|
||||||
|
**1.0.2** - .NET 6 upgrade.
|
||||||
|
**1.0.3** - The ```ExecutionTimeInSeconds``` parameter has been replaced with ```ExecutionFrequency``` which accepts values in the format ```30s```, ```10m```, ```1h``` or ```1d```.
|
|
@ -0,0 +1,37 @@
|
||||||
|
using System;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace GoDaddyDDNS.Utils
|
||||||
|
{
|
||||||
|
internal static class TimeSpanUtils
|
||||||
|
{
|
||||||
|
public static TimeSpan ParseTimeInterval(string timeInterval)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(timeInterval))
|
||||||
|
throw new ArgumentException("Time interval cannot be null or empty.");
|
||||||
|
|
||||||
|
var formatRegex = new Regex(@"^(\d+)([smhd])$", RegexOptions.IgnoreCase);
|
||||||
|
var match = formatRegex.Match(timeInterval);
|
||||||
|
|
||||||
|
if (!match.Success)
|
||||||
|
throw new ArgumentException("Invalid time interval format. Use format like '30s', '10m', '1h', or '1d'.");
|
||||||
|
|
||||||
|
var value = int.Parse(timeInterval.Substring(0, timeInterval.Length - 1));
|
||||||
|
var unit = timeInterval.Substring(timeInterval.Length - 1).ToLower();
|
||||||
|
|
||||||
|
switch (unit)
|
||||||
|
{
|
||||||
|
case "s": // seconds
|
||||||
|
return TimeSpan.FromSeconds(value);
|
||||||
|
case "m": // minutes
|
||||||
|
return TimeSpan.FromMinutes(value);
|
||||||
|
case "h": // hours
|
||||||
|
return TimeSpan.FromHours(value);
|
||||||
|
case "d": // days
|
||||||
|
return TimeSpan.FromDays(value);
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Invalid time interval unit.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using GoDaddyDDNS.Abstractions;
|
using GoDaddyDDNS.Abstractions;
|
||||||
|
using GoDaddyDDNS.Utils;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
@ -12,16 +13,15 @@ namespace GoDaddyDDNS
|
||||||
{
|
{
|
||||||
private readonly ILogger<Worker> _logger;
|
private readonly ILogger<Worker> _logger;
|
||||||
private readonly IDynamicDNSService _dynamicDNSService;
|
private readonly IDynamicDNSService _dynamicDNSService;
|
||||||
private readonly int _delay;
|
private readonly TimeSpan _delay;
|
||||||
|
|
||||||
|
|
||||||
public Worker(ILogger<Worker> logger, IDynamicDNSService dynamicDNSService, IConfiguration configuration)
|
public Worker(ILogger<Worker> logger, IDynamicDNSService dynamicDNSService, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_logger=logger;
|
_logger=logger;
|
||||||
_dynamicDNSService=dynamicDNSService;
|
_dynamicDNSService=dynamicDNSService;
|
||||||
|
|
||||||
var delayInSeconds = configuration.GetValue<int>("ExecutionTimeInSeconds");
|
var delay = configuration.GetValue<string>("ExecutionFrequency");
|
||||||
_delay = Convert.ToInt32(TimeSpan.FromSeconds(delayInSeconds).TotalMilliseconds);
|
_delay = TimeSpanUtils.ParseTimeInterval(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
|
|
@ -17,5 +17,5 @@
|
||||||
"Records": [ "@" ],
|
"Records": [ "@" ],
|
||||||
"Key": "*********",
|
"Key": "*********",
|
||||||
"Secret": "*********",
|
"Secret": "*********",
|
||||||
"ExecutionTimeInSeconds": 60
|
"ExecutionFrequency": "60s"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue