Ejemplo n.º 1
0
        public NativeHandleAddInAdapter(FrameworkElement root, ContractHandle adapter, string name = null)
        {
            Debug.Assert(null != root);
            Debug.Assert(null != adapter);
            Debug.Assert(adapter.Contract is IObserverContract);
            root.VerifyAccess();

            observer = adapter;

            var parameters = new HwndSourceParameters(name ?? "AddInWindow")
            {
                ParentWindow = new IntPtr(-3),
                WindowStyle  = 0x40000000
            };

            hwndSource = new HwndSource(parameters)
            {
                RootVisual    = root,
                SizeToContent = SizeToContent.Manual
            };

            if (hwndSource.CompositionTarget != null)
            {
                hwndSource.CompositionTarget.BackgroundColor = Colors.White;
            }

            hwndSource.AddHook(HwndSourceHook);

            CommandManager.AddCanExecuteHandler(root, CanExecuteRoutedEventHandler);
            CommandManager.AddExecutedHandler(root, ExecuteRoutedEventHandler);

            // TODO: Refactoring
            Debug.WriteLine("--\t\t\t\t\t\t\t Handle: {0}\t--\tWindow: {1}", hwndSource.Handle.ToString("x8"), parameters.WindowName);
        }
Ejemplo n.º 2
0
        protected override void OnFinalRevoke()
        {
            if (null != hwndSource)
            {
                CommandManager.RemoveCanExecuteHandler((UIElement)hwndSource.RootVisual, CanExecuteRoutedEventHandler);
                CommandManager.RemoveExecutedHandler((UIElement)hwndSource.RootVisual, ExecuteRoutedEventHandler);

                if (!hwndSource.CheckAccess())
                {
                    hwndSource.Dispatcher.Invoke(hwndSource.Dispose);
                }
                else
                {
                    hwndSource.Dispose();
                }
                hwndSource = null;
            }

            if (null != observer)
            {
                observer.Dispose();
                observer = null;
            }
            base.OnFinalRevoke();
        }
        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);
        }
Ejemplo n.º 4
0
        public Person_ContractToViewAddInSideAdapter(IPersonContract personContract)
        {
            this.personContract = personContract;
            this.contractHandle = new ContractHandle(personContract);

            this.notifier = new PropertyChangedNotifier();
            this.notifier.PropertyChanged += notifier_PropertyChanged;
            this.personContract.PropertyChangedNotifier = this.notifier;
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        internal AddInController(AddInControllerImpl impl, Object hostViewOfAddIn, ContractHandle contractHandle)
        {
            System.Diagnostics.Contracts.Contract.Requires(impl != null);

            _impl = impl;

            _hostViewOfAddIn = hostViewOfAddIn;

            _contractHandle = contractHandle;
        }
Ejemplo n.º 7
0
        public NativeHandleHostAdapter(INativeHandleContract nativeHandleContract, ObserverHostAdapter adapter)
        {
            Debug.Assert(null != nativeHandleContract);
            contract = new ContractHandle(nativeHandleContract);
            observer = adapter;

            PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);
            Dispatcher.ShutdownFinished += OnDispatcherShutdown;

            //if (null == observer) return;
            //observer.Execute += ExecutedRoutedCommandHandler;
            //observer.CanExecute += CanExecuteRoutedCommandHandler;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="ContractToView1HostSideAdapter" /> class.
        /// </summary>
        /// <param name="contract">The contract.</param>
        public ContractToView1HostSideAdapter(IWPFAddInContract1 contract)
        {
            // Adapt the contract (IWPFAddInContract) to the host application's
            // view of the contract (IWPFAddInHostView1)
            this.contract = contract;

            // Prevent the reference to the contract from being released while the
            // host application uses the add-in
            if (contract == null)
            {
                return;
            }
            contractHandle = new ContractHandle(contract);
        }
        public FrameworkElement GetControl()
        {
            FrameworkElement element = null;

            var contract = _contract.GetControl();
            var handle   = new ContractHandle(contract);

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                element = FrameworkElementAdapters.ContractToViewAdapter(contract);
                //element = FrameworkElementAsyncAdapters.ContractToViewAdapter(contract);
                element.Unloaded += (s, e) => handle.Dispose();
            }));


            return(element);
        }
