Esempio n. 1
0
        public Task RunAsync()
        {
            Task t = new Task(() =>
            {
                m_Transport.OnMessage((sensorMessage) =>
                {
                    dynamic msg = sensorMessage as dynamic;

                    m_TraceMethod(String.Format("Message: {0}", msg.MessageId));

                    if (msg.Properties.ContainsKey("Start"))
                    {
                        startTelemetryLoop(msg);
                    }
                    else if (msg.Properties.ContainsKey("Stop"))
                    {
                        stopTelemetryLoop();
                    }

                    return(true);
                }, new System.Threading.CancellationToken(), m_OnMsgRcvArg);
            });

            t.Start();

            return(t);
        }
Esempio n. 2
0
        public void OnMessage_Test()
        {
            ClearQueue_Test();

            string deviceId = ConfigurationManager.AppSettings["DeviceId"];

            IIotApi conn = getConnector();

            ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]);

            for (int i = 0; i < 10; i++)
            {
                svcClient.SendAsync(deviceId, createServiceMessage(new { MessageId = i.ToString() })).Wait();
            }

            int cnt         = 0;
            var tokenSource = new CancellationTokenSource();

            conn.OnMessage((msg) => {
                cnt++;

                if (cnt == 10)
                {
                    tokenSource.Cancel();
                }

                return(true);
            }, tokenSource.Token);
        }
Esempio n. 3
0
        public void ClearQueue_Test()
        {
            string deviceId = ConfigurationManager.AppSettings["DeviceId"];

            IIotApi conn = getConnector();

            ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]);

            int cnt         = 0;
            var tokenSource = new CancellationTokenSource();

            conn.OnMessage((msg) => {
                if (msg == null)
                {
                    tokenSource.Cancel();
                }

                return(true);
            }, tokenSource.Token).Wait();
        }