Пример #1
0
        internal override void SetSessionStateItem(string name, object value, bool writeItem)
        {
            AliasProviderDynamicParameters dynamicParameters = base.DynamicParameters as AliasProviderDynamicParameters;
            AliasInfo item = null;
            bool      flag = (dynamicParameters != null) && dynamicParameters.OptionsSet;

            if (value == null)
            {
                if (flag)
                {
                    item = (AliasInfo)this.GetSessionStateItem(name);
                    if (item != null)
                    {
                        item.SetOptions(dynamicParameters.Options, (bool)base.Force);
                    }
                }
                else
                {
                    this.RemoveSessionStateItem(name);
                }
            }
            else
            {
                string str = value as string;
                if (str != null)
                {
                    if (flag)
                    {
                        item = base.SessionState.Internal.SetAliasValue(name, str, dynamicParameters.Options, (bool)base.Force, base.Context.Origin);
                    }
                    else
                    {
                        item = base.SessionState.Internal.SetAliasValue(name, str, (bool)base.Force, base.Context.Origin);
                    }
                }
                else
                {
                    AliasInfo info2 = value as AliasInfo;
                    if (info2 == null)
                    {
                        throw PSTraceSource.NewArgumentException("value");
                    }
                    AliasInfo alias = new AliasInfo(name, info2.Definition, base.Context.ExecutionContext, info2.Options);
                    if (flag)
                    {
                        alias.SetOptions(dynamicParameters.Options, (bool)base.Force);
                    }
                    item = base.SessionState.Internal.SetAliasItem(alias, (bool)base.Force, base.Context.Origin);
                }
            }
            if (writeItem && (item != null))
            {
                base.WriteItemObject(item, item.Name, false);
            }
        }
Пример #2
0
        internal override void SetSessionStateItem(string name, object value, bool writeItem)
        {
            using (AliasProvider.tracer.TraceMethod(name, new object[0]))
            {
                AliasProviderDynamicParameters dynamicParameters = this.DynamicParameters as AliasProviderDynamicParameters;
                AliasInfo aliasInfo1 = (AliasInfo)null;
                bool      flag       = dynamicParameters != null && dynamicParameters.OptionsSet;
                switch (value)
                {
                case null:
                    if (flag)
                    {
                        aliasInfo1 = (AliasInfo)this.GetSessionStateItem(name);
                        if (aliasInfo1 != null)
                        {
                            aliasInfo1.SetOptions(dynamicParameters.Options, (bool)this.Force);
                            break;
                        }
                        break;
                    }
                    this.RemoveSessionStateItem(name);
                    break;

                case string str:
                    aliasInfo1 = !flag?this.SessionState.Internal.SetAliasValue(name, str, (bool)this.Force, this.Context.Origin) : this.SessionState.Internal.SetAliasValue(name, str, dynamicParameters.Options, (bool)this.Force, this.Context.Origin);

                    break;

                case AliasInfo aliasInfo:
                    AliasInfo alias = new AliasInfo(name, aliasInfo.Definition, this.Context.ExecutionContext, aliasInfo.Options);
                    if (flag)
                    {
                        alias.SetOptions(dynamicParameters.Options, (bool)this.Force);
                    }
                    aliasInfo1 = this.SessionState.Internal.SetAliasItem(alias, (bool)this.Force, this.Context.Origin);
                    break;

                default:
                    throw AliasProvider.tracer.NewArgumentException(nameof(value));
                }
                if (!writeItem || aliasInfo1 == null)
                {
                    return;
                }
                this.WriteItemObject((object)aliasInfo1, aliasInfo1.Name, false);
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the alias of the specified name to the specified value.
        /// </summary>
        /// <param name="name">
        /// The name of the alias to set.
        /// </param>
        /// <param name="value">
        /// The new value for the alias.
        /// </param>
        /// <param name="writeItem">
        /// If true, the item that was set should be written to WriteItemObject.
        /// </param>
#pragma warning disable 0162
        internal override void SetSessionStateItem(string name, object value, bool writeItem)
        {
            Dbg.Diagnostics.Assert(
                !string.IsNullOrEmpty(name),
                "The caller should verify this parameter");

            AliasProviderDynamicParameters dynamicParameters =
                DynamicParameters as AliasProviderDynamicParameters;

            AliasInfo item = null;

            bool dynamicParametersSpecified = dynamicParameters != null && dynamicParameters.OptionsSet;

            if (value == null)
            {
                if (dynamicParametersSpecified)
                {
                    item = (AliasInfo)GetSessionStateItem(name);

                    if (item != null)
                    {
                        item.SetOptions(dynamicParameters.Options, Force);
                    }
                }
                else
                {
                    RemoveSessionStateItem(name);
                }
            }
            else
            {
                do // false loop
                {
                    string stringValue = value as string;
                    if (stringValue != null)
                    {
                        if (dynamicParametersSpecified)
                        {
                            item = SessionState.Internal.SetAliasValue(name, stringValue, dynamicParameters.Options, Force, Context.Origin);
                        }
                        else
                        {
                            item = SessionState.Internal.SetAliasValue(name, stringValue, Force, Context.Origin);
                        }

                        break;
                    }

                    AliasInfo alias = value as AliasInfo;
                    if (alias != null)
                    {
                        AliasInfo newAliasInfo =
                            new AliasInfo(
                                name,
                                alias.Definition,
                                this.Context.ExecutionContext,
                                alias.Options);

                        if (dynamicParametersSpecified)
                        {
                            newAliasInfo.SetOptions(dynamicParameters.Options, Force);
                        }

                        item = SessionState.Internal.SetAliasItem(newAliasInfo, Force, Context.Origin);
                        break;
                    }

                    throw PSTraceSource.NewArgumentException("value");
                } while (false);
            }

            if (writeItem && item != null)
            {
                WriteItemObject(item, item.Name, false);
            }
        }