public MainWindow()
    {
        InitializeComponent();
        listBox  = new ListBox();
        Content  = listBox;
        myButton = new Button {
            Content = "Click me"
        };
        myButton.Click += (sender, args) =>
        {
            myButton.Content  = "Lorem ipsum dolor sit amet.";
            myButton.FontSize = 24;
        };
        dummyGrid = new Grid();
        dummyGrid.ColumnDefinitions.Add(new ColumnDefinition()
        {
            Width = GridLength.Auto
        });
        dummyGrid.RowDefinitions.Add(new RowDefinition()
        {
            Height = GridLength.Auto
        });
        dummyGrid.Children.Add(myButton);
        var frameworkElement =
            FrameworkElementAdapters.ContractToViewAdapter(
                FrameworkElementAdapters.ViewToContractAdapter(dummyGrid));

        listBox.Items.Add(frameworkElement);
        // Automatically adjust HwndHost's size when the grid changes
        dummyGrid.SizeChanged += (sender, args) =>
        {
            frameworkElement.Width  = args.NewSize.Width;
            frameworkElement.Height = args.NewSize.Height;
        };
    }
Ejemplo n.º 2
0
 /// <summary>
 ///  Initializes the given entry point by calling <see cref="HostedEntryPoint.Initialize"/>
 ///  returning the given framework as an INativeHandleContract.
 /// </summary>
 public INativeHandleContract Initialize(Dictionary <string, string> configuration,
                                         out Dictionary <string, string> returnedConfiguration)
 {
     _element = _entryPoint.Initialize(configuration);
     returnedConfiguration = configuration;
     return(FrameworkElementAdapters.ViewToContractAdapter(_element));
 }
Ejemplo n.º 3
0
        private void LoadDomain()
        {
            if (scriptDomain == null)
            {
                try
                {
                    AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                    AppDomainSetup setup = new AppDomainSetup()
                    {
                        ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                        PrivateBinPath  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    };
                    scriptDomain = AppDomain.CreateDomain(DomainName, AppDomain.CurrentDomain.Evidence, setup);
                    VSContext.InitializeAppDomain(scriptDomain);
#if USE_APP_DOMAIN
                    proxy = (VSInteractiveWindowProxy)scriptDomain.CreateInstanceAndUnwrap(typeof(VSInteractiveWindowProxy).Assembly.FullName, typeof(VSInteractiveWindowProxy).FullName);
                    var control = FrameworkElementAdapters.ContractToViewAdapter(proxy.CreateControl());
#else
                    var control = new VSInteractiveWindowControl();
#endif

                    grid.Children.Clear();
                    grid.Children.Add(control);
                }
                catch (Exception ex)
                {
#if DEBUG
                    System.Windows.MessageBox.Show("Loading domain failed:\n" + ex.ToString());
#endif
                }
            }
        }
Ejemplo n.º 4
0
    public void DoTheTrick()
    {
        var uControl = LoadAssembly("assemblyName", "interfaceName");

        panel.Content = FrameworkElementAdapters.ContractToViewAdapter(uControl);
        remoteWorker.RemoteInvoke("methodName", new object[] { });
    }
Ejemplo n.º 5
0
        public INativeHandleContract RegisterContent()
        {
            FrameworkElement      element  = m_View.RegisterContent();
            INativeHandleContract contract = FrameworkElementAdapters.ViewToContractAdapter(element);

            return(contract);
        }
Ejemplo n.º 6
0
        public object ToContract(Control control)
        {
            var content = DesignPanel.GetContent(control);
            var view    = content.ToNative(true);

            return(FrameworkElementAdapters.ViewToContractAdapter(view));
        }
Ejemplo n.º 7
0
    public INativeHandleContract GetAddInUI()
    {
        FrameworkElement      fe   = this.wpfAddInView as FrameworkElement; // return instance directly instead of creating new one by wpfAddInView.GetAddInUI();
        INativeHandleContract inhc = FrameworkElementAdapters.ViewToContractAdapter(fe);

        return(inhc);
    }
Ejemplo n.º 8
0
        /// <summary>
        ///     Gets the user interface.
        /// </summary>
        /// <returns></returns>
        public INativeHandleContract GetUserInterface( )
        {
            FrameworkElement      fe   = _view.GetUserInterface( );
            INativeHandleContract inhc = FrameworkElementAdapters.ViewToContractAdapter(fe);

            return(inhc);
        }
