public async Task <ActionResult <Bitmap> > Post([FromBody] MandelBrotRequest request)
        {
            logger.LogInformation("Client Connected");
            try
            {
                Bitmap bm = await this.service.GetMandelBrotBitmap(request);

                if (bm == null)
                {
                    logger.LogError("Bitmap is null");
                    return(BadRequest("Ops something went wrong"));
                }
                else
                {
                    logger.LogInformation("Return Bitmap");
                    MandelbrotBitMapAnswer bta = new MandelbrotBitMapAnswer();


                    using (MemoryStream ms = new MemoryStream())
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(ms, bm);
                        bta.Picture = ms.ToArray();
                    }
                    return(Ok(bta));
                }
            }
            catch (Exception)
            {
                logger.LogError("Exception is thrown in the service");
                return(BadRequest("Ops something went wrong"));
            }
        }
Esempio n. 2
0
        private async Task GetBitMapAsync(IHost host, MandelBrotRequest request)
        {
            try
            {
                var    service = host.Services.GetService <MandelBrotClientService>();
                Bitmap bm      = await service.GetMandelbrotBitmap(request);

                this.Result = BitmapToImageSource(bm);
                MessageBox.Show("Success");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        public async Task <Bitmap> GetMandelbrotBitmap(MandelBrotRequest request)
        {
            string      json    = JsonConvert.SerializeObject(request);
            HttpContent content = new StringContent(json, Encoding.UTF8, "application/json");
            var         resp    = await _httpClient.PostAsync("api/MandelBrot", content);

            resp.EnsureSuccessStatusCode();
            string newJson = await resp.Content.ReadAsStringAsync();

            var    answer = JsonConvert.DeserializeObject <MandelbrotBitMapAnswer>(newJson);
            Bitmap c      = null;

            using (MemoryStream ms = new MemoryStream(answer.Picture))
            {
                BinaryFormatter bf = new BinaryFormatter();
                c = (Bitmap)bf.Deserialize(ms);
            }
            return(c);
        }