Add Ping command
This commit is contained in:
@@ -8,7 +8,7 @@ namespace PlantBox.Shared.Communication.Commands
|
||||
/// A class serializable to a <see cref="CommandPacket"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public abstract class CommandSerializable<T>
|
||||
public abstract class CommandSerializable<T> where T : new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Serialize all the values in a string <see cref="Array"/>,
|
||||
|
||||
41
PlantBox.Shared/Communication/Commands/Ping.cs
Normal file
41
PlantBox.Shared/Communication/Commands/Ping.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace PlantBox.Shared.Communication.Commands
|
||||
{
|
||||
public class Ping : CommandSerializable<Ping>
|
||||
{
|
||||
public string Message { get; set; }
|
||||
|
||||
public Ping()
|
||||
{
|
||||
|
||||
}
|
||||
public Ping(string message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public override Ping Deserialize(string[] arguments)
|
||||
{
|
||||
if (arguments == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(arguments));
|
||||
}
|
||||
if (arguments.Length < 1)
|
||||
{
|
||||
throw new ArgumentException($"Excepted at least 1 argument, got {arguments.Length}");
|
||||
}
|
||||
|
||||
Message = arguments[0];
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string[] Serialize()
|
||||
{
|
||||
return new string[] { Message };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user