/// <summary> /// Fires the event. /// </summary> /// <param name="genuineEventArgs">The event parameters.</param> public void Fire(GenuineEventArgs genuineEventArgs) { // acquire read access and get a list of the event receivers object[] handlers; using(new ReaderAutoLocker(this._handlersLock)) handlers = this._handlers.ToArray(); foreach (IGenuineEventHandler iGenuineEventHandler in handlers) { try { iGenuineEventHandler.OnGenuineEvent(genuineEventArgs); } catch(Exception) { using(new WriterAutoLocker(this._handlersLock)) this._handlers.Remove(iGenuineEventHandler); } } // fire the global event as well if (genuineEventArgs.EventType == GenuineEventType.GTcpConnectionAccepted) this.FireGlobalEvent(genuineEventArgs); else GenuineThreadPool.QueueUserWorkItem(new WaitCallback(this.FireGlobalEvent), genuineEventArgs, false); }
public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { if (e.SourceException == null) { Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString()); } else { Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(), e.SourceException); } if (e.EventType == GenuineEventType.GeneralServerRestartDetected) { // server has been restarted so it does not know that we have been subscribed to // messages and ours nickname lock (ChatClient.IChatServerLock) { ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom), RemoteHostUri + "/ChatServer.rem"); ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname); } } }
/// <summary> /// Catches Genuine Channels events and removes client session when /// user disconnects. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { if (e.SourceException == null) { Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString()); } else { Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(), e.SourceException); } if (e.EventType == GenuineEventType.GeneralConnectionClosed) { // the client disconnected string nickname = e.HostInformation["Nickname"] as string; if (nickname != null) { Console.WriteLine("Client \"{0}\" has been disconnected.", nickname); } } }
/// <summary> /// Processes events thrown by Genuine Channels. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { string remoteHostInfo = e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(); switch (e.EventType) { case GenuineEventType.GeneralConnectionEstablished: this.UpdateLog("Connection is established by {0}.", remoteHostInfo); break; case GenuineEventType.GeneralConnectionClosed: if (e.SourceException != null) { this.UpdateLog("Connection to the host {0} is closed due to the exception: {1}.", remoteHostInfo, e.SourceException); } else { this.UpdateLog("Connection to the host {0} is closed.", remoteHostInfo, e.SourceException); } break; case GenuineEventType.GeneralConnectionReestablishing: if (e.SourceException != null) { this.UpdateLog("Connection to the host {0} has been broken due to the exception: {1} but will probably be restored.", remoteHostInfo, e.SourceException); } else { this.UpdateLog("Connection to the host {0} has been broken but will probably be restored.", remoteHostInfo); } break; } }
/// <summary> /// Fires the event. /// </summary> /// <param name="genuineEventArgs">The event parameters.</param> public void Fire(GenuineEventArgs genuineEventArgs) { // acquire read access and get a list of the event receivers object[] handlers; using (new ReaderAutoLocker(this._handlersLock)) handlers = this._handlers.ToArray(); foreach (IGenuineEventHandler iGenuineEventHandler in handlers) { try { iGenuineEventHandler.OnGenuineEvent(genuineEventArgs); } catch (Exception) { using (new WriterAutoLocker(this._handlersLock)) this._handlers.Remove(iGenuineEventHandler); } } // fire the global event as well if (genuineEventArgs.EventType == GenuineEventType.GTcpConnectionAccepted) { this.FireGlobalEvent(genuineEventArgs); } else { GenuineThreadPool.QueueUserWorkItem(new WaitCallback(this.FireGlobalEvent), genuineEventArgs, false); } }
public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { if (e.SourceException == null) { Console.WriteLine("Global event: {0}\r\nUrl: {1}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString()); } else { Console.WriteLine("Global event: {0}\r\nUrl: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(), e.SourceException); } if (e.EventType == GenuineEventType.GeneralServerRestartDetected) { // server has been restarted so it does not know that we need messages and ours nickname lock (ChatClient.IChatServerLock) { ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom), ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem"); ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname); } } }
public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { if (e.SourceException == null) { Console.WriteLine("Global event: {0}\r\nUrl: {1}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString()); } else { Console.WriteLine("Global event: {0}\r\nUrl: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(), e.SourceException); } }
/// <summary> /// Fires the GenuineChannelsGlobalEvent event with specified parameters. /// </summary> /// <param name="sender">The source object.</param> /// <param name="e">Event arguments.</param> public static void FireGlobalEvent(object sender, GenuineEventArgs e) { GenuineChannelsGlobalEventHandler clonedEvent = null; lock (_genuineChannelsGlobalEventObject) { if (_genuineChannelsGlobalEvent == null) return ; clonedEvent = (GenuineChannelsGlobalEventHandler) _genuineChannelsGlobalEvent.Clone(); } clonedEvent(sender, e); }
private static void GenuineGlobalEventProvider_GenuineChannelsGlobalEvent(object sender, GenuineEventArgs e) { switch (e.EventType) { case GenuineEventType.GeneralConnectionClosed: log.Error(string.Format("{0} - The GTCP server channel has released all resources associated with client connection and will not be able to accept a reconnection from it.", e.HostInformation.Url)); // what does this mean? we are still able to reconnect break; case GenuineEventType.GeneralConnectionReestablishing: log.Error(string.Format("{0} - Connection is broken but will attempt to reconnect to the server automatically.", e.HostInformation.Url)); break; case GenuineEventType.GeneralServerRestartDetected: log.Error(string.Format("{0} - Server restart detected. Have to relogin and to resubscribe to events.", e.HostInformation.Url)); DoLogin(); break; default: log.Debug(string.Format("{0} - GenuineChannelsGlobalEvent: {1}", e.HostInformation.Url, e.EventType)); break; } }
/// <summary> /// Catches Genuine Channels events and removes client session when /// user disconnects. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { if (e.SourceException == null) Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString()); else Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(), e.SourceException); if (e.EventType == GenuineEventType.GeneralConnectionClosed) { // the client disconnected string nickname = e.HostInformation["Nickname"] as string; if (nickname != null) Console.WriteLine("Client \"{0}\" has been disconnected.", nickname); } }
public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { if (e.SourceException == null) Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString()); else Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(), e.SourceException); if (e.EventType == GenuineEventType.GeneralServerRestartDetected) { // server has been restarted so it does not know that we have been subscribed to // messages and ours nickname lock(ChatClient.IChatServerLock) { ChatClient.IChatServer = (IChatServer) Activator.GetObject(typeof(IChatRoom), ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem"); ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname); } } }
private static void GenuineGlobalEventProvider_GenuineChannelsGlobalEvent(object sender, GenuineEventArgs e) { switch (e.EventType) { case GenuineEventType.GeneralConnectionReestablishing: case GenuineEventType.GeneralConnectionClosed: IsConnectedInternal = false; break; default: break; } }
private void GenuineGlobalEventProvider_GenuineChannelsGlobalEvent(object sender, GenuineEventArgs e) { if (log.IsDebugEnabled) { if (e.SourceException == null) { log.Debug( string.Format("Global event: {0}\r\nUrl: {1}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString())); } else { log.Debug( string.Format("Global event: {0}\r\nUrl: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(), e.SourceException)); } } if (e.EventType == GenuineEventType.GeneralConnectionClosed) { // remove client session SessionId sessionId = e.HostInformation["id"] as SessionId; if (sessionId != null) { // user can be actually logged out here, if client application was closed properly // Logout handles this case string userName = string.Empty; try { userName = GetUser(sessionId).LoginName; } // have to logout even if name lookup fails catch (Exception) { } Logout(sessionId); if (log.IsDebugEnabled) { log.Debug( string.Format("Client {0} (url = {1}, session ID={2}) has been disconnected.", userName, e.HostInformation.PhysicalAddress == null ? "<not specified>" : e.HostInformation.PhysicalAddress.ToString(), sessionId.Id)); } } } else { // check if it was logout already - close connection // doesn't work. there is no session available after successfull logout. /* if (e.EventType == GenuineEventType.GeneralConnectionReestablishing) { SessionId sessionId = e.HostInformation["id"] as SessionId; if (sessionId != null) { try { // is user logged out? if (GetCurrentUser(sessionId) == null) { string url = e.HostInformation.PhysicalAddress == null ? "<not specified>" : e.HostInformation.PhysicalAddress.ToString(); e.HostInformation.ITransportContext.KnownHosts.ReleaseHostResources( e.HostInformation, GenuineExceptions.Get_Receive_ConnectionClosed("user is logged out")); if (log.IsDebugEnabled) { log.Debug( string.Format( "Releasing host resources due to user logout (url = {0}, session ID = {1})", url, sessionId.Id)); } } } catch { } } }*/ } }
/// <summary> /// Genuine Event handler. /// </summary> /// <param name="genuineEventArgs">The event arguments.</param> public void OnGenuineEvent(GenuineEventArgs genuineEventArgs) { this.FireGenuineEvent(genuineEventArgs); }
private static void GenuineGlobalEventProvider_GenuineChannelsGlobalEvent(object sender, GenuineEventArgs e) { switch (e.EventType) { case GenuineEventType.HostResourcesReleased: if (!DoLogin()) { return; } FormWait.HideWaitForm(); break; default: log.Debug(string.Format("{0} - GenuineChannelsGlobalEvent: {1}", e.HostInformation.Url, e.EventType)); break; } }
/// <summary> /// Fires the GenuineChannelsGlobalEvent event with the specified parameters. /// </summary> /// <param name="e">Event arguments.</param> public void FireGenuineEvent(GenuineEventArgs e) { // LOG: BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter; if ( binaryLogWriter != null && binaryLogWriter[LogCategory.ChannelEvent] > 0 ) { binaryLogWriter.WriteEvent(LogCategory.ChannelEvent, "BasicChannelWithSecurity.FireGenuineEvent", LogMessageType.ChannelEvent, e.SourceException, null, e.HostInformation, null, GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, null, null, -1, (int) e.EventType, 0, 0, null, null, null, null, "The channel event is raised."); } if (e.EventType == GenuineEventType.GTcpConnectionAccepted || e.EventType == GenuineEventType.GHttpConnectionAccepted) this.PerformEventSending(e); else GenuineThreadPool.QueueUserWorkItem(new WaitCallback(this.PerformEventSending), e, false); }
/// <summary> /// Catches Genuine Channels events and removes client session when /// user disconnects. /// This Method do the following things /// 1-show source exception if its not null else its show the profile information of user /// 2-Handling GeneralConnectionReestablishing,GeneralConnectionClosed event-types /// do following things on these events: /// -get profile using GenuineEventArgs e parameter....profile=e.HostInformation["Profile"] /// -by seaching conference staticServerInstance.SearchConference(profile.ConferenceID) use the /// DetachUser() method of conference room... /// DetachUser do two things /// -Remove URI from dispatcher list to assure that this paticipant no longer able to receive message /// -Send all participant a message of "ControlMessage" type with ControlCode.AttendeeDropped to update their Participant lists /// 3-Add message of leaving user from meeting /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e) { try { if (e.SourceException == null) #if TESTING Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString()); #endif //else { #if TESTING Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(), e.SourceException); #endif ClientProfile profile=e.HostInformation["Profile"] as ClientProfile; if(profile != null) { #if TESTING Console.WriteLine("An Exception has occured where profile Name = " + profile.Name); #endif } else { #if TESTING Console.WriteLine("An Exception has occured where profile was not found"); #endif } } /* Effect of handling event of type e.EventType == GenuineEventType.GeneralConnectionReestablishing "if a user disconnected from meeting then its clear all his participant list when its connected again it dont add user list that comes from server; to correct this problem we will write code in the client app to add users in the list." */ /* Some event types description * 1--GTcpConnectionAccepted--The GTCP server channel has accepted a connection. You can analyze the IP address of the remote host and decline * the connection. See the explanation below. * 2--GeneralConnectionEstablished--The GTCP client channel has connected to the server.The GTCP server channel has accepted a connection opened * by the client. * 3--GeneralConnectionReestablishing--The GTCP client channel recongnizes that the connection is broken but will attempt to reconnect to the server * automatically.The GTCP server channel recognizes that the connection is broken and the client is expected to reestablish the * connection within the specified time span. * 4--GeneralConnectionClosed--The GTCP server channel has released all resources * associated with an appropriate client connection and will not be able to accept a reconnection from it. * The GTCP client channel has closed the connection to the remote peer. */ /* some info about this event handler. * Belikov.GenuineChannels.DotNetRemotingLayer.GenuineGlobalEventProvider provides the global * GenuineChannelsGlobalEvent event fired for each Genuine Channels event. You can attach a * handler to it if you want to process events generated by all channels and services. */ if (e.EventType == GenuineEventType.GeneralConnectionClosed ||e.EventType == GenuineEventType.GeneralConnectionReestablishing ) { // the client disconnected ClientProfile profile=e.HostInformation["Profile"] as ClientProfile;//string ConnectionID= e.HostInformation["ConnectionID"] as string; staticServerInstance.SearchConference(profile.ConferenceID).DetachUser(profile); ST_flowMsg FlowMsgObj = new ST_flowMsg (); FlowMsgObj.meetID = profile.ConferenceID ; FlowMsgObj.curDate= DateTime.Now.Year + "-" + DateTime.Now.Month +"-" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second; FlowMsgObj.curMsg = profile.Name +" has left from "+ profile.ConferenceID+ " conference." ; FlowMsgObj.MsgCategory = "Attendee Joins and Leaves"; //staticServerInstance.flowMsgs.Add(FlowMsgObj); FlowMsgObj = null; #if TESTING Console.WriteLine("Client \"{0}\" has been disconnected.", profile.ConferenceID); #endif } } catch(Exception) { } }
/// <summary> /// Fires the event. /// </summary> /// <param name="genuineEventArgsAsObject">Event parameters.</param> internal void FireGlobalEvent(object genuineEventArgsAsObject) { GenuineEventArgs genuineEventArgs = (GenuineEventArgs)genuineEventArgsAsObject; GenuineGlobalEventProvider.FireGlobalEvent(this.ITransportContext, genuineEventArgs); }
private void GenuineGlobalEventProvider_GenuineChannelsGlobalEvent(object sender, GenuineEventArgs e) { if (log.IsDebugEnabled) { if (e.SourceException == null) { log.Debug( string.Format("Global event: {0}\r\nUrl: {1}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString())); } else { log.Debug( string.Format("Global event: {0}\r\nUrl: {1}\r\nException: {2}", e.EventType, e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(), e.SourceException)); } } if (e.EventType == GenuineEventType.GeneralConnectionClosed) { // remove client session SessionId sessionId = e.HostInformation["id"] as SessionId; if (sessionId != null) { // user can be actually logged out here, if client application was closed properly // Logout handles this case string userName = string.Empty; try { userName = GetUser(sessionId).LoginName; } // have to logout even if name lookup fails catch (Exception) { } Logout(sessionId); if (log.IsDebugEnabled) { log.Debug( string.Format("Client {0} (url = {1}, session ID={2}) has been disconnected.", userName, e.HostInformation.PhysicalAddress == null ? "<not specified>" : e.HostInformation.PhysicalAddress.ToString(), sessionId.Id)); } } } else { // check if it was logout already - close connection // doesn't work. there is no session available after successfull logout. /* * if (e.EventType == GenuineEventType.GeneralConnectionReestablishing) * { * SessionId sessionId = e.HostInformation["id"] as SessionId; * if (sessionId != null) * { * try * { * // is user logged out? * if (GetCurrentUser(sessionId) == null) * { * string url = e.HostInformation.PhysicalAddress == null * ? "<not specified>" * : e.HostInformation.PhysicalAddress.ToString(); * e.HostInformation.ITransportContext.KnownHosts.ReleaseHostResources( * e.HostInformation, * GenuineExceptions.Get_Receive_ConnectionClosed("user is logged out")); * if (log.IsDebugEnabled) * { * log.Debug( * string.Format( * "Releasing host resources due to user logout (url = {0}, session ID = {1})", * url, sessionId.Id)); * } * } * } * catch * { * } * } * }*/ } }