Ejemplo n.º 1
0
        private static MshExpression GetDefaultNameExpression(PSObject so)
        {
            MshExpression retVal = GetDefaultNameExpression(so.PSStandardMembers) ??
                                   GetDefaultNameExpression(MaskDeserializedAndGetStandardMembers(so));

            return(retVal);
        }
Ejemplo n.º 2
0
        internal MshExpression CreateFromExpressionToken(ExpressionToken et, DatabaseLoadingInfo loadingInfo)
        {
            if (!et.isScriptBlock)
            {
                return(new MshExpression(et.expressionValue));
            }
            if (this._expressionCache != null)
            {
                MshExpression expression;
                if (this._expressionCache.TryGetValue(et, out expression))
                {
                    return(expression);
                }
            }
            else
            {
                this._expressionCache = new Dictionary <ExpressionToken, MshExpression>();
            }
            ScriptBlock scriptBlock = ScriptBlock.Create(et.expressionValue);

            scriptBlock.DebuggerStepThrough = true;
            if ((loadingInfo != null) && loadingInfo.isFullyTrusted)
            {
                scriptBlock.LanguageMode = 0;
            }
            MshExpression expression2 = new MshExpression(scriptBlock);

            this._expressionCache.Add(et, expression2);
            return(expression2);
        }
Ejemplo n.º 3
0
        private int MatchTypeIndex(string typeName, PSObject currentObject, MshExpression ex)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return(-1);
            }
            int num = 0;

            foreach (string a in this._typeNameHierarchy)
            {
                if (string.Equals(a, typeName, StringComparison.OrdinalIgnoreCase) && this.MatchCondition(currentObject, ex))
                {
                    return(num);
                }
                if (num == 0)
                {
                    if (!this._useInheritance)
                    {
                        break;
                    }
                }
                ++num;
            }
            return(-1);
        }
Ejemplo n.º 4
0
        protected FormatPropertyField GenerateFormatPropertyField(List <FormatToken> formatTokenList, PSObject so, int enumerationLimit, out MshExpressionResult result)
        {
            result = null;
            FormatPropertyField fpf = new FormatPropertyField();

            if (formatTokenList.Count != 0)
            {
                FormatToken        token = formatTokenList[0];
                FieldPropertyToken fpt   = token as FieldPropertyToken;
                if (fpt != null)
                {
                    MshExpression ex = this.expressionFactory.CreateFromExpressionToken(fpt.expression, this.dataBaseInfo.view.loadingInfo);
                    fpf.propertyValue = this.GetExpressionDisplayValue(so, enumerationLimit, ex, fpt.fieldFormattingDirective, out result);
                }
                else
                {
                    TextToken tt = token as TextToken;
                    if (tt != null)
                    {
                        fpf.propertyValue = this.dataBaseInfo.db.displayResourceManagerCache.GetTextTokenString(tt);
                    }
                }
            }
            else
            {
                fpf.propertyValue = "";
            }
            return(fpf);
        }
Ejemplo n.º 5
0
 internal static List<MshResolvedExpressionParameterAssociation> ExpandAll(PSObject target)
 {
     List<string> propertyNamesFromView = GetPropertyNamesFromView(target, PSMemberViewTypes.Adapted);
     List<string> list2 = GetPropertyNamesFromView(target, PSMemberViewTypes.Base);
     List<string> collection = GetPropertyNamesFromView(target, PSMemberViewTypes.Extended);
     List<string> list4 = new List<string>();
     if (propertyNamesFromView.Count != 0)
     {
         list4 = propertyNamesFromView;
     }
     else
     {
         list4 = list2;
     }
     list4.AddRange(collection);
     Dictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
     List<MshResolvedExpressionParameterAssociation> list5 = new List<MshResolvedExpressionParameterAssociation>();
     foreach (string str in list4)
     {
         if (!dictionary.ContainsKey(str))
         {
             dictionary.Add(str, null);
             MshExpression expression = new MshExpression(str, true);
             list5.Add(new MshResolvedExpressionParameterAssociation(null, expression));
         }
     }
     return list5;
 }
Ejemplo n.º 6
0
 private void InitializeGroupBy()
 {
     if ((this.parameters != null) && (this.parameters.groupByParameter != null))
     {
         MshExpression entry        = this.parameters.groupByParameter.GetEntry("expression") as MshExpression;
         string        displayLabel = null;
         object        obj2         = this.parameters.groupByParameter.GetEntry("label");
         if (obj2 != AutomationNull.Value)
         {
             displayLabel = obj2 as string;
         }
         this.groupingManager = new GroupingInfoManager();
         this.groupingManager.Initialize(entry, displayLabel);
     }
     else if (this.dataBaseInfo.view != null)
     {
         GroupBy groupBy = this.dataBaseInfo.view.groupBy;
         if ((groupBy != null) && ((groupBy.startGroup != null) && (groupBy.startGroup.expression != null)))
         {
             MshExpression groupingExpression = this.expressionFactory.CreateFromExpressionToken(groupBy.startGroup.expression, this.dataBaseInfo.view.loadingInfo);
             this.groupingManager = new GroupingInfoManager();
             this.groupingManager.Initialize(groupingExpression, null);
         }
     }
 }
Ejemplo n.º 7
0
        internal static MshExpression GetDisplayNameExpression(
            PSObject target,
            MshExpressionFactory expressionFactory)
        {
            MshExpression defaultNameExpression = PSObjectHelper.GetDefaultNameExpression(target);

            if (defaultNameExpression != null)
            {
                return(defaultNameExpression);
            }
            string[] strArray = new string[6]
            {
                "name",
                "id",
                "key",
                "*key",
                "*name",
                "*id"
            };
            foreach (string s in strArray)
            {
                List <MshExpression> mshExpressionList = new MshExpression(s).ResolveNames(target);
                while (mshExpressionList.Count > 0 && (mshExpressionList[0].ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) || mshExpressionList[0].ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) || mshExpressionList[0].ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase)))
                {
                    mshExpressionList.RemoveAt(0);
                }
                if (mshExpressionList.Count != 0)
                {
                    return(mshExpressionList[0]);
                }
            }
            return((MshExpression)null);
        }
