/// <summary> /// a factory method which creates the listener and makes it start listening. /// </summary> /// <param name="appName"></param> /// <returns></returns> public static void StartListening(string appName, LinkEventHandler handler) { s_appName = appName; FwBroker broker = FwBroker.GetBroker(); s_port = broker.RegisterAndGetPort(appName); FwLinkListener.OnLinkRequest += handler; ChannelServices.RegisterChannel(new TcpChannel(s_port)); RemotingConfiguration.ApplicationName = appName; RemotingConfiguration.RegisterWellKnownServiceType(typeof(FwLinkListener), "listener", WellKnownObjectMode.Singleton ); //although we don't really need to use it, we create this object now //so that we can preload with appropriate properties. string path = FwLinkListener.GetPortPath(s_port, appName); FwLinkListener listener = (FwLinkListener)Activator.GetObject(typeof(FwLinkListener), path); if (listener == null) { throw new ApplicationException("Could not create the initial listener for this application"); } listener.Test(); }
public void Activate() { if (FwLinkListener.AttemptLink(this)) { return; } throw new ApplicationException("Could not connect to " + m_appName); }
/// <summary> /// Attempts to find an application which matches the link, and passes the link to that application. /// Does not attempt to launch new applications. /// </summary> /// <param name="link"></param> /// <returns>true if it successfully linked to a running application</returns> public static bool AttemptLink(FwLink link) { try { FwBroker broker = FwBroker.GetBroker(); int port = broker.GetRunningApplicationPort(link.ApplicationName); //note that this will not fail, even if no one is listening on that channel FwLinkListener listener = (FwLinkListener)Activator.GetObject(typeof(FwLinkListener), GetPortPath(port, link.ApplicationName)); //but this will fail if we did not really connect to a listener listener.Request(link); return(true); } catch (Exception error) { } return(false); }