Example #1
0
        /// <summary>
        /// Azure에 구축된 Web App으로 IBS와의 통신 상태 데이터를 전송하는 함수
        /// </summary>
        /// <param name="webappURL"></param>
        /// <param name="comStatus"></param>
        /// <param name="buildingID"></param>
        /// <param name="deviceID"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public async Task <bool> PostWebAPI(string webappURL, ComHttpPacket comStatus, string type)
        {
            bool   result = true;
            string json   = string.Empty;

            try
            {
                json = JsonConvert.SerializeObject(comStatus);

                StringContent data = new StringContent(json, Encoding.UTF8, "application/json");

                httpClientFactory = serviceProvider.GetService <IHttpClientFactory>();

                var client = httpClientFactory.CreateClient();
                client.DefaultRequestHeaders.Add("type", type);
                client.Timeout = TimeSpan.FromMinutes(2);

                var response = await client.PostAsync(new Uri(webappURL + "/event/elevator/health"), data);

                Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [HttpClientTransfer : health] {json} Send To WebApp");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [health error] Data : {json}");
                Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [health error] {ex.Message}");
                result = false;
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// IBS와 엣지간의 통신 상태를 체크하는 Timer 메소드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommCheck(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [Controller : CommCheck] Check Commmunication between IBS and Edge");

            if (ClientSocket != null)
            {
                ComHttpPacket comHttpPacket = new ComHttpPacket();

                try
                {
                    var dataType = "";

                    comHttpPacket.building_id         = this.buildingID;
                    comHttpPacket.inspection_datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                    if (ClientSocket.IsConnected)
                    {
                        dataType = "general";
                        comHttpPacket.inspection_result_val = "connected";
                        comHttpPacket.inspection_result_cd  = "0";
                    }
                    else
                    {
                        dataType = "emergency";
                        comHttpPacket.inspection_result_val = "disconnected";
                        comHttpPacket.inspection_result_cd  = "1";
                    }

                    Task <bool> task = Task.Run <bool>(async() => await httpClientTransfer.PostWebAPI(azureWebAppURL, comHttpPacket, dataType));
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [Controller : CommCheck] {ex.Message}");
                }
            }
        }