Ejemplo n.º 8
0
 internal override object Verify(object val, TerminatingErrorContext invocationContext, bool originalParameterWasHashTable)
 {
     if (val == null)
     {
         throw PSTraceSource.NewArgumentNullException("val");
     }
     ScriptBlock scriptBlock = val as ScriptBlock;
     if (scriptBlock != null)
     {
         return new MshExpression(scriptBlock);
     }
     string str = val as string;
     if (str != null)
     {
         if (string.IsNullOrEmpty(str))
         {
             this.ProcessEmptyStringError(originalParameterWasHashTable, invocationContext);
         }
         MshExpression expression2 = new MshExpression(str);
         if (this._noGlobbing && expression2.HasWildCardCharacters)
         {
             this.ProcessGlobbingCharactersError(originalParameterWasHashTable, str, invocationContext);
         }
         return expression2;
     }
     PSTraceSource.NewArgumentException("val");
     return null;
 }
Ejemplo n.º 9
0
        internal static List <MshResolvedExpressionParameterAssociation> ExpandAll(PSObject target)
        {
            List <string> propertyNamesFromView = GetPropertyNamesFromView(target, PSMemberViewTypes.Adapted);
            List <string> list2      = GetPropertyNamesFromView(target, PSMemberViewTypes.Base);
            List <string> collection = GetPropertyNamesFromView(target, PSMemberViewTypes.Extended);
            List <string> list4      = new List <string>();

            if (propertyNamesFromView.Count != 0)
            {
                list4 = propertyNamesFromView;
            }
            else
            {
                list4 = list2;
            }
            list4.AddRange(collection);
            Dictionary <string, object> dictionary = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            List <MshResolvedExpressionParameterAssociation> list5 = new List <MshResolvedExpressionParameterAssociation>();

            foreach (string str in list4)
            {
                if (!dictionary.ContainsKey(str))
                {
                    dictionary.Add(str, null);
                    MshExpression expression = new MshExpression(str, true);
                    list5.Add(new MshResolvedExpressionParameterAssociation(null, expression));
                }
            }
            return(list5);
        }
Ejemplo n.º 10
0
        internal override object Verify(object val, TerminatingErrorContext invocationContext, bool originalParameterWasHashTable)
        {
            if (val == null)
            {
                throw PSTraceSource.NewArgumentNullException("val");
            }
            ScriptBlock scriptBlock = val as ScriptBlock;

            if (scriptBlock != null)
            {
                return(new MshExpression(scriptBlock));
            }
            string str = val as string;

            if (str != null)
            {
                if (string.IsNullOrEmpty(str))
                {
                    this.ProcessEmptyStringError(originalParameterWasHashTable, invocationContext);
                }
                MshExpression expression2 = new MshExpression(str);
                if (this._noGlobbing && expression2.HasWildCardCharacters)
                {
                    this.ProcessGlobbingCharactersError(originalParameterWasHashTable, str, invocationContext);
                }
                return(expression2);
            }
            PSTraceSource.NewArgumentException("val");
            return(null);
        }
Ejemplo n.º 11
0
 internal MshExpression CreateFromExpressionToken(ExpressionToken et, DatabaseLoadingInfo loadingInfo)
 {
     if (!et.isScriptBlock)
     {
         return new MshExpression(et.expressionValue);
     }
     if (this._expressionCache != null)
     {
         MshExpression expression;
         if (this._expressionCache.TryGetValue(et, out expression))
         {
             return expression;
         }
     }
     else
     {
         this._expressionCache = new Dictionary<ExpressionToken, MshExpression>();
     }
     ScriptBlock scriptBlock = ScriptBlock.Create(et.expressionValue);
     scriptBlock.DebuggerStepThrough = true;
     if ((loadingInfo != null) && loadingInfo.isFullyTrusted)
     {
         scriptBlock.LanguageMode = 0;
     }
     MshExpression expression2 = new MshExpression(scriptBlock);
     this._expressionCache.Add(et, expression2);
     return expression2;
 }
Ejemplo n.º 12
0
        private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject)
        {
            int num1 = -1;

            foreach (TypeOrGroupReference reference in appliesTo.referenceList)
            {
                MshExpression ex = (MshExpression)null;
                if (reference.conditionToken != null)
                {
                    ex = this._expressionFactory.CreateFromExpressionToken(reference.conditionToken);
                }
                int num2 = -1;
                if (reference is TypeReference typeReference)
                {
                    num2 = this.MatchTypeIndex(typeReference.name, currentObject, ex);
                }
                else
                {
                    TypeGroupDefinition groupDefinition = DisplayDataQuery.FindGroupDefinition(this._db, (reference as TypeGroupReference).name);
                    if (groupDefinition != null)
                    {
                        num2 = this.ComputeBestMatchInGroup(groupDefinition, currentObject, ex);
                    }
                }
                if (num2 == 0)
                {
                    return(num2);
                }
                if (num1 == -1 || num1 < num2)
                {
                    num1 = num2;
                }
            }
            return(num1);
        }
Ejemplo n.º 13
0
        private static int ComputeDefaultAlignment(PSObject so, MshExpression ex)
        {
            List <MshExpressionResult> rList = ex.GetValues(so);

            if ((rList.Count == 0) || (rList[0].Exception != null))
            {
                return(TextAlignment.Left);
            }

            object val = rList[0].Result;

            if (val == null)
            {
                return(TextAlignment.Left);
            }

            PSObject soVal     = PSObject.AsPSObject(val);
            var      typeNames = soVal.InternalTypeNames;

            if (string.Equals(PSObjectHelper.PSObjectIsOfExactType(typeNames),
                              "System.String", StringComparison.OrdinalIgnoreCase))
            {
                return(TextAlignment.Left);
            }

            if (DefaultScalarTypes.IsTypeInList(typeNames))
            {
                return(TextAlignment.Right);
            }

            return(TextAlignment.Left);
        }
