示例#1
0
        /// <summary>
        /// Creates a client channel and obtains a reference to the remoting service exposed by the server -
        /// in this case, the remoting service exposed by the first instance. Calls a function of the remoting service
        /// class to pass on command line arguments from the second instance to the first and cause it to activate itself.
        /// </summary>
        /// <param name="channelName">Application's IPC channel name.</param>
        /// <param name="args">
        /// Command line arguments for the second instance, passed to the first instance to take appropriate action.
        /// </param>
        private static void SignalFirstInstance(string channelName, IList <string> args)
        {
            IpcClientChannel secondInstanceChannel = new IpcClientChannel();

            ChannelServices.RegisterChannel(secondInstanceChannel, true);

            string remotingServiceUrl = IpcProtocol + channelName + "/" + RemoteServiceName;

            // Obtain a reference to the remoting service exposed by the server i.e the first instance of the application
            IPCRemoteService firstInstanceRemoteServiceReference = (IPCRemoteService)RemotingServices.Connect(typeof(IPCRemoteService), remotingServiceUrl);

            // Check that the remote service exists, in some cases the first instance may not yet have created one, in which case
            // the second instance should just exit
            if (firstInstanceRemoteServiceReference != null)
            {
                // Invoke a method of the remote service exposed by the first instance passing on the command line
                // arguments and causing the first instance to activate itself
                try
                {
                    firstInstanceRemoteServiceReference.InvokeFirstInstance(args);
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }
示例#2
0
        private static void SignalFirstInstance(string channelName, IList <string> args)
        {
            IpcClientChannel secondInstanceChannel = new IpcClientChannel();

            ChannelServices.RegisterChannel(secondInstanceChannel, true);

            string remotingServiceUrl = IpcProtocol + channelName + "/" + RemoteServiceName;

            IPCRemoteService firstInstanceRemoteServiceReference = (IPCRemoteService)RemotingServices.Connect(typeof(IPCRemoteService), remotingServiceUrl);

            firstInstanceRemoteServiceReference?.InvokeFirstInstance(args);
        }
示例#3
0
        private static void SignalFirstInstance(string channelName, IList <string> args)
        {
            IpcClientChannel chnl = new IpcClientChannel();

            ChannelServices.RegisterChannel(chnl, true);
            string           url     = "ipc://" + channelName + "/SingleInstanceApplicationService";
            IPCRemoteService service = (IPCRemoteService)RemotingServices.Connect(typeof(IPCRemoteService), url);

            if (service != null)
            {
                service.InvokeFirstInstance(args);
            }
        }
示例#4
0
        private static void CreateRemoteService(string channelName)
        {
            BinaryServerFormatterSinkProvider sinkProvider = new BinaryServerFormatterSinkProvider
            {
                TypeFilterLevel = TypeFilterLevel.Full
            };
            IDictionary properties = new Dictionary <string, string>();

            properties["name"]                     = channelName;
            properties["portName"]                 = channelName;
            properties["exclusiveAddressUse"]      = "false";
            SingleInstance <TApplication> .channel = new IpcServerChannel(properties, sinkProvider);
            ChannelServices.RegisterChannel(SingleInstance <TApplication> .channel, true);
            IPCRemoteService service = new IPCRemoteService();

            RemotingServices.Marshal(service, "SingleInstanceApplicationService");
        }
示例#5
0
        private static void CreateRemoteService(string channelName)
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Dictionary <string, string>();

            props["name"]                = channelName;
            props["portName"]            = channelName;
            props["exclusiveAddressUse"] = "false";

            channel = new IpcServerChannel(props, serverProvider);
            ChannelServices.RegisterChannel(channel, true);
            IPCRemoteService remoteService = new IPCRemoteService();

            RemotingServices.Marshal(remoteService, RemoteServiceName);
        }
示例#6
0
        private static void CreateRemoteService(string channelName)
        {
            var serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Dictionary <string, string>();

            props["name"]                = channelName;
            props["portName"]            = channelName;
            props["exclusiveAddressUse"] = "false";
            // Create the IPC Server channel with the channel properties
            channel = new IpcServerChannel(props, serverProvider);
            // Register the channel with the channel services
            ChannelServices.RegisterChannel(channel, true);
            // Expose the remote service with the REMOTE_SERVICE_NAME
            var remoteService = new IPCRemoteService();

            RemotingServices.Marshal(remoteService, RemoteServiceName);
        }
示例#7
0
        /// <summary>
        /// Delivers the command line arguments to the first application instance, via a .NET remoting call to a remote service.
        /// </summary>
        /// <param name="applicationId">The application ID which identifies the application as a single instance.</param>
        /// <param name="args">The command line arguments to deliver.</param>
        protected override void OnDeliverArgumentsToFirstInstance(string applicationId, string[] args)
        {
            IpcClientChannel secondInstanceChannel = new IpcClientChannel();

            ChannelServices.RegisterChannel(secondInstanceChannel, true);

            string remotingServiceUrl = String.Format("ipc://{0}/{1}", applicationId, RemoteServiceName);

            // Obtain a reference to the remoting service exposed by the server i.e the first instance of the application
            IPCRemoteService firstInstanceRemoteServiceReference = (IPCRemoteService)RemotingServices.Connect(typeof(IPCRemoteService), remotingServiceUrl);

            // Check that the remote service exists, in some cases the first instance may not yet have created one, in which case
            // the second instance should just exit
            if (firstInstanceRemoteServiceReference != null)
            {
                // Invoke a method of the remote service exposed by the first instance passing on the command line
                // arguments and causing the first instance to activate itself
                firstInstanceRemoteServiceReference.DeliverArguments(args);
            }
        }
示例#8
0
        /// <summary>
        /// Initalize a listener for incoming command line arguments, as the first application instance, using a remoting IPC service.
        /// </summary>
        /// <param name="applicationId">The application ID which identifies the application as a single instance.</param>
        protected override void OnInitializeFirstInstance(string applicationId)
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Dictionary <string, string>();

            props["name"]                = applicationId;
            props["portName"]            = applicationId;
            props["exclusiveAddressUse"] = "false";

            // Create the IPC Server channel with the channel properties
            channel = new IpcServerChannel(props, serverProvider);

            // Register the channel with the channel services
            ChannelServices.RegisterChannel(channel, true);

            // Expose the remote service with the "RemoteServiceName"
            IPCRemoteService remoteService = new IPCRemoteService(this);

            RemotingServices.Marshal(remoteService, RemoteServiceName);
        }
        /// <summary>
        /// Initalize a listener for incoming command line arguments, as the first application instance, using a remoting IPC service.
        /// </summary>
        /// <param name="applicationId">The application ID which identifies the application as a single instance.</param>
        protected override void OnInitializeFirstInstance(string applicationId)
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Dictionary<string, string>();

            props["name"] = applicationId;
            props["portName"] = applicationId;
            props["exclusiveAddressUse"] = "false";

            // Create the IPC Server channel with the channel properties
            channel = new IpcServerChannel(props, serverProvider);

            // Register the channel with the channel services
            ChannelServices.RegisterChannel(channel, true);

            // Expose the remote service with the "RemoteServiceName"
            IPCRemoteService remoteService = new IPCRemoteService(this);
            RemotingServices.Marshal(remoteService, RemoteServiceName);
        }
        /// <summary>
        /// Creates a remote service for communication.
        /// </summary>
        /// <param name="channelName">Application's IPC channel name.</param>
        private static void CreateRemoteService(string channelName)
        {
            BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
            serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary props = new Dictionary<string, string>();

            props["name"] = channelName;
            props["portName"] = channelName;
            props["exclusiveAddressUse"] = "false";

            // Create the IPC Server channel with the channel properties
            channel = new IpcServerChannel(props, serverProvider);

            // Register the channel with the channel services
            ChannelServices.RegisterChannel(channel, true);

            // Expose the remote service with the REMOTE_SERVICE_NAME
            IPCRemoteService remoteService = new IPCRemoteService();
            RemotingServices.Marshal(remoteService, RemoteServiceName);
        }