public void TestConnectFutureSuccessTiming() { Int32 port = 12345; IoAcceptor acceptor = CreateAcceptor(); acceptor.Bind(CreateEndPoint(port)); StringBuilder buf = new StringBuilder(); try { IoConnector connector = CreateConnector(); connector.SessionCreated += (s, e) => buf.Append("1"); connector.SessionOpened += (s, e) => buf.Append("2"); connector.ExceptionCaught += (s, e) => buf.Append("X"); IConnectFuture future = connector.Connect(CreateEndPoint(port)); future.Await(); buf.Append("3"); future.Session.Close(true); // sessionCreated() will fire before the connect future completes // but sessionOpened() may not Assert.IsTrue(new Regex("12?32?").IsMatch(buf.ToString())); } finally { acceptor.Unbind(); acceptor.Dispose(); } }
public virtual void TestConnectFutureFailureTiming() { Int32 port = 12345; StringBuilder buf = new StringBuilder(); IoConnector connector = CreateConnector(); connector.SessionCreated += (s, e) => buf.Append("X"); connector.SessionOpened += (s, e) => buf.Append("Y"); connector.ExceptionCaught += (s, e) => buf.Append("Z"); try { IConnectFuture future = connector.Connect(CreateEndPoint(port)); future.Await(); buf.Append("1"); try { future.Session.Close(true); Assert.Fail(); } catch { // Signifies a successful test execution Assert.IsTrue(true); } Assert.AreEqual("1", buf.ToString()); } finally { connector.Dispose(); } }
public DeviceSinamicsG(DeviceExtended deviceextended) { this.deviceUserGroup = deviceextended.usergroup; this.device = deviceextended.device; driveObject = device.DeviceItems[1].GetService <DriveObjectContainer>().DriveObjects[0]; safetyTelegram = driveObject.Telegrams.Find(TelegramType.SafetyTelegram); mainTelegram = driveObject.Telegrams.Find(TelegramType.MainTelegram); additionalTelegram = driveObject.Telegrams.Find(TelegramType.AdditionalTelegram); supplementaryTelegram = driveObject.Telegrams.Find(TelegramType.SupplementaryTelegram); profinetInterface = getProfinetInetface(); ioConnector = profinetInterface.IoConnectors[0]; node = profinetInterface.Nodes[0]; Name = device.DeviceItems[1].Name; PowerModule = device.DeviceItems[2].TypeIdentifier; safetyAddress = GetSafetyAddress(); safetHwAddress_in = getSafetyHwAddressIn(); safetHwAddress_out = getSafetyHwAddressOut(); hwAddress_in = getHwAddressIn(); hwAddress_out = getHwAddressOut(); hwAddress_supp_in = getHwAddressSuppIn(); hwAddress_supp_out = getHwAddressSuppOut(); hwAddress_add_in = getHwAddressAddIn(); hwAddress_add_out = getHwAddressAddOut(); ioSystem = ioConnector.ConnectedToIoSystem; subnet = node.ConnectedSubnet; ipAddress = node.GetAttribute("Address").ToString(); pnDeviceNameAuto = node.GetAttribute("PnDeviceNameAutoGeneration").ToString(); pnDeviceName = node.GetAttribute("PnDeviceName").ToString(); PnDeviceNumber = (int)ioConnector.GetAttribute("PnDeviceNumber"); networkPorts = GetNetworkPorts(); }
public void TestUnbindDisconnectsClients() { Bind(true); IoConnector connector = NewConnector(); IoSession[] sessions = new IoSession[5]; for (int i = 0; i < sessions.Length; i++) { IConnectFuture future = connector.Connect(CreateEndPoint(port)); future.Await(); sessions[i] = future.Session; Assert.IsTrue(sessions[i].Connected); Assert.IsTrue(sessions[i].Write(IoBuffer.Allocate(1)).Await().Written); } // Wait for the server side sessions to be created. Thread.Sleep(500); ICollection <IoSession> managedSessions = acceptor.ManagedSessions.Values; Assert.AreEqual(5, managedSessions.Count); acceptor.Unbind(); // Wait for the client side sessions to close. Thread.Sleep(500); //Assert.AreEqual(0, managedSessions.Count); foreach (IoSession element in managedSessions) { Assert.IsFalse(element.Connected); } }
public void Connect(IPEndPoint target) { Connector = new AsyncSocketConnector(); Connector.ConnectTimeoutInMillis = 10000; //Connector.FilterChain.AddLast("logging", new LoggingFilter()); Connector.Handler = this; //var ssl = new CustomSslFilter((X509Certificate)null); //ssl.SslProtocol = System.Security.Authentication.SslProtocols.Tls; //Connector.FilterChain.AddFirst("ssl", ssl); Connector.FilterChain.AddLast("protocol", new ProtocolCodecFilter(new AriesProtocol(Kernel))); var future = Connector.Connect(target, new Action <IoSession, IConnectFuture>(OnConnect)); Task.Run(() => { if (!future.Await(10000)) { SessionClosed(null); } if (future.Canceled || future.Exception != null) { SessionClosed(null); } }); }
public void Connect(IPEndPoint target) { Connector = new AsyncSocketConnector(); Connector.ConnectTimeoutInMillis = 10000; Connector.Handler = this; Connector.FilterChain.AddLast("protocol", new ProtocolCodecFilter(new FSOSandboxProtocol())); Connector.Connect(target, new Action <IoSession, IConnectFuture>(OnConnect)); }
public void Connect(IPEndPoint target) { if (Connector != null) { //old connector might still be establishing connection... //we need to stop that Connector.Handler = new NullIOHandler(); //don't hmu //we can't cancel a mina.net connector, but we can sure as hell ~~avenge it~~ stop it from firing events. //if we tried to dispose it, we'd get random disposed object exceptions because mina doesn't expect you to cancel that early. Disconnect(); //if we have already established a connection, make sure it is closed. } Connector = new AsyncSocketConnector(); var connector = Connector; Connector.ConnectTimeoutInMillis = 10000; //Connector.FilterChain.AddLast("logging", new LoggingFilter()); Connector.Handler = this; //var ssl = new CustomSslFilter((X509Certificate)null); //ssl.SslProtocol = System.Security.Authentication.SslProtocols.Tls; //Connector.FilterChain.AddFirst("ssl", ssl); Connector.FilterChain.AddLast("protocol", new ProtocolCodecFilter(new AriesProtocol(Kernel))); var future = Connector.Connect(target, (IoSession session, IConnectFuture future2) => { if (future2.Canceled || future2.Exception != null) { if (connector.Handler != null) { SessionClosed(session); } } if (connector.Handler is NullIOHandler) { session.Close(true); } else { this.Session = session; } }); Task.Run(() => { if (!future.Await(10000)) { SessionClosed(null); } if (future.Canceled || future.Exception != null) { SessionClosed(null); } }); }
private void CreateAndConnectIOSystem() { Subnet mySubnet = null; foreach (var subnet in MyProject.Subnets) { mySubnet = subnet; SetTextInRichTextBox(Color.Black, $"[{subnet.Name}] is founded"); } foreach (IoSystem ioSystem1 in mySubnet.IoSystems) { SetTextInRichTextBox(Color.Black, $"[{ioSystem1.Name}] is founded"); } NetworkInterface networkInterface = null; IoSystem ioSystem = null; foreach (Device device in MyProject.Devices) { foreach (DeviceItem Dev1 in device.DeviceItems) { foreach (DeviceItem Dev2 in Dev1.DeviceItems) { if (Dev2.Name == "PROFINET interface_1" || Dev2.Name == "PROFINET interface" || Dev2.Name == "PROFINET Interface_1" || Dev2.Name == "SCALANCE interface_1") { networkInterface = ((IEngineeringServiceProvider)Dev2).GetService <NetworkInterface>(); if ((networkInterface.InterfaceOperatingMode & InterfaceOperatingModes.IoController) != 0) { SetTextInRichTextBox(Color.Black, "Bingo IO Controller"); IoControllerComposition ioControllers = networkInterface.IoControllers; IoController ioController = ioControllers.First(); if (ioController.IoSystem != null) { SetTextInRichTextBox(Color.Blue, $"{ioController.IoSystem.Name} IO system is already connected"); } if ((ioController != null) && (ioController.IoSystem == null)) { ioSystem = ioController.CreateIoSystem(""); } } if ((networkInterface.InterfaceOperatingMode & InterfaceOperatingModes.IoDevice) != 0) { SetTextInRichTextBox(Color.Black, "Bingo IO Device"); IoConnectorComposition ioConnectors = networkInterface.IoConnectors; IoConnector ioConnector = ioConnectors.First(); if (ioConnector != null) { ioConnector.ConnectToIoSystem(ioSystem); } } } } } } }
public void TestSessionCallbackInvocation() { Int32 callbackInvoked = 0; Int32 sessionCreatedInvoked = 1; Int32 sessionCreatedInvokedBeforeCallback = 2; Boolean[] assertions = { false, false, false }; CountdownEvent countdown = new CountdownEvent(2); IConnectFuture[] callbackFuture = new IConnectFuture[1]; Int32 port = 12345; IoAcceptor acceptor = CreateAcceptor(); IoConnector connector = CreateConnector(); try { acceptor.Bind(CreateEndPoint(port)); connector.SessionCreated += (s, e) => { assertions[sessionCreatedInvoked] = true; assertions[sessionCreatedInvokedBeforeCallback] = !assertions[callbackInvoked]; countdown.Signal(); }; IConnectFuture future = connector.Connect(CreateEndPoint(port), (s, f) => { assertions[callbackInvoked] = true; callbackFuture[0] = f; countdown.Signal(); }); Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(5)), "Timed out waiting for callback and IoHandler.sessionCreated to be invoked"); Assert.IsTrue(assertions[callbackInvoked], "Callback was not invoked"); Assert.IsTrue(assertions[sessionCreatedInvoked], "IoHandler.sessionCreated was not invoked"); Assert.IsFalse(assertions[sessionCreatedInvokedBeforeCallback], "IoHandler.sessionCreated was invoked before session callback"); Assert.AreSame(future, callbackFuture[0], "Callback future should have been same future as returned by connect"); } finally { try { connector.Dispose(); } finally { acceptor.Dispose(); } } }
public void Connect(IPEndPoint target) { Connector = new AsyncSocketConnector(); Connector.ConnectTimeoutInMillis = 10000; //Connector.FilterChain.AddLast("logging", new LoggingFilter()); Connector.Handler = this; //var ssl = new CustomSslFilter((X509Certificate)null); //ssl.SslProtocol = System.Security.Authentication.SslProtocols.Tls; //Connector.FilterChain.AddFirst("ssl", ssl); Connector.FilterChain.AddLast("protocol", new ProtocolCodecFilter(new AriesProtocol(Kernel))); Connector.Connect(target, new Action <IoSession, IConnectFuture>(OnConnect)); }
public void Start() { connector = new AsyncDatagramConnector(); connector.FilterChain.AddLast("RTPS", new ProtocolCodecFilter(new MessageCodecFactory())); connector.ExceptionCaught += (s, e) => { Console.WriteLine(e.Exception); }; connector.MessageReceived += (s, e) => { Console.WriteLine("Session recv..."); }; connector.MessageSent += (s, e) => { Console.WriteLine("Session sent..."); }; connector.SessionCreated += (s, e) => { Console.WriteLine("Session created..."); }; connector.SessionOpened += (s, e) => { Console.WriteLine("Session opened..."); }; connector.SessionClosed += (s, e) => { Console.WriteLine("Session closed..."); }; connector.SessionIdle += (s, e) => { Console.WriteLine("Session idle..."); }; IConnectFuture connFuture = connector.Connect(new IPEndPoint(locator.SocketAddress, locator.Port)); connFuture.Await(); connFuture.Complete += (s, e) => { IConnectFuture f = (IConnectFuture)e.Future; if (f.Connected) { Console.WriteLine("...connected"); session = f.Session; } else { Console.WriteLine("Not connected...exiting"); } }; }
public void TestUnbindResume() { Bind(true); IoConnector connector = NewConnector(); IoSession session = null; IConnectFuture future = connector.Connect(CreateEndPoint(port)); future.Await(); session = future.Session; Assert.IsTrue(session.Connected); Assert.IsTrue(session.Write(IoBuffer.Allocate(1)).Await().Written); // Wait for the server side session to be created. Thread.Sleep(500); ICollection <IoSession> managedSession = acceptor.ManagedSessions.Values; Assert.AreEqual(1, managedSession.Count); acceptor.Unbind(); // Wait for the client side sessions to close. Thread.Sleep(500); //Assert.AreEqual(0, managedSession.Count); foreach (IoSession element in managedSession) { Assert.IsFalse(element.Connected); } // Rebind Bind(true); // Check again the connection future = connector.Connect(CreateEndPoint(port)); future.Await(); session = future.Session; Assert.IsTrue(session.Connected); Assert.IsTrue(session.Write(IoBuffer.Allocate(1)).Await().Written); // Wait for the server side session to be created. Thread.Sleep(500); managedSession = acceptor.ManagedSessions.Values; Assert.AreEqual(1, managedSession.Count); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public ShellViewModel() { //获取事件聚合器 _aggregator = ServiceLocator.Current.GetInstance<IEventAggregator>(); _aggregator.GetEvent<UpdateFileCollectionEvent>().Subscribe(updateFileCollection => { UpdateInfo = $"更新包编译日期:{updateFileCollection.ReleaseTime}\r\n更新内容:{updateFileCollection.Description}"; }); if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) { // Code runs in Blend --> create design time data. } else { //获取Socket _connector = ServiceLocator.Current.GetInstance<IoConnector>(); } }
/// <summary> /// Constructor /// </summary> /// <param name="ipAddress"></param> /// <param name="portNo"></param> private void init(IPAddress ipAddress, int portNo) { try { // 1. CONNECTOR 를 생성한다. this.connector = new AsyncSocketConnector(); this.connector.FilterChain.AddLast("logger", new LoggingFilter()); ObjectSerializationCodecFactory objectSerializationCodecFactory = new ObjectSerializationCodecFactory(); objectSerializationCodecFactory.EncoderMaxObjectSize = CommConst.MAX_TRANSDATA_SIZE; this.connector.FilterChain.AddLast("codec", new ProtocolCodecFilter(objectSerializationCodecFactory)); this.connector.SessionClosed += (o, e) => OnSessionClosed(); this.connector.MessageReceived += OnMessageReceived; // 2. 상대방에게 접속을 시도한다. this.endPoint = new IPEndPoint(ipAddress, portNo); this.Connect(); } catch (Exception ex) { throw new Exception(String.Format("{0}:{1}에 연결할 수 없습니다.", ipAddress, portNo), ex); } }
private void SetNetwork(Device device, Subnet subnet, IoSystem ioSystem, string ipAddress, string pnDeviceNameAuto, string pnDeviceName, int PnDeviceNumber) { foreach (DeviceItem deviceItem in device.DeviceItems[1].DeviceItems) { if (deviceItem.Name.Contains("PROFINET")) { IoConnector ioConnector = deviceItem.GetService <NetworkInterface>().IoConnectors[0]; Node node = deviceItem.GetService <NetworkInterface>().Nodes[0]; node.ConnectToSubnet(subnet); ioConnector.ConnectToIoSystem(ioSystem); node.SetAttribute("Address", ipAddress); ioConnector.SetAttribute("PnDeviceNumber", PnDeviceNumber); if (pnDeviceNameAuto.Equals("False")) { node.SetAttribute("PnDeviceNameAutoGeneration", false); node.SetAttribute("PnDeviceName", pnDeviceName); } } } }
public void SetUp() { result = ""; acceptor = new AsyncDatagramAcceptor(); connector = new AsyncDatagramConnector(); }
void Awake() { _instance = this; _startSelected = false; }
public void TestSendLargeFile() { Assert.AreEqual(FILE_SIZE, file.Length, "Test file not as big as specified"); CountdownEvent countdown = new CountdownEvent(1); Boolean[] success = { false }; Exception[] exception = { null }; Int32 port = 12345; IoAcceptor acceptor = CreateAcceptor(); IoConnector connector = CreateConnector(); try { acceptor.ExceptionCaught += (s, e) => { exception[0] = e.Exception; e.Session.Close(true); }; Int32 index = 0; acceptor.MessageReceived += (s, e) => { IoBuffer buffer = (IoBuffer)e.Message; while (buffer.HasRemaining) { int x = buffer.GetInt32(); if (x != index) { throw new Exception(String.Format("Integer at {0} was {1} but should have been {0}", index, x)); } index++; } if (index > FILE_SIZE / 4) { throw new Exception("Read too much data"); } if (index == FILE_SIZE / 4) { success[0] = true; e.Session.Close(true); } }; acceptor.Bind(CreateEndPoint(port)); connector.ExceptionCaught += (s, e) => { exception[0] = e.Exception; e.Session.Close(true); }; connector.SessionClosed += (s, e) => countdown.Signal(); IConnectFuture future = connector.Connect(CreateEndPoint(port)); future.Await(); IoSession session = future.Session; session.Write(file); countdown.Wait(); if (exception[0] != null) { throw exception[0]; } Assert.IsTrue(success[0], "Did not complete file transfer successfully"); Assert.AreEqual(1, session.WrittenMessages, "Written messages should be 1 (we wrote one file)"); Assert.AreEqual(FILE_SIZE, session.WrittenBytes, "Written bytes should match file size"); } finally { try { connector.Dispose(); } finally { acceptor.Dispose(); } } }