Exemple #1
0
        /// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
        /// <param term='commandName'>The name of the command to execute.</param>
        /// <param term='executeOption'>Describes how the command should be run.</param>
        /// <param term='varIn'>Parameters passed from the caller to the command handler.</param>
        /// <param term='varOut'>Parameters passed from the command handler to the caller.</param>
        /// <param term='handled'>Informs the caller if the command was handled or not.</param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if (commandName == "SSMSAddin.Connect.SSMSAddin")
                {
                    Document document = ((DTE2)ServiceCache.ExtensibilityModel).ActiveDocument;
                    if (document != null)
                    {
                        //replace currently selected text
                        TextSelection selection = (TextSelection)document.Selection;


                        //selection.Insert(@"xxxxxx", (Int32)EnvDTE.vsInsertFlags.vsInsertFlagsContainNewText);
                        //VisualisationPane myControl = new VisualisationPane();
                        //Windows2 myWindow = (Windows2) _applicationObject.Windows;
                        //var window = myWindow.CreateToolWindow2(_addInInstance,
                        //    System.Reflection.Assembly.GetExecutingAssembly().Location, "SSMSAddin.VisualisationPane",
                        //    "xxxx", "{5B7F8C1C-65B9-2aca-1Ac3-12AcBbAF21d5}", myControl);
                        //window.Visible = true;


                        try
                        {
                            RegistryAccess ra = new RegistryAccess("SQLDep", false);
                            // "3c81b7e5-109f-49c0-bfc7-a67c3cb67b62"
                            string userAccountId = ra.Read("userAccountId");


                            bool        execute = false;
                            bool        save    = false;
                            AskUserForm askUser = new AskUserForm(userAccountId);

                            // Show testDialog as a modal dialog and determine if DialogResult = OK.
                            if (askUser.ShowDialog(null) == DialogResult.OK)
                            {
                                // Read the contents of testDialog's TextBox.
                                execute       = true;
                                userAccountId = askUser.UserId;
                                save          = askUser.StoreAble;
                            }
                            else
                            {
                            }
                            askUser.Dispose();

                            if (save)
                            {
                                ra.Write("userAccountId", userAccountId);
                            }

                            if (execute)
                            {
                                string result = "";
                                string json   = "{ \"userAccountId\":\"" + userAccountId + "\", \"dialect\":\"mssql\", \"queries\": [ { \"sourceCode\": \"" + selection.Text + "\" } ] }";
                                using (var client = new WebClient())
                                {
                                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                                    result = client.UploadString("https://sqldep.com/api/rest/sqlset/create/", "POST", json);

                                    // REMOVE
                                    // MessageBox.Show(result);
                                }

                                // PARSE RESULTS HERE AND DISPLAY ON PANEL
                                XmlDocument doc    = JsonConvert.DeserializeXmlNode(result, "Root");
                                string      retUrl = doc["Root"]["urlToVisualisation"].InnerText;

                                // otevre IE (chrome)
                                System.Diagnostics.Process.Start(retUrl);

                                // okenko - take moznost
                                //myControl.webBrowser1.Navigate(retUrl);
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                    }

                    handled = true;
                    return;
                }
            }
        }
Exemple #2
0
        /// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
        /// <param term='commandName'>The name of the command to execute.</param>
        /// <param term='executeOption'>Describes how the command should be run.</param>
        /// <param term='varIn'>Parameters passed from the caller to the command handler.</param>
        /// <param term='varOut'>Parameters passed from the command handler to the caller.</param>
        /// <param term='handled'>Informs the caller if the command was handled or not.</param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if (commandName == "SSMSAddin.Connect.SSMSAddin")
                {
                    Document document = ((DTE2)ServiceCache.ExtensibilityModel).ActiveDocument;
                    if (document != null)
                    {
                        //replace currently selected text
                        TextSelection selection = (TextSelection)document.Selection;

                        //selection.Insert(@"xxxxxx", (Int32)EnvDTE.vsInsertFlags.vsInsertFlagsContainNewText);
                        //VisualisationPane myControl = new VisualisationPane();
                        //Windows2 myWindow = (Windows2) _applicationObject.Windows;
                        //var window = myWindow.CreateToolWindow2(_addInInstance,
                        //    System.Reflection.Assembly.GetExecutingAssembly().Location, "SSMSAddin.VisualisationPane",
                        //    "xxxx", "{5B7F8C1C-65B9-2aca-1Ac3-12AcBbAF21d5}", myControl);
                        //window.Visible = true;

                        try
                        {
                            RegistryAccess ra = new RegistryAccess("SQLDep", false);
                            // "3c81b7e5-109f-49c0-bfc7-a67c3cb67b62"
                            string userAccountId = ra.Read("userAccountId");

                            bool execute = false;
                            bool save = false;
                            AskUserForm askUser = new AskUserForm(userAccountId);

                            // Show testDialog as a modal dialog and determine if DialogResult = OK.
                            if (askUser.ShowDialog(null) == DialogResult.OK)
                            {
                                // Read the contents of testDialog's TextBox.
                                execute = true;
                                userAccountId = askUser.UserId;
                                save = askUser.StoreAble;
                            }
                            else
                            {
                            }
                            askUser.Dispose();

                            if (save)
                            {
                                ra.Write("userAccountId", userAccountId);
                            }

                            if (execute)
                            {
                                string result = "";
                                string json = "{ \"userAccountId\":\"" + userAccountId + "\", \"dialect\":\"mssql\", \"queries\": [ { \"sourceCode\": \"" + selection.Text + "\" } ] }";
                                using (var client = new WebClient())
                                {
                                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                                    result = client.UploadString("https://sqldep.com/api/rest/sqlset/create/", "POST", json);

                                    // REMOVE
                                    // MessageBox.Show(result);
                                }

                                // PARSE RESULTS HERE AND DISPLAY ON PANEL
                                XmlDocument doc = JsonConvert.DeserializeXmlNode(result, "Root");
                                string retUrl = doc["Root"]["urlToVisualisation"].InnerText;

                                // otevre IE (chrome)
                                System.Diagnostics.Process.Start(retUrl);

                                // okenko - take moznost
                                //myControl.webBrowser1.Navigate(retUrl);

                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                    }

                    handled = true;
                    return;
                }
            }
        }