C#: Rewrite GodotTools messaging protocol

This commit is contained in:
Ignacio Etcheverry 2020-05-09 20:45:43 +02:00
parent f3bcd5f8dd
commit 3ce09246d1
42 changed files with 2245 additions and 1053 deletions

View file

@ -0,0 +1,23 @@
using GodotTools.IdeMessaging.Requests;
using GodotTools.IdeMessaging.Utils;
using Newtonsoft.Json;
namespace GodotTools.IdeMessaging
{
public abstract class ResponseAwaiter : NotifyAwaiter<Response>
{
public abstract void SetResult(MessageContent content);
}
public class ResponseAwaiter<T> : ResponseAwaiter
where T : Response, new()
{
public override void SetResult(MessageContent content)
{
if (content.Status == MessageStatus.Ok)
SetResult(JsonConvert.DeserializeObject<T>(content.Body));
else
SetResult(new T {Status = content.Status});
}
}
}