Exemple #1
0
        public void TestBatchSend()
        {
            IotApi api = new IotApi().
                         RegisterModule(getDefaultModule(false));

            api.Open(new System.Collections.Generic.Dictionary <string, object>());

            api.SendAsync(new List <object>
            {
                new { Prop1 = 1.23, Prop2 = ":)" },
                new { Prop1 = 1.2, Prop2 = ":):)" }
            },

                          (msgs) =>
            {
                Assert.True(msgs.Count == 2);
                Assert.True(((dynamic)msgs[0]).Prop1 == 1.23);
                Assert.True(((dynamic)msgs[1]).Prop2 == ":):)");
            },
                          (msgs, err) =>
            {
                throw err;
            },
                          null).Wait();
        }
Exemple #2
0
        public void TestInit()
        {
            Assert.Throws(typeof(AggregateException), () =>
            {
                IotApi api = new IotApi();

                api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" }).Wait();
            });
        }
Exemple #3
0
        /// <summary>
        /// Format the string input as a XML-RPC Request and return the Response in string. If the operation has fault, it returns an exception message.
        /// </summary>
        /// <param name="ccu">Carrier Object</param>
        /// <param name="m_Request">Local string Request. Input format: "Sensor Action Value"</param>
        /// <param name="m_Result">Response message from server in string</param>
        /// <returns></returns>
        private async Task <string> SendandReceive(IotApi iotApi, string request)
        {
            Ccu ccu = new Ccu();

            var    methodCall = ccu.PrepareMethodCall(request);
            string response   = "";

            await iotApi.SendAsync(methodCall, (responseMessages) =>
            {
                if (MethodResponse.isMethodResponse(responseMessages))
                {
                    MethodResponse res = responseMessages as MethodResponse;

                    if (ccu.isGetList)
                    {
                        response = ccu.GetListDevices(res);
                    }
                    else
                    {
                        if (!ccu.isGetMethod)
                        {
                            // Set Methods do not return any value. Detecting no value means the operation is done
                            if (res.ReceiveParams.Count() == 0)
                            {
                                response = "Operation is done!";
                            }

                            // Set methods can not return any value
                            else
                            {
                                throw new InvalidOperationException("The operation cannot return any value!");
                            }
                        }
                        else
                        {
                            // Get methods must return a value, if not it must be an error
                            if (res.ReceiveParams.Count() == 0)
                            {
                                throw new InvalidOperationException("No value returned or error");
                            }

                            // Collecting the returned value
                            else
                            {
                                response = res.ReceiveParams.First().Value.ToString();
                            }
                        }
                    }
                }
            },
                                   (error) =>
            {
                response = error.Message;
            });

            return(response);
        }
Exemple #4
0
        public void OpenTest()
        {
            Dictionary <string, object> arg = new Dictionary <string, object>();

            arg.Add("endpoint", "opc.tcp://aqib:51210/UA/SampleServer");

            IotApi api = new IotApi();

            api.RegisterModule(new OPCConnector());
            api.Open(arg);
            api.SendAsync("ffff").Wait();
        }
Exemple #5
0
        public void TestOpen_Door()
        {
            IotApi connector = new IotApi()
                               .RegisterModule(new XmlRpc());

            Dictionary <string, object> agr = new Dictionary <string, object>()
            {
                { "Uri", "http://192.168.0.222:2001" },
                { "Mock", false }
            };

            connector.Open(agr);

            MethodCall request = new MethodCall()
            {
                MethodName = "setValue",
                SendParams = new List <Param>()
                {
                    new Param()
                    {
                        Value = (string)"LEQ1335713:1",
                    },
                    new Param()
                    {
                        Value = (string)"STATE",
                    },
                    new Param()
                    {
                        Value = (bool)true,
                    },
                }
            };

            try
            {
                connector.SendAsync(request,
                                    (onMessage) =>
                {
                    Assert.True(onMessage != null);
                },
                                    (error) =>
                {
                    throw error;
                }).Wait();
            }catch (Exception ex)
            {
                Assert.True(ex != null);
            }
        }
Exemple #6
0
        public void TestSimpleSend()
        {
            IotApi api = new IotApi();

            api.Open();

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                          (msgs) =>
            {
            },
                          (msgs, err) =>
            {
            },
                          null).Wait();
            ;
        }
