コード例 #1
0
        public static bool ShowWaitingPopup(string message, IReadOnlyList <LongAction> actions, IActionLog log)
        {
            CommonMessagePump msgPump = new CommonMessagePump();

            msgPump.AllowCancel        = true;
            msgPump.EnableRealProgress = true;
            msgPump.WaitTitle          = "R Tools for Visual Studio";
            msgPump.WaitText           = message;
            msgPump.TotalSteps         = actions.Count;

            CancellationTokenSource cts = new CancellationTokenSource();
            Task task = Task.Run(() => {
                for (int i = 0; i < actions.Count; i++)
                {
                    cts.Token.ThrowIfCancellationRequested();
                    msgPump.CurrentStep = i + 1;
                    if (actions[i].Name == null)
                    {
                        msgPump.ProgressText = string.Format(CultureInfo.InvariantCulture, Resources.LongOperationProgressMessage1, i + 1, msgPump.TotalSteps);
                    }
                    else
                    {
                        msgPump.ProgressText = string.Format(CultureInfo.InvariantCulture, Resources.LongOperationProgressMessage2, i + 1, msgPump.TotalSteps, actions[i].Name);
                    }
                    actions[i].Action(actions[i].Data, cts.Token);
                }
            }, cts.Token);

            CommonMessagePumpExitCode exitCode;

            if (!VsAppShell.Current.IsUnitTestEnvironment)
            {
                exitCode = msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            }
            else
            {
                exitCode = CommonMessagePumpExitCode.HandleSignaled;
            }

            if (exitCode == CommonMessagePumpExitCode.UserCanceled || exitCode == CommonMessagePumpExitCode.ApplicationExit)
            {
                cts.Cancel();
                msgPump                    = new CommonMessagePump();
                msgPump.AllowCancel        = false;
                msgPump.EnableRealProgress = false;
                // Wait for the async operation to actually cancel.
                msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            }

            if (task.IsCanceled)
            {
                return(false);
            }
            try {
                task.Wait();
            } catch (Exception ex) {
                log?.Write(LogVerbosity.Minimal, MessageCategory.Error, "Long operation exception: " + ex.Message);
            }
            return(true);
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            TeamProjectPicker picker = new TeamProjectPicker(TeamProjectPickerMode.MultiProject, false);

            if (picker.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            ProjectInfo[]            projectsInfo             = picker.SelectedProjects;
            TfsTeamProjectCollection tfsTeamProjecttollection = picker.SelectedTeamProjectCollection;

            DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2;

            Debug.Assert(dte2 != null, "dte2 != null");

            if (projectsInfo.Length == 0)
            {
                // ReSharper disable once SuspiciousTypeConversion.Global
                IServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte2);

                VsShellUtilities.ShowMessageBox(serviceProvider,
                                                "At least one team project must be selected",
                                                "Tfs Permission Visualizer Error:",
                                                OLEMSGICON.OLEMSGICON_WARNING,
                                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                return;
            }

            string dgmlTempFilePath = System.IO.Path.GetTempFileName() + ".dgml";

            CommonMessagePump msgPump = new CommonMessagePump
            {
                AllowCancel        = false,
                EnableRealProgress = false,
                WaitTitle          = "Building Permission graph...",
                WaitText           = "Please wait while we are building security groups Permission graph."
            };


            System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Run(() =>
            {
                TfsPermissionGraphGenerator generator = new TfsPermissionGraphGenerator();
                XDocument xDocument = generator.GenerateDependencyGraph(tfsTeamProjecttollection, projectsInfo);
                xDocument.Save(dgmlTempFilePath);
            });

            // ReSharper disable once SuspiciousTypeConversion.Global
            // ReSharper disable once PossibleInvalidCastException
            CommonMessagePumpExitCode exitCode = msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);

            dte2.ItemOperations.OpenFile(dgmlTempFilePath);
        }
