Ejemplo n.º 1
0
        /// <summary>
        ///     Initialization of the package; this method is called right after the package is sited, so this is the place
        ///     where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering InitializeAsync() of: {0}", ToString()));
            await base.InitializeAsync(cancellationToken, progress);

            IDEBuildLogger.UserRegistryRoot = UserRegistryRoot;

            // Switching to main thread to use GetService RPC and cast to service interface (which may involve COM operations)
            // Note: most of our work is not supposed to be heavy, mostly registration of services and callbacks
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            solutionEventsListener = new SolutionEventsListener(this);
            solutionEventsListener.BeforeSolutionClosed += solutionEventsListener_BeforeSolutionClosed;
            solutionEventsListener.AfterSolutionBackgroundLoadComplete += solutionEventsListener_AfterSolutionBackgroundLoadComplete;
            solutionEventsListener.AfterActiveConfigurationChange += SolutionEventsListener_AfterActiveConfigurationChange;
            solutionEventsListener.StartupProjectChanged += SolutionEventsListener_OnStartupProjectChanged;

            dte2 = GetGlobalService(typeof(SDTE)) as DTE2;

            // Register the C# language service
            var serviceContainer = this as IServiceContainer;
            errorListProvider = new ErrorListProvider(this)
            {
                ProviderGuid = new Guid("ad1083c5-32ad-403d-af3d-32fee7abbdf1"),
                ProviderName = "Xenko Shading Language"
            };
            var langService = new NShaderLanguageService(errorListProvider);
            langService.SetSite(this);
            langService.InitializeColors(); // Make sure to initialize colors before registering!
            serviceContainer.AddService(typeof(NShaderLanguageService), langService, true);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
            if (null != mcs)
            {
                XenkoCommands.ServiceProvider = this;
                XenkoCommands.RegisterCommands(mcs);
            }

            // Register a timer to call our language service during
            // idle periods.
            var mgr = GetService(typeof(SOleComponentManager))
                                       as IOleComponentManager;
            if (m_componentID == 0 && mgr != null)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime |
                                              (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal |
                                              (uint)_OLECADVF.olecadvfRedrawOff |
                                              (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                int hr = mgr.FRegisterComponent(this, crinfo, out m_componentID);
            }

            // Go back to async thread
            await TaskScheduler.Default;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initialization of the package; this method is called right after the package is sited, so this is the place
        ///     where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
            base.Initialize();

            IDEBuildLogger.UserRegistryRoot = UserRegistryRoot;

            solutionEventsListener = new SolutionEventsListener(this);
            solutionEventsListener.AfterSolutionBackgroundLoadComplete += solutionEventsListener_AfterSolutionBackgroundLoadComplete;

            // Initialize the build monitor, that will display BuildEngine results in the Build Output pane.
            buildLogPipeGenerator = new BuildLogPipeGenerator(this);

            dte2 = GetGlobalService(typeof(SDTE)) as DTE2;

            // Register the C# language service
            var serviceContainer = this as IServiceContainer;
            var langService      = new NShaderLanguageService();

            langService.SetSite(this);
            serviceContainer.AddService(typeof(NShaderLanguageService), langService, true);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                ParadoxCommands.ServiceProvider = this;
                ParadoxCommands.RegisterCommands(mcs);
            }

            // Get General Output pane (for error logging)
            var generalOutputPane = GetGeneralOutputPane();

            var paradoxSdkDir = ParadoxCommandsProxy.ParadoxSdkDir;

            if (paradoxSdkDir == null)
            {
                generalOutputPane.OutputStringThreadSafe("Could not find Paradox SDK directory.\r\n");
                generalOutputPane.Activate();
            }

            // Start PackageBuildMonitorRemote in a separate app domain
            buildMonitorDomain = ParadoxCommandsProxy.CreateAppDomain();
            try
            {
                var remoteCommands = ParadoxCommandsProxy.CreateProxy(buildMonitorDomain);
                remoteCommands.StartRemoteBuildLogServer(new BuildMonitorCallback(dte2), buildLogPipeGenerator.LogPipeUrl);
            }
            catch (Exception e)
            {
                generalOutputPane.OutputStringThreadSafe(string.Format("Error loading Paradox SDK: {0}\r\n", e));
                generalOutputPane.Activate();

                // Unload domain right away
                AppDomain.Unload(buildMonitorDomain);
                buildMonitorDomain = null;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initialization of the package; this method is called right after the package is sited, so this is the place
        ///     where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
            base.Initialize();

            IDEBuildLogger.UserRegistryRoot = UserRegistryRoot;

            solutionEventsListener = new SolutionEventsListener(this);
            solutionEventsListener.BeforeSolutionClosed += solutionEventsListener_BeforeSolutionClosed;
            solutionEventsListener.AfterSolutionBackgroundLoadComplete += solutionEventsListener_AfterSolutionBackgroundLoadComplete;
            solutionEventsListener.AfterActiveConfigurationChange      += SolutionEventsListener_AfterActiveConfigurationChange;
            solutionEventsListener.StartupProjectChanged += SolutionEventsListener_OnStartupProjectChanged;

            dte2 = GetGlobalService(typeof(SDTE)) as DTE2;

            // Register the C# language service
            var serviceContainer = this as IServiceContainer;

            errorListProvider = new ErrorListProvider(this)
            {
                ProviderGuid = new Guid("ad1083c5-32ad-403d-af3d-32fee7abbdf1"),
                ProviderName = "Xenko Shading Language"
            };
            var langService = new NShaderLanguageService(errorListProvider);

            langService.SetSite(this);
            langService.InitializeColors(); // Make sure to initialize colors before registering!
            serviceContainer.AddService(typeof(NShaderLanguageService), langService, true);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                XenkoCommands.ServiceProvider = this;
                XenkoCommands.RegisterCommands(mcs);
            }

            // Register a timer to call our language service during
            // idle periods.
            var mgr = GetService(typeof(SOleComponentManager))
                      as IOleComponentManager;

            if (m_componentID == 0 && mgr != null)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime |
                                   (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal |
                                     (uint)_OLECADVF.olecadvfRedrawOff |
                                     (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                int hr = mgr.FRegisterComponent(this, crinfo, out m_componentID);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Initialization of the package; this method is called right after the package is sited, so this is the place
        ///     where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));
            base.Initialize();

            IDEBuildLogger.UserRegistryRoot = UserRegistryRoot;

            solutionEventsListener = new SolutionEventsListener(this);
            solutionEventsListener.AfterSolutionBackgroundLoadComplete += solutionEventsListener_AfterSolutionBackgroundLoadComplete;

            // Initialize the build monitor, that will display BuildEngine results in the Build Output pane.
            buildLogPipeGenerator = new BuildLogPipeGenerator(this);

            dte2 = GetGlobalService(typeof(SDTE)) as DTE2;

            // Register the C# language service
            var serviceContainer  = this as IServiceContainer;
            var errorListProvider = new ErrorListProvider(this)
            {
                ProviderGuid = new Guid("ad1083c5-32ad-403d-af3d-32fee7abbdf1"),
                ProviderName = "Paradox Shading Language"
            };
            var langService = new NShaderLanguageService(errorListProvider);

            langService.SetSite(this);
            langService.InitializeColors(); // Make sure to initialize colors before registering!
            serviceContainer.AddService(typeof(NShaderLanguageService), langService, true);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                ParadoxCommands.ServiceProvider = this;
                ParadoxCommands.RegisterCommands(mcs);
            }

            // Get General Output pane (for error logging)
            var generalOutputPane = GetGeneralOutputPane();

            var paradoxSdkDir = ParadoxCommandsProxy.ParadoxSdkDir;

            if (paradoxSdkDir == null)
            {
                generalOutputPane.OutputStringThreadSafe("Could not find Paradox SDK directory.\r\n");
                generalOutputPane.Activate();
            }

            // Start PackageBuildMonitorRemote in a separate app domain
            buildMonitorDomain = ParadoxCommandsProxy.CreateParadoxDomain();
            try
            {
                var remoteCommands = ParadoxCommandsProxy.CreateProxy(buildMonitorDomain);
                remoteCommands.StartRemoteBuildLogServer(new BuildMonitorCallback(dte2), buildLogPipeGenerator.LogPipeUrl);
            }
            catch (Exception e)
            {
                generalOutputPane.OutputStringThreadSafe(string.Format("Error loading Paradox SDK: {0}\r\n", e));
                generalOutputPane.Activate();

                // Unload domain right away
                AppDomain.Unload(buildMonitorDomain);
                buildMonitorDomain = null;
            }

            // Preinitialize the parser in a separate thread
            var thread = new System.Threading.Thread(
                () =>
            {
                try
                {
                    ParadoxCommandsProxy.GetProxy().Initialize(null);
                }
                catch (Exception ex)
                {
                    generalOutputPane.OutputStringThreadSafe(string.Format("Error Initializing Paradox Language Service: {0}\r\n", ex.InnerException ?? ex));
                    generalOutputPane.Activate();
                    errorListProvider.Tasks.Add(new ErrorTask(ex.InnerException ?? ex));
                }
            });

            thread.Start();

            // Register a timer to call our language service during
            // idle periods.
            var mgr = GetService(typeof(SOleComponentManager))
                      as IOleComponentManager;

            if (m_componentID == 0 && mgr != null)
            {
                OLECRINFO[] crinfo = new OLECRINFO[1];
                crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime |
                                   (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal |
                                     (uint)_OLECADVF.olecadvfRedrawOff |
                                     (uint)_OLECADVF.olecadvfWarningsOff;
                crinfo[0].uIdleTimeInterval = 1000;
                int hr = mgr.FRegisterComponent(this, crinfo, out m_componentID);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///   Initializes the package; this method is called right after the package is sited, so this is the place
        ///   where all the initialization that rely on services provided by Visual Studio is executed.
        /// </summary>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering InitializeAsync() of: {0}", ToString()));
            await base.InitializeAsync(cancellationToken, progress);

            IDEBuildLogger.UserRegistryRoot = UserRegistryRoot;

            // Switching to main thread to use GetService RPC and cast to service interface (which may involve COM operations)
            // Note: most of our work is not supposed to be heavy, mostly registration of services and callbacks
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            solutionEventsListener = new SolutionEventsListener(this);
            solutionEventsListener.BeforeSolutionClosed           += solutionEventsListener_BeforeSolutionClosed;
            solutionEventsListener.AfterSolutionOpened            += solutionEventsListener_AfterSolutionOpened;
            solutionEventsListener.AfterActiveConfigurationChange += SolutionEventsListener_AfterActiveConfigurationChange;
            solutionEventsListener.StartupProjectChanged          += SolutionEventsListener_OnStartupProjectChanged;

            // Register the C# language service
            // Inspired by https://github.com/IInspectable/Nav.Language.Extensions/commit/08af3d897afac5a54975660fa03f4b629da405e1#diff-b73c0f368f242625f60cfad9cc11f2d5R88
            AddService(typeof(NShaderLanguageService), async(container, cancelToken, type) =>
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancelToken);
                errorListProvider = new ErrorListProvider(this)
                {
                    ProviderGuid = new Guid("ad1083c5-32ad-403d-af3d-32fee7abbdf1"),
                    ProviderName = "Stride Shading Language"
                };

                var langService = new NShaderLanguageService(errorListProvider);
                langService.SetSite(this);
                // Make sure to initialize colors before registering!
                langService.InitializeColors();
                return(langService);
            },
                       promote: true);

            // Add our command handlers for menu (commands must exist in the .vsct file)
            if (await GetServiceAsync(typeof(IMenuCommandService)) is OleMenuCommandService menuCommandService)
            {
                StrideCommands.ServiceProvider = this;
                StrideCommands.RegisterCommands(menuCommandService);
            }

            // Register a timer to call our language service during
            // idle periods.
            if (m_componentID == 0 && GetService(typeof(SOleComponentManager)) is IOleComponentManager componentManager)
            {
                var crInfo = new OLECRINFO[1];
                crInfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO));
                crInfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime |
                                   (uint)_OLECRF.olecrfNeedPeriodicIdleTime;
                crInfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal |
                                     (uint)_OLECADVF.olecadvfRedrawOff |
                                     (uint)_OLECADVF.olecadvfWarningsOff;
                crInfo[0].uIdleTimeInterval = 1000;
                componentManager.FRegisterComponent(this, crInfo, out m_componentID);
            }

            // If there's already a solution loaded, process it
            var dte = (DTE)GetService(typeof(DTE));

            if (dte.Solution.IsOpen)
            {
                await InitializeCommandProxy();
            }

            // Go back to async thread
            await TaskScheduler.Default;
        }