private void SENDDDD(string data) { try { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPHostEntry hostEntry = Dns.GetHostEntry(TenMayDangGoi); IPAddress[] addressList = hostEntry.AddressList; IPAddress[] array = addressList; IPAddress address = default(IPAddress); foreach (IPAddress iPAddress in array) { if (iPAddress.AddressFamily == AddressFamily.InterNetwork) { address = iPAddress; break; } } IPEndPoint remoteEP = new IPEndPoint(address, 15123); socket.SendTimeout = 1000; socket.Connect(remoteEP); byte[] bytes = Encoding.ASCII.GetBytes(data); socket.Send(bytes, bytes.Length, SocketFlags.None); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception ex2 = ex; StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(3, "Kết nối bị lỗi."); ProjectData.ClearProjectError(); } }
public HTransportManager(HTransport tranpsport) { this.Transport = tranpsport; this.Transport.onData += Transport_onData; this.Transport.onStatus += Transport_onStatus; ConnectionProfile internetConnectProfile = NetworkInformation.GetInternetConnectionProfile(); if (internetConnectProfile == null) { this.hasNetwork = false; } else { switch (internetConnectProfile.GetNetworkConnectivityLevel()) { case NetworkConnectivityLevel.None: this.hasNetwork = false; break; case NetworkConnectivityLevel.LocalAccess: case NetworkConnectivityLevel.InternetAccess: case NetworkConnectivityLevel.ConstrainedInternetAccess: this.hasNetwork = true; break; } } networkStatusChangedCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChanged); if (!registeredNetworkStatusNotif) { NetworkInformation.NetworkStatusChanged += networkStatusChangedCallback; registeredNetworkStatusNotif = true; } }
public void ExtractAndIdentifyTarFiles() { var uuid = Uuid.Of("c3db9d4e-720c-4f75-bfb6-de90231dc44c"); string pathToExtractedFilesRegex = ArkadeProcessingArea.WorkDirectory.FullName + Path.DirectorySeparatorChar + "..............-" + uuid + Path.DirectorySeparatorChar + uuid; pathToExtractedFilesRegex = pathToExtractedFilesRegex.Replace("\\", "\\\\"); var extractorMock = new Mock <ICompressionUtility>(); extractorMock.Setup(e => e.ExtractFolderFromArchive(It.IsAny <FileInfo>(), It.IsAny <DirectoryInfo>())); var archiveType = ArchiveType.Noark5; var identifierMock = new Mock <IArchiveIdentifier>(); identifierMock.Setup(i => i.Identify(It.IsAny <string>())).Returns(archiveType); var statusEventHandler = new StatusEventHandler(); string file = TestUtil.TestDataDirectory + Path.DirectorySeparatorChar + "tar" + Path.DirectorySeparatorChar + "Noark3-eksempel-1" + Path.DirectorySeparatorChar + uuid + ".tar"; TestSession testSession = new TestSessionFactory(extractorMock.Object, statusEventHandler) .NewSession(ArchiveFile.Read(file, archiveType)); var archive = testSession.Archive; archive.Should().NotBeNull(); archive.Uuid.Should().Be(uuid); archive.WorkingDirectory.Root().DirectoryInfo().FullName.Should().MatchRegex(pathToExtractedFilesRegex); archive.ArchiveType.Should().Be(archiveType); System.IO.Directory.Delete(archive.WorkingDirectory.Root().DirectoryInfo().FullName, true); }
private static void RegisterEvent(string eventName, StatusEventHandler handler) { _eventLock.Write(() => { _events.Add(eventName, handler); }); }
public override bool Connect(string deviceName) { if (!port.IsOpen) { if (!ConnectToBluegiga()) { return(false); } } bool commandStarted = false; bool connectionEst = false; byte connectionHandle = 0; AutoResetEvent resp = new AutoResetEvent(false); ConnectDirectEventHandler connectResp = delegate(object sender, ConnectDirectEventArgs e) { if (e.result == 0) { commandStarted = true; connectionHandle = e.connection_handle; resp.Set(); } }; StatusEventHandler connectionStatus = delegate(object sender, StatusEventArgs e) { connectionEst = true; resp.Set(); }; bluetooth.BLEResponseGAPConnectDirect += connectResp; bluetooth.BLEEventConnectionStatus += connectionStatus; foreach (BluetoothDevice device in discoveredDevices) { if (device.Name.Equals(deviceName)) { this.device = device; bluetooth.SendCommand(this.port, bluetooth.BLECommandGAPConnectDirect(device.BluetoothAddress, 0, 20, 40, 100, 1)); resp.WaitOne(200); if (commandStarted) { this.device.ConnectionHandle = connectionHandle; resp.WaitOne(1000); } break; } } bluetooth.BLEResponseGAPConnectDirect -= connectResp; bluetooth.BLEEventConnectionStatus -= connectionStatus; if (connectionEst) { isConnected = true; } return(connectionEst); }
internal virtual void OnStatusEvent(object sender, StatusEventArgs e) { nlogger.Info("RemoteConnectLib::OnStatusEvent start[EventType:{0}] [Text:{1}]", e.EventType, e.Text); // If keep alive event then set KeepAliveArrived if ((Enums.eventInts)e.EventType == eventInts.KeepAliveEvent) { // Mask bug in BladeRunner 1.5++ for SCS 1.0 if (e.Text == "StatusEvent " + Constants.CommTestString) { e.EventType = (int)eventInts.PingStatusEvent; } else { _KeepAliveArrived = true; return; } } StatusEventHandler handler = _ComStatusEvent; if (handler != null) { // Invokes the delegates. handler(this, e); } }
private void GenerateStatusEvent(StatusEventArgs args) { if (StatusEventHandler != null && StatusEventHandler.GetInvocationList().Length > 0) { StatusEventHandler(this, args); } }
public HTransportManager(HTransport tranpsport) { this.Transport = tranpsport; this.Transport.onData += Transport_onData; this.Transport.onStatus += Transport_onStatus; ConnectionProfile internetConnectProfile = NetworkInformation.GetInternetConnectionProfile(); if (internetConnectProfile == null) this.hasNetwork = false; else { switch (internetConnectProfile.GetNetworkConnectivityLevel()) { case NetworkConnectivityLevel.None: this.hasNetwork = false; break; case NetworkConnectivityLevel.LocalAccess: case NetworkConnectivityLevel.InternetAccess: case NetworkConnectivityLevel.ConstrainedInternetAccess: this.hasNetwork = true; break; } } networkStatusChangedCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChanged); if (!registeredNetworkStatusNotif) { NetworkInformation.NetworkStatusChanged += networkStatusChangedCallback; registeredNetworkStatusNotif = true; } }
public void RemoveStatusEventHandler(EventHandler <StatusEventArgs> statusEventHandler) { if (StatusEventHandler != null) { if (Array.IndexOf(StatusEventHandler.GetInvocationList(), statusEventHandler) != -1) { StatusEventHandler -= statusEventHandler; } } }
/// <summary> /// 调用主窗口函数 /// </summary> /// <param name="str"></param> public void SendStatusLabel(string str) { StatusEventHandler handler = StatusLabelEvent; EventsClass.StatusEventArgs e = new EventsClass.StatusEventArgs(str); if (handler != null) { handler(this, e); } }
public static void FireStatus(object sender, StatusEventHandler eventHandler, string str, System.Drawing.Color c) { //StatusEventHandler handler = eventHandler; if (eventHandler != null) { StatusEventArgs args = new StatusEventArgs(); args.Text = str; args.TextColor = c; eventHandler(sender, args); } }
public void AddStatusEventHandler(EventHandler <StatusEventArgs> statusEventHandler) { if (StatusEventHandler == null) { StatusEventHandler += statusEventHandler; } else { if (Array.IndexOf(StatusEventHandler.GetInvocationList(), statusEventHandler) == -1) { StatusEventHandler += statusEventHandler; } } }
public StatusEventArgs Execute() { Byte[] connect = Ble.Lib.BLECommandGAPConnectDirect((byte[])this.ServiceUUID, this.Address, 0x20, 0x30, 0x100, 0); StatusEventHandler handler = this.FindConnection; Ble.Lib.BLEEventConnectionStatus += handler; Ble.SendCommand(this.Port, connect); this.WaitEvent(() => _connectionResponse != null); Ble.Lib.BLEEventConnectionStatus -= handler; // not needed anymore return(_connectionResponse); }
public GithubWebhookController( IssueCommentEventHandler issueCommentEventHandler, PullRequestReviewEventHandler pullRequestReviewEventHandler, PullRequestEventHandler pullRequestEventHandler, PushEventHandler pushEventHandler, StatusEventHandler statusEventHandler) { handlers = new Dictionary <string, Func <JObject, Task <WebhookResponse> > > { { "issue_comment", data => issueCommentEventHandler.Handle(data.ToObject <IssueCommentEvent>()) }, { "pull_request_review", data => pullRequestReviewEventHandler.Handle(data.ToObject <PullRequestReviewEvent>()) }, { "pull_request", data => pullRequestEventHandler.Handle(data.ToObject <PullRequestEvent>()) }, { "status", data => statusEventHandler.Handle(data.ToObject <StatusEvent>()) }, { "push", data => pushEventHandler.Handle(data.ToObject <PushEvent>()) }, }; }
private void KiemTra() { checked { while (true) { if (flagSrarting) { if (countKiemTra < 3) { Thread.Sleep(1000); countKiemTra++; Sendata("ONCALL"); continue; } break; } return; } flagSrarting = false; countKiemTra = 0; try { udpRecive.Close(); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception ex2 = ex; ProjectData.ClearProjectError(); } try { udpSend.Close(); } catch (Exception ex3) { ProjectData.SetProjectError(ex3); Exception ex4 = ex3; ProjectData.ClearProjectError(); } flagSrarting = false; countKiemTra = 0; StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(1, TenMayDangGoi); } }
public HTransportManager(HTransport tranpsport) { this.Transport = tranpsport; this.Transport.onData += Transport_onData; this.Transport.onStatus += Transport_onStatus; if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType == NetworkInterfaceType.None) this.hasNetwork = false; else this.hasNetwork = true; networkStatusChangedCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChanged); if (!registeredNetworkStatusNotif) { NetworkInformation.NetworkStatusChanged += networkStatusChangedCallback; registeredNetworkStatusNotif = true; } }
public void EndCall() { flagSrarting = false; countKiemTra = 0; try { udpRecive.Close(); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception ex2 = ex; ProjectData.ClearProjectError(); } try { udpSend.Close(); } catch (Exception ex3) { ProjectData.SetProjectError(ex3); Exception ex4 = ex3; ProjectData.ClearProjectError(); } flagSrarting = false; countKiemTra = 0; try { Sendata("ENDCALL"); } catch (Exception ex5) { ProjectData.SetProjectError(ex5); Exception ex6 = ex5; ProjectData.ClearProjectError(); } StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(1, TenMayDangGoi); }
/// <summary> /// 仅针对类型<typeparamref name="T"/>注册状态事件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="eventType"></param> /// <param name="action"></param> public static void Register <T>(StatusEventType eventType, StatusEventHandler handler) where T : IDomainObject { Register(typeof(T), eventType, handler); }
public void XuLyData(Socket sock) { string text = ""; try { byte[] array = new byte[1025]; sock.ReceiveTimeout = 3000; int length = sock.Receive(array, array.Length, SocketFlags.None); text = Encoding.ASCII.GetString(array, 0, array.Length); string text2 = text.Substring(0, length); string left = text2; if (Operators.CompareString(left, "ENDCALL", false) == 0) { flagSrarting = false; countKiemTra = 0; try { udpRecive.Close(); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception ex2 = ex; ProjectData.ClearProjectError(); } try { udpSend.Close(); } catch (Exception ex3) { ProjectData.SetProjectError(ex3); Exception ex4 = ex3; ProjectData.ClearProjectError(); } flagSrarting = false; countKiemTra = 0; StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(1, TenMayDangGoi); } else if (Operators.CompareString(left, "BUSY", false) == 0) { StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(0, TenMayDangGoi); } else if (Operators.CompareString(left, "ONCALL", false) == 0) { countKiemTra = 0; } else if (Operators.CompareString(left, "OK", false) == 0) { flagSrarting = true; IPHostEntry hostEntry = Dns.GetHostEntry(TenMayDangGoi); IPAddress[] addressList = hostEntry.AddressList; IPAddress[] array2 = addressList; IPAddress address = default(IPAddress); foreach (IPAddress iPAddress in array2) { if (iPAddress.AddressFamily == AddressFamily.InterNetwork) { address = iPAddress; break; } } udpSend = new UdpClient(); udpRecive = new UdpClient(15346); send_Com = new IPEndPoint(address, 15345); recive_Com = new IPEndPoint(address, 15346); Thread thread = new Thread(Send); thread.Start(); Thread thread2 = new Thread(Receive); thread2.Start(); Thread thread3 = new Thread(KiemTra); thread3.Start(); StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(2, TenMayDangGoi); } else if (flagSrarting) { Sendata("BUSY"); } else { TenMayDangGoi = text2; flagSrarting = true; Sendata("OK"); udpSend = new UdpClient(); udpRecive = new UdpClient(15345); IPHostEntry hostEntry2 = Dns.GetHostEntry(TenMayDangGoi); IPAddress[] addressList2 = hostEntry2.AddressList; IPAddress[] array3 = addressList2; IPAddress address2 = default(IPAddress); foreach (IPAddress iPAddress2 in array3) { if (iPAddress2.AddressFamily == AddressFamily.InterNetwork) { address2 = iPAddress2; break; } } send_Com = new IPEndPoint(address2, 15346); recive_Com = new IPEndPoint(address2, 15345); Thread thread4 = new Thread(Send); thread4.Start(); Thread thread5 = new Thread(Receive); thread5.Start(); Thread thread6 = new Thread(KiemTra); thread6.Start(); StatusEventHandler statusEvent = StatusEvent; statusEvent?.Invoke(2, TenMayDangGoi); } } catch (Exception ex5) { ProjectData.SetProjectError(ex5); Exception ex6 = ex5; ProjectData.ClearProjectError(); } sock.Close(); }
public static void FireStatusInfo(object sender, StatusEventHandler eventHandler, string str) { FireStatus(sender, eventHandler, str, System.Drawing.Color.Blue); }
public static void FireStatusError(object sender, StatusEventHandler eventHandler, string str) { FireStatus(sender, eventHandler, str, System.Drawing.Color.Red); }
/// <summary> /// 注册全局状态事件,任何对象的状态改变都会触发该事件 /// </summary> /// <param name="eventType"></param> /// <param name="action"></param> public static void Register(StatusEventType eventType, StatusEventHandler handler) { string eventName = GetEventName(typeof(IDomainObject), eventType); RegisterEvent(eventName, handler); }
/// <summary> /// 仅针对类型<paramref name="objectType"/>注册状态事件 /// </summary> /// <typeparam name="objectType"></typeparam> /// <param name="eventType"></param> /// <param name="action"></param> public static void Register(Type objectType, StatusEventType eventType, StatusEventHandler handler) { string eventName = GetEventName(objectType, eventType); RegisterEvent(eventName, handler); }
public void SetLogHandler(NNTPClient nc) { logfile = new StatusEventHandler(ListChanged); nc.StatusMessage += logfile; // new StatusEventHandler(LogForm.ListChanged); }