示例#1
0
        public VisualStudioInstance(Process process, DTE dte)
        {
            _hostProcess = process;
            _dte = dte;

            dte.ExecuteCommandAsync(VisualStudioCommandNames.VsStartServiceCommand).GetAwaiter().GetResult();

            _integrationServiceChannel = new IpcClientChannel($"IPC channel client for {_hostProcess.Id}", sinkProvider: null);
            ChannelServices.RegisterChannel(_integrationServiceChannel, ensureSecurity: true);

            // Connect to a 'well defined, shouldn't conflict' IPC channel
            var serviceUri = string.Format($"ipc://{IntegrationService.PortNameFormatString}", _hostProcess.Id);
            _integrationService = (IntegrationService)(Activator.GetObject(typeof(IntegrationService), $"{serviceUri}/{typeof(IntegrationService).FullName}"));
            _integrationService.Uri = serviceUri;

            // There is a lot of VS initialization code that goes on, so we want to wait for that to 'settle' before
            // we start executing any actual code.
            _integrationService.Execute(typeof(RemotingHelper), nameof(RemotingHelper.WaitForSystemIdle));

            _csharpInteractiveWindow = new Lazy<CSharpInteractiveWindow>(() => new CSharpInteractiveWindow(this));
            _editorWindow = new Lazy<EditorWindow>(() => new EditorWindow(this));
            _solutionExplorer = new Lazy<SolutionExplorer>(() => new SolutionExplorer(this));
            _workspace = new Lazy<Workspace>(() => new Workspace(this));

            // Ensure we are in a known 'good' state by cleaning up anything changed by the previous instance
            Cleanup();
        }
示例#2
0
        public VisualStudioInstance(Process process, DTE dte)
        {
            _hostProcess = process;
            _dte         = dte;

            dte.ExecuteCommandAsync(VisualStudioCommandNames.VsStartServiceCommand).GetAwaiter().GetResult();

            _integrationServiceChannel = new IpcClientChannel($"IPC channel client for {_hostProcess.Id}", sinkProvider: null);
            ChannelServices.RegisterChannel(_integrationServiceChannel, ensureSecurity: true);

            // Connect to a 'well defined, shouldn't conflict' IPC channel
            var serviceUri = string.Format($"ipc://{IntegrationService.PortNameFormatString}", _hostProcess.Id);

            _integrationService     = (IntegrationService)(Activator.GetObject(typeof(IntegrationService), $"{serviceUri}/{typeof(IntegrationService).FullName}"));
            _integrationService.Uri = serviceUri;

            // There is a lot of VS initialization code that goes on, so we want to wait for that to 'settle' before
            // we start executing any actual code.
            _integrationService.Execute(typeof(RemotingHelper), nameof(RemotingHelper.WaitForSystemIdle));

            _csharpInteractiveWindow = new Lazy <CSharpInteractiveWindow>(() => new CSharpInteractiveWindow(this));
            _editorWindow            = new Lazy <EditorWindow>(() => new EditorWindow(this));
            _solutionExplorer        = new Lazy <SolutionExplorer>(() => new SolutionExplorer(this));
            _workspace = new Lazy <Workspace>(() => new Workspace(this));

            // Ensure we are in a known 'good' state by cleaning up anything changed by the previous instance
            Cleanup();
        }
        public VisualStudioInstance(Process hostProcess, EnvDTE.DTE dte)
        {
            _hostProcess = hostProcess;
            _dte         = dte;

            StartRemoteIntegrationService(dte);

            _integrationServiceChannel = new IpcClientChannel($"IPC channel client for {_hostProcess.Id}", sinkProvider: null);
            ChannelServices.RegisterChannel(_integrationServiceChannel, ensureSecurity: true);

            // Connect to a 'well defined, shouldn't conflict' IPC channel
            _integrationService = IntegrationService.GetInstanceFromHostProcess(hostProcess);

            // Create marshal-by-ref object that runs in host-process.
            _inProc = ExecuteInHostProcess <VisualStudio_InProc>(
                type: typeof(VisualStudio_InProc),
                methodName: nameof(VisualStudio_InProc.Create));

            // There is a lot of VS initialization code that goes on, so we want to wait for that to 'settle' before
            // we start executing any actual code.
            _inProc.WaitForSystemIdle();

            this.CSharpInteractiveWindow = new CSharpInteractiveWindow_OutOfProc(this);
            this.Editor                = new Editor_OutOfProc(this);
            this.SolutionExplorer      = new SolutionExplorer_OutOfProc(this);
            this.VisualStudioWorkspace = new VisualStudioWorkspace_OutOfProc(this);

            this.SendKeys = new SendKeys(this);

            // Ensure we are in a known 'good' state by cleaning up anything changed by the previous instance
            CleanUp();
        }