Ejemplo n.º 14
0
        private void SetUpActiveProperty(PSObject so)
        {
            List <MshParameter> parameters = null;

            if (base.inputParameters != null)
            {
                parameters = base.inputParameters.mshParameterList;
            }
            if ((parameters != null) && (parameters.Count > 0))
            {
                base.activeAssociationList = AssociationManager.ExpandParameters(parameters, so);
            }
            else
            {
                MshExpression displayNameExpression = PSObjectHelper.GetDisplayNameExpression(so, base.expressionFactory);
                if (displayNameExpression != null)
                {
                    base.activeAssociationList = new List <MshResolvedExpressionParameterAssociation>();
                    base.activeAssociationList.Add(new MshResolvedExpressionParameterAssociation(null, displayNameExpression));
                }
                else
                {
                    base.activeAssociationList = AssociationManager.ExpandDefaultPropertySet(so, base.expressionFactory);
                    if (base.activeAssociationList.Count <= 0)
                    {
                        base.activeAssociationList = AssociationManager.ExpandAll(so);
                    }
                }
            }
        }
        internal MshResolvedExpressionParameterAssociation(MshParameter parameter, MshExpression expression)
        {
            if (expression == null)
                throw PSTraceSource.NewArgumentNullException("expression");

            OriginatingParameter = parameter;
            ResolvedExpression = expression;
        }
Ejemplo n.º 16
0
        internal MshResolvedExpressionParameterAssociation(MshParameter parameter, MshExpression expression)
        {
            if (expression == null)
                throw PSTraceSource.NewArgumentNullException("expression");

            OriginatingParameter = parameter;
            ResolvedExpression = expression;
        }
Ejemplo n.º 17
0
        private ListViewEntry GenerateListViewEntryFromDataBaseInfo(PSObject so, int enumerationLimit)
        {
            ListViewEntry lve = new ListViewEntry();

            ListControlEntryDefinition activeListControlEntryDefinition =
                GetActiveListControlEntryDefinition(_listBody, so);

            foreach (ListControlItemDefinition listItem in activeListControlEntryDefinition.itemDefinitionList)
            {
                if (!EvaluateDisplayCondition(so, listItem.conditionToken))
                {
                    continue;
                }

                ListViewField       lvf = new ListViewField();
                MshExpressionResult result;
                lvf.formatPropertyField = GenerateFormatPropertyField(listItem.formatTokenList, so, enumerationLimit, out result);

                // we need now to provide a label
                if (listItem.label != null)
                {
                    // if the directive provides one, we use it
                    lvf.label = this.dataBaseInfo.db.displayResourceManagerCache.GetTextTokenString(listItem.label);
                }
                else if (result != null)
                {
                    // if we got a valid match from the Mshexpression, use it as a label
                    lvf.label = result.ResolvedExpression.ToString();
                }
                else
                {
                    // we did fail getting a result (i.e. property does not exist on the object)

                    // we try to fall back and see if we have an un-resolved MshExpression
                    FormatToken        token = listItem.formatTokenList[0];
                    FieldPropertyToken fpt   = token as FieldPropertyToken;
                    if (fpt != null)
                    {
                        MshExpression ex = this.expressionFactory.CreateFromExpressionToken(fpt.expression, this.dataBaseInfo.view.loadingInfo);

                        // use the un-resolved MshExpression string as a label
                        lvf.label = ex.ToString();
                    }
                    else
                    {
                        TextToken tt = token as TextToken;
                        if (tt != null)
                        {
                            // we had a text token, use it as a label (last resort...)
                            lvf.label = this.dataBaseInfo.db.displayResourceManagerCache.GetTextTokenString(tt);
                        }
                    }
                }
                lve.listViewFieldList.Add(lvf);
            }
            return(lve);
        }
Ejemplo n.º 18
0
        private static MshExpression GetDefaultNameExpression(PSObject so)
        {
            MshExpression defaultNameExpression = GetDefaultNameExpression(so.PSStandardMembers);

            if (defaultNameExpression == null)
            {
                defaultNameExpression = GetDefaultNameExpression(MaskDeserializedAndGetStandardMembers(so));
            }
            return(defaultNameExpression);
        }
