Add CaptorsRequest

This commit is contained in:
2019-03-23 22:07:09 +01:00
parent d7d60f30af
commit d81bf5d8ec
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace PlantBox.Shared.Communication.Commands
{
public enum CaptorsInterval
{
Monthly,
Weekly,
Daily,
Hourly,
Minutely
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace PlantBox.Shared.Communication.Commands
{
public class CaptorsRequest : CommandSerializable<CaptorsRequest>
{
public CaptorsInterval Interval { get; set; }
public int Number { get; set; }
public CaptorsRequest()
{
}
public CaptorsRequest(CaptorsInterval interval, int number)
{
Interval = interval;
Number = number;
}
public override CaptorsRequest Deserialize(string[] arguments)
{
if (arguments == null)
{
throw new ArgumentNullException(nameof(arguments));
}
if (arguments.Length < 2)
{
throw new ArgumentException($"Excepted 2 arguments, got {arguments.Length}");
}
Interval = (CaptorsInterval)Enum.Parse(typeof(CaptorsInterval), arguments[0], true);
Number = int.Parse(arguments[0], CultureInfo.InvariantCulture);
return this;
}
public override string[] Serialize()
{
return new[] { Interval.ToString(), Number.ToString(CultureInfo.InvariantCulture) };
}
}
}