예제 #1
0
        private void TDRawDeviceEvent(IntPtr data, int controllerId, int callbackId, IntPtr context)
        {
            string parsedData = Marshal.PtrToStringAnsi(data);

            if (string.IsNullOrWhiteSpace(parsedData))
            {
                return;
            }

            RawCommandReceivedEventArgs eventArgs = new RawCommandReceivedEventArgs(controllerId, parsedData);

            RawCommandReceived.Trigger(this, eventArgs);
        }
예제 #2
0
        private void TelldusCoreService_RawCommandReceived(object sender, RawCommandReceivedEventArgs e)
        {
            // always check if webhook is configured
            webHookService.SendRawCommandWebHook(e);

            // filter for the log
            if (e.Values.ContainsKey("class") && e.Values["class"] == "sensor")
            {
                return;
            }

            logger.LogInformation($"Raw data recieved: {e.RawData}");
        }
예제 #3
0
        public async Task SendRawCommandWebHook(RawCommandReceivedEventArgs rawCommand)
        {
            string jsonData = JsonConvert.SerializeObject(new { rawCommand.ControllerID, rawCommand.RawData });

            foreach (string url in configuration.GetSection("Webhooks:RawCommands").Get <string[]>())
            {
                try
                {
                    bool result = await SendData(url, jsonData);

                    if (!result)
                    {
                        throw new Exception("Invalid response from url");
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"Failed to send raw command to webhook: {url}");
                }
            }
        }