Provides functionality for publishing stored procedures to projects or databases
Exemplo n.º 1
0
        public void PublishDacpac(string rFile) {
            var fs = new FileSystem();
            var settings = new SqlSProcPublishSettings();
            settings.TargetType = PublishTargetType.Dacpac;

            SetupProjectMocks("project.rproj");

            var builder = Substitute.For<IDacPacBuilder>();
            builder.When(x => x.Build(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<string>>())).Do(c => {
                c.Args()[0].Should().Be("project.dacpac");
                c.Args()[1].Should().Be("project");

                var e = c.Args()[2] as IEnumerable<string>;
                e.Should().HaveCount(1);
                e.First().Should().StartWith("CREATE PROCEDURE ProcName");
            });

            _dacServices.GetBuilder().Returns(builder);

            var files = new string[] { Path.Combine(_files.DestinationPath, rFile) };
            var publisher = new SProcPublisher(_appShell, _pss, fs, _dacServices);
            publisher.Publish(settings, files);

            builder.Received(1).Build(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<IEnumerable<string>>());
        }
Exemplo n.º 2
0
        private void Handle() {
            var project = _pss.GetSelectedProject<IVsHierarchy>()?.GetDTEProject();
            if (project != null) {
                var sprocFiles = project.GetSProcFiles(_pss);
                if (sprocFiles.Any()) {
                    try {
                        // Make sure all files are saved and up to date on disk.
                        var dte = _appShell.GetGlobalService<DTE>(typeof(DTE));
                        dte.ExecuteCommand("File.SaveAll");

                        var publisher = new SProcPublisher(_appShell, _pss, _fs, _dacServicesProvider.GetDacPackageServices());
                        var settings = new SqlSProcPublishSettings(_settings);
                        publisher.Publish(settings, sprocFiles);
                    } catch (Exception ex) {
                        _appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.SqlPublish_PublishError, ex.Message));
                    }
                } else {
                    _appShell.ShowErrorMessage(Resources.SqlPublishDialog_NoSProcFiles);
                }
            }
        }