Example #1
0
        /// <summary>
        /// Initializes a new instance of the CompletionResult class.
        /// </summary>
        /// <param name="completionText">The text to be used as the auto completion result.</param>
        /// <param name="listItemText">The text to be displayed in a list.</param>
        /// <param name="resultType">The type of completion result.</param>
        /// <param name="toolTip">The text for the tooltip with details to be displayed about the object.</param>
        public CompletionResult(string completionText, string listItemText, CompletionResultType resultType, string toolTip)
        {
            if (String.IsNullOrEmpty(completionText))
            {
                throw PSTraceSource.NewArgumentNullException("completionText");
            }

            if (String.IsNullOrEmpty(listItemText))
            {
                throw PSTraceSource.NewArgumentNullException("listItemText");
            }

            if (resultType < CompletionResultType.Text || resultType > CompletionResultType.DynamicKeyword)
            {
                throw PSTraceSource.NewArgumentOutOfRangeException("resultType", resultType);
            }

            if (String.IsNullOrEmpty(toolTip))
            {
                throw PSTraceSource.NewArgumentNullException("toolTip");
            }

            _completionText = completionText;
            _listItemText   = listItemText;
            _toolTip        = toolTip;
            _resultType     = resultType;
        }
Example #2
0
 public T this[int index]
 {
     get
     {
         lock (this.syncObject)
         {
             return(this.data[index]);
         }
     }
     set
     {
         lock (this.syncObject)
         {
             if ((index < 0) || (index >= this.data.Count))
             {
                 throw PSTraceSource.NewArgumentOutOfRangeException("index", index, PSDataCollection <T> .resBaseName, "IndexOutOfRange", new object[] { 0, this.data.Count - 1 });
             }
             if (this.serializeInput)
             {
                 value = (T)Convert.ChangeType(this.GetSerializedObject(value), typeof(T));
             }
             this.data[index] = value;
         }
     }
 }
Example #3
0
 public TableControlColumnHeader(string label, int width, System.Management.Automation.Alignment alignment)
 {
     if (width < 0)
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("width", width);
     }
     this._label     = label;
     this._width     = width;
     this._alignment = alignment;
 }
        /// <summary>
        /// Public constructor for TableControlColumnHeader.
        /// </summary>
        /// <param name="label">Could be null if no label to specify</param>
        /// <param name="width">The Value should be non-negative</param>
        /// <param name="alignment">The default value is Alignment.Undefined</param>
        public TableControlColumnHeader(string label, int width, Alignment alignment)
        {
            if (width < 0)
            {
                throw PSTraceSource.NewArgumentOutOfRangeException("width", width);
            }

            this.Label     = label;
            this.Width     = width;
            this.Alignment = alignment;
        }
Example #5
0
 public void RemoveAt(int index)
 {
     lock (this.syncObject)
     {
         if ((index < 0) || (index >= this.data.Count))
         {
             throw PSTraceSource.NewArgumentOutOfRangeException("index", index, PSDataCollection <T> .resBaseName, "IndexOutOfRange", new object[] { 0, this.data.Count - 1 });
         }
         this.RemoveItem(index);
     }
 }
Example #6
0
 public ValidateSetAttribute(params string[] validValues)
 {
     if (validValues == null)
     {
         throw PSTraceSource.NewArgumentNullException("validValues");
     }
     if (validValues.Length == 0)
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("validValues", validValues);
     }
     this.validValues = validValues;
 }
        /// <summary>
        /// Initializes a new instance of the ArgumentCompletionsAttribute class.
        /// </summary>
        /// <param name="completions">List of complete values.</param>
        /// <exception cref="ArgumentNullException">For null arguments.</exception>
        /// <exception cref="ArgumentOutOfRangeException">For invalid arguments.</exception>
        public ArgumentCompletionsAttribute(params string[] completions)
        {
            if (completions == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(completions));
            }

            if (completions.Length == 0)
            {
                throw PSTraceSource.NewArgumentOutOfRangeException(nameof(completions), completions);
            }

            _completions = completions;
        }
 public ValidateLengthAttribute(int minLength, int maxLength)
 {
     if (minLength < 0)
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("minLength", minLength);
     }
     if (maxLength <= 0)
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("maxLength", maxLength);
     }
     if (maxLength < minLength)
     {
         throw new ValidationMetadataException("ValidateLengthMaxLengthSmallerThanMinLength", null, Metadata.ValidateLengthMaxLengthSmallerThanMinLength, new object[0]);
     }
     this.minLength = minLength;
     this.maxLength = maxLength;
 }
Example #9
0
        ProgressRecord(int activityId, string activity, string statusDescription)
        {
            if (activityId < 0)
            {
                // negative Ids are reserved to indicate "no id" for parent Ids.

                throw PSTraceSource.NewArgumentOutOfRangeException("activityId", activityId, ProgressRecordStrings.ArgMayNotBeNegative, "activityId");
            }
            if (String.IsNullOrEmpty(activity))
            {
                throw PSTraceSource.NewArgumentException("activity", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "activity");
            }
            if (String.IsNullOrEmpty(statusDescription))
            {
                throw PSTraceSource.NewArgumentException("activity", ProgressRecordStrings.ArgMayNotBeNullOrEmpty, "statusDescription");
            }

            _id       = activityId;
            _activity = activity;
            _status   = statusDescription;
        }
