Beispiel #1
0
        public override async void ButtonCallback(object sender, EventArgs e)
        {
            var menuCommand = sender as OleMenuCommand;

            if (menuCommand == null)
            {
                return;
            }

            if (!m_downloading)
            {
                try
                {
                    m_downloading       = true;
                    menuCommand.Visible = false;
                    if (!await CheckForInternetConnection())
                    {
                        m_downloading       = false;
                        menuCommand.Visible = true;
                        return;
                    }

                    m_monoFile.ResetToDefaultDirectory();

                    bool downloadNew = !m_monoFile.CheckFileValid();

                    if (downloadNew)
                    {
                        Output.ProgressBarLabel = "Downloading Mono";
                        await m_monoFile.DownloadMono(Output);

                        //Verify Download
                        bool verified = m_monoFile.CheckFileValid();

                        if (verified)
                        {
                            // Show a Message Box to prove we were here
                            IVsUIShell uiShell = (IVsUIShell)Package.PublicGetService(typeof(SVsUIShell));
                            Guid       clsid   = Guid.Empty;
                            int        result;
                            uiShell.ShowMessageBox(
                                0,
                                ref clsid,
                                "Mono Successfully Downloaded. Would you like to install it to the RoboRIO?",
                                string.Format(CultureInfo.CurrentCulture, "", ToString()),
                                string.Empty,
                                0,
                                OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                OLEMSGICON.OLEMSGICON_INFO,
                                0, // false
                                out result);
                            if (result == 6)
                            {
                                //Install Mono.
                                await m_installButton.DeployMono(m_installButton.GetMenuCommand());
                            }
                        }
                        else
                        {
                            // Show a Message Box to prove we were here
                            IVsUIShell uiShell = (IVsUIShell)Package.PublicGetService(typeof(SVsUIShell));
                            Guid       clsid   = Guid.Empty;
                            int        result;
                            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                                   0,
                                                                                   ref clsid,
                                                                                   "Mono Download Failed. Please Try Again",
                                                                                   string.Format(CultureInfo.CurrentCulture, "", ToString()),
                                                                                   string.Empty,
                                                                                   0,
                                                                                   OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                                   OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                                   OLEMSGICON.OLEMSGICON_INFO,
                                                                                   0, // false
                                                                                   out result));
                        }
                    }
                    else
                    {
                        // Show a Message Box to prove we were here
                        IVsUIShell uiShell = (IVsUIShell)Package.PublicGetService(typeof(SVsUIShell));
                        Guid       clsid   = Guid.Empty;
                        int        result;
                        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                                                                               0,
                                                                               ref clsid,
                                                                               "Mono Already Downloaded",
                                                                               string.Format(CultureInfo.CurrentCulture, "", ToString()),
                                                                               string.Empty,
                                                                               0,
                                                                               OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                                               OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                                                                               OLEMSGICON.OLEMSGICON_INFO,
                                                                               0, // false
                                                                               out result));
                    }
                }
                catch (Exception ex)
                {
                    Output.WriteLine(ex.ToString());
                    m_downloading       = false;
                    menuCommand.Visible = true;
                }
                m_downloading       = false;
                menuCommand.Visible = true;
            }
        }
Beispiel #2
0
        public override void ButtonCallback(object sender, EventArgs e)
        {
            ThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                var menuCommand = sender as OleMenuCommand;
                if (menuCommand == null)
                {
                    return;
                }

                if (!m_downloading)
                {
                    try
                    {
                        m_downloading       = true;
                        menuCommand.Visible = false;
                        // We're just going right back to doing something on the UI thread, so just resume back on the UI thread.
                        if (!await CheckForInternetConnectionAsync().ConfigureAwait(true))
                        {
                            m_downloading       = false;
                            menuCommand.Visible = true;
                            return;
                        }

                        m_monoFile.ResetToDefaultDirectory();

                        bool downloadNew = !m_monoFile.CheckFileValid();

                        if (downloadNew)
                        {
                            Output.ProgressBarLabel = "Downloading Mono";
                            await m_monoFile.DownloadMonoAsync(Output).ConfigureAwait(false);

                            //Verify Download
                            bool verified = m_monoFile.CheckFileValid();

                            if (verified)
                            {
                                // Show a Message Box to prove we were here
                                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                                IVsUIShell uiShell = Package.PublicGetService <IVsUIShell, SVsUIShell>();
                                Guid clsid         = Guid.Empty;
                                int result         = await ShowMessageAsync("Mono Successfully Downloaded. Would you like to install it to the RoboRIO?",
                                                                            string.Empty).ConfigureAwait(false);
                                if (result == 6)
                                {
                                    //Install Mono.
                                    await m_installButton.DeployMonoAsync(m_installButton.GetMenuCommand()).ConfigureAwait(false);
                                }
                            }
                            else
                            {
                                // Show a Message Box to prove we were here
                                await ShowMessageAsync("Mono Download Failed. Please Try Again", string.Empty).ConfigureAwait(false);
                            }
                        }
                        else
                        {
                            // Show a Message Box to prove we were here
                            IVsUIShell uiShell = Package.PublicGetService <IVsUIShell, SVsUIShell>();
                            await ShowMessageAsync("Mono Already Downloaded", string.Empty).ConfigureAwait(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        await Output.WriteLineAsync(ex.ToString()).ConfigureAwait(false);
                        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                        m_downloading       = false;
                        menuCommand.Visible = true;
                    }
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    m_downloading       = false;
                    menuCommand.Visible = true;
                }
            });
        }