コード例 #1
0
        private ScriptCommandSet(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            _package = package;

            OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService != null)
            {
                var scriptMenuCommandId = new CommandID(CommandSet, CommandScriptId);
                var scriptMenuCommand   = new MenuCommand(this.MenuScriptCallback, scriptMenuCommandId);
                commandService.AddCommand(scriptMenuCommand);

                var runMenuCommandId = new CommandID(CommandSet, CommandRunId);
                var runMenuCommand   = new MenuCommand(this.MenuRunCallback, runMenuCommandId);
                commandService.AddCommand(runMenuCommand);
            }

            DTE2         dte         = (DTE2)ServiceProvider.GetService(typeof(DTE));
            IHostContext hostCtx     = new HostContext(dte);
            IWindowsUser windowsUser = new WindowsUser();

            string registryMasterKey = Registry.CurrentUser.Name + "\\Software\\SSMScripter";

            IScripterParser        scripterParser        = new ScripterParser();
            IScripter              scripter              = new SmoScripter();
            IScripterConfigStorage scripterConfigStorage = new ScripterConfigRegistryStorage(registryMasterKey);

            _scriptAction = new ScriptAction(hostCtx, scripter, scripterParser, scripterConfigStorage);

            IRunConfigStorage   runConfigStorage   = new RunConfigRegistryStorage(registryMasterKey);
            IRunContextProvider runContextProvider = new RunContextProvider(hostCtx, runConfigStorage);
            IRunParamsProcessor runParamsProcessor = new RunParamsProcessor(windowsUser);
            IRunProcessStarter  runProcessStarter  = new RunProcessStarter();

            _runAction = new RunAction(runContextProvider, runParamsProcessor, runProcessStarter);
        }
コード例 #2
0
        private IEnumerable <ICommand> CreateCommands()
        {
            IHostContext hostCtx     = new HostContext(_app);
            IWindowsUser windowsUser = new WindowsUser();

            string registryMasterKey = Registry.CurrentUser.Name + "\\Software\\SSMScripter";

            IScripterParser        scripterParser        = new ScripterParser();
            IScripter              scripter              = new SmoScripter();
            IScripterConfigStorage scripterConfigStorage = new ScripterConfigRegistryStorage(registryMasterKey);
            ScriptAction           scriptAction          = new ScriptAction(hostCtx, scripter, scripterParser, scripterConfigStorage);

            yield return(new ScriptCommand(_app, _addin, scriptAction));

            IRunConfigStorage   runConfigStorage   = new RunConfigRegistryStorage(registryMasterKey);
            IRunContextProvider runContextProvider = new RunContextProvider(hostCtx, runConfigStorage);
            IRunParamsProcessor runParamsProcessor = new RunParamsProcessor(windowsUser);
            IRunProcessStarter  runProcessStarter  = new RunProcessStarter();
            RunAction           runAction          = new RunAction(runContextProvider, runParamsProcessor, runProcessStarter);


            yield return(new RunCommand(_app, _addin, runAction));
        }