}     // CurrentLocation

        /// <summary>
        /// Gets the namespace specific path of the current working directory
        /// for the specified namespace.
        /// </summary>
        ///
        /// <param name="namespaceID">
        /// An identifier that uniquely identifies the namespace to get the
        /// current working directory for.
        /// </param>
        ///
        /// <returns>
        /// The namespace specific path of the current working directory for
        /// the specified namespace.
        /// </returns>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="namespaceID"/> is null.
        /// </exception>
        ///
        /// <exception cref="ProviderNotFoundException">
        /// If <paramref name="namespacesID"/> refers to a provider that does not exist.
        /// </exception>
        ///
        /// <exception cref="DriveNotFoundException">
        /// If a current drive cannot be found for the provider <paramref name="namespaceID"/>
        /// </exception>
        ///
        internal PathInfo GetNamespaceCurrentLocation(string namespaceID)
        {
            if (namespaceID == null)
            {
                throw PSTraceSource.NewArgumentNullException("namespaceID");
            }

            // If namespace ID is empty, we will use the current working drive

            PSDriveInfo drive = null;

            if (namespaceID.Length == 0)
            {
                ProvidersCurrentWorkingDrive.TryGetValue(CurrentDrive.Provider, out drive);
            }
            else
            {
                // First check to see if the provider exists

                ProvidersCurrentWorkingDrive.TryGetValue(GetSingleProvider(namespaceID), out drive);
            }

            if (drive == null)
            {
                DriveNotFoundException e =
                    new DriveNotFoundException(
                        namespaceID,
                        "DriveNotFound",
                        SessionStateStrings.DriveNotFound);
                throw e;
            }

            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);

            context.Drive = drive;

            // Now make the namespace specific path

            string path = null;

            if (drive.Hidden)
            {
                if (LocationGlobber.IsProviderDirectPath(drive.CurrentLocation))
                {
                    path = drive.CurrentLocation;
                }
                else
                {
                    path = LocationGlobber.GetProviderQualifiedPath(drive.CurrentLocation, drive.Provider);
                }
            }
            else
            {
                path = LocationGlobber.GetDriveQualifiedPath(drive.CurrentLocation, drive);
            }
            return(new PathInfo(drive, drive.Provider, path, new SessionState(this)));
        } // GetNamespaceCurrentLocation
Ejemplo n.º 2
0
 public override string ToString()
 {
     using (PathInfo.tracer.TraceMethod(this.path, new object[0]))
     {
         string path = this.path;
         string str  = this.drive == (PSDriveInfo)null || this.drive.Hidden ? LocationGlobber.GetProviderQualifiedPath(this.path, this.provider) : LocationGlobber.GetDriveQualifiedPath(this.path, this.drive);
         PathInfo.tracer.WriteLine("result = {0}", (object)str);
         return(str);
     }
 }