Exemple #7
0
        public void TestSimpleSend()
        {
            IotApi api = new IotApi();

            api.Open();

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                          (msgs) =>
            {
                throw new InvalidOperationException("This should not be executed, because no pipeline is defined!");
            },
                          (msgs, err) =>
            {
                throw new InvalidOperationException("This should not be executed, because no pipeline is defined!");
            },
                          null).Wait();
        }
Exemple #8
0
        public void TestSend()
        {
            IotApi api = new IotApi();

            api.Open(new System.Collections.Generic.Dictionary <string, object>());

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                          (msgs) =>
            {
                Assert.IsTrue(msgs.Count == 1);
                // Assert.IsTrue(((dynamic)msgs[0]).Prop1 == 1.2);
            },
                          (msgs, err) =>
            {
                throw err;
            },
                          null).Wait();
        }
Exemple #9
0
        public void TestSend()
        {
            IotApi api = new IotApi().
                         RegisterModule(getDefaultModule(false));

            api.Open(new System.Collections.Generic.Dictionary <string, object>());

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                          (result) =>
            {
                Assert.True(((dynamic)result).Prop1 == 1.2);
                Assert.True(((dynamic)result).Prop2 == ":)");
            },
                          (msgs, err) =>
            {
                throw err;
            },
                          null).Wait();
        }
Exemple #10
0
        public void TestSendWithRetry()
        {
            IotApi api = new IotApi()
                         .RegisterRetryModule(2, TimeSpan.FromSeconds(1))
                         .RegisterPersistModule(new Dictionary <string, object>())
                         .RegisterModule(getDefaultModule(false));


            api.Open();

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                          (result) =>
            {
                Assert.True(((dynamic)result).Prop1 == 1.2);
            },
                          (msgs, err) =>
            {
                throw err;
            },
                          null).Wait();
        }
Exemple #11
0
        public void NodeWriteTest()
        {
            Dictionary <string, object> arg = new Dictionary <string, object>();

            arg.Add("endpoint", "opc.tcp://aqib:51210/UA/SampleServer");

            IotApi api = new IotApi();

            api.RegisterModule(new OPCConnector());
            api.Open(arg);


            var list = new List <MonitoredItem> {
                new MonitoredItem(new Subscription().DefaultItem)
                {
                    DisplayName = "ServerStatusCurrentTime", StartNodeId = "i=2267"
                }
            };

            api.SendAsync(list).Wait();
            //
        }
Exemple #12
0
        public void TestSendWithRetry()
        {
            IotApi api = new IotApi();

            api
            .RegisterRetry(2, TimeSpan.FromSeconds(1))
            .RegisterPersist(new Dictionary <string, object>())
            .RegisterModule(getDefaultModule(true));

            api.Open(new System.Collections.Generic.Dictionary <string, object>());

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                          (msgs) =>
            {
                Assert.IsTrue(msgs.Count == 1);
            },
                          (msgs, err) =>
            {
                throw err;
            },
                          null).Wait();
        }
Exemple #13
0
        public static void RegisterTest()
        {
            IotApi api = new IotApi();

            api.RegisterModule(new MQTTSnConnector());

            Dictionary <string, object> agr = new Dictionary <string, object>();

            agr.Add("ip", "127.0.0.1");

            agr.Add("port", 100);

            api.Open(agr);

            MessageInterface.RegisterWrk register = new MessageInterface.RegisterWrk();
            register.register.topicId   = new byte[] { };
            register.register.topicName = ASCIIEncoding.ASCII.GetBytes("");
            register.register.messageId = ASCIIEncoding.ASCII.GetBytes(Convert.ToString(2).PadLeft(2, '0'));
            register.register.length    = Convert.ToByte(6 + "ff".Length);

            api.SendAsync(register);
        }
Exemple #14
0
        public void TestFailSendWithRetry()
        {
            Assert.Throws(typeof(AggregateException), () =>
            {
                IotApi api = new IotApi();
                api
                .RegisterRetryModule(2, TimeSpan.FromSeconds(1))
                .RegisterPersistModule(new Dictionary <string, object>())
                .RegisterModule(getDefaultModule(true));

                api.Open(new System.Collections.Generic.Dictionary <string, object>());

                api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" },
                              (result) =>
                {
                    Assert.True(((dynamic)result).Prop1 == 1.2);
                },
                              (msgs, err) =>
                {
                    throw err;
                },
                              null).Wait();
            });
        }
Exemple #15
0
        public void TestInit()
        {
            IotApi api = new IotApi();

            api.SendAsync(new { Prop1 = 1.2, Prop2 = ":)" }).Wait();
        }