Ejemplo n.º 9
0
    public Window1()
    {
        InitializeComponent();
        m_stackPanel = new StackPanel {
            Orientation = Orientation.Vertical
        };
        m_stackPanel.Background = Brushes.Red;
        m_expander = new Expander
        {
            ExpandDirection = ExpandDirection.Right,
            Background      = Brushes.Blue,
            IsExpanded      = true,
        };
        m_expander.Expanded  += CheckStuff;
        m_expander.Collapsed += CheckStuff;
        Rectangle r = new Rectangle {
            Fill = Brushes.LightGray, Height = 300, Width = 300
        };

        m_expander.Content = r;
        StackPanel stackPanel = new StackPanel();

        stackPanel.Children.Add(m_expander);
        m_expanderAddIn = FrameworkElementAdapters.ContractToViewAdapter(FrameworkElementAdapters.ViewToContractAdapter(stackPanel));
        Binding binding = new Binding("ActualHeight");

        binding.Source = m_expander;
        m_expanderAddIn.SetBinding(FrameworkElement.HeightProperty, binding);
        m_stackPanel.Children.Add(m_expanderAddIn);
        Content = m_stackPanel;
    }
Ejemplo n.º 10
0
        private void StartHost()
        {
            var processInfo = new ProcessStartInfo
            {
                Arguments        = new TypedArgs(parentProcessId, PluginInfo.AssemblyFile, instanceName).ToArgs(),
                CreateNoWindow   = true, // Note: The command window might be helpful to search for errors.
                UseShellExecute  = false,
                FileName         = "PluginHost.exe",
                WorkingDirectory = Path.GetDirectoryName(PluginInfo.AssemblyFile)
            };

            using (var readyEvent = new EventWaitHandle(false, EventResetMode.ManualReset, instanceName + ".Ready"))
            {
                var pluginProcess = Process.Start(processInfo);
                pluginProcess.EnableRaisingEvents = true;
                pluginProcess.Exited += PluginProcessExited;
                if (!readyEvent.WaitOne(3000))
                {
                    throw new InvalidOperationException("Plugin host process not ready.");
                }
            }

            var url = "ipc://" + instanceName + "/PluginLoader";

            pluginLoader = (IPluginLoader)Activator.GetObject(typeof(IPluginLoader), url);
            // TODO: This won't work if the plugin crashes during startup!
            var contract = pluginLoader.LoadPlugin(PluginInfo.AssemblyFile, PluginInfo.PluginControllerName);

            RemoteView = FrameworkElementAdapters.ContractToViewAdapter(contract);
        }