示例#4
0
        public static void Execute(this IntegrationService integrationService, string assemblyFilePath, string typeFullName, string methodName, BindingFlags bindingFlags = (BindingFlags.Public | BindingFlags.Static), params object[] parameters)
        {
            var result = integrationService.Execute(assemblyFilePath, typeFullName, methodName, bindingFlags, parameters);

            if (result != null)
            {
                throw new InvalidOperationException("The specified call was not expected to return a value.");
            }
        }
示例#5
0
        public static T Execute <T>(this IntegrationService integrationService, string assemblyFilePath, string typeFullName, string methodName, BindingFlags bindingFlags = (BindingFlags.Public | BindingFlags.Static), params object[] parameters)
        {
            var objectUri = integrationService.Execute(assemblyFilePath, typeFullName, methodName, bindingFlags, parameters);

            if (objectUri == null)
            {
                throw new InvalidOperationException("The specified call was expected to return a value.");
            }

            return((T)(Activator.GetObject(typeof(T), $"{integrationService.Uri}/{objectUri}")));
        }
        /// <summary>Starts the IPC server for the Integration Test service.</summary>
        private void StartServiceCallback(object sender, EventArgs e)
        {
            if (_startServiceMenuCmd.Enabled)
            {
                _service = new IntegrationService();
                _serviceChannel = new IpcServerChannel(null, DefaultPortName, DefaultSinkProvider);

                var serviceType = typeof(IntegrationService);
                _marshalledService = RemotingServices.Marshal(_service, serviceType.FullName, serviceType);

                _serviceChannel.StartListening(null);

                SwapAvailableCommands(_startServiceMenuCmd, _stopServiceMenuCmd);
            }
        }
示例#7
0
        public VisualStudioInstance(Process process, DTE dte)
        {
            _hostProcess = process;
            _dte         = dte;

            ExecuteDteCommandAsync("Tools.StartIntegrationTestService").GetAwaiter().GetResult();

            _serviceChannel = new IpcClientChannel($"ipc channel client for {_hostProcess.Id}", sinkProvider: null);
            ChannelServices.RegisterChannel(_serviceChannel, ensureSecurity: true);

            // Connect to a 'well defined, shouldn't conflict' IPC channel
            _serviceUri = string.Format($"ipc://{IntegrationService.PortNameFormatString}", _hostProcess.Id);
            _service    = (IntegrationService)(Activator.GetObject(typeof(IntegrationService), $"{_serviceUri}/{typeof(IntegrationService).FullName}"));

            _csharpInteractiveWindow = new Lazy <InteractiveWindow>(() => InteractiveWindow.CreateCSharpInteractiveWindow(this));
            _editorWindow            = new Lazy <EditorWindow>(() => new EditorWindow(this));
            _solutionExplorer        = new Lazy <SolutionExplorer>(() => new SolutionExplorer(this));
        }
        /// <summary>Stops the IPC server for the Integration Test service.</summary>
        private void StopServiceCallback(object sender, EventArgs e)
        {
            if (_stopServiceMenuCmd.Enabled)
            {
                _serviceChannel?.StopListening(null);

                _marshalledService = null;
                _serviceChannel = null;
                _service = null;

                SwapAvailableCommands(_stopServiceMenuCmd, _startServiceMenuCmd);
            }
        }
示例#9
0
 public static void Execute(this IntegrationService integrationService, Type type, string methodName, BindingFlags bindingFlags = (BindingFlags.Public | BindingFlags.Static), params object[] parameters)
 => Execute(integrationService, type.Assembly.Location, type.FullName, methodName, bindingFlags, parameters);