示例#1
0
文件: UaTest.cs 项目: mrvluiz/h-opc
        public void UaTestSessionRecreate()
        {
            var client = new TestExtendUaClient(new Uri(ConfigurationManager.AppSettings["UATestEndpoint"]));

            client.Connect();
            var     i          = 0;
            Session oldSession = null;

            client.ServerConnectionLost += (object sender, EventArgs e) =>
            {
                if (i > 0)
                {
                    return;
                }
                i++;
                Assert.AreEqual(OpcStatus.NotConnected, client.Status);
                // store the session to make sure a new one is created
                oldSession = client.SessionExtended;
                client.RecreateSession();
                // put server back in good working order
                client.SessionExtended.OperationTimeout  = 200;
                client.SessionExtended.KeepAliveInterval = 100;
            };
            client.SessionExtended.OperationTimeout  = 0;
            client.SessionExtended.KeepAliveInterval = 10;
            Thread.Sleep(100);
            Assert.Greater(i, 0);
            // Give some time to call recreate
            Thread.Sleep(100);
            Assert.AreNotSame(oldSession, client.SessionExtended);
        }
示例#2
0
文件: UaTest.cs 项目: mrvluiz/h-opc
        public void UaTestKeepAliveNotifyDisconnect()
        {
            var client = new TestExtendUaClient(new Uri(ConfigurationManager.AppSettings["UATestEndpoint"]));

            client.Connect();
            var i = 0;

            client.ServerConnectionLost += (object sender, EventArgs e) =>
            {
                i++;
            };

            /* Basicallly kill server by not letting any
             * operations complete */
            client.SessionExtended.OperationTimeout = 0;
            // make sure sessionkeepalive executes at least once
            client.SessionExtended.KeepAliveInterval = 10;
            // give ample time to call sessionkeepalive
            Thread.Sleep(100);

            /* 'i' should only be one because SessionKeepAlive
             * only calls ServerConnectionLost if Status
             * is connected. Before it calls
             * ServerConnectionLost, it sets Status to
             * NotConnected */
            Assert.AreEqual(1, i);
        }
示例#3
0
文件: UaTest.cs 项目: mrvluiz/h-opc
        public void UaTestExtension()
        {
            var client = new TestExtendUaClient(new Uri(ConfigurationManager.AppSettings["UATestEndpoint"]));

            client.Connect();
            Assert.IsInstanceOf(typeof(Session), client.SessionExtended);
        }
示例#4
0
文件: UaTest.cs 项目: mrvluiz/h-opc
        public void UaTestReConnect()
        {
            var client = new TestExtendUaClient(new Uri(ConfigurationManager.AppSettings["UATestEndpoint"]));

            /* Should throw error because session should not be
             * initialized without calling connect */
            Assert.Throws <System.NullReferenceException>(() => client.ReConnect());
        }