コード例 #3
0
        public static Task DoPreviewActiveItem()
        {
            var msgPump = new CommonMessagePump();

            msgPump.AllowCancel        = false;
            msgPump.EnableRealProgress = true;
            msgPump.WaitTitle          = "Rendering report";
            msgPump.WaitText           = "This should NOT take several minutes. :)";

            var task = Task.Run(async() => await DoPreviewActiveItemInner(msgPump));

            msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            return(task);
        }
コード例 #4
0
        public static bool ShowWaitingPopup(string message, IReadOnlyList<LongAction> actions) {
            CommonMessagePump msgPump = new CommonMessagePump();
            msgPump.AllowCancel = true;
            msgPump.EnableRealProgress = true;
            msgPump.WaitTitle = "R Tools for Visual Studio";
            msgPump.WaitText = message;
            msgPump.TotalSteps = actions.Count;

            CancellationTokenSource cts = new CancellationTokenSource();
            Task task = Task.Run(() => {
                for (int i = 0; i < actions.Count; i++) {
                    cts.Token.ThrowIfCancellationRequested();
                    msgPump.CurrentStep = i + 1;
                    if (actions[i].Name == null) {
                        msgPump.ProgressText = string.Format(Resources.LongOperationProgressMessage1, i + 1, msgPump.TotalSteps);
                    } else {
                        msgPump.ProgressText = string.Format(Resources.LongOperationProgressMessage2, i + 1, msgPump.TotalSteps, actions[i].Name);
                    }
                    actions[i].Action(actions[i].Data);
                }
            }, cts.Token);

            CommonMessagePumpExitCode exitCode;
            if (!VsAppShell.Current.IsUnitTestEnvironment) {
                exitCode = msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            } else {
                exitCode = CommonMessagePumpExitCode.HandleSignaled;
            }

            if (exitCode == CommonMessagePumpExitCode.UserCanceled || exitCode == CommonMessagePumpExitCode.ApplicationExit) {
                cts.Cancel();
                msgPump = new CommonMessagePump();
                msgPump.AllowCancel = false;
                msgPump.EnableRealProgress = false;
                // Wait for the async operation to actually cancel.
                msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            }

            if (task.IsCanceled) {
                return false;
            }
            try {
                task.Wait();
            } catch (Exception ex) {
                GeneralLog.Write(ex);
            }
            return true;
        }
コード例 #5
0
        private async Task GenerateImagesMainThread(SourceImage source)
        {
            CommonMessagePump pump = new CommonMessagePump();
            pump.AllowCancel = true;
            pump.WaitTitle = "Creating scaled images";
            pump.WaitText = "Adding to the project takes time...";

            CancellationTokenSource tokenSource = new CancellationTokenSource();
            CancellationToken token = tokenSource.Token;

            Task task = Task.Run(() => GenerateImagesBackgroundThread(source, token, pump), token);

            CommonMessagePumpExitCode code = pump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            tokenSource.Cancel();
            await task;
        }
コード例 #6
0
        public static void PumpAction(string title, string text, Action action)
        {
            // see http://stackoverflow.com/questions/13457948/how-to-display-waiting-popup-from-visual-studio-extension

            var pump = new CommonMessagePump
            {
                AllowCancel        = false,
                EnableRealProgress = false,
                WaitTitle          = title,
                WaitText           = text
            };

            //var task = PumpActionStaTask(action);
            var task = System.Threading.Tasks.Task.Run(action);

            // ignore exit code - we can't cancel, anything - have to wait to the task anyway...
            pump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);

            task.Wait();

            // this is debugging code...
            // details go to the output window anyway

            //try
            //{
            //    task.Wait();
            //}
            //catch (Exception e)
            //{
            //    // COM exception while GenerateRaw tries to log an error to VisualStudio
            //    // wtf is that?!

            //    MessageBox.Show(e.Message, "Error");

            //    var aggr = e as AggregateException;
            //    if (aggr != null)
            //        foreach (var aggrInner in aggr.Flatten().InnerExceptions)
            //        {
            //            var message = string.Format("AggregateInner: {0}: {1}\r\n{2}", aggrInner.GetType().Name, aggrInner.Message,
            //                aggrInner.StackTrace);
            //            MessageBox.Show(message, "Error");
            //        }

            //    throw;
            //}
        }
