Пример #1
0
        /// <summary>
        /// a factory method which creates the listener and makes it start listening.
        /// </summary>
        /// <param name="appName"></param>
        /// <returns></returns>

        public static FwLinkReceiver StartReceiving(string appName, LinkEventHandler handler)
        {
            s_appName = appName;

            s_port = 6000;            //broker.RegisterAndGetPort(appName);

            FwLinkReceiver.OnLinkRequest += handler;

            try
            {
                //.Net 2.0 introduced a security boolean here.
                //If set to true here, then when we try to do the
                //ChannelServices.Activate, it hangs until the program quits
                //then launches the app again.
                ChannelServices.RegisterChannel(new TcpChannel(s_port), false);
            }
            catch
            {
                throw new ApplicationException(Strings.ListenerPortTaken);
            }

            //nb: to future maintainers, be careful about deciding to release this port during some kind of destructor
            //nb: "there is a time delay for the system to release the port. It
            //	is about 2 minutes. After that the port is free and you can reuse it."

            RemotingConfiguration.ApplicationName = appName;

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(FwLinkReceiver),
                                                               "receiver",
                                                               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     = FwLink.GetPortPath(s_port, appName);
            FwLinkReceiver listener = (FwLinkReceiver)Activator.GetObject(typeof(FwLinkReceiver), path);

            if (listener == null)
            {
                throw new ApplicationException(Strings.CannotCreateListener);
            }

            return(listener);
        }
Пример #2
0
 /// <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 bool ActivateExisting()
 {
     try
     {
         int port = 6000;
         //note that this will not fail, even if no one is listening on that channel
         FwLinkReceiver receiver =
             (FwLinkReceiver)Activator.GetObject(typeof(FwLinkReceiver),
                                                 GetPortPath(port, ApplicationName));
         //but this test will fail if we did not really connect to a receiver
         receiver.Request(this);
         return(true);
     }
     catch (Exception)
     {
         //nb: at the moment, we just assume that the failure was caused by the target application not running yet
     }
     return(false);
 }
Пример #3
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="arguments">Command line arguments.</param>
		public FwXApp(string[] arguments) : base(arguments)
		{
			try
			{
				m_linkReceiver = FwLinkReceiver.StartReceiving(Application.ProductName,
					new FwLinkReceiver.LinkEventHandler(OnIncomingLink));
			}
			catch (Exception e)
			{
				MessageBox.Show(e.Message,
					String.Format(xWorksStrings.ProblemStarting0, this.ProductName),
					MessageBoxButtons.OK,
					MessageBoxIcon.Warning);
			}
		}