Ejemplo n.º 10
0
        protected virtual void Dispose(bool disposing)
        {
            PresentationSource.RemoveSourceChangedHandler(this, OnSourceChanged);
            Dispatcher.ShutdownFinished -= OnDispatcherShutdown;

            if (null != observer)
            {
                //    observer.Execute -= ExecutedRoutedCommandHandler;
                //    observer.CanExecute -= CanExecuteRoutedCommandHandler;
                observer = null;
            }

            if (null != contract)
            {
                contract.Dispose();
                contract = null;
            }

            hWnd = new HandleRef(null, IntPtr.Zero);
        }
        public WPFAddIn_ContractToViewHostSideAdapter(IWPFAddInContract wpfAddInContract)
        {
            // Adapt the contract (IWPFAddInContract) to the host application's
            // view of the contract (WPFAddInHostView)
            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);

            // Convert the INativeHandleContract for the add-in UI that was passed
            // from the add-in side of the isolation boundary to a FrameworkElement
            string aqn = typeof(INativeHandleContract).AssemblyQualifiedName;
            INativeHandleContract inhc = (INativeHandleContract)wpfAddInContract.QueryContract(aqn);
            FrameworkElement      fe   = (FrameworkElement)FrameworkElementAdapters.ContractToViewAdapter(inhc);

            // Add FrameworkElement (which displays the UI provided by the add-in) as
            // content of the view (a UserControl)
            this.Content = fe;
        }
Ejemplo n.º 12
0
 public HostObjectContractToViewAddInAdapter(IHostObjectContract contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
Ejemplo n.º 13
0
 public MyPluginContractToHostViewAdapter(IMyPluginContract contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public LogContractToViewAddInAdapter(ILog contract)
 {
     Contract = contract;
     _handle  = new ContractHandle(contract);
 }
Ejemplo n.º 15
0
 public HostAdapter(IContractV1 contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
Ejemplo n.º 16
0
 public LoggerC2V(ILogger contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public ProcessorContractToHostViewAdapter(IProcessorContract contract)
 {
     this.contract = contract;
     handle        = new ContractHandle(contract);
 }
 public CalculatorContractToViewHostAdapter(ICalculatorContract contract)
 {
     this.contract = contract;
     handle        = new ContractHandle(contract);
 }
Ejemplo n.º 19
0
 public ManufacturerContractToAddInViewAdapter(IManufacturerContract contract)
 {
     this.contract = contract;
     handle        = new ContractHandle(contract);
 }
Ejemplo n.º 20
0
 public OperationC2V(IOperation contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public ImageProcessorContractToViewHostAdapter(Contract.IImageProcessorContract contract)
 {
     this.contract  = contract;
     contractHandle = new ContractHandle(contract);
 }
Ejemplo n.º 22
0
 public ModuleC2V(IModule contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
Ejemplo n.º 23
0
 public SayHelloHostViewAdapter(ISayHelloAddIn contract)
 {
     this._contract = contract;
     _handle        = new ContractHandle(contract);
 }
Ejemplo n.º 24
0
 public PlatformC2V(IPlatform contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public SightstonePluginHostSideAdapter(ISightstonePluginContract sightstonePluginContract)
 {
     _sightstonePluginContract = sightstonePluginContract;
     _contractHandle           = new ContractHandle(sightstonePluginContract);
 }
 public BookInfoContractToViewHostAdapter(Library.IBookInfoContract contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(contract);
 }
 public ImageProcessorContractToViewHostAdapter(IImageProcessorContract contract)
 {
     _contract       = contract;
     _contractHandle = new ContractHandle(contract);
 }
Ejemplo n.º 28
0
 public WpfAddInHostAdapter(IWpfAddIn contract)
 {
     m_Contract = contract;
     m_Handle   = new ContractHandle(contract);
 }
 public OperationContractToViewAdapter(Calculator.Contracts.IOperationContract contract)
 {
     _contract = contract;
     _handle   = new ContractHandle(_contract);
 }
 public OperationContractToViewHostAdapter(IOperationContract contract)
 {
     Contract = contract;
     _handle  = new ContractHandle(contract);
 }