Beispiel #1
0
        public bool Start()
        {
            if (this == s_currentProcess)
            {
                throw new InvalidOperationException(Res.OperationNotValidOnCurrentProcess);
            }

            if (_process == null)
            {
                lock (_processLock) {
                    if (_process == null)
                    {
                        _process = CreateAddInProcess();

                        // register for SendShuttingDown callbacks
                        AddInServer addInServer = GetAddInServer();
                        addInServer.Initialize(new EventWorker(this));
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        // This helper method may be called indirectly from user code via Shutdown()
        // or by a finalizer thread cleaning up the remote process.
        private void ShutDownUnlessCancelled(CancelEventArgs args)
        {
            if (ShuttingDown != null)
            {
                ShuttingDown(this, args);
            }

            if (args.Cancel)
            {
                return;
            }

            try
            {
                lock (_processLock) {
                    // Give addins a chance to clean up by running finalizers
                    // We'll get a remoting exception trying to read the response from this though.
                    AddInServer server = GetAddInServer();

                    _process = null;
                    _guid    = Guid.Empty;

                    // Warning - if this was called from the finalizer thread of AddInProcess,
                    // nothing after this next call will execute, even if it's in a finally block,
                    // due to the calling process being torn down.
                    server.ExitProcess();
                }
            }
            catch (RemotingException) {}
            catch (System.Runtime.Serialization.SerializationException) {}
        }
Beispiel #3
0
        internal static T Activate <T>(AddInToken token, AddInProcess process, PermissionSet permissionSet)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (permissionSet == null)
            {
                throw new ArgumentNullException("permissionSet");
            }
            if (process == null)
            {
                throw new ArgumentNullException("process");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            // check that they have ExecutionPermission.  Otherwise OOP remoting fails
            // by shutting down the pipe, leaving the user scratching his head.
            if (!permissionSet.IsUnrestricted())
            {
                SecurityPermission     p             = (SecurityPermission)permissionSet.GetPermission(typeof(SecurityPermission));
                SecurityPermissionFlag requiredFlags = SecurityPermissionFlag.Execution;
                if (p == null || (p.Flags & requiredFlags) != requiredFlags)
                {
                    throw new ArgumentException(Res.NeedSecurityFlags);
                }
            }

            RemotingHelper.InitializeClientChannel();

            AddInServer addInServer = process.GetAddInServer();

            AddInServerWorker addInServerWorker = addInServer.CreateDomain(token, permissionSet);
            AddInEnvironment  fullEnvironment   = new AddInEnvironment(process, addInServerWorker);

            return(ActivateOutOfProcess <T>(token, fullEnvironment, true));
        }