コード例 #1
0
ファイル: ProgressManager.cs プロジェクト: vors/PSParallel
        public static ProgressRecord WithRecordType(this ProgressRecord record, ProgressRecordType recordType)
        {
            var r = CloneProgressRecord(record);

            r.RecordType = recordType;
            return(r);
        }
コード例 #2
0
ファイル: ProgressRecord.cs プロジェクト: nickchal/pash
 internal ProgressRecord(ProgressRecord other)
 {
     this.parentId = -1;
     this.percent = -1;
     this.secondsRemaining = -1;
     this.activity = other.activity;
     this.currentOperation = other.currentOperation;
     this.id = other.id;
     this.parentId = other.parentId;
     this.percent = other.percent;
     this.secondsRemaining = other.secondsRemaining;
     this.status = other.status;
     this.type = other.type;
 }
コード例 #3
0
ファイル: ProgressRecord.cs プロジェクト: modulexcite/pash-1
 internal ProgressRecord(ProgressRecord other)
 {
     this.parentId         = -1;
     this.percent          = -1;
     this.secondsRemaining = -1;
     this.activity         = other.activity;
     this.currentOperation = other.currentOperation;
     this.id               = other.id;
     this.parentId         = other.parentId;
     this.percent          = other.percent;
     this.secondsRemaining = other.secondsRemaining;
     this.status           = other.status;
     this.type             = other.type;
 }
コード例 #4
0
		protected void WriteCurrentProgress(LocalizedString activityDesc, LocalizedString status, ProgressRecordType recordType, int percent)
		{
			base.WriteProgress(new ExProgressRecord(0, activityDesc, status)
			{
				RecordType = recordType,
				PercentComplete = percent
			});
		}
コード例 #5
0
ファイル: Computer.cs プロジェクト: dfinke/powershell
 /// <summary>
 /// Write out progress
 /// </summary>
 /// <param name="activity"></param>
 /// <param name="status"></param>
 /// <param name="percent"></param>
 /// <param name="progressRecordType"></param>
 private void WriteProgress(string activity, string status, int percent, ProgressRecordType progressRecordType)
 {
     ProgressRecord progress = new ProgressRecord(_activityId, activity, status);
     progress.PercentComplete = percent;
     progress.RecordType = progressRecordType;
     WriteProgress(progress);
 }
コード例 #6
0
 public static ProgressRecord WithRecordType(this ProgressRecord progressRecord, ProgressRecordType progressRecordType)
 {
     progressRecord.RecordType = progressRecordType;
     return(progressRecord);
 }