Ejemplo n.º 11
0
        public Control FromContract(object contract)
        {
            var view = FrameworkElementAdapters.ContractToViewAdapter((INativeHandleContract)contract);

            view.Focusable = false;             // otherwise editor loses focus when switching back to its tab.. may be a better way around this.
            return(new Control(new NativeControl(view)));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// By default returns real control object.
 /// </summary>
 /// <param name="contractAdapter">If <b>True</b>, the <see cref="System.AddIn.Contract.INativeHandleContract"/> instance returned.</param>
 /// <returns>Control object</returns>
 public object GetControl(bool contractAdapter = false)
 {
     if (contractAdapter)
     {
         return(FrameworkElementAdapters.ViewToContractAdapter(Control));
     }
     return(Control);
 }
Ejemplo n.º 13
0
        public RemotePlugin(IPlugin plugin)
        {
            _plugin = plugin;
            var control       = plugin.CreateControl();
            var localContract = FrameworkElementAdapters.ViewToContractAdapter(control);

            Contract = new NativeHandleContractInsulator(localContract);
        }
Ejemplo n.º 14
0
        public INativeHandleContract GetAddInUI(IPersonContract personContract)
        {
            Person_ContractToViewAddInSideAdapter personView = new Person_ContractToViewAddInSideAdapter(personContract);
            FrameworkElement      fe          = this.addInView.GetAddInUI(personView);
            INativeHandleContract addInUIHwnd = FrameworkElementAdapters.ViewToContractAdapter(fe);

            return(addInUIHwnd);
        }
        /// <summary>
        /// ContractBase.QueryContract must be overridden to:
        /// * Safely return a window handle for an add-in UI to the host
        ///   application's application.
        /// * Enable tabbing between host application UI and add-in UI, in the
        ///   "add-in is a UI" scenario.
        /// </summary>
        public override IContract QueryContract(string contractIdentifier)
        {
            if (contractIdentifier.Equals(typeof(INativeHandleContract).AssemblyQualifiedName))
            {
                return(FrameworkElementAdapters.ViewToContractAdapter(this.wpfAddInView));
            }

            return(base.QueryContract(contractIdentifier));
        }
Ejemplo n.º 16
0
        public static async Task <INativeHandleContract> CreateViewContract(string threadName, Func <FrameworkElement> factory)
        {
            INativeHandleContract contract = null;
            var dispatcher = await GetOrCreateDispatcherAsync(threadName);

            await dispatcher.BeginInvoke(() => contract = FrameworkElementAdapters.ViewToContractAdapter(factory()));

            return(contract);
        }
Ejemplo n.º 17
0
        public INativeHandleContract GetAddInStatusUI()
        {
            // Convert the FrameworkElement from the add-in to an INativeHandleContract
            // that will be passed across the isolation boundary to the host application.
            FrameworkElement      fe   = this.wpfAddInView.GetAddInStatusUI();
            INativeHandleContract inhc = FrameworkElementAdapters.ViewToContractAdapter(fe);

            return(inhc);
        }
Ejemplo n.º 18
0
        public FrameworkElement GetAddInUI()
        {
            // Convert the INativeHandleContract that was passed from the add-in side
            // of the isolation boundary to a FrameworkElement
            INativeHandleContract inhc = this._wpfAddInContract.GetAddInUI();
            FrameworkElement      fe   = FrameworkElementAdapters.ContractToViewAdapter(inhc);

            return(fe);
        }
Ejemplo n.º 19
0
        public FrameworkElement GetAddInUI(IPersonView personView)
        {
            Person_ViewToContractHostSideAdapter personContract = new Person_ViewToContractHostSideAdapter(personView);

            INativeHandleContract addInUIHwnd = this.addInContract.GetAddInUI(personContract);
            FrameworkElement      addInUI     = FrameworkElementAdapters.ContractToViewAdapter(addInUIHwnd);

            return(addInUI);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///  Tear down any app domain that currently exists, create a new one and reload the control in
        ///  the given app domain.
        /// </summary>
        public async void Reload()
        {
            UnloadDomain();

            Status = ControlHostStatus.Waiting;

            if (!File.Exists(_configuration.PathToAssembly))
            {
                // try again in a little bit
                _timer.Start();
                return;
            }

            AdditionalInformation = null;
            Status = ControlHostStatus.Loading;

            try
            {
                // creating an app-domain (and loading everything etc.) takes a while, so do it on a background
                // thread and resume later.
                await Task.Run(() =>
                {
                    _lastDomain = AppDomainUtils.CreateShadowAppDomain("Document-Host")
                                  .ResolveAssembliesFrom(_rootDictionary);

                    _currentEntryPoint = _lastDomain.CreateInstanceOf <InAppDomainController>()
                                         .FindEntryPoint(_assemblyToObserve);
                });

                // dictionaries are serialized (read: copied) instead of passed by reference across app-domains
                Dictionary <string, string> tempConfiguration;
                var reference = _currentEntryPoint.Initialize(_configuration.Data, out tempConfiguration);
                _configuration.Data = tempConfiguration;

                var proxyElement = FrameworkElementAdapters.ContractToViewAdapter(reference);

                Host = proxyElement;
                proxyElement.Loaded += delegate
                {
                    Keyboard.Focus(proxyElement);
                    TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
                    Host.MoveFocus(request);
                };

                Status = ControlHostStatus.Valid;
            }
            catch (Exception exception)
            {
                AdditionalInformation = exception.ToString();
                UnloadDomain(ignoreShutdown: true);

                Status = ControlHostStatus.Waiting;
            }
        }
        /// <summary>
        ///     Gets the options user interface.
        /// </summary>
        /// <returns></returns>
        public FrameworkElement GetOptionsUserInterface( )
        {
            /////
            // Convert the INativeHandleContract that was passed from the add-in side
            // of the isolation boundary to a FrameworkElement
            /////
            INativeHandleContract inhc = _contract.GetOptionsUserInterface( );

            FrameworkElement fe = FrameworkElementAdapters.ContractToViewAdapter(inhc);

            return(fe);
        }
Ejemplo n.º 22
0
        private INativeHandleContract LoadPluginCore(string assembly, string typeName)
        {
            var objectHandle = Activator.CreateInstance(assembly, typeName);

            pluginController = (IPluginController)objectHandle.Unwrap();
            pluginController.Initialize();
            var view      = pluginController.CreateMainView();
            var contract  = FrameworkElementAdapters.ViewToContractAdapter((FrameworkElement)view);
            var insulator = new NativeHandleContractInsulator(contract);

            return(insulator);
        }
        /// <summary>
        ///     Gets the tool bar.
        /// </summary>
        /// <returns></returns>
        public FrameworkElement GetToolBar( )
        {
            /////
            // Convert the INativeHandleContract that was passed from the add-in side
            // of the isolation boundary to a FrameworkElement
            /////
            INativeHandleContract inhc = _contract.GetToolBar( );

            FrameworkElement toolbar = FrameworkElementAdapters.ContractToViewAdapter(inhc);

            return(toolbar);
        }
Ejemplo n.º 24
0
        public object ToContract(Control control)
        {
            var view = control.ToNative(true);

            var holder = new swc.ScrollViewer
            {
                HorizontalScrollBarVisibility = swc.ScrollBarVisibility.Disabled,
                VerticalScrollBarVisibility   = swc.ScrollBarVisibility.Disabled,
                Content = view
            };

            return(FrameworkElementAdapters.ViewToContractAdapter(holder));
        }
Ejemplo n.º 25
0
        public void ShowWindow(IRemoteControl window)
        {
            if (window == null)
            {
                throw new ArgumentException("Window argument cannot be null");
            }

            bool   IsContract           = false;
            bool   IsAirspaceDecoration = false;
            object Control = null;

            try {
                Control = window.GetControl();
            } catch (SerializationException) {
                INativeHandleContract contract = window.GetControl(true) as INativeHandleContract;
                if (contract != null)
                {
                    Control              = FrameworkElementAdapters.ContractToViewAdapter(contract);
                    IsContract           = true;
                    IsAirspaceDecoration = window.EnableAirspaceFix;
                }
            }
            if (Control != null)
            {
                if (CurrentWindow != null)
                {
                    WindowStack.Push(CurrentWindow);
                }

                if (IsContract && IsAirspaceDecoration)
                {
                    Control = new AirspaceDecorator()
                    {
                        AirspaceMode = AirspaceMode.Redirect,
                        IsInputRedirectionEnabled  = true,
                        IsOutputRedirectionEnabled = true,
                        Background = Brushes.White,
                        Content    = Control
                    };
                }

                CurrentWindow = window;
                CurrentWindow.OnShow();
                UpdateTransition(Control, ((IsContract && !IsAirspaceDecoration) || (this.IsContract && !this.IsAirspaceDecoration))
                    ? TransitionType.Normal
                    : DefaultTransition);
                this.IsContract           = IsContract;
                this.IsAirspaceDecoration = IsAirspaceDecoration;
            }
        }
        /// <summary>
        /// Gets the add in UI.
        /// </summary>
        /// <returns></returns>
        public INativeHandleContract GetAddInUi()
        {
            // Convert the FrameworkElement from the add-in to an INativeHandleContract
            // that will be passed across the isolation boundary to the host application.
            var frameworkElement = view.GetAddInUi();

            if (frameworkElement == null)
            {
                return(null);
            }

            var nativeHandleContract = FrameworkElementAdapters.ViewToContractAdapter(frameworkElement);

            return(nativeHandleContract);
        }
        /// <summary>
        ///     Gets the add in UI.
        /// </summary>
        /// <returns></returns>
        public FrameworkElement GetAddInUi()
        {
            // Convert the INativeHandleContract that was passed from the add-in side
            // of the isolation boundary to a FrameworkElement
            var nativeHandleContract = contract.GetAddInUi();

            if (nativeHandleContract == null)
            {
                return(null);
            }

            var frameworkElement = FrameworkElementAdapters.ContractToViewAdapter(nativeHandleContract);

            return(frameworkElement);
        }
        //public INativeHandleContract GetAddInUI()
        //{
        //    // Convert the FrameworkElement from the add-in to an INativeHandleContract
        //    // that will be passed across the isolation boundary to the host application.
        //    FrameworkElement fe = this._wpfAddInView.GetAddInUI();
        //    INativeHandleContract inhc = FrameworkElementAdapters.ViewToContractAdapter(fe);
        //    return inhc;
        //}

        public INativeHandleContract GetAddInUI()
        {
            // Convert the FrameworkElement from the add-in to an INativeHandleContract
            // that will be passed across the isolation boundary to the host application.
            System.AddIn.Contract.INativeHandleContract value = null;
            _ad.DoWork(
                delegate
            {
                //This special adapter has one purposes:
                //1. Cut off the standard WPF tabbing support to ensure that it doesn't do its work on the wrong thread (by ensuring it doesn't do it at all)
                FrameworkElement fe        = _wpfAddInView.GetAddInUI();
                INativeHandleContract inhc = FrameworkElementAdapters.ViewToContractAdapter(fe);
                value = new MyNativeHandle(inhc);
            }
                );
            return(value);
        }
        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.º 30
0
    public INativeHandleContract GetControl(string AssemblyName, string strFullNamespaceName)
    {
        var assembly = Assembly.LoadFrom(m_strAssemblyDirectory + AssemblyName);
        var type1    = typeof(IUPiAssemblyProcedure);
        var type2    = typeof(IUPiCardProcedure);
        var type3    = typeof(IUPiDatabaseFrame);
        var type4    = typeof(IUPiUserFrame);
        var t        = from T in assembly.GetTypes() where type1.IsAssignableFrom(T) || type2.IsAssignableFrom(T) || type3.IsAssignableFrom(T) || type4.IsAssignableFrom(T) select T;

        if (t.Count <Type>() == 0)
        {
            return(null);
        }
        var tName = t.First <Type>().FullName;

        _currentInstance = assembly.CreateInstance(tName);
        return(FrameworkElementAdapters.ViewToContractAdapter((FrameworkElement)_currentInstance));
    }