Beispiel #1
0
        private void CancelWatering(object sender, CancelWateringArgs e)
        {
            if (String.IsNullOrWhiteSpace(e.Token))
            {
                this._logger.LogError("InternalCommsService_CancelWatering_NoToken");
                return;
            }

            using (WebClient client = new WebClient())
            {
                client.Headers.Add("accept", "application/json");
                client.Headers.Add("accept-encoding", "gzip, deflate");
                client.Headers.Add("Content-Type", "application/json");

                string path = "/cancelWatering";

                try
                {
                    string response = client.UploadString(this._nodeServiceUrl + path, JsonConvert.SerializeObject(new CancelWateringDto
                    {
                        deviceToken = e.Token,
                        level       = e.Level
                    }));
                }
                catch (Exception ex)
                {
                    this._logger.LogError("InternalCommsService_CancelWatering_Exception", ex);
                }
            }
        }
Beispiel #2
0
        private void cancelWatering(object sender, CancelWateringArgs args)
        {
            this._logger.LogInformation("WsControllerCancelWateringToken", "Token {0}", args.Token);
            if (this._token == args.Token && this._webSocket != null && this._webSocket.State == WebSocketState.Open)
            {
                this._logger.LogInformation("WsControllerCancelWateringArgs", "CancelWatering arguments: {0}", (int)args.Level);
                var bytes = System.Text.Encoding.UTF8.GetBytes(String.Format("C:{0}", (int)args.Level));

                this._webSocket.SendAsync(new System.ArraySegment <byte>(bytes), WebSocketMessageType.Text, true, CancellationToken.None);
            }
        }