public SingleInstanceProxy GetProxy(SingleInstanceDelegate @delegate)
 {
     return SingleInstanceProxy.GetInstance(@delegate);
 }
Esempio n. 2
0
 public static SingleInstanceProxy GetInstance(SingleInstanceDelegate app)
 {
     return new SingleInstanceProxyImpl(app());
 }
Esempio n. 3
0
 /// <summary>
 ///     Attempt to instantiate a single instance of the given ISingleInstanceApplication.
 ///     If one already exists, pass the command line arguments to the existing one.
 /// </summary>
 /// <param name="app">
 ///     The method which would be used to retrieve an ISingleInstanceApplication object when instantiating
 ///     the new object.
 /// </param>
 /// <remarks>
 ///     Note: When using this method and the SingleInstanceDelegate is null, the method can only be used to determine
 ///     whether the application is already running.
 /// </remarks>
 /// <returns><see langword="true" /> if this is the first instance, otherwise <see langword="false" /></returns>
 public abstract bool InstantiateSingleInstance(SingleInstanceDelegate app);
Esempio n. 4
0
            public override bool InstantiateSingleInstance(SingleInstanceDelegate app)
            {
                // Get name info
                var uniqueName = Assembly.GetEntryAssembly().GetName().Name;
                ThrowHelper.IfNullOrEmptyThenThrow(() => uniqueName);
                var name = uniqueName + Environment.UserName;
                _proxyUri = "ipc://" + name + "/" + ProxyObjectName;

                bool isFirstInstance;

                try
                {
                    _singleInstanceMutex = new Mutex(true, name, out isFirstInstance);

                    if (isFirstInstance)
                        CreateInstanceOfApplication(name, app);
                    else
                    {
                        // Get Commandline args
                        CommandLineArgs = GetCommandLineArgs(uniqueName);
                        SendMessageToFirstInstance(CommandLineArgs);
                    }
                }
                catch (Exception ex)
                {
                    throw new SingleInstancingException(
                        "Failed to instantiate a new SingleInstanceService object.  See InnerException for more details.",
                        ex);
                }
                return isFirstInstance;
            }
Esempio n. 5
0
            //private string GetUniqueName()
            //{
            //    var uniqueName = Assembly.GetEntryAssembly().GetName().Name;
            //    ThrowHelper.IfNullOrEmptyThenThrow(() => uniqueName);
            //    return uniqueName + Environment.UserName;
            //    //return name;
            //}
            private void CreateInstanceOfApplication(string channelName,
                SingleInstanceDelegate @delegate)
            {
                // Create an IPC server channel to listen for SingleInstanceProxy object requests
                _ipcChannel = _serviceProxy.CreateServerChannel(channelName);

                // Register the channel and get it ready for use
                _serviceProxy.RegisterChannel(_ipcChannel);

                // Register the service which gets the SingleInstanceProxy object,
                // so it can be accessible by IPC client channels
                _serviceProxy.RegisterType<SingleInstanceProxy>(ProxyObjectName);

                // Attempt to retrieve the enforcer from the delegated method
                _proxy = _factory.GetProxy(@delegate);

                // Publish the first proxy object so IPC clients
                // requesting a proxy would receive a reference to it
                _serviceProxy.Marshal(_proxy, ProxyObjectName);
            }