Ejemplo n.º 19
0
 internal bool IsMatch(MshExpression expression)
 {
     for (int i = 0; i < this._wildcardPatterns.Length; i++)
     {
         if (this._wildcardPatterns[i].IsMatch(expression.ToString()))
         {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 20
0
 internal static bool Evaluate(PSObject obj, MshExpression ex, out MshExpressionResult expressionResult)
 {
     expressionResult = null;
     List<MshExpressionResult> res = ex.GetValues(obj);
     if (res.Count == 0)
         return false;
     if (res[0].Exception != null)
     {
         expressionResult = res[0];
         return false;
     }
     return LanguagePrimitives.IsTrue(res[0].Result);
 }
Ejemplo n.º 21
0
        internal static MshExpressionResult GetDisplayName(
            PSObject target,
            MshExpressionFactory expressionFactory)
        {
            MshExpression displayNameExpression = PSObjectHelper.GetDisplayNameExpression(target, expressionFactory);

            if (displayNameExpression == null)
            {
                return((MshExpressionResult)null);
            }
            List <MshExpressionResult> values = displayNameExpression.GetValues(target);

            return(values.Count == 0 || values[0].Exception != null ? (MshExpressionResult)null : values[0]);
        }
Ejemplo n.º 22
0
        internal static MshExpressionResult GetDisplayName(PSObject target, MshExpressionFactory expressionFactory)
        {
            MshExpression displayNameExpression = GetDisplayNameExpression(target, expressionFactory);

            if (displayNameExpression != null)
            {
                List <MshExpressionResult> values = displayNameExpression.GetValues(target);
                if ((values.Count != 0) && (values[0].Exception == null))
                {
                    return(values[0]);
                }
            }
            return(null);
        }
Ejemplo n.º 23
0
        internal static List <MshResolvedExpressionParameterAssociation> ExpandParameters(List <MshParameter> parameters, PSObject target)
        {
            List <MshResolvedExpressionParameterAssociation> list = new List <MshResolvedExpressionParameterAssociation>();

            foreach (MshParameter parameter in parameters)
            {
                MshExpression entry = parameter.GetEntry("expression") as MshExpression;
                foreach (MshExpression expression2 in entry.ResolveNames(target))
                {
                    list.Add(new MshResolvedExpressionParameterAssociation(parameter, expression2));
                }
            }
            return(list);
        }
Ejemplo n.º 24
0
        private bool MatchCondition(PSObject currentObject, MshExpression ex)
        {
            if (ex == null)
            {
                return(true);
            }
            MshExpressionResult expressionResult;
            bool flag = DisplayCondition.Evaluate(currentObject, ex, out expressionResult);

            if (expressionResult != null && expressionResult.Exception != null)
            {
                this._failedResultsList.Add(expressionResult);
            }
            return(flag);
        }
Ejemplo n.º 25
0
 internal List<MshExpressionResult> GetValues(PSObject target, bool expand, bool eatExceptions)
 {
     List<MshExpressionResult> list = new List<MshExpressionResult>();
     if (this._script != null)
     {
         MshExpressionResult item = new MshExpression(this._script).GetValue(target, eatExceptions);
         list.Add(item);
         return list;
     }
     foreach (MshExpression expression2 in this.ResolveNames(target, expand))
     {
         MshExpressionResult result2 = expression2.GetValue(target, eatExceptions);
         list.Add(result2);
     }
     return list;
 }
Ejemplo n.º 26
0
        internal static bool Evaluate(PSObject obj, MshExpression ex, out MshExpressionResult expressionResult)
        {
            expressionResult = null;
            List <MshExpressionResult> res = ex.GetValues(obj);

            if (res.Count == 0)
            {
                return(false);
            }
            if (res[0].Exception != null)
            {
                expressionResult = res[0];
                return(false);
            }
            return(LanguagePrimitives.IsTrue(res[0].Result));
        }
Ejemplo n.º 27
0
        private int ComputeBestMatch(AppliesTo appliesTo, PSObject currentObject)
        {
            int best = BestMatchIndexUndefined;

            foreach (TypeOrGroupReference r in appliesTo.referenceList)
            {
                MshExpression ex = null;
                if (r.conditionToken != null)
                {
                    ex = _expressionFactory.CreateFromExpressionToken(r.conditionToken);
                }

                int           currentMatch = BestMatchIndexUndefined;
                TypeReference tr           = r as TypeReference;

                if (tr != null)
                {
                    // we have a type
                    currentMatch = MatchTypeIndex(tr.name, currentObject, ex);
                }
                else
                {
                    // we have a type group reference
                    TypeGroupReference tgr = r as TypeGroupReference;

                    // find the type group definition the reference points to
                    TypeGroupDefinition tgd = DisplayDataQuery.FindGroupDefinition(_db, tgr.name);

                    if (tgd != null)
                    {
                        // we found the group, see if the group has the type
                        currentMatch = ComputeBestMatchInGroup(tgd, currentObject, ex);
                    }
                }
                if (currentMatch == BestMatchIndexPerfect)
                {
                    return(currentMatch);
                }

                if (best == BestMatchIndexUndefined || best < currentMatch)
                {
                    best = currentMatch;
                }
            }

            return(best);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// create an expression from an expression token
        /// </summary>
        /// <param name="et">expression token to use</param>
        /// <param name="loadingInfo">The context from which the file was loaded</param>
        /// <returns>constructed expression</returns>
        /// <exception cref="ParseException"></exception>
        internal MshExpression CreateFromExpressionToken(ExpressionToken et, DatabaseLoadingInfo loadingInfo)
        {
            if (et.isScriptBlock)
            {
                // we cache script blocks from expression tokens
                if (_expressionCache != null)
                {
                    MshExpression value;
                    if (_expressionCache.TryGetValue(et, out value))
                    {
                        // got a hit on the cache, just return
                        return(value);
                    }
                }
                else
                {
                    _expressionCache = new Dictionary <ExpressionToken, MshExpression>();
                }

                bool isFullyTrusted = false;
                bool isProductCode  = false;
                if (loadingInfo != null)
                {
                    isFullyTrusted = loadingInfo.isFullyTrusted;
                    isProductCode  = loadingInfo.isProductCode;
                }

                // no hit, we build one and we cache
                ScriptBlock sb = ScriptBlock.CreateDelayParsedScriptBlock(et.expressionValue, isProductCode: isProductCode);
                sb.DebuggerStepThrough = true;

                if (isFullyTrusted)
                {
                    sb.LanguageMode = PSLanguageMode.FullLanguage;
                }

                MshExpression ex = new MshExpression(sb);

                _expressionCache.Add(et, ex);

                return(ex);
            }

            // we do not cache if it is just a property name
            return(new MshExpression(et.expressionValue));
        }
Ejemplo n.º 29
0
        internal static List <MshResolvedExpressionParameterAssociation> ExpandParameters(List <MshParameter> parameters, PSObject target)
        {
            List <MshResolvedExpressionParameterAssociation> retVal = new List <MshResolvedExpressionParameterAssociation>();

            foreach (MshParameter par in parameters)
            {
                MshExpression        expression             = par.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
                List <MshExpression> expandedExpressionList = expression.ResolveNames(target);

                foreach (MshExpression ex in expandedExpressionList)
                {
                    retVal.Add(new MshResolvedExpressionParameterAssociation(par, ex));
                }
            }

            return(retVal);
        }
Ejemplo n.º 30
0
        internal List <MshExpressionResult> GetValues(PSObject target, bool expand, bool eatExceptions)
        {
            List <MshExpressionResult> list = new List <MshExpressionResult>();

            if (this._script != null)
            {
                MshExpressionResult item = new MshExpression(this._script).GetValue(target, eatExceptions);
                list.Add(item);
                return(list);
            }
            foreach (MshExpression expression2 in this.ResolveNames(target, expand))
            {
                MshExpressionResult result2 = expression2.GetValue(target, eatExceptions);
                list.Add(result2);
            }
            return(list);
        }
        private bool EvaluateDisplayCondition(PSObject so, ExpressionToken conditionToken)
        {
            if (conditionToken == null)
            {
                return(true);
            }

            MshExpression       ex = _expressionFactory.CreateFromExpressionToken(conditionToken, _loadingInfo);
            MshExpressionResult expressionResult;
            bool retVal = DisplayCondition.Evaluate(so, ex, out expressionResult);

            if (expressionResult != null && expressionResult.Exception != null)
            {
                _errorManager.LogMshExpressionFailedResult(expressionResult, so);
            }
            return(retVal);
        }
Ejemplo n.º 32
0
        private bool EvaluateDisplayCondition(PSObject so, ExpressionToken conditionToken)
        {
            MshExpressionResult result;

            if (conditionToken == null)
            {
                return(true);
            }
            MshExpression ex   = this.expressionFactory.CreateFromExpressionToken(conditionToken, this.loadingInfo);
            bool          flag = DisplayCondition.Evaluate(so, ex, out result);

            if ((result != null) && (result.Exception != null))
            {
                this.errorManager.LogMshExpressionFailedResult(result, so);
            }
            return(flag);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Retrieve the display name. It looks for a well known property and,
        /// if not found, it uses some heuristics to get a "close" match
        /// </summary>
        /// <param name="target">shell object to process</param>
        /// <param name="expressionFactory">expression factory to create MshExpression</param>
        /// <returns>resolved MshExpression; null if no match was found</returns>
        internal static MshExpression GetDisplayNameExpression(PSObject target, MshExpressionFactory expressionFactory)
        {
            // first try to get the expression from the object (types.ps1xml data)
            MshExpression expressionFromObject = GetDefaultNameExpression(target);

            if (expressionFromObject != null)
            {
                return(expressionFromObject);
            }

            // we failed the default display name, let's try some well known names
            // trying to get something potentially useful
            string[] knownPatterns = new string[] {
                "name", "id", "key", "*key", "*name", "*id",
            };

            // go over the patterns, looking for the first match
            foreach (string pattern in knownPatterns)
            {
                MshExpression        ex       = new MshExpression(pattern);
                List <MshExpression> exprList = ex.ResolveNames(target);

                while ((exprList.Count > 0) && (
                           exprList[0].ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) ||
                           exprList[0].ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) ||
                           exprList[0].ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) ||
                           exprList[0].ToString().Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase)))
                {
                    exprList.RemoveAt(0);
                }

                if (exprList.Count == 0)
                {
                    continue;
                }

                // if more than one match, just return the first one
                return(exprList[0]);
            }

            // we did not find anything
            return(null);
        }
Ejemplo n.º 34
0
        internal static string GetExpressionDisplayValue(
            PSObject so,
            int enumerationLimit,
            MshExpression ex,
            FieldFormattingDirective directive,
            StringFormatError formatErrorObject,
            MshExpressionFactory expressionFactory,
            out MshExpressionResult result)
        {
            result = (MshExpressionResult)null;
            List <MshExpressionResult> values = ex.GetValues(so);

            if (values.Count == 0)
            {
                return("");
            }
            result = values[0];
            return(result.Exception != null ? "" : PSObjectHelper.FormatField(directive, result.Result, enumerationLimit, formatErrorObject, expressionFactory));
        }
Ejemplo n.º 35
0
        internal static List <MshResolvedExpressionParameterAssociation> ExpandTableParameters(List <MshParameter> parameters, PSObject target)
        {
            List <MshResolvedExpressionParameterAssociation> list = new List <MshResolvedExpressionParameterAssociation>();

            foreach (MshParameter parameter in parameters)
            {
                MshExpression        entry = parameter.GetEntry("expression") as MshExpression;
                List <MshExpression> list2 = entry.ResolveNames(target);
                if (!entry.HasWildCardCharacters && (list2.Count == 0))
                {
                    list.Add(new MshResolvedExpressionParameterAssociation(parameter, entry));
                }
                foreach (MshExpression expression2 in list2)
                {
                    list.Add(new MshResolvedExpressionParameterAssociation(parameter, expression2));
                }
            }
            return(list);
        }
Ejemplo n.º 36
0
 private int ComputeBestMatchInGroup(TypeGroupDefinition tgd, PSObject currentObject, MshExpression ex)
 {
     int num = -1;
     int num2 = 0;
     foreach (TypeReference reference in tgd.typeReferenceList)
     {
         int num3 = this.MatchTypeIndex(reference.name, currentObject, ex);
         if (num3 == 0)
         {
             return num3;
         }
         if ((num == -1) || (num < num3))
         {
             num = num3;
         }
         num2++;
     }
     return num;
 }
Ejemplo n.º 37
0
        /// <summary>
        /// it gets the display name value
        /// </summary>
        /// <param name="target">shell object to process</param>
        /// <param name="expressionFactory">expression factory to create MshExpression</param>
        /// <returns>MshExpressionResult if successful; null otherwise</returns>
        internal static MshExpressionResult GetDisplayName(PSObject target, MshExpressionFactory expressionFactory)
        {
            // get the expression to evaluate
            MshExpression ex = GetDisplayNameExpression(target, expressionFactory);

            if (ex == null)
            {
                return(null);
            }

            // evaluate the expression
            List <MshExpressionResult> resList = ex.GetValues(target);

            if (resList.Count == 0 || resList[0].Exception != null)
            {
                // no results or the retrieval on the first one failed
                return(null);
            }
            // return something only if the first match was successful
            return(resList[0]);
        }
Ejemplo n.º 38
0
 private static int ComputeDefaultAlignment(PSObject so, MshExpression ex)
 {
     List<MshExpressionResult> values = ex.GetValues(so);
     if ((values.Count != 0) && (values[0].Exception == null))
     {
         object result = values[0].Result;
         if (result != null)
         {
             ConsolidatedString internalTypeNames = PSObject.AsPSObject(result).InternalTypeNames;
             if (string.Equals(PSObjectHelper.PSObjectIsOfExactType(internalTypeNames), "System.String", StringComparison.OrdinalIgnoreCase))
             {
                 return 1;
             }
             if (DefaultScalarTypes.IsTypeInList(internalTypeNames))
             {
                 return 3;
             }
         }
     }
     return 1;
 }
        internal override object Verify(object val,
                                        TerminatingErrorContext invocationContext,
                                        bool originalParameterWasHashTable)
        {
            if (val == null)
            {
                throw PSTraceSource.NewArgumentNullException("val");
            }

            // need to check the type:
            // it can be a string or a script block
            ScriptBlock sb = val as ScriptBlock;

            if (sb != null)
            {
                MshExpression ex = new MshExpression(sb);
                return(ex);
            }

            string s = val as string;

            if (s != null)
            {
                if (string.IsNullOrEmpty(s))
                {
                    ProcessEmptyStringError(originalParameterWasHashTable, invocationContext);
                }
                MshExpression ex = new MshExpression(s);
                if (_noGlobbing)
                {
                    if (ex.HasWildCardCharacters)
                    {
                        ProcessGlobbingCharactersError(originalParameterWasHashTable, s, invocationContext);
                    }
                }
                return(ex);
            }
            PSTraceSource.NewArgumentException("val");
            return(null);
        }
Ejemplo n.º 40
0
        private int ComputeBestMatchInGroup(TypeGroupDefinition tgd, PSObject currentObject, MshExpression ex)
        {
            int best = BestMatchIndexUndefined;
            int k = 0;
            foreach (TypeReference tr in tgd.typeReferenceList)
            {
                int currentMatch = MatchTypeIndex(tr.name, currentObject, ex);
                if (currentMatch == BestMatchIndexPerfect)
                    return currentMatch;

                if (best == BestMatchIndexUndefined || best < currentMatch)
                {
                    best = currentMatch;
                }
                k++;
            }
            return best;
        }
Ejemplo n.º 41
0
 private bool MatchCondition(PSObject currentObject, MshExpression ex)
 {
     MshExpressionResult result;
     if (ex == null)
     {
         return true;
     }
     bool flag = DisplayCondition.Evaluate(currentObject, ex, out result);
     if ((result != null) && (result.Exception != null))
     {
         this._failedResultsList.Add(result);
     }
     return flag;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Initialize with the grouping property data
 /// </summary>
 /// <param name="groupingExpression">name of the grouping property</param>
 /// <param name="displayLabel">display name of the property</param>
 internal void Initialize(MshExpression groupingExpression, string displayLabel)
 {
     _groupingKeyExpression = groupingExpression;
     _label = displayLabel;
 }
Ejemplo n.º 43
0
 internal MshExpressionResult(object res, MshExpression re, System.Exception e)
 {
     this._result = res;
     this._resolvedExpression = re;
     this._exception = e;
 }
Ejemplo n.º 44
0
 private int MatchTypeIndex(string typeName, PSObject currentObject, MshExpression ex)
 {
     if (!string.IsNullOrEmpty(typeName))
     {
         int num = 0;
         foreach (string str in this._typeNameHierarchy)
         {
             if (string.Equals(str, typeName, StringComparison.OrdinalIgnoreCase) && this.MatchCondition(currentObject, ex))
             {
                 return num;
             }
             if ((num == 0) && !this._useInheritance)
             {
                 break;
             }
             num++;
         }
     }
     return -1;
 }
Ejemplo n.º 45
0
 internal ExpressionColumnInfo(string staleObjectPropertyName, string displayName, MshExpression expression)
     : base(staleObjectPropertyName, displayName)
 {
     _expression = expression;
 }
Ejemplo n.º 46
0
        internal static List<MshResolvedExpressionParameterAssociation> ExpandAll(PSObject target)
        {
            List<string> adaptedProperties = GetPropertyNamesFromView(target, PSMemberViewTypes.Adapted);
            List<string> baseProperties = GetPropertyNamesFromView(target, PSMemberViewTypes.Base);
            List<string> extendedProperties = GetPropertyNamesFromView(target, PSMemberViewTypes.Extended);

            var displayedProperties = adaptedProperties.Count != 0 ? adaptedProperties : baseProperties;
            displayedProperties.AddRange(extendedProperties);

            Dictionary<string, object> duplicatesFinder = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            List<MshResolvedExpressionParameterAssociation> retVal = new List<MshResolvedExpressionParameterAssociation>();
            foreach (string property in displayedProperties)
            {
                if (!duplicatesFinder.ContainsKey(property))
                {
                    duplicatesFinder.Add(property, null);
                    MshExpression expr = new MshExpression(property, true);
                    retVal.Add(new MshResolvedExpressionParameterAssociation(null, expr));
                }
            }
            return retVal;
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Retrieve the display name. It looks for a well known property and,
        /// if not found, it uses some heuristics to get a "close" match
        /// </summary>
        /// <param name="target">shell object to process</param>
        /// <param name="expressionFactory">expression factory to create MshExpression</param>
        /// <returns>resolved MshExpression; null if no match was found</returns>
        internal static MshExpression GetDisplayNameExpression(PSObject target, MshExpressionFactory expressionFactory)
        {
            // first try to get the expression from the object (types.ps1xml data)
            MshExpression expressionFromObject = GetDefaultNameExpression(target);
            if (expressionFromObject != null)
            {
                return expressionFromObject;
            }

            // we failed the default display name, let's try some well known names
            // trying to get something potentially useful
            string[] knownPatterns = new string[] {
                "name", "id", "key", "*key", "*name", "*id",
            };

            // go over the patterns, looking for the first match
            foreach (string pattern in knownPatterns)
            {
                MshExpression ex = new MshExpression(pattern);
                List<MshExpression> exprList = ex.ResolveNames(target);

                while ((exprList.Count > 0) && (
                    exprList[0].ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) ||
                    exprList[0].ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) ||
                    exprList[0].ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) ||
                    exprList[0].ToString().Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase)))
                {
                    exprList.RemoveAt(0);
                }

                if (exprList.Count == 0)
                    continue;

                // if more than one match, just return the first one
                return exprList[0];
            }

            // we did not find anything
            return null;
        }
