public byte[] ProcessHighChartsRequest(HighCharts chart)
        {
            if (ExeProcess.HasExited)
            {
                if (_keepAlive)
                {
                    StartServer();
                }
                else
                {
                    Dispose();
                    throw new Exception("could not process.  Server is no longer running and KeepAlive is set to false.");
                }
            }
            var newGuid = Guid.NewGuid();

            var temporaryGraphImageFile = Path.Combine(TemporaryImagesDirectory, $"{newGuid}.png");

            var wrapper = new HighChartsRenderServerWrapper()
            {
                infile = JsonConvert.SerializeObject(chart.options,
                                                     Formatting.Indented,
                                                     _jsonSerializerSettings),
                constr   = "Chart",
                outfile  = temporaryGraphImageFile,
                callback = chart.callback
            };

            return(PostRequestAndReturnBytesOnSuccess(wrapper, temporaryGraphImageFile));
        }
        private byte[] PostRequestAndReturnBytesOnSuccess(HighChartsRenderServerWrapper wrapper, string temporaryGraphImageFile)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"http://{_ip}:{_port}");


            request.ContentType = "application/json";


            request.Timeout = isFirstRun() ? 20000 : TimeoutBeforeRetry;
            request.Method  = "POST";

            var postData = JsonConvert.SerializeObject(wrapper, _jsonSerializerSettings);

            if (isFirstRun())
            {
                Thread.Sleep(350);
            }

            bool sucess  = false;
            var  retries = 0;

            while (retries > Maxretries || sucess != true)
            {
                try
                {
                    using (var streamWriter = new StreamWriter(request.GetRequestStream()))
                    {
                        streamWriter.Write(postData);
                        streamWriter.Flush();
                        streamWriter.Close();
                    }

                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            var bytesToReturn = File.ReadAllBytes(temporaryGraphImageFile);
                            CreatedTempFiles.Add(temporaryGraphImageFile);
                            return(bytesToReturn);
                        }
                    }
                    sucess = true;
                }
                catch (Exception ex)
                {
                    if (retries + 1 == Maxretries)
                    {
                        throw;
                    }
                    retries++;
                }
            }
            return(null);
        }