示例#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);
        }
        public void Compose_when_unknown_token()
        {
            string input    = "$(Server) $(Database) $(User) $(UnknownToken123) $(Password)";
            string expected = "127.0.0.1 MYDATABASE user1 $(UnknownToken123) user1pass";

            SqlConnectionStringBuilder connstr = new SqlConnectionStringBuilder()
            {
                DataSource         = "127.0.0.1",
                InitialCatalog     = "MYDATABASE",
                UserID             = "user1",
                Password           = "******",
                IntegratedSecurity = false
            };

            IWindowsUser       windowsUser = A.Fake <IWindowsUser>();
            RunParamsProcessor processor   = new RunParamsProcessor(windowsUser);

            string result = processor.Compose(input, connstr);

            Assert.Equal(expected, result);
        }
        public void Compose_when_integrated_security()
        {
            string input    = "$(Server) $(Database) $(User) $(Password)";
            string expected = "127.0.0.1 MYDATABASE user1 ";

            SqlConnectionStringBuilder connstr = new SqlConnectionStringBuilder()
            {
                DataSource         = "127.0.0.1",
                InitialCatalog     = "MYDATABASE",
                IntegratedSecurity = true,
            };

            IWindowsUser windowsUser = A.Fake <IWindowsUser>();

            A.CallTo(() => windowsUser.Name).Returns("user1");

            RunParamsProcessor processor = new RunParamsProcessor(windowsUser);

            string result = processor.Compose(input, connstr);

            Assert.Equal(expected, result);
        }
示例#4
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));
        }