/// <summary> Constructor for SocketServer Suppport </summary> /// <param name="socketServer"> A Reference to the parent SocketServer </param> /// <param name="clientSocket"> The Socket object we are encapsulating </param> /// <param name="socketListArray"> The index of the SocketServer Socket List Array </param> /// <param name="ipAddress"> The IpAddress of the remote server </param> /// <param name="port"> The Port of the remote server </param> /// <param name="messageHandler"> Reference to the user defined message handler function </param> /// <param name="closeHandler"> Reference to the user defined close handler function </param> /// <param name="errorHandler"> Reference to the user defined error handler function </param> /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param> /// <param name="userArg"> A Reference to the Users arguments </param> public SocketClient(SocketServer socketServer, Socket clientSocket, string ipAddress, int port, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) : this(sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler) { // Set reference to SocketServer this.socketServer = socketServer; // Init the socket references this.clientSocket = clientSocket; // Set the Ipaddress and Port this.ipAddress = ipAddress; this.port = port; // Init the NetworkStream reference this.networkStream = new NetworkStream(this.clientSocket); // Set these socket options this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReceiveBuffer, this.receiveBufferSize); this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.SendBuffer, this.sendBufferSize); this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.DontLinger, 1); this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Tcp, System.Net.Sockets.SocketOptionName.NoDelay, 1); // Wait for a message Receive(); }
void packet_OnClose(string error) { if (closed) { return; } foreach (MsgInfo broken in incoming.Values) { var bb = broken; bb.Seq.Enqueue(() => { if (!bb.Closed) { bb.Message.End("Connection closed before message finished"); bb.Closed = true; } }); } incoming = null; outgoing = null; closed = true; CloseEventHandler handler = OnClose; if (handler != null) { handler.BeginInvoke(error, null, null); } }
void OnRequestClose() { CloseEventHandler handler = this.RequestClose; if (handler != null) { handler(this, new CloseEventArgs(1)); } }
/// <summary> /// Закрытие нескольких панелей /// </summary> /// <param name="numPageForClose">количество закрываемых панелей</param> public void CloseAnyPage(int numPageForClose) { CloseEventHandler handler = this.RequestClose; if (handler != null) { handler(this, new CloseEventArgs(numPageForClose)); } }
protected virtual SocketClient AcceptedSocketClient(SocketServer socketServer, Socket clientSocket, string ipAddress, int port, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) { return(new SocketClient(socketServer, clientSocket, ipAddress, port, sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler)); }
static void OnClose() { CloseEventHandler handler = Close; if (handler != null) { handler(); } }
void RaiseCloseEvent(string why) { evq.Enqueue(() => { CloseEventHandler ch = OnClose; if (ch != null) { ch(why); } }); }
/// <summary> /// Overloaded constructor for client support /// </summary> /// <param name="sendBufferSize"></param> /// <param name="receiveBufferSize"></param> /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param> /// <param name="userArg"> A Reference to the Users arguments </param> /// <param name="messageHandler"> Reference to the user defined message handler method </param> /// <param name="closeHandler"> Reference to the user defined close handler method </param> /// <param name="errorHandler"> Reference to the user defined error handler method </param> public SocketClient(int sendBufferSize, int receiveBufferSize, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler ) : this(sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler) { //Set the size of the send/receive buffers this.sendBufferSize = sendBufferSize; this.receiveBufferSize = receiveBufferSize; }
private void ShowByOCR_Load(object sender, EventArgs e) { webBrowser1.ObjectForScripting = this; webBrowser1.DocumentText = Properties.Resources.text; textBox1.BackColor = Cache.MainColor; textBox1.ForeColor = label1.ForeColor = label2.ForeColor = Cache.TextColor; BackgroundWorker work = new BackgroundWorker(); work.DoWork += new DoWorkEventHandler(work_DoWork); work.RunWorkerCompleted += new RunWorkerCompletedEventHandler(work_RunWorkerCompleted); work.RunWorkerAsync(this); CloseEvent += new CloseEventHandler(JClosed); }
private void TShowByGetWord_Load(object sender, EventArgs e) { SetLicenseID(LICENSEID); SetDelay(300); webBrowser1.ObjectForScripting = this; webBrowser1.DocumentText = Properties.Resources.text; callbackHighlightReady = new NotifyCallBack(OnHighlightReady); SetHighlightReadyCallback(callbackHighlightReady); callbackMouseMonitor = new NotifyCallBack(OnMouseMonitor); SetMouseMonitorCallback(callbackMouseMonitor); EnableHighlightCapture(true); CloseEvent += new CloseEventHandler(JClosed); }
static void Main(string[] args) { //React to close window event, CTRL-C, kill, etc _handler += new CloseEventHandler(Handler); if (!IsMono) { SetConsoleCtrlHandler(_handler, true); } //Catch unhandled exceptions CrashReporter.DefaultFileName = "ManicDiggerServerCrash.txt"; CrashReporter.EnableGlobalExceptionHandling(true); new Program(args); }
public static void RegisterEvents(this RenderWindow window, Board board, ShapeManager shapeManager) { if (closeEventHandler != null) { window.Closed -= closeEventHandler.HandleEvent; } closeEventHandler = new CloseEventHandler(window); window.Closed += closeEventHandler.HandleEvent; if (mouseButtonEventHandler != null) { window.MouseButtonPressed -= mouseButtonEventHandler.HandleEvent; } mouseButtonEventHandler = new MouseButtonEventHandler(window, board, shapeManager); window.MouseButtonPressed += mouseButtonEventHandler.HandleEvent; }
private void Main_Load(object sender, EventArgs e) { if (!PingIpOrDomainName("www.baidu.com")) { new JMessageBox("提示", "无网络连接,本工具无法使用!", 0).ShowDialog(); Application.Exit(); } RefeshColor(); HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Ctrl, Keys.Q); HotKey.RegisterHotKey(Handle, 101, HotKey.KeyModifiers.Ctrl, Keys.W); HotKey.RegisterHotKey(Handle, 102, HotKey.KeyModifiers.Ctrl, Keys.E); TeanslateApi = "百度Baidu"; webBrowser1.ObjectForScripting = this; webBrowser1.DocumentText = Properties.Resources.text; ShowMenuEvent += new ShowMenuEventHandler(ShowMenu); CloseEvent += new CloseEventHandler(JClosed); textBox1.BackColor = Cache.MainColor; label2.ForeColor = label4.ForeColor = textBox1.ForeColor = radioButton1.ForeColor = radioButton2.ForeColor = radioButton3.ForeColor = radioButton4.ForeColor = Cache.TextColor; }
public async Task Should_send_messages_to_participants_and_service_bus_on_close() { _eventHandler = new CloseEventHandler(EventHubContextMock.Object, ConferenceCache, LoggerMock.Object, VideoApiClientMock.Object); var conference = TestConference; var participantCount = conference.Participants.Count + 1; // plus one for admin var callbackEvent = new CallbackEvent { EventType = EventType.Close, EventId = Guid.NewGuid().ToString(), ConferenceId = conference.Id, TimeStampUtc = DateTime.UtcNow }; await _eventHandler.HandleAsync(callbackEvent); // Verify messages sent to event hub clients EventHubClientMock.Verify(x => x.ConferenceStatusMessage(conference.Id, ConferenceStatus.Closed), Times.Exactly(participantCount)); }
private async Task RunRead() { bool hasError = false; try { await RunReadLoop(); } catch (SocketException ex) { hasError = true; ErrorHandler?.Invoke(ex); } catch (Exception ex) { } finally { socket.Dispose(); CloseEventHandler?.Invoke(hasError); } }
/// <summary> /// Constructor for client support /// </summary> /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param> /// <param name="userArg"> A Reference to the Users arguments </param> /// <param name="messageHandler"> Reference to the user defined message handler method </param> /// <param name="closeHandler"> Reference to the user defined close handler method </param> /// <param name="errorHandler"> Reference to the user defined error handler method </param> public SocketClient(int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) { // Create the raw buffer this.SizeOfRawBuffer = sizeOfRawBuffer; this.RawBuffer = new Byte[this.SizeOfRawBuffer]; // Save the user argument this.userArg = userArg; // Set the handler methods this.messageHandler = messageHandler; this.closeHandler = closeHandler; this.errorHandler = errorHandler; // Set the async socket method handlers this.callbackReadMethod = new AsyncCallback(ReceiveComplete); this.callbackWriteMethod = new AsyncCallback(SendComplete); this.m_Connected = true; // Init the dispose flag this.disposed = false; }
/// <summary> /// Constructor for client support /// </summary> /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param> /// <param name="userArg"> A Reference to the Users arguments </param> /// <param name="messageHandler"> Reference to the user defined message handler method </param> /// <param name="closeHandler"> Reference to the user defined close handler method </param> /// <param name="errorHandler"> Reference to the user defined error handler method </param> public SocketClient(int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) { // Create the raw buffer this.SizeOfRawBuffer = sizeOfRawBuffer; this.RawBuffer = new Byte[this.SizeOfRawBuffer]; // Save the user argument this.userArg = userArg; // Set the handler methods this.messageHandler = messageHandler; this.closeHandler = closeHandler; this.errorHandler = errorHandler; // Set the async socket method handlers this.callbackReadMethod = new AsyncCallback(ReceiveComplete); this.callbackWriteMethod = new AsyncCallback(SendComplete); this.m_Connected = true; // Init the dispose flag this.disposed = false; }
private static extern bool SetConsoleCtrlHandler(CloseEventHandler handler, bool add);
/// <summary> /// Overloaded constructor for client support /// </summary> /// <param name="sendBufferSize"></param> /// <param name="receiveBufferSize"></param> /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param> /// <param name="userArg"> A Reference to the Users arguments </param> /// <param name="messageHandler"> Reference to the user defined message handler method </param> /// <param name="closeHandler"> Reference to the user defined close handler method </param> /// <param name="errorHandler"> Reference to the user defined error handler method </param> public SocketClient(int sendBufferSize, int receiveBufferSize, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler ) : this(sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler) { //Set the size of the send/receive buffers this.sendBufferSize = sendBufferSize; this.receiveBufferSize = receiveBufferSize; }
void TileCreator_Closed(Widget sender, CloseEventArgs e) { Closed -= new CloseEventHandler(TileCreator_Closed); TypeTextBox.TextBox.TextAdded -= new TextAddedEventHandler(TextBox_TextAdded); KeepOldCheckBox.Seal(); }
void MapHandler_Closed(Widget sender, CloseEventArgs e) { Closed -= new CloseEventHandler(MapHandler_Closed); CurrentTool = TmpCurrentTool; ToolMainBox.Seal(false); }
void ObjectMan_Closed(Widget sender, CloseEventArgs e) { Closed -= new CloseEventHandler(ObjectMan_Closed); SelectButton.Seal(); ObjectMan.Instance.Open(); }
protected virtual SocketClient AcceptedSocketClient(SocketServer socketServer, Socket clientSocket, string ipAddress, int port, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) { return new SocketClient(socketServer, clientSocket, ipAddress, port, sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler); }
public override void Open(OpeningInfo openingInfo = null) { base.Open(openingInfo); if (openingInfo == null) return; if (!openingInfo.IsValid(1)) return; String mode = openingInfo.GetMode(); switch (mode) { case "TileManEditMode": String tileType = openingInfo.GetArg<String>("Type"); String textureType = openingInfo.GetArg<String>("TextureType"); OldType = tileType; TypeTextBox.TextBox.Reset(tileType); TextureButton.Text = textureType; TypeTextBox.TextBox.TextAdded += new TextAddedEventHandler(TextBox_TextAdded); Closed += new CloseEventHandler(TileCreator_Closed); break; } }
/// <summary> /// Function to start the SocketServer /// </summary> /// <param name="ipAddress"> The IpAddress to listening on </param> /// <param name="port"> The Port to listen on </param> /// <param name="sizeOfRawBuffer"> Size of the Raw Buffer </param> /// <param name="userArg"> User supplied arguments </param> /// <param name="messageHandler"> Function pointer to the user MessageHandler function </param> /// <param name="acceptHandler"> Function pointer to the user AcceptHandler function </param> /// <param name="closeHandler"> Function pointer to the user CloseHandler function </param> /// <param name="errorHandler"> Function pointer to the user ErrorHandler function </param> public void Start(string ipAddress, int port, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, AcceptEventHandler acceptHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) { // Is an AcceptThread currently running if (this.acceptThread == null) { // Set connection values this.IpAddress = ipAddress; this.Port = port; // Save the Handler Functions this.messageHandler = messageHandler; this.acceptHandler = acceptHandler; this.closeHandler = closeHandler; this.errorHandler = errorHandler; // Save the buffer size and user arguments this.SizeOfRawBuffer = sizeOfRawBuffer; this.UserArg = userArg; // Create a new TCPListner and start it up var endpoint = GetIPEndPoint(this.ipAddress, this.port); this.tcpListener = new TcpListener(endpoint); this.tcpListener.Start(maxAccept); // Start the listening thread if one is currently not running ThreadStart tsThread = new ThreadStart(AcceptThread); this.acceptThread = new Thread(tsThread); this.acceptThread.Name = "Notification.Accept"; this.acceptThread.Start(); } }
/// <summary> /// Function to start the SocketServer /// </summary> /// <param name="ipAddress"> The IpAddress to listening on </param> /// <param name="port"> The Port to listen on </param> /// <param name="sizeOfRawBuffer"> Size of the Raw Buffer </param> /// <param name="userArg"> User supplied arguments </param> /// <param name="messageHandler"> Function pointer to the user MessageHandler function </param> /// <param name="acceptHandler"> Function pointer to the user AcceptHandler function </param> /// <param name="closeHandler"> Function pointer to the user CloseHandler function </param> /// <param name="errorHandler"> Function pointer to the user ErrorHandler function </param> public void Start(string ipAddress, int port, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, AcceptEventHandler acceptHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) { // Is an AcceptThread currently running if (this.acceptThread == null) { // Set connection values this.IpAddress = ipAddress; this.Port = port; // Save the Handler Functions this.messageHandler = messageHandler; this.acceptHandler = acceptHandler; this.closeHandler = closeHandler; this.errorHandler = errorHandler; // Save the buffer size and user arguments this.SizeOfRawBuffer = sizeOfRawBuffer; this.UserArg = userArg; // Create a new TCPListner and start it up var endpoint = GetIPEndPoint(this.ipAddress, this.port); this.tcpListener = new TcpListener(endpoint); this.tcpListener.Start(maxAccept); // Start the listening thread if one is currently not running ThreadStart tsThread = new ThreadStart(AcceptThread); this.acceptThread = new Thread(tsThread); this.acceptThread.Name = "Notification.Accept"; this.acceptThread.Start(); } }
/// <summary> Constructor for SocketServer Suppport </summary> /// <param name="socketServer"> A Reference to the parent SocketServer </param> /// <param name="clientSocket"> The Socket object we are encapsulating </param> /// <param name="socketListArray"> The index of the SocketServer Socket List Array </param> /// <param name="ipAddress"> The IpAddress of the remote server </param> /// <param name="port"> The Port of the remote server </param> /// <param name="messageHandler"> Reference to the user defined message handler function </param> /// <param name="closeHandler"> Reference to the user defined close handler function </param> /// <param name="errorHandler"> Reference to the user defined error handler function </param> /// <param name="sizeOfRawBuffer"> The size of the raw buffer </param> /// <param name="userArg"> A Reference to the Users arguments </param> public SocketClient(SocketServer socketServer, Socket clientSocket, string ipAddress, int port, int sizeOfRawBuffer, object userArg, MessageEventHandler messageHandler, CloseEventHandler closeHandler, ErrorEventHandler errorHandler) : this(sizeOfRawBuffer, userArg, messageHandler, closeHandler, errorHandler) { // Set reference to SocketServer this.socketServer = socketServer; // Init the socket references this.clientSocket = clientSocket; // Set the Ipaddress and Port this.ipAddress = ipAddress; this.port = port; // Init the NetworkStream reference this.networkStream = new NetworkStream(this.clientSocket); // Set these socket options this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReceiveBuffer, this.receiveBufferSize); this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.SendBuffer, this.sendBufferSize); this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.DontLinger, 1); this.clientSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Tcp, System.Net.Sockets.SocketOptionName.NoDelay, 1); // Wait for a message Receive(); }
private static extern bool SetConsoleCtrlHandler(CloseEventHandler handler, bool add);
static void Main(string[] args) { //React to close window event, CTRL-C, kill, etc _handler += new CloseEventHandler(Handler); if (!IsMono) { SetConsoleCtrlHandler(_handler, true); } //Catch unhandled exceptions CrashReporter.DefaultFileName = "ManicDiggerServerCrash.txt"; CrashReporter.EnableGlobalExceptionHandling(true); new Program(args); }
public override void Open(OpeningInfo openingInfo = null) { base.Open(openingInfo); if (openingInfo == null) return; if (!openingInfo.IsValid(1)) return; String mode = openingInfo.GetArg<String>("Mode"); switch (mode) { case "ObjectPencilSelectMode": SelectButton.Seal(false); SelectButton.Clicked += new ClickEventHandler(SelectButton_Clicked); DisplayScreen.ScreenClicked += new ClickEventHandler(DisplayScreen_ScreenClicked); Closed += new CloseEventHandler(ObjectMan_Closed); break; } }
public override void Open(OpeningInfo openingInfo = null) { base.Open(openingInfo); if (openingInfo == null) return; if (!openingInfo.IsValid(1)) return; String mode = openingInfo.GetArg<String>("Mode"); switch (mode) { case "PointCreatorMode": ToolMainBox.Seal(); Closed += new CloseEventHandler(MapHandler_Closed); TmpCurrentTool = CurrentTool; CurrentTool = null; break; } }