Interaction logic for AuthDialog.xaml
Inheritance: System.Windows.Window
コード例 #1
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 async void MenuItemCallback(object sender, EventArgs e)
        {
            var gistClient = new GistsApi.GistClient(Properties.APIKeys.GistClientID,
                                                     Properties.APIKeys.GistClientSecret,
                                                     "GistsForVisualStudio/1.0");

            var authDialog = new AuthDialog();

            authDialog.webBrowser.Navigate(gistClient.AuthorizeUrl);
            authDialog.ShowDialog();
            if (authDialog.DialogResult == true)
            {
                await gistClient.Authorize(authDialog.authCode);

                var viewHost = GetCurrentViewHost();
                var filename = Path.GetFileName(GetCurrentFilename(viewHost));

                var publishDialog = new PublishGistDialog()
                {
                    Filename = Path.GetFileName(filename)
                };
                if (publishDialog.ShowDialog() == true)
                {
                    string codeToPublish;
                    if (publishDialog.PublishOnlySelection)
                    {
                        codeToPublish = GetSelectedTextFromEditor(viewHost);
                    }
                    else
                    {
                        codeToPublish = GetAllTextFromEditor(viewHost);
                    }


                    var gistFiles = new[] { Tuple.Create(filename, codeToPublish) };

                    var result = await gistClient.CreateAGist(publishDialog.Description, publishDialog.IsPublic, gistFiles);

                    var successDialog = new SuccessDialog()
                    {
                        Hyperlink = new Uri(result.html_url)
                    };
                    successDialog.ShowDialog();
                }
            }
        }
コード例 #2
0
ファイル: CreateGist.cs プロジェクト: rprouse/Gists
        /// <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 async void MenuItemCallback(object sender, EventArgs e)
        {
            var gistClient = new GistsApi.GistClient(Properties.Settings.Default.ClientID,
                                                     Properties.Settings.Default.ClientSecret,
                                                     "GistsForVisualStudio/1.0");

            var authDialog = new AuthDialog();
            authDialog.webBrowser.Navigate(gistClient.AuthorizeUrl);
            authDialog.ShowDialog();
            if (authDialog.DialogResult == true)
            {
                await gistClient.Authorize(authDialog.authCode);

                var viewHost = GetCurrentViewHost();
                var filename = Path.GetFileName(GetCurrentFilename(viewHost));

                var publishDialog = new PublishGistDialog();
                publishDialog.Filename = Path.GetFileName(filename);

                if (publishDialog.ShowDialog() == true)
                {
                    string codeToPublish;
                    if (publishDialog.PublishOnlySelection)
                    {
                        codeToPublish = GetSelectedTextFromEditor(viewHost);
                    }
                    else
                    {
                        codeToPublish = GetAllTextFromEditor(viewHost);
                    }


                    var gistFiles = new[] { Tuple.Create(filename, codeToPublish) };

                    var result = await gistClient.CreateAGist(publishDialog.Description, publishDialog.IsPublic, gistFiles);

                    var successDialog = new SuccessDialog();
                    successDialog.Hyperlink = new Uri(result.html_url);

                    successDialog.ShowDialog();
                }
            }
        }