Example #10
0
 public ProgressRecord(int activityId, string activity, string statusDescription)
 {
     this.parentId         = -1;
     this.percent          = -1;
     this.secondsRemaining = -1;
     if (activityId < 0)
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("activityId", activityId, "ProgressRecordStrings", "ArgMayNotBeNegative", new object[] { "activityId" });
     }
     if (string.IsNullOrEmpty(activity))
     {
         throw PSTraceSource.NewArgumentException("activity", "ProgressRecordStrings", "ArgMayNotBeNullOrEmpty", new object[] { "activity" });
     }
     if (string.IsNullOrEmpty(statusDescription))
     {
         throw PSTraceSource.NewArgumentException("activity", "ProgressRecordStrings", "ArgMayNotBeNullOrEmpty", new object[] { "statusDescription" });
     }
     this.id       = activityId;
     this.activity = activity;
     this.status   = statusDescription;
 }
Example #11
0
 public CompletionResult(string completionText, string listItemText, CompletionResultType resultType, string toolTip)
 {
     if (string.IsNullOrEmpty(completionText))
     {
         throw PSTraceSource.NewArgumentNullException("completionText");
     }
     if (string.IsNullOrEmpty(listItemText))
     {
         throw PSTraceSource.NewArgumentNullException("listItemText");
     }
     if ((resultType < CompletionResultType.Text) || (resultType > CompletionResultType.Type))
     {
         throw PSTraceSource.NewArgumentOutOfRangeException("resultType", resultType);
     }
     if (string.IsNullOrEmpty(toolTip))
     {
         throw PSTraceSource.NewArgumentNullException("toolTip");
     }
     this.completionText = completionText;
     this.listItemText   = listItemText;
     this.toolTip        = toolTip;
     this.resultType     = resultType;
 }
Example #12
0
        } // GetScopeByID

        /// <summary>
        /// Given a scope ID, walks the scope list to the appropriate scope and returns it.
        /// </summary>
        /// <param name="scopeID">
        /// The numeric indexer to the scope relative to the current scope.
        /// </param>
        /// <returns>
        /// The scope at the index specified.  The index is relative to the current
        /// scope.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="scopeID"/> is less than zero or greater than the number of currently
        /// active scopes.
        /// </exception>
        internal SessionStateScope GetScopeByID(int scopeID)
        {
            SessionStateScope processingScope = _currentScope;
            int originalID = scopeID;

            while (scopeID > 0 && processingScope != null)
            {
                processingScope = processingScope.Parent;
                scopeID--;
            }

            if (processingScope == null && scopeID >= 0)
            {
                ArgumentOutOfRangeException outOfRange =
                    PSTraceSource.NewArgumentOutOfRangeException(
                        ScopeParameterName,
                        originalID,
                        SessionStateStrings.ScopeIDExceedsAvailableScopes,
                        originalID);
                throw outOfRange;
            }

            return(processingScope);
        } // GetScopeByID
Example #13
0
        /// <summary>
        /// Given a scope identifier, returns the proper session state scope.
        /// </summary>
        /// <param name="scopeID">
        /// A scope identifier that is either one of the "special" scopes like
        /// "global", "local", or "private, or a numeric ID of a relative scope
        /// to the current scope.
        /// </param>
        /// <returns>
        /// The scope identified by the scope ID or the current scope if the
        /// scope ID is not defined as a special or numeric scope identifier.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// If <paramref name="scopeID"/> is less than zero, or not
        /// a number and not "script", "global", "local", or "private"
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="scopeID"/> is less than zero or greater than the number of currently
        /// active scopes.
        /// </exception>
        internal SessionStateScope GetScopeByID(string scopeID)
        {
            SessionStateScope result = _currentScope;

            if (!string.IsNullOrEmpty(scopeID))
            {
                if (String.Equals(
                        scopeID,
                        StringLiterals.Global,
                        StringComparison.OrdinalIgnoreCase))
                {
                    result = GlobalScope;
                }
                else if (String.Equals(
                             scopeID,
                             StringLiterals.Local,
                             StringComparison.OrdinalIgnoreCase))
                {
                    result = _currentScope;
                }
                else if (String.Equals(
                             scopeID,
                             StringLiterals.Private,
                             StringComparison.OrdinalIgnoreCase))
                {
                    result = _currentScope;
                }
                else if (String.Equals(
                             scopeID,
                             StringLiterals.Script,
                             StringComparison.OrdinalIgnoreCase))
                {
                    // Get the current script scope from the stack.
                    result = _currentScope.ScriptScope;
                }
                else
                {
                    // Since the scope is not any of the special scopes
                    // try parsing it as an ID

                    try
                    {
                        int scopeNumericID = Int32.Parse(scopeID, System.Globalization.CultureInfo.CurrentCulture);

                        if (scopeNumericID < 0)
                        {
                            throw PSTraceSource.NewArgumentOutOfRangeException(ScopeParameterName, scopeID);
                        }

                        result = GetScopeByID(scopeNumericID) ?? _currentScope;
                    }
                    catch (FormatException)
                    {
                        throw PSTraceSource.NewArgumentException(ScopeParameterName, AutomationExceptions.InvalidScopeIdArgument, ScopeParameterName);
                    }
                    catch (OverflowException)
                    {
                        throw PSTraceSource.NewArgumentOutOfRangeException(ScopeParameterName, scopeID);
                    }
                }
            }

            return(result);
        } // GetScopeByID