private void btnSaveSettings_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(connectionStringInput.Text))
            {
                MessageBox.Show("Connection string cannot be empty");
                return;
            }

            try
            {
                VsShellSettingsService.WriteSetting("TargetConnectionString", connectionStringInput.Text);

                if (!VsShellSettingsService.ReadSetting <bool>("IsExtensionConfigured"))
                {
                    VsShellSettingsService.WriteSetting("IsExtensionConfigured", true);
                }
            }
            catch (Exception ex)
            {
                NotificationService.PopMessage
                (
                    "Something went wrong!",
                    $"An error occurred when saving the setting.\n{ex.Message}",
                    messageIcon: Microsoft.VisualStudio.Shell.Interop.OLEMSGICON.OLEMSGICON_WARNING
                );
            }

            Close();
        }
示例#2
0
        /// <summary>
        /// Initializes the singleton instance of the command.
        /// </summary>
        /// <param name="package">Owner package, not null.</param>
        public static async Task InitializeAsync(AsyncPackage package)
        {
            // Switch to the main thread - the call to AddCommand in PeekSpSpanCommand's constructor requires
            // the UI thread.
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

            OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            Instance = new PeekSpContextCommand(package, commandService);

            VsShellSettingsService.Initialise(package);
            NotificationService.Initialise(package);
            EditorService.Initialise(package);
        }
示例#3
0
        internal async Task <string> GetStoredProcedureAsync(string storedProcedureName)
        {
            var procedureTuple = QueryService.ParseStoredProcedureName(storedProcedureName);

            var parsedCommand =
                string.Format
                (
                    CommandTempaltes.GetContents,
                    procedureTuple.Item1,
                    procedureTuple.Item2
                ); //need to check if the sp exists? TODO.

            using (var connection = new SqlConnection())
            {
                connection.ConnectionString = VsShellSettingsService.ReadSetting <string>("TargetConnectionString");

                using (var command = new SqlCommand(parsedCommand))
                {
                    command.CommandType = System.Data.CommandType.Text;
                    command.Connection  = connection;

                    var contentBuilder = new StringBuilder();

                    await connection.OpenAsync();

                    using (var sqlReader = await command.ExecuteReaderAsync())
                    {
                        if (sqlReader.HasRows)
                        {
                            while (await sqlReader.ReadAsync())
                            {
                                contentBuilder.Append(sqlReader.GetString(0));
                            }
                        }

                        sqlReader.Close();
                    }

                    connection.Close();

                    var contentesult = contentBuilder.ToString();
                    return(contentesult);
                }
            }
        }
示例#4
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            //TODO: Check if the extension is configured first.
            //If not, show an info bar with "Configure DB Strings"
            //Otherwise, carry on as usual.


            if (!VsShellSettingsService.ReadSetting <bool>("IsExtensionConfigured"))
            {
                InfoBarService.Instance.ShowInfoBar
                (
                    "Hi! Looks like DbPeek is initialised for the first time. Configure now?",
                    new InfoBarHyperlink("Configure", HyperlinkCommands.Configure),
                    new InfoBarHyperlink("Later", HyperlinkCommands.Later)
                );

                return;
            }

            //if everything's alright, capture the selected text.
            var capturedText = EditorService.GetSelection();

            if (!string.IsNullOrWhiteSpace(capturedText))
            {
                try
                {
                    var result = ThreadHelper.JoinableTaskFactory.Run(async delegate
                    {
                        return(await SpUtilsService.Instance.GetStoredProcedureAsync(capturedText));
                    });

                    var dumpFile = FileService.CreateFileWithContents(result);
                    VsShellUtilities.OpenDocument((IServiceProvider)ServiceProvider, @dumpFile);
                }
                catch (Exception ex)
                {
                    NotificationService.PopMessage("Something went wrong!", ex.Message);
                }
            }
        }
 private void SetExistingConnectionString()
 {
     connectionStringInput.Text = VsShellSettingsService.ReadSetting <string>("TargetConnectionString");
 }