Add Info Command
This commit is contained in:
21
PlantBox.Shared/Communication/Commands/InfoRequest.cs
Normal file
21
PlantBox.Shared/Communication/Commands/InfoRequest.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Shared.Communication.Commands
|
||||||
|
{
|
||||||
|
public class InfoRequest : CommandSerializable<InfoRequest>
|
||||||
|
{
|
||||||
|
public override Command Command => Command.Info;
|
||||||
|
|
||||||
|
public override InfoRequest Deserialize(string[] arguments)
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] Serialize()
|
||||||
|
{
|
||||||
|
return Array.Empty<string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
47
PlantBox.Shared/Communication/Commands/InfoResponse.cs
Normal file
47
PlantBox.Shared/Communication/Commands/InfoResponse.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Shared.Communication.Commands
|
||||||
|
{
|
||||||
|
public class InfoResponse : CommandSerializable<InfoResponse>
|
||||||
|
{
|
||||||
|
public override Command Command => Command.Info;
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
public PlantType Type { get; set; }
|
||||||
|
public PlantState State { get; set; }
|
||||||
|
public double Water { get; set; }
|
||||||
|
|
||||||
|
public override InfoResponse Deserialize(string[] arguments)
|
||||||
|
{
|
||||||
|
if (arguments == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(arguments));
|
||||||
|
}
|
||||||
|
if (arguments.Length < 4)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Excepted 4 arguments, got {arguments.Length}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Name = arguments[0];
|
||||||
|
Type = (PlantType)Enum.Parse(typeof(PlantType), arguments[1], true);
|
||||||
|
State = (PlantState)Enum.Parse(typeof(PlantState), arguments[2], true);
|
||||||
|
Water = double.Parse(arguments[3], CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] Serialize()
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
Name,
|
||||||
|
Type.ToString(),
|
||||||
|
State.ToString(),
|
||||||
|
Water.ToString(CultureInfo.InvariantCulture)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
PlantBox.Shared/Communication/Commands/PlantState.cs
Normal file
13
PlantBox.Shared/Communication/Commands/PlantState.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Shared.Communication.Commands
|
||||||
|
{
|
||||||
|
public enum PlantState
|
||||||
|
{
|
||||||
|
Bad,
|
||||||
|
Warning,
|
||||||
|
Good
|
||||||
|
}
|
||||||
|
}
|
||||||
14
PlantBox.Shared/Communication/Commands/PlantType.cs
Normal file
14
PlantBox.Shared/Communication/Commands/PlantType.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace PlantBox.Shared.Communication.Commands
|
||||||
|
{
|
||||||
|
public enum PlantType
|
||||||
|
{
|
||||||
|
Bamboo,
|
||||||
|
Bonsai,
|
||||||
|
Cactus,
|
||||||
|
Ficus,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user