Ejemplo n.º 1
0
        private void UpdateBackground(object source, EventArgs e)
        {
            //if (this._busyType == BusyType.Heavy)
            //{
            //    this._busyType = BusyType.Light;
            //}
            //else
            //{
            //    this._busyType++;
            //}

            //var carriageDto = new CarriageDto() { Id = 1, Status = (int)this._busyType };
            //var content = new StringContent(JsonConvert.SerializeObject(carriageDto), Encoding.UTF8, "application/json");

            //var response = client.PutAsync(BaseUrl + "/" + 1, content).Result;

            var response = this.client.GetAsync(BaseUrl + "/" + 1).Result;

            var         text = response.Content.ReadAsStringAsync().Result;
            CarriageDto dto  = JsonConvert.DeserializeObject <CarriageDto>(text);

            this._busyType = (BusyType)dto.Status;

            var image = this.GetImageUri(this._busyType);

            this.Background = new ImageBrush(new BitmapImage(image));
        }
Ejemplo n.º 2
0
        private void DrawRectangle(HttpClient client, int offset, Canvas layoutRoot)
        {
            var response = client.GetAsync(baseUrl + "/" + offset).Result;

            if (!response.IsSuccessStatusCode)
            {
                Console.WriteLine(response.StatusCode);
                return;
            }

            var         text = response.Content.ReadAsStringAsync().Result;
            CarriageDto dto  = JsonConvert.DeserializeObject <CarriageDto>(text);

            Color color;

            switch (dto.Status)
            {
            case 0:
                color = Colors.Green;
                break;

            case 1:
                color = Colors.Orange;
                break;

            case 2:
                color = Colors.Red;
                break;

            default:
                color = Colors.Gray;
                break;
            }

            layoutRoot.Children.Clear();

            Rectangle exampleRectangle = new Rectangle();

            exampleRectangle.Width  = layoutRoot.ActualWidth;
            exampleRectangle.Height = layoutRoot.ActualHeight;
            // Create a SolidColorBrush and use it to
            // paint the rectangle.
            SolidColorBrush myBrush = new SolidColorBrush(color);

            exampleRectangle.Stroke          = Brushes.White;
            exampleRectangle.StrokeThickness = 4;
            exampleRectangle.Fill            = myBrush;
            layoutRoot.Children.Insert(0, exampleRectangle);
        }