Ejemplo n.º 3
0
        public override string ToString()
        {
            string path = this.path;

            if ((this.drive == null) || this.drive.Hidden)
            {
                return(LocationGlobber.GetProviderQualifiedPath(path, this.provider));
            }
            path = LocationGlobber.GetDriveQualifiedPath(path, this.drive);
            return(path);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a string representing the MSH path.
        /// </summary>
        /// <returns>
        /// A string representing the MSH path.
        /// </returns>
        public override string ToString()
        {
            string result = _path;

            if (_drive is null ||
                _drive.Hidden)
            {
                // For hidden drives just return the current location
                result =
                    LocationGlobber.GetProviderQualifiedPath(
                        _path,
                        _provider);
            }
Ejemplo n.º 5
0
        private PSObject WrapOutputInPSObject(object item, string path)
        {
            if (item == null)
            {
                throw PSTraceSource.NewArgumentNullException("item");
            }
            PSObject obj2 = new PSObject(item);
            PSObject obj3 = item as PSObject;

            if (obj3 != null)
            {
                obj2.InternalTypeNames = new ConsolidatedString(obj3.InternalTypeNames);
            }
            string providerQualifiedPath = LocationGlobber.GetProviderQualifiedPath(path, this.ProviderInfo);

            obj2.AddOrSetProperty("PSPath", providerQualifiedPath);
            providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSPath", providerQualifiedPath });
            NavigationCmdletProvider provider = this as NavigationCmdletProvider;

            if ((provider != null) && (path != null))
            {
                string str2 = null;
                if (this.PSDriveInfo != null)
                {
                    str2 = provider.GetParentPath(path, this.PSDriveInfo.Root, this.Context);
                }
                else
                {
                    str2 = provider.GetParentPath(path, string.Empty, this.Context);
                }
                string str3 = string.Empty;
                if (!string.IsNullOrEmpty(str2))
                {
                    str3 = LocationGlobber.GetProviderQualifiedPath(str2, this.ProviderInfo);
                }
                obj2.AddOrSetProperty("PSParentPath", str3);
                providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSParentPath", str3 });
                string childName = provider.GetChildName(path, this.Context);
                obj2.AddOrSetProperty("PSChildName", childName);
                providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSChildName", childName });
            }
            if (this.PSDriveInfo != null)
            {
                obj2.AddOrSetProperty(this.PSDriveInfo.GetNotePropertyForProviderCmdlets("PSDrive"));
                providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSDrive", this.PSDriveInfo });
            }
            obj2.AddOrSetProperty(this.ProviderInfo.GetNotePropertyForProviderCmdlets("PSProvider"));
            providerBaseTracer.WriteLine("Attaching {0} = {1}", new object[] { "PSProvider", this.ProviderInfo });
            return(obj2);
        }
Ejemplo n.º 6
0
 private PSObject WrapOutputInPSObject(object item, string path)
 {
     using (CmdletProvider.providerBaseTracer.TraceMethod(path, new object[0]))
     {
         PSObject psObject1 = item != null ? new PSObject(item) : throw CmdletProvider.providerBaseTracer.NewArgumentNullException(nameof(item));
         if (item is PSObject psObject)
         {
             psObject1.TypeNames.Clear();
             foreach (string typeName in psObject.TypeNames)
             {
                 psObject1.TypeNames.Add(typeName);
             }
         }
         string         providerQualifiedPath = LocationGlobber.GetProviderQualifiedPath(path, this.ProviderInfo);
         PSNoteProperty psNoteProperty1       = new PSNoteProperty("PSPath", (object)providerQualifiedPath);
         psObject1.Properties.Add((PSPropertyInfo)psNoteProperty1, true);
         CmdletProvider.providerBaseTracer.WriteLine("Attaching {0} = {1}", (object)"PSPath", (object)providerQualifiedPath);
         if (this is NavigationCmdletProvider navigationCmdletProvider && path != null)
         {
             string path1 = !(this.PSDriveInfo != (PSDriveInfo)null) ? navigationCmdletProvider.GetParentPath(path, string.Empty, this.Context) : navigationCmdletProvider.GetParentPath(path, this.PSDriveInfo.Root, this.Context);
             string str   = string.Empty;
             if (!string.IsNullOrEmpty(path1))
             {
                 str = LocationGlobber.GetProviderQualifiedPath(path1, this.ProviderInfo);
             }
             PSNoteProperty psNoteProperty2 = new PSNoteProperty("PSParentPath", (object)str);
             psObject1.Properties.Add((PSPropertyInfo)psNoteProperty2, true);
             CmdletProvider.providerBaseTracer.WriteLine("Attaching {0} = {1}", (object)"PSParentPath", (object)str);
             string         childName       = navigationCmdletProvider.GetChildName(path, this.Context);
             PSNoteProperty psNoteProperty3 = new PSNoteProperty("PSChildName", (object)childName);
             psObject1.Properties.Add((PSPropertyInfo)psNoteProperty3, true);
             CmdletProvider.providerBaseTracer.WriteLine("Attaching {0} = {1}", (object)"PSChildName", (object)childName);
         }
         if (this.PSDriveInfo != (PSDriveInfo)null)
         {
             PSNoteProperty psNoteProperty2 = new PSNoteProperty("PSDrive", (object)this.PSDriveInfo);
             psObject1.Properties.Add((PSPropertyInfo)psNoteProperty2, true);
             CmdletProvider.providerBaseTracer.WriteLine("Attaching {0} = {1}", (object)"PSDrive", (object)this.PSDriveInfo);
         }
         PSNoteProperty psNoteProperty4 = new PSNoteProperty("PSProvider", (object)this.ProviderInfo);
         psObject1.Properties.Add((PSPropertyInfo)psNoteProperty4, true);
         CmdletProvider.providerBaseTracer.WriteLine("Attaching {0} = {1}", (object)"PSProvider", (object)this.ProviderInfo);
         return(psObject1);
     }
 }