コード例 #7
0
        ////////////////////////////////////////////////////////////////////////

        #region IExecute Members
        public override ReturnCode Execute(
            Interpreter interpreter,
            IClientData clientData,
            ArgumentList arguments,
            ref Result result
            )
        {
            if (interpreter == null)
            {
                result = "invalid interpreter";
                return(ReturnCode.Error);
            }

            _Cmdlets.Script script = GetScriptCmdlet(clientData, ref result);

            if (script == null)
            {
                return(ReturnCode.Error);
            }

            if (arguments == null)
            {
                result = "invalid argument list";
                return(ReturnCode.Error);
            }

            if (arguments.Count < 2)
            {
                result = String.Format(
                    "wrong # args: should be \"{0} option ?arg ...?\"",
                    this.Name);

                return(ReturnCode.Error);
            }

            ReturnCode code       = ReturnCode.Ok;
            string     subCommand = arguments[1];
            bool       tried      = false;

            code = Utility.TryExecuteSubCommandFromEnsemble(
                interpreter, this, clientData, arguments, true,
                false, ref subCommand, ref tried, ref result);

            if ((code == ReturnCode.Ok) && !tried)
            {
                switch (subCommand)
                {
                case "about":
                {
                    if (arguments.Count == 2)
                    {
                        IPlugin plugin = this.Plugin;

                        if (plugin != null)
                        {
                            code = plugin.About(
                                interpreter, ref result);
                        }
                        else
                        {
                            result = "invalid command plugin";
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "debug":
                {
                    if (arguments.Count == 3)
                    {
                        try
                        {
                            script.WriteDebug(arguments[2]);         /* throw */
                            result = String.Empty;
                        }
                        catch (Exception e)
                        {
                            Engine.SetExceptionErrorCode(interpreter, e);

                            result = e;
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} text\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "error":
                {
                    if (arguments.Count == 4)
                    {
                        object enumValue = Utility.TryParseEnum(
                            typeof(ReturnCode), arguments[2],
                            true, true, ref result);

                        if (enumValue is ReturnCode)
                        {
                            try
                            {
                                script.WriteErrorRecord(
                                    (ReturnCode)enumValue,
                                    arguments[3]);         /* throw */

                                result = String.Empty;
                            }
                            catch (Exception e)
                            {
                                Engine.SetExceptionErrorCode(interpreter, e);

                                result = e;
                                code   = ReturnCode.Error;
                            }
                        }
                        else
                        {
                            code = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} code result\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "invoke":
                {
                    if (arguments.Count >= 3)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                                new Option(null, OptionFlags.None, Index.Invalid,
                                           Index.Invalid, "-addtohistory", null)
                            }, Utility.GetFixupReturnValueOptions().Values);

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 2,
                                                      Index.Invalid, true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 1) == arguments.Count))
                            {
                                Type        returnType;
                                ObjectFlags objectFlags;
                                string      objectName;
                                string      interpName;
                                bool        create;
                                bool        dispose;
                                bool        alias;
                                bool        aliasRaw;
                                bool        aliasAll;
                                bool        aliasReference;
                                bool        toString;

                                Utility.ProcessFixupReturnValueOptions(
                                    options, null, out returnType, out objectFlags,
                                    out objectName, out interpName, out create,
                                    out dispose, out alias, out aliasRaw,
                                    out aliasAll, out aliasReference, out toString);

                                bool addToHistory = false;

                                if (options.IsPresent("-addtohistory"))
                                {
                                    addToHistory = true;
                                }

                                Collection <PSObject> returnValue = null;

                                try
                                {
                                    code = InvokePipeline(
                                        arguments[argumentIndex], addToHistory,
                                        ref returnValue, ref result);
                                }
                                catch (Exception e)
                                {
                                    Engine.SetExceptionErrorCode(interpreter, e);

                                    result = e;
                                    code   = ReturnCode.Error;
                                }

                                if (code == ReturnCode.Ok)
                                {
                                    ObjectOptionType objectOptionType =
                                        Utility.GetOptionType(aliasRaw, aliasAll);

                                    code = Utility.FixupReturnValue(interpreter,
                                                                    GetBinder(interpreter, this.Plugin),
                                                                    interpreter.CultureInfo, returnType,
                                                                    objectFlags, Utility.GetInvokeOptions(
                                                                        objectOptionType), objectOptionType,
                                                                    objectName, interpName, returnValue,
                                                                    create, dispose, alias, aliasReference,
                                                                    toString, ref result);
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(
                                        options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = String.Format(
                                        "wrong # args: should be \"{0} {1} ?options? script\"",
                                        this.Name, subCommand);
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} ?options? script\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "options":
                {
                    if (arguments.Count == 2)
                    {
                        IPlugin plugin = this.Plugin;

                        if (plugin != null)
                        {
                            code = plugin.Options(
                                interpreter, ref result);
                        }
                        else
                        {
                            //
                            // NOTE: There is (normally) no plugin
                            //       context for this library.
                            //
                            code = GetDefineConstants(ref result);
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "progress":
                {
                    if (arguments.Count >= 5)
                    {
                        OptionDictionary options = new OptionDictionary(
                            new IOption[] {
                                new Option(null, OptionFlags.MustHaveValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-currentOperation", null),
                                new Option(null, OptionFlags.MustHaveIntegerValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-parentActivityId", null),
                                new Option(null, OptionFlags.MustHaveIntegerValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-percentComplete", null),
                                new Option(typeof(ProgressRecordType),
                                           OptionFlags.MustHaveIntegerValue | OptionFlags.NoCase,
                                           Index.Invalid, Index.Invalid, "-recordType",
                                           new Variant((ProgressRecordType)(-1))),
                                new Option(null, OptionFlags.MustHaveIntegerValue |
                                           OptionFlags.NoCase, Index.Invalid, Index.Invalid,
                                           "-secondsRemaining", null),
                                new Option(null, OptionFlags.None, Index.Invalid,
                                           Index.Invalid, Option.EndOfOptions, null)
                            });

                        int argumentIndex = Index.Invalid;

                        code = interpreter.GetOptions(options, arguments, 0, 2,
                                                      Index.Invalid, true, ref argumentIndex, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            if ((argumentIndex != Index.Invalid) &&
                                ((argumentIndex + 3) == arguments.Count))
                            {
                                Variant value            = null;
                                string  currentOperation = null;

                                if (options.IsPresent("-currentOperation", true, ref value))
                                {
                                    currentOperation = value.ToString();
                                }

                                int parentActivityId = Identifier.Invalid;

                                if (options.IsPresent("-parentActivityId", true, ref value))
                                {
                                    parentActivityId = (int)value.Value;
                                }

                                int percentComplete = Percent.Invalid;

                                if (options.IsPresent("-percentComplete", true, ref value))
                                {
                                    percentComplete = (int)value.Value;
                                }

                                ProgressRecordType recordType = (ProgressRecordType)(-1);

                                if (options.IsPresent("-recordType", true, ref value))
                                {
                                    recordType = (ProgressRecordType)value.Value;
                                }

                                int secondsRemaining = Count.Invalid;

                                if (options.IsPresent("-secondsRemaining", true, ref value))
                                {
                                    secondsRemaining = (int)value.Value;
                                }

                                int activityId = Identifier.Invalid;

                                code = Value.GetInteger2(
                                    (IGetValue)arguments[argumentIndex], ValueFlags.AnyInteger,
                                    interpreter.CultureInfo, ref activityId, ref result);

                                if (code == ReturnCode.Ok)
                                {
                                    try
                                    {
                                        ProgressRecord progressRecord = new ProgressRecord(
                                            activityId, arguments[argumentIndex + 1],
                                            arguments[argumentIndex + 2]);         /* throw */

                                        if (currentOperation != null)
                                        {
                                            progressRecord.CurrentOperation = currentOperation;
                                        }

                                        if (parentActivityId != Identifier.Invalid)
                                        {
                                            progressRecord.ParentActivityId = parentActivityId;         /* throw */
                                        }
                                        if (percentComplete != Percent.Invalid)
                                        {
                                            progressRecord.PercentComplete = percentComplete;         /* throw */
                                        }
                                        if (recordType != (ProgressRecordType)(-1))
                                        {
                                            progressRecord.RecordType = recordType;         /* throw */
                                        }
                                        if (secondsRemaining != Count.Invalid)
                                        {
                                            progressRecord.SecondsRemaining = secondsRemaining;
                                        }

                                        script.WriteProgress(progressRecord);         /* throw */

                                        result = String.Empty;
                                    }
                                    catch (Exception e)
                                    {
                                        Engine.SetExceptionErrorCode(interpreter, e);

                                        result = e;
                                        code   = ReturnCode.Error;
                                    }
                                }
                            }
                            else
                            {
                                if ((argumentIndex != Index.Invalid) &&
                                    Option.LooksLikeOption(arguments[argumentIndex]))
                                {
                                    result = OptionDictionary.BadOption(
                                        options, arguments[argumentIndex]);
                                }
                                else
                                {
                                    result = String.Format(
                                        "wrong # args: should be \"{0} {1} ?options? activityId activity statusDescription\"",
                                        this.Name, subCommand);
                                }

                                code = ReturnCode.Error;
                            }
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} ?options? activityId activity statusDescription\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "remove":
                {
                    if (arguments.Count == 2)
                    {
                        code = script.RemoveMetaCommand(interpreter, ref result);

                        if (code == ReturnCode.Ok)
                        {
                            result = String.Empty;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "status":
                {
                    if (arguments.Count == 2)
                    {
                        result = StringList.MakeList(
                            "Disposed", script.Disposed,         /* PEDANTIC */
                            "FlagsCallback", script.FlagsCallback,
                            "StateCallback", script.StateCallback,
                            "ParameterCallback", script.ParameterCallback,
                            "Listener", script.Listener,
                            "PreInitialize", script.PreInitialize,
                            "CreateFlags", script.CreateFlags,
                            "EngineFlags", script.EngineFlags,
                            "SubstitutionFlags", script.SubstitutionFlags,
                            "EventFlags", script.EventFlags,
                            "ExpressionFlags", script.ExpressionFlags,
                            "Console", script.Console,
                            "Unsafe", script.Unsafe,
                            "Standard", script.Standard,
                            "Force", script.Force,
                            "Exceptions", script.Exceptions,
                            "Policies", script.Policies,
                            "Deny", script.Deny,
                            "MetaCommand", script.MetaCommand,
                            "Text", script.Text,
                            "Interpreter", script.Interpreter,
                            "Tokens", script.Tokens,
                            "CommandRuntime", script.CommandRuntime,
                            "Stopping", script.Stopping);         /* throw */
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1}\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                case "verbose":
                {
                    if (arguments.Count == 3)
                    {
                        try
                        {
                            script.WriteVerbose(arguments[2]);         /* throw */
                            result = String.Empty;
                        }
                        catch (Exception e)
                        {
                            Engine.SetExceptionErrorCode(interpreter, e);

                            result = e;
                            code   = ReturnCode.Error;
                        }
                    }
                    else
                    {
                        result = String.Format(
                            "wrong # args: should be \"{0} {1} text\"",
                            this.Name, subCommand);

                        code = ReturnCode.Error;
                    }
                    break;
                }

                default:
                {
                    result = Utility.BadSubCommand(
                        interpreter, null, null, subCommand, this, null, null);

                    code = ReturnCode.Error;
                    break;
                }
                }
            }

            return(code);
        }
コード例 #8
0
ファイル: PSActivity.cs プロジェクト: nickchal/pash
		protected void WriteProgressRecord(NativeActivityContext context, PSDataCollection<ProgressRecord> progress, string statusDescription, ProgressRecordType type)
		{
			string displayName;
			int num = 0;
			if (progress != null)
			{
				string str = null;
				if (this.PSProgressMessage != null)
				{
					str = this.PSProgressMessage.Get(context);
					if (this.PSProgressMessage.Expression != null && string.IsNullOrEmpty(str))
					{
						return;
					}
				}
				if (str != null)
				{
					displayName = string.Concat(base.DisplayName, ": ", str);
				}
				else
				{
					displayName = base.DisplayName;
					if (string.IsNullOrEmpty(displayName))
					{
						displayName = base.GetType().Name;
					}
				}
				ProgressRecord progressRecord = new ProgressRecord(0, displayName, statusDescription);
				progressRecord.RecordType = type;
				string str1 = string.Concat(base.Id, ":");
				HostParameterDefaults extension = context.GetExtension<HostParameterDefaults>();
				if (extension != null)
				{
					HostSettingCommandMetadata hostCommandMetadata = extension.HostCommandMetadata;
					if (hostCommandMetadata != null)
					{
						object[] commandName = new object[3];
						commandName[0] = hostCommandMetadata.CommandName;
						commandName[1] = hostCommandMetadata.StartLineNumber;
						commandName[2] = hostCommandMetadata.StartColumnNumber;
						str1 = string.Concat(str1, string.Format(CultureInfo.CurrentCulture, Resources.ProgressPositionMessage, commandName));
					}
				}
				progressRecord.CurrentOperation = str1;
				foreach (PropertyDescriptor property in context.DataContext.GetProperties())
				{
					if (!string.Equals(property.DisplayName, "PSParentActivityID", StringComparison.OrdinalIgnoreCase))
					{
						if (!string.Equals(property.DisplayName, "ProgressPreference", StringComparison.OrdinalIgnoreCase))
						{
							continue;
						}
						string value = property.GetValue(context.DataContext) as string;
						if (string.IsNullOrEmpty(value) || !string.Equals(value, "SilentlyContinue", StringComparison.OrdinalIgnoreCase) && !string.Equals(value, "Ignore", StringComparison.OrdinalIgnoreCase))
						{
							continue;
						}
						return;
					}
					else
					{
						object obj = property.GetValue(context.DataContext);
						if (obj == null || !LanguagePrimitives.TryConvertTo<int>(obj, CultureInfo.InvariantCulture, out num))
						{
							continue;
						}
						progressRecord.ParentActivityId = num;
					}
				}
				progress.Add(progressRecord);
				return;
			}
			else
			{
				return;
			}
		}
コード例 #9
0
		private void WriteProgress(string activity, string status, int percent, ProgressRecordType progressRecordType)
		{
			ProgressRecord progressRecord = new ProgressRecord(this._activityId, activity, status);
			progressRecord.PercentComplete = percent;
			progressRecord.RecordType = progressRecordType;
			base.WriteProgress(progressRecord);
		}
コード例 #10
0
ファイル: HostUi.cs プロジェクト: shohel1980/poshtools-dev
        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;
                }
                }
            }
        }
コード例 #11
0
 public static ProgressRecord WithRecordType(this ProgressRecord record, ProgressRecordType recordType)
 {
     var r = CloneProgressRecord(record);
     r.RecordType = recordType;
     return r;
 }