Exemplo n.º 1
0
        /// <summary>
        /// output string into output window (general pane)
        /// </summary>
        /// <param name="output">string to output</param>
        private void OutputString(string output)
        {
            if (_generalPane == null)
            {
                try
                {
                    IVsOutputWindow outWindow       = PowerShellToolsPackage.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
                    Guid            generalPaneGuid = VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
                    // By default this is no pane created in output window, so we need to create one by our own
                    // This call won't do anything if there is one exists
                    int hr = outWindow.CreatePane(generalPaneGuid, "General", 1, 1);
                    outWindow.GetPane(ref generalPaneGuid, out _generalPane);
                }
                catch (Exception ex)
                {
                    Log.Error("Failed to create general pane of output window due to exception: ", ex);
                    throw;
                }
            }

            if (_generalPane != null)
            {
                _generalPane.Activate();                     // Brings this pane into view
                _generalPane.OutputStringThreadSafe(output); // Thread-safe so the the output order can be preserved
            }
        }
Exemplo n.º 2
0
        internal void VSOutputProgress(long sourceId, ProgressRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            //TODO: If Visual studio ever has a global event/task pane, this would be a perfect place to tie into here.

            var statusBar = (IVsStatusbar)PowerShellToolsPackage.GetGlobalService(typeof(SVsStatusbar));

            if (statusBar != null)
            {
                uint cookie = 0;

                ProgressRecordType progressStatus = record.RecordType;

                string label = string.Format(ResourceStrings.ProgressBarFormat, record.Activity, record.StatusDescription);

                switch (progressStatus)
                {
                case ProgressRecordType.Processing:
                {
                    if (record.PercentComplete >= 0 && record.PercentComplete < 100)
                    {
                        statusBar.Progress(ref cookie, 1, label, (uint)record.PercentComplete, 100);
                    }
                    else if (record.PercentComplete == 100)
                    {
                        statusBar.Progress(ref cookie, 1, "", 0, 0);
                    }
                    else
                    {
                        // According to PS ProgressRecord docs, Negative values means a progress bar should not be displayed.

                        lock (AnimationProgressSyncObject)
                        {
                            if (_animationProgressSources.Add(sourceId))         //Returns false if already exists.
                            {
                                // This is needed because Visual Studio keeps a count of each animation.
                                // Animation is removed only when count goes to zero.
                                statusBar.Animation(1, AnimationIconGeneralIndex);
                            }

                            statusBar.SetText(label);
                        }
                    }
                    //Currently, we do not show Seconds Remaining
                    break;
                }

                case ProgressRecordType.Completed:
                {
                    //Only other value is ProgressRecordType.Completed

                    if (record.PercentComplete >= 0)
                    {
                        statusBar.Progress(ref cookie, 0, string.Empty, 0, 0);
                    }
                    else
                    {
                        lock (AnimationProgressSyncObject)
                        {
                            if (_animationProgressSources.Remove(sourceId))          //returns false if item not found.
                            {
                                statusBar.Animation(0, AnimationIconGeneralIndex);
                            }

                            statusBar.SetText(label);
                        }
                    }
                    break;
                }
                }
            }
        }