コード例 #7
0
        private static async Task DoPreviewActiveItemInner(CommonMessagePump msgPump)
        {
            try
            {
                msgPump.TotalSteps    = 5;
                msgPump.CurrentStep   = 1;
                msgPump.ProgressText  = "Preparing jsreport server";
                msgPump.StatusBarText = msgPump.ProgressText;

                await ReportingServerManagerAdapter.EnsureStartedAsync().ConfigureAwait(false);

                msgPump.CurrentStep   = 2;
                msgPump.ProgressText  = "Synchronizing templates";
                msgPump.StatusBarText = msgPump.ProgressText;

                _dte.ExecuteCommand("File.SaveAll");

                _dte.Solution.SolutionBuild.BuildProject(_dte.Solution.SolutionBuild.ActiveConfiguration.Name, ReportingServerManagerAdapter.CurrentProject.UniqueName, true);
                if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
                {
                    MessageBox.Show("Fix build errors first", "jsreport error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                await ReportingServerManagerAdapter.SynchronizeTemplatesAsync().ConfigureAwait(false);

                msgPump.CurrentStep   = 3;
                msgPump.ProgressText  = "Rendering template in jsreport";
                msgPump.StatusBarText = msgPump.ProgressText;


                string definitionPath = _dte.ActiveDocument.FullName.RemoveFromEnd(".html").RemoveFromEnd(".js");
                var    rd             = ReadReportDefinition(definitionPath);

                //jsreport shortid is case sensitive and _dte.ActiveDocument.Name sometime does not return exact filename value
                var     shortid = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(_dte.ActiveDocument.ProjectItem.Name));
                dynamic report  = await ReportingServerManagerAdapter.RenderAsync(shortid, rd.SampleData);

                msgPump.CurrentStep   = 4;
                msgPump.ProgressText  = "Opening report";
                msgPump.StatusBarText = msgPump.ProgressText;

                string tempFile = Path.GetTempFileName();
                tempFile = Path.ChangeExtension(tempFile, report.FileExtension);

                using (FileStream fileStream = File.Create(tempFile))
                {
                    report.Content.CopyTo(fileStream);
                }

                OpenFileInBrowser(tempFile);
            }
            catch (WeakJsReportException e)
            {
                MessageBox.Show(e.Message, "jsreport error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error when processing template", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
コード例 #8
0
        public static void PumpAction(string title, string text, Action action)
        {
            // see http://stackoverflow.com/questions/13457948/how-to-display-waiting-popup-from-visual-studio-extension

            var pump = new CommonMessagePump
            {
                AllowCancel = false,
                EnableRealProgress = false,
                WaitTitle = title,
                WaitText = text
            };

            //var task = PumpActionStaTask(action);
            var task = System.Threading.Tasks.Task.Run(action);

            // ignore exit code - we can't cancel, anything - have to wait to the task anyway...
            pump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);

            task.Wait();

            // this is debugging code...
            // details go to the output window anyway

            //try
            //{
            //    task.Wait();
            //}
            //catch (Exception e)
            //{
            //    // COM exception while GenerateRaw tries to log an error to VisualStudio
            //    // wtf is that?!

            //    MessageBox.Show(e.Message, "Error");

            //    var aggr = e as AggregateException;
            //    if (aggr != null)
            //        foreach (var aggrInner in aggr.Flatten().InnerExceptions)
            //        {
            //            var message = string.Format("AggregateInner: {0}: {1}\r\n{2}", aggrInner.GetType().Name, aggrInner.Message,
            //                aggrInner.StackTrace);
            //            MessageBox.Show(message, "Error");
            //        }

            //    throw;
            //}
        }
コード例 #9
0
ファイル: SetupHelpers.cs プロジェクト: dsueltenfuss/vstools
        private static async Task DoPreviewActiveItemInner(CommonMessagePump msgPump)
        {
            try
            {
                msgPump.TotalSteps = 5;
                msgPump.CurrentStep = 1;
                msgPump.ProgressText = "Preparing jsreport server";
                msgPump.StatusBarText = msgPump.ProgressText;

                await ReportingServerManagerAdapter.EnsureStartedAsync().ConfigureAwait(false);

                msgPump.CurrentStep = 2;
                msgPump.ProgressText = "Synchronizing templates";
                msgPump.StatusBarText = msgPump.ProgressText;

                _dte.ExecuteCommand("File.SaveAll");

                _dte.Solution.SolutionBuild.BuildProject(_dte.Solution.SolutionBuild.ActiveConfiguration.Name, ReportingServerManagerAdapter.CurrentProject.UniqueName, true);
                if (_dte.Solution.SolutionBuild.LastBuildInfo > 0)
                {
                    MessageBox.Show("Fix build errors first", "jsreport error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                await ReportingServerManagerAdapter.SynchronizeTemplatesAsync().ConfigureAwait(false);

                msgPump.CurrentStep = 3;
                msgPump.ProgressText = "Rendering template in jsreport";
                msgPump.StatusBarText = msgPump.ProgressText;


                string definitionPath = _dte.ActiveDocument.FullName.RemoveFromEnd(".html").RemoveFromEnd(".js");
                var rd = ReadReportDefinition(definitionPath);

                //jsreport shortid is case sensitive and _dte.ActiveDocument.Name sometime does not return exact filename value
                var shortid = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(_dte.ActiveDocument.ProjectItem.Name));
                dynamic report = await ReportingServerManagerAdapter.RenderAsync(shortid, rd.SampleData);

                msgPump.CurrentStep = 4;
                msgPump.ProgressText = "Opening report";
                msgPump.StatusBarText = msgPump.ProgressText;

                string tempFile = Path.GetTempFileName();
                tempFile = Path.ChangeExtension(tempFile, report.FileExtension);

                using (FileStream fileStream = File.Create(tempFile))
                {
                    report.Content.CopyTo(fileStream);
                }

                OpenFileInBrowser(tempFile);
            }
            catch (WeakJsReportException e)
            {
                MessageBox.Show(e.Message, "jsreport error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error when processing template", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
コード例 #10
0
ファイル: SetupHelpers.cs プロジェクト: dsueltenfuss/vstools
        public static Task DoPreviewActiveItem()
        {
            var msgPump = new CommonMessagePump();
            msgPump.AllowCancel = false;
            msgPump.EnableRealProgress = true;
            msgPump.WaitTitle = "Rendering report";
            msgPump.WaitText = "This should NOT take several minutes. :)";

            var task = Task.Run(async () => await DoPreviewActiveItemInner(msgPump));
            msgPump.ModalWaitForHandles(((IAsyncResult)task).AsyncWaitHandle);
            return task;
        }
コード例 #11
0
        private void GenerateImagesBackgroundThread(SourceImage source, CancellationToken token, CommonMessagePump mainThreadPump)
        {
            int totalSets = source.SetsToGenerate.Count();
            int curSet = 0;

            foreach (OutputSet set in source.SetsToGenerate)
            {
                if (!token.IsCancellationRequested)
                {
                    curSet++;
                    mainThreadPump.WaitText = $"Checking existing images ({curSet} of {totalSets}):\r\n{set.UnscaledPath}";
                    this.OnGeneratingSet(set);
                }
            }

            int totalImages = source.ImagesToGenerate.Count();
            int curImage = 0;

            foreach (OutputImage image in source.ImagesToGenerate)
            {
                if (!token.IsCancellationRequested)
                {
                    curImage++;
                    mainThreadPump.WaitText = $"Adding to the project ({curImage} of {totalImages}):\r\n{image.Path}";
                    this.GenerateImage(image);
                    this.OnGeneratedImage(image);
                }
            }
        }