public StreamlabsOBSSubscriptionHandler([NotNull] StreamlabsOBSRequest request,
                                         CancellationToken cancellationToken = default,
                                         [NotNull] string pipeName           = "slobs")
 {
     // TODO check externCancellationToken
     this.request  = request ?? throw new ArgumentNullException(nameof(request));
     this.pipeName = pipeName ?? throw new ArgumentNullException(nameof(pipeName));
     if (cancellationToken != default)
     {
         _externCancellationToken = cancellationToken;
     }
 }
        public async Task <StreamlabsOBSResponse> SendRequestAsync(StreamlabsOBSRequest request,
                                                                   bool loadPromises = true)
        {
            using NamedPipeClientStream pipe = new NamedPipeClientStream(pipeName);
            using StreamReader reader        = new StreamReader(pipe);
            using StreamWriter writer        = new StreamWriter(pipe)
                  {
                      NewLine = "\n"
                  };

            await pipe.ConnectAsync(5000).ConfigureAwait(false);

            await writer.WriteLineAsync(request.ToJson()).ConfigureAwait(false);

            await writer.FlushAsync().ConfigureAwait(false);

            pipe.WaitForPipeDrain();

            string responsJson = await reader.ReadLineAsync().ConfigureAwait(false);

            StreamlabsOBSResponse response = JsonConvert.DeserializeObject <StreamlabsOBSResponse>(responsJson);

            response.JsonResponse = responsJson;

            if (!loadPromises)
            {
                return(response);
            }

            if (!response.IsEnumberabeResult() && response.Results.IsPromise())
            {
                response.Results = JsonConvert.DeserializeObject <StreamlabsOBSResponse>(await reader.ReadLineAsync().ConfigureAwait(false)).Results;
            }

            return(response);
        }
 public IEnumerable <TResult> SendRequest <TResult>(StreamlabsOBSRequest request, bool servePromises = false)
 {
     return(SendRequestAsync(request).ConfigureAwait(false).GetAwaiter().GetResult().GetResults <TResult>());
 }
 public StreamlabsOBSResponse SendRequest(StreamlabsOBSRequest request, bool servePromises = false)
 {
     return(SendRequestAsync(request).ConfigureAwait(false).GetAwaiter().GetResult());
 }