Ejemplo n.º 1
0
        internal override void SetSessionStateItem(string path, object value, bool writeItem)
        {
            Path name = PathIntrinsics.RemoveDriveName(path);

            path = name.TrimStartSlash();

            if (value == null)
            {
                Environment.SetEnvironmentVariable(path, null);
            }
            else
            {
                if (value is DictionaryEntry)
                {
                    value = ((DictionaryEntry)value).Value;
                }
                string str = value as string;
                if (str == null)
                {
                    str = PSObject.AsPSObject(value).ToString();
                }
                Environment.SetEnvironmentVariable(path, str);
                DictionaryEntry item = new DictionaryEntry(path, str);
                if (writeItem)
                {
                    WriteItemObject(item, path, false);
                }
            }
        }
Ejemplo n.º 2
0
        internal override object GetSessionStateItem(string name)
        {
            Path path = PathIntrinsics.RemoveDriveName(name);

            path = path.TrimStartSlash();
            return(SessionState.Alias.Get(path));
        }
Ejemplo n.º 3
0
        internal override void SetSessionStateItem(string name, object value, bool writeItem)
        {
            Path path = PathIntrinsics.RemoveDriveName(name);

            name = path.TrimStartSlash();

            PSVariable variable = null;

            if (value != null)
            {
                variable = value as PSVariable;
                if (variable == null)
                {
                    variable = new PSVariable(name, value);
                }
                else if (String.Compare(name, variable.Name, true, System.Globalization.CultureInfo.CurrentCulture) != 0)
                {
                    PSVariable var = new PSVariable(name, variable.Value, variable.Options, variable.Attributes);
                    var.Description = variable.Description;
                    variable        = var;
                }
            }
            else
            {
                variable = new PSVariable(name, null);
            }
            // TODO: can be Force'ed
            SessionState.PSVariable.Set(variable);
            PSVariable item = SessionState.PSVariable.Get(variable.Name);

            if (writeItem && (item != null))
            {
                WriteItemObject(item, item.Name, false);
            }
        }
Ejemplo n.º 4
0
        internal override object GetSessionStateItem(string name)
        {
            Path path = PathIntrinsics.RemoveDriveName(name);

            path = path.TrimStartSlash();
            string environmentVariable = Environment.GetEnvironmentVariable(path);

            if (environmentVariable != null)
            {
                return(new DictionaryEntry(path, environmentVariable));
            }
            return(null);
        }
Ejemplo n.º 5
0
        protected override void GetItem(Path name)
        {
            // HACK: should it be this way?

            if (string.Equals("variable:\\", name, StringComparison.CurrentCultureIgnoreCase))
            {
                name = PathIntrinsics.RemoveDriveName(name);
                GetChildItems(name, false);
            }
            else
            {
                GetItem(PathIntrinsics.RemoveDriveName(name));
            }
        }
Ejemplo n.º 6
0
        internal PathInfo SetLocation(string path, ProviderRuntime providerRuntime)
        {
            // TODO: deal with paths starting with ".\"

            if (path == null)
            {
                throw new NullReferenceException("Path can't be null");
            }

            path = PathIntrinsics.NormalizePath(path);

            ProviderInfo provider  = null;
            string       driveName = null;

            string      str          = path;
            string      providerId   = null;
            PSDriveInfo currentDrive = CurrentDrive;

            // If path doesn't start with a drive name
            if (path.StartsWith(PathIntrinsics.CorrectSlash.ToString()))
            {
                provider = CurrentLocation.Provider;
            }
            else if (PathIntrinsics.IsAbsolutePath(path, out driveName))
            {
                _currentDrive = GetDrive(driveName, null);

                path = PathIntrinsics.NormalizePath(PathIntrinsics.RemoveDriveName(path));
            }

            _currentDrive.CurrentLocation = path;

            _providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive;

            SetVariable("PWD", CurrentLocation);
            return(CurrentLocation);


            PSDriveInfo drive = CurrentDrive;

            SetLocation(path);
        }
Ejemplo n.º 7
0
        internal override void SetSessionStateItem(string name, object value, bool writeItem)
        {
            Path path = PathIntrinsics.RemoveDriveName(name);

            path = path.TrimStartSlash();

            if (value is Array)
            {
                var array = (Array)value;
                if (array.Length > 1)
                {
                    throw new PSArgumentException("value");
                }
                value = array.GetValue(0);
            }

            var aliasInfo = new AliasInfo(path, value.ToString(), null);

            SessionState.Alias.Set(aliasInfo, "global");

            var a = SessionState.Alias.Get(path);

            Console.WriteLine(a.Definition);
        }
Ejemplo n.º 8
0
 protected override void GetItem(string path)
 {
     path = PathIntrinsics.RemoveDriveName(new Path(path).TrimEndSlash());
     GetChildItems(path, false);
 }
Ejemplo n.º 9
0
 protected override void GetItem(string name)
 {
     name = PathIntrinsics.RemoveDriveName(new Path(name).TrimEndSlash());
     GetChildItems(name, false);
 }
Ejemplo n.º 10
0
        protected override void GetItem(Path name)
        {
            Path path = PathIntrinsics.RemoveDriveName(name.TrimEndSlash());

            GetChildItems(path, false);
        }