Ejemplo n.º 48
0
        internal List<MshExpressionResult> GetValues(PSObject target, bool expand, bool eatExceptions)
        {
            List<MshExpressionResult> retVal = new List<MshExpressionResult>();

            // process the script case
            if (Script != null)
            {
                MshExpression scriptExpression = new MshExpression(Script);
                MshExpressionResult r = scriptExpression.GetValue(target, eatExceptions);
                retVal.Add(r);
                return retVal;
            }

            // process the expression
            List<MshExpression> resolvedExpressionList = this.ResolveNames(target, expand);

            foreach (MshExpression re in resolvedExpressionList)
            {
                MshExpressionResult r = re.GetValue(target, eatExceptions);
                retVal.Add(r);
            }

            return retVal;
        }
        internal override object Verify(object val,
                                        TerminatingErrorContext invocationContext,
                                        bool originalParameterWasHashTable)
        {
            if (val == null)
            {
                throw PSTraceSource.NewArgumentNullException("val");
            }

            // need to check the type:
            // it can be a string or a script block
            ScriptBlock sb = val as ScriptBlock;
            if (sb != null)
            {
                MshExpression ex = new MshExpression(sb);
                return ex;
            }

            string s = val as string;
            if (s != null)
            {
                if (string.IsNullOrEmpty(s))
                {
                    ProcessEmptyStringError(originalParameterWasHashTable, invocationContext);
                }
                MshExpression ex = new MshExpression(s);
                if (_noGlobbing)
                {
                    if (ex.HasWildCardCharacters)
                        ProcessGlobbingCharactersError(originalParameterWasHashTable, s, invocationContext);
                }
                return ex;
            }
            PSTraceSource.NewArgumentException("val");
            return null;
        }
Ejemplo n.º 50
0
 internal MshExpressionResult(object res, MshExpression re, Exception e)
 {
     Result = res;
     ResolvedExpression = re;
     Exception = e;
 }
Ejemplo n.º 51
0
        internal List<MshExpression> ResolveNames(PSObject target, bool expand)
        {
            List<MshExpression> retVal = new List<MshExpression>();

            if (_isResolved)
            {
                retVal.Add(this);
                return retVal;
            }

            if (Script != null)
            {
                // script block, just add it to the list and be done
                MshExpression ex = new MshExpression(Script);

                ex._isResolved = true;
                retVal.Add(ex);
                return retVal;
            }

            // we have a string value
            IEnumerable<PSMemberInfo> members = null;
            if (HasWildCardCharacters)
            {
                // get the members first: this will expand the globbing on each parameter
                members = target.Members.Match(_stringValue,
                                            PSMemberTypes.Properties | PSMemberTypes.PropertySet);
            }
            else
            {
                // we have no globbing: try an exact match, because this is quicker.
                PSMemberInfo x = target.Members[_stringValue];

                List<PSMemberInfo> temp = new List<PSMemberInfo>();
                if (x != null)
                {
                    temp.Add(x);
                }
                members = temp;
            }

            // we now have a list of members, we have to expand property sets
            // and remove duplicates
            List<PSMemberInfo> temporaryMemberList = new List<PSMemberInfo>();

            foreach (PSMemberInfo member in members)
            {
                // it can be a property set
                PSPropertySet propertySet = member as PSPropertySet;
                if (propertySet != null)
                {
                    if (expand)
                    {
                        // NOTE: we expand the property set under the
                        // assumption that it contains property names that
                        // do not require any further expansion
                        Collection<string> references = propertySet.ReferencedPropertyNames;

                        for (int j = 0; j < references.Count; j++)
                        {
                            ReadOnlyPSMemberInfoCollection<PSPropertyInfo> propertyMembers =
                                                target.Properties.Match(references[j]);
                            for (int jj = 0; jj < propertyMembers.Count; jj++)
                            {
                                temporaryMemberList.Add(propertyMembers[jj]);
                            }
                        }
                    }
                    continue;
                }
                // it can be a property
                if (member is PSPropertyInfo)
                {
                    temporaryMemberList.Add(member);
                }
            }

            Hashtable hash = new Hashtable();

            // build the list of unique values: remove the possible duplicates
            // from property set expansion
            foreach (PSMemberInfo m in temporaryMemberList)
            {
                if (!hash.ContainsKey(m.Name))
                {
                    MshExpression ex = new MshExpression(m.Name);

                    ex._isResolved = true;
                    retVal.Add(ex);
                    hash.Add(m.Name, null);
                }
            }

            return retVal;
        }
Ejemplo n.º 52
0
        /// <summary>
        /// helper to retrieve the value of an MshExpression and to format it
        /// </summary>
        /// <param name="so">shell object to process</param>
        /// <param name="enumerationLimit">limit on IEnumerable enumeration</param>
        /// <param name="ex">expression to use for retrieval</param>
        /// <param name="directive">format directive to use for formatting</param>
        /// <param name="formatErrorObject"></param>
        /// <param name="expressionFactory">expression factory to create MshExpression</param>
        /// <param name="result"> not null if an error condition arose</param>
        /// <returns>formatted string</returns>
        internal static string GetExpressionDisplayValue(
            PSObject so,
            int enumerationLimit,
            MshExpression ex,
            FieldFormattingDirective directive,
            StringFormatError formatErrorObject,
            MshExpressionFactory expressionFactory,
            out MshExpressionResult result)
        {
            result = null;
            List<MshExpressionResult> resList = ex.GetValues(so);

            if (resList.Count == 0)
            {
                return "";
            }

            result = resList[0];
            if (result.Exception != null)
            {
                return "";
            }
            return PSObjectHelper.FormatField(directive, result.Result, enumerationLimit, formatErrorObject, expressionFactory);
        }
Ejemplo n.º 53
0
 private int MatchTypeIndex(string typeName, PSObject currentObject, MshExpression ex)
 {
     if (string.IsNullOrEmpty(typeName))
         return BestMatchIndexUndefined;
     int k = 0;
     foreach (string name in _typeNameHierarchy)
     {
         if (string.Equals(name, typeName, StringComparison.OrdinalIgnoreCase)
                     && MatchCondition(currentObject, ex))
         {
             return k;
         }
         if (k == 0 && !_useInheritance)
             break;
         k++;
     }
     return BestMatchIndexUndefined;
 }
Ejemplo n.º 54
0
        private static int ComputeDefaultAlignment(PSObject so, MshExpression ex)
        {
            List<MshExpressionResult> rList = ex.GetValues(so);

            if ((rList.Count == 0) || (rList[0].Exception != null))
                return TextAlignment.Left;

            object val = rList[0].Result;
            if (val == null)
                return TextAlignment.Left;

            PSObject soVal = PSObject.AsPSObject(val);
            var typeNames = soVal.InternalTypeNames;
            if (string.Equals(PSObjectHelper.PSObjectIsOfExactType(typeNames),
                                "System.String", StringComparison.OrdinalIgnoreCase))
                return TextAlignment.Left;

            if (DefaultScalarTypes.IsTypeInList(typeNames))
                return TextAlignment.Right;

            return TextAlignment.Left;
        }
Ejemplo n.º 55
0
        private bool MatchCondition(PSObject currentObject, MshExpression ex)
        {
            if (ex == null)
                return true;

            MshExpressionResult expressionResult;
            bool retVal = DisplayCondition.Evaluate(currentObject, ex, out expressionResult);
            if (expressionResult != null && expressionResult.Exception != null)
            {
                _failedResultsList.Add(expressionResult);
            }
            return retVal;
        }
Ejemplo n.º 56
0
 protected string GetExpressionDisplayValue(PSObject so, int enumerationLimit, MshExpression ex,
             FieldFormattingDirective directive)
 {
     MshExpressionResult resolvedExpression;
     return GetExpressionDisplayValue(so, enumerationLimit, ex, directive, out resolvedExpression);
 }
Ejemplo n.º 57
0
 internal List<MshExpression> ResolveNames(PSObject target, bool expand)
 {
     List<MshExpression> list = new List<MshExpression>();
     if (this._isResolved)
     {
         list.Add(this);
         return list;
     }
     if (this._script != null)
     {
         MshExpression item = new MshExpression(this._script) {
             _isResolved = true
         };
         list.Add(item);
         return list;
     }
     IEnumerable<PSMemberInfo> enumerable = null;
     if (this.HasWildCardCharacters)
     {
         enumerable = target.Members.Match(this._stringValue, PSMemberTypes.PropertySet | PSMemberTypes.Properties);
     }
     else
     {
         PSMemberInfo info = target.Members[this._stringValue];
         List<PSMemberInfo> list2 = new List<PSMemberInfo>();
         if (info != null)
         {
             list2.Add(info);
         }
         enumerable = list2;
     }
     List<PSMemberInfo> list3 = new List<PSMemberInfo>();
     foreach (PSMemberInfo info2 in enumerable)
     {
         PSPropertySet set = info2 as PSPropertySet;
         if (set != null)
         {
             if (expand)
             {
                 Collection<string> referencedPropertyNames = set.ReferencedPropertyNames;
                 for (int i = 0; i < referencedPropertyNames.Count; i++)
                 {
                     ReadOnlyPSMemberInfoCollection<PSPropertyInfo> infos = target.Properties.Match(referencedPropertyNames[i]);
                     for (int j = 0; j < infos.Count; j++)
                     {
                         list3.Add(infos[j]);
                     }
                 }
             }
         }
         else if (info2 is PSPropertyInfo)
         {
             list3.Add(info2);
         }
     }
     Hashtable hashtable = new Hashtable();
     foreach (PSMemberInfo info3 in list3)
     {
         if (!hashtable.ContainsKey(info3.Name))
         {
             MshExpression expression2 = new MshExpression(info3.Name) {
                 _isResolved = true
             };
             list.Add(expression2);
             hashtable.Add(info3.Name, null);
         }
     }
     return list;
 }
Ejemplo n.º 58
0
        protected string GetExpressionDisplayValue(PSObject so, int enumerationLimit, MshExpression ex,
                    FieldFormattingDirective directive, out MshExpressionResult expressionResult)
        {
            StringFormatError formatErrorObject = null;
            if (_errorManager.DisplayFormatErrorString)
            {
                // we send a format error object down to the formatting calls
                // only if we want to show the formatting error strings
                formatErrorObject = new StringFormatError();
            }

            string retVal = PSObjectHelper.GetExpressionDisplayValue(so, enumerationLimit, ex,
                                directive, formatErrorObject, expressionFactory, out expressionResult);

            if (expressionResult != null)
            {
                // we obtained a result, check if there is an error
                if (expressionResult.Exception != null)
                {
                    _errorManager.LogMshExpressionFailedResult(expressionResult, so);
                    if (_errorManager.DisplayErrorStrings)
                    {
                        retVal = _errorManager.ErrorString;
                    }
                }
                else if (formatErrorObject != null && formatErrorObject.exception != null)
                {
                    // if we did no thave any errors in the expression evaluation
                    // we might have errors in the formatting, if present
                    _errorManager.LogStringFormatError(formatErrorObject);
                    if (_errorManager.DisplayErrorStrings)
                    {
                        retVal = _errorManager.FormatErrorString;
                    }
                }
            }
            return retVal;
        }
Ejemplo n.º 59
0
 protected string GetExpressionDisplayValue(PSObject so, int enumerationLimit, MshExpression ex, FieldFormattingDirective directive, out MshExpressionResult expressionResult)
 {
     StringFormatError formatErrorObject = null;
     if (this.errorManager.DisplayFormatErrorString)
     {
         formatErrorObject = new StringFormatError();
     }
     string errorString = PSObjectHelper.GetExpressionDisplayValue(so, enumerationLimit, ex, directive, formatErrorObject, this.expressionFactory, out expressionResult);
     if (expressionResult != null)
     {
         if (expressionResult.Exception != null)
         {
             this.errorManager.LogMshExpressionFailedResult(expressionResult, so);
             if (this.errorManager.DisplayErrorStrings)
             {
                 errorString = this.errorManager.ErrorString;
             }
             return errorString;
         }
         if ((formatErrorObject != null) && (formatErrorObject.exception != null))
         {
             this.errorManager.LogStringFormatError(formatErrorObject);
             if (this.errorManager.DisplayErrorStrings)
             {
                 errorString = this.errorManager.FormatErrorString;
             }
         }
     }
     return errorString;
 }
Ejemplo n.º 60
0
        /// <summary>
        /// create an expression from an expression token
        /// </summary>
        /// <param name="et">expression token to use</param>
        /// <param name="loadingInfo">The context from which the file was loaded</param>
        /// <returns>constructed expression</returns>
        /// <exception cref="ParseException"></exception>
        internal MshExpression CreateFromExpressionToken(ExpressionToken et, DatabaseLoadingInfo loadingInfo)
        {
            if (et.isScriptBlock)
            {
                // we cache script blocks from expression tokens
                if (_expressionCache != null)
                {
                    MshExpression value;
                    if (_expressionCache.TryGetValue(et, out value))
                    {
                        // got a hit on the cache, just return
                        return value;
                    }
                }
                else
                {
                    _expressionCache = new Dictionary<ExpressionToken, MshExpression>();
                }

                bool isFullyTrusted = false;
                bool isProductCode = false;
                if (loadingInfo != null)
                {
                    isFullyTrusted = loadingInfo.isFullyTrusted;
                    isProductCode = loadingInfo.isProductCode;
                }

                // no hit, we build one and we cache
                ScriptBlock sb = ScriptBlock.CreateDelayParsedScriptBlock(et.expressionValue, isProductCode: isProductCode);
                sb.DebuggerStepThrough = true;

                if (isFullyTrusted)
                {
                    sb.LanguageMode = PSLanguageMode.FullLanguage;
                }

                MshExpression ex = new MshExpression(sb);

                _expressionCache.Add(et, ex);

                return ex;
            }

            // we do not cache if it is just a property name
            return new MshExpression(et.expressionValue);
        }