Exemple #1
0
        internal AddInController(AddInControllerImpl impl, Object hostViewOfAddIn, ContractHandle contractHandle)
        {
            System.Diagnostics.Contracts.Contract.Requires(impl != null);

            _impl = impl;

            _hostViewOfAddIn = hostViewOfAddIn;

            _contractHandle = contractHandle;
        }
        public static TView ContractToViewAdapter <TView>(ContractHandle contract, PipelineStoreLocation location)
        {
            if (location != PipelineStoreLocation.ApplicationBase)
            {
                throw new ArgumentException(Res.InvalidPipelineStoreLocation, "location");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            String appBase = AddInStore.GetAppBase();

            return(ContractToViewAdapterImpl <TView>(contract, appBase, false));
        }
        private static TView ContractToViewAdapterImpl <TView>(ContractHandle contract, String pipelineRoot, bool demand)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }
            if (pipelineRoot == null)
            {
                throw new ArgumentNullException("pipelineRoot");
            }
            if (String.IsNullOrEmpty(pipelineRoot))
            {
                throw new ArgumentException(Res.PathCantBeEmpty);
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            if (demand)
            {
                new FileIOPermission(FileIOPermissionAccess.Read, pipelineRoot).Demand();
            }

            Type     havType     = typeof(TView);
            TypeInfo havTypeInfo = new TypeInfo(havType);

            List <PartialToken> partialTokens = AddInStore.GetPartialTokens(pipelineRoot);

            foreach (PartialToken partialToken in partialTokens)
            {
                if (AddInStore.Contains(partialToken.HostAdapter.HostAddinViews, havTypeInfo))
                {
                    partialToken.PipelineRootDirectory = pipelineRoot;

                    //Ask for something that can implement the contract in this partial token.  The result will
                    //either be null, the addin adapter itself, or another addin adapter
                    IContract subcontract = contract.Contract.QueryContract(partialToken._contract.TypeInfo.AssemblyQualifiedName);
                    if (subcontract != null)
                    {
                        //Instantiate the adapter and pass in the addin to its constructor
                        TView hav = AddInActivator.ActivateHostAdapter <TView>(partialToken, subcontract);
                        return(hav);
                    }
                }
            }

            // Don't let the ref count go to zero too soon, before we increment it in ActivateHostAdapter
            // This is important when QueryContract returns the addIn adapter itself.  A GC at that point
            // may collect the ContractHandle and decrement the ref count to zero before we have a chance to increment it
            System.GC.KeepAlive(contract);

            // return null.  Compiler makes us return default(TView), which will be null
            return(default(TView));
        }
Exemple #4
0
        public ContractEnumeratorAdapter(IEnumeratorContract <T> enumerator, Converter <T, U> wrapper)
        {
            if (enumerator == null)
            {
                throw new ArgumentNullException("enumerator");
            }
            if (wrapper == null)
            {
                throw new ArgumentNullException("wrapper");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            m_enumerator = enumerator;
            m_wrapper    = wrapper;

            m_contractHandle = new ContractHandle((IContract)m_enumerator);
        }
Exemple #5
0
        public void RevokeLifetimeToken(int token)
        {
            lock (m_lifetimeTokens)
            {
                if (!m_lifetimeTokens.Remove(token))
                {
                    throw new InvalidOperationException(Res.LifetimeTokenNotFound);
                }

                if (m_lifetimeTokens.Count == 0)
                {
                    m_zeroReferencesLeft = true;
                    // hook to allow subclasses to clean up
                    OnFinalRevoke();

                    IContract owner = ContractHandle.AppDomainOwner(AppDomain.CurrentDomain);
                    if (owner != null)
                    {
                        if (owner == this)
                        {
                            // Create a separate thread to unload this appdomain, because we
                            // cannot shut down an appdomain from the Finalizer thread (though there
                            // is a bug that allows us to do so after the first appdomain has been
                            // unloaded, but let's not rely on that).
                            // We can consider using an threadpool thread to do this, but that would add
                            // test burden.

                            SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.ControlThread);
                            permission.Assert();

                            System.Threading.ThreadStart threadDelegate = new System.Threading.ThreadStart(AppDomainUnload);
                            System.Threading.Thread      unloaderThread = new System.Threading.Thread(threadDelegate);
                            unloaderThread.Start();
                        }
                        else
                        {
                            owner.RevokeLifetimeToken(m_tokenOfAppdomainOwner);
                        }
                    }
                }
            }
        }
Exemple #6
0
        public int AcquireLifetimeToken()
        {
            if (m_zeroReferencesLeft)
            {
                throw new InvalidOperationException(Res.TokenCountZero);
            }

            int next;

            lock (m_lifetimeTokens)
            {
                // Lazily initialize m_random for perf.
                if (m_random == null)
                {
                    m_random = new Random();
                }

                next = m_random.Next();
                while (m_lifetimeTokens.Contains(next))
                {
                    next = m_random.Next();
                }
                m_lifetimeTokens.Add(next);

                if (m_lifetimeTokens.Count == 1)
                {
                    // Register as a sponsor the first time a token is aquired.
                    // need to do this here instead of in InitializeLifetimeService because of a bug in remoting
                    // involving security.
                    RegisterAsSponsor();

                    // Increment ref count on appdomain owner if needed
                    IContract owner = ContractHandle.AppDomainOwner(AppDomain.CurrentDomain);
                    if (owner != null && owner != this)
                    {
                        m_tokenOfAppdomainOwner = owner.AcquireLifetimeToken();
                    }
                }
            }

            return(next);
        }
Exemple #7
0
        public ContractListAdapter(IListContract <T> source, Converter <T, U> wrapper, Converter <U, T> unwrapper)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (wrapper == null)
            {
                throw new ArgumentNullException("wrapper");
            }
            if (unwrapper == null)
            {
                throw new ArgumentNullException("unwrapper");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            m_listContract = source;
            m_wrapper      = wrapper;
            m_unwrapper    = unwrapper;

            m_contractHandle = new ContractHandle(m_listContract);
        }
Exemple #8
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        void Dispose(bool disposing)
        {
            if (m_contractHandle != null)
            {
                if (disposing)
                {
                    try
                    {
                        m_contractHandle.Dispose();

                        if (m_enumerator != null)
                        {
                            m_enumerator.Dispose();
                        }
                    }
                    catch (AppDomainUnloadedException) { }
                    catch (RemotingException) { }
                }

                m_contractHandle = null;
            }
        }
 public CalculatorContractToViewHostSideAdapter(ICalc1Contract contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
Exemple #10
0
 public LocationC2V(ILocation contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public static TView ContractToViewAdapter <TView>(ContractHandle contract, string pipelineRoot)
 {
     return(ContractToViewAdapterImpl <TView>(contract, pipelineRoot, true));
 }
 public SayHelloHostViewAdapter(ISayHelloAddIn contract)
 {
     this._contract = contract;
     _handle = new ContractHandle(contract);
 }
        public WPFAddIn_ContractToViewHostSideAdapter(IWPFAddInContract wpfAddInContract)
        {
            // Adapt the contract (IWPFAddInContract) to the host application's 
            // view of the contract (IWPFAddInHostView) 
            this.wpfAddInContract = wpfAddInContract;

            // Prevent the reference to the contract from being released while the 
            // host application uses the add-in 
            this.wpfAddInContractHandle = new ContractHandle(wpfAddInContract);
        }
 public LogEventArgsContractToViewAddInAdapter(ILogEventArgs contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
        internal static AddInController GetAddInController(Object addIn)
        {
            if (addIn == null)
                throw new ArgumentNullException("addIn");
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            AddInControllerImpl controllerImpl = FindController(addIn, false);

            //return new wrapper
            if (controllerImpl != null)
            {
                // Try and increase the ref count on the addin.  If we fail, perhaps
                // because the user already called Dispose() on the HVA, that's OK.  Still allow
                // them to use the AddInController to examine the AddInToken 
                ContractHandle handle = null;
                try
                {
                     handle = new ContractHandle(controllerImpl._contract);
                }
                catch (Exception) {}
                return new AddInController(controllerImpl, addIn, handle);
            }

            throw new ArgumentException(Res.ControllerNotFound);
        }
Exemple #16
0
 public CalculatorContractToViewHostSideAdapter(ICalc1Contract contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public ILogEventHandlerContractToViewHostAdapter(ILogEventHandler contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public VisualCalculatorContractToViewHostAdapter(Calculator.Contracts.IVisualCalculatorContract contract)
 {
     _contract = contract;
     _handle = new ContractHandle(_contract);
 }
 public OperationC2V(IOperation contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public void ContractToCEGViewAdapter(ICEContract contract)
 {
     this.contract = contract;
     handle = new ContractHandle(contract);
 }
 public LibraryManagerContractToViewHostAdapter(Library.ILibraryManagerContract contract)
 {
     _contract = contract;
     _handle   = new System.AddIn.Pipeline.ContractHandle(contract);
 }
 public ContractToLPViewAdapter(ILPContract contract)
 {
     this.contract = contract;
     handle = new ContractHandle(contract);
 }
 public HostObjectContractToViewAddInAdapter(Contract.IHostObjectContract contract)
 {
     this.contract = contract;
     this.handle = new ContractHandle(contract);
 }
 public WpfAddInHostAdapter(IWpfAddIn contract)
 {
     m_Contract = contract;
     m_Handle = new ContractHandle(contract);
 }
Exemple #25
0
 public PortC2V(IPort contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public ParamTypeC2V(IParamType contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
Exemple #27
0
        public HostSideAdapter(IMyContract contract)
        {
            _contract = contract;

            _handle = new ContractHandle(contract);
        }
 public IsolatedElementContractToViewHostAdapter(ICustomAddInContract contract)
 {
     this._contract = contract;
     this._tokenHandle = new ContractHandle(contract);
 }
 public NumberProcessorContractToViewHostAdapter(Contract.INumberProcessorContract contract)
 {            
     this.contract = contract;
     contractHandle = new ContractHandle(contract);
 }
 public ModuleInfoC2V(IModuleInfo contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public PlayerContractToViewHostSideAdapter(IHangmanPlayer player)
 {
     _player = player;
     _handle = new ContractHandle(_player);
 }
 public OperationContractToViewAdapter(Calculator.Contracts.IOperationContract contract)
 {
     _contract = contract;
     _handle = new ContractHandle(_contract);
 }
 public BookInfoContractToViewAddInAdapter(Library.IBookInfoContract contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public CalculatorPluginContractToViewHostSideAdapter(ICalculatorPluginContract calculatorPluginContract)
 {
     _calculatorPluginContract = calculatorPluginContract;
     _contractHandle = new ContractHandle(calculatorPluginContract);
 }
 public LoggerC2V(ILogger contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public CapabilityC2V(ICapability contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
Exemple #37
0
 public ModuleStateC2V(HomeOS.Hub.Platform.Contracts.IModuleState contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
Exemple #38
0
 public RoleC2V(IRole contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }
 public CalculatorContractToViewHostAdapter(ICalc2Contract contract)
 {
     _contract = contract;
     _handle   = new System.AddIn.Pipeline.ContractHandle(contract);
 }
 public PlatformC2V(IPlatform contract)
 {
     _contract = contract;
     _handle = new ContractHandle(contract);
 }