Esempio n. 1
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);
        }
Esempio n. 2
0
        private PSObject GetItemAsPSObject(object item, Path path)
        {
            if (item == null)
            {
                throw new Exception("Item can't be null");
            }

            PSObject psObject = PSObject.AsPSObject(item);

            PSObject obj3 = item as PSObject;

            if (obj3 != null)
            {
                psObject.TypeNames.Clear();
                foreach (string str in obj3.TypeNames)
                {
                    psObject.TypeNames.Add(str);
                }
            }

            // Add full path as a property
            string providerFullPath = PathIntrinsics.GetFullProviderPath(ProviderInfo, path);

            psObject.Properties.Add(new PSNoteProperty("PSPath", providerFullPath));

            NavigationCmdletProvider provider = this as NavigationCmdletProvider;

            if ((provider != null) && (path != null))
            {
                string parentPath = null;
                if (PSDriveInfo == null)
                {
                    parentPath = provider.GetParentPath(path, string.Empty, ProviderRuntime);
                }
                else
                {
                    parentPath = provider.GetParentPath(path, PSDriveInfo.Root, ProviderRuntime);
                }

                if (!string.IsNullOrEmpty(parentPath))
                {
                    parentPath = PathIntrinsics.GetFullProviderPath(ProviderInfo, parentPath);
                }
                else
                {
                    parentPath = string.Empty;
                }
                psObject.Properties.Add(new PSNoteProperty("PSParentPath", parentPath));

                string childName = provider.GetChildName(path, ProviderRuntime);
                psObject.Properties.Add(new PSNoteProperty("PSChildName", childName));
            }

            if (PSDriveInfo != null)
            {
                psObject.Properties.Add(new PSNoteProperty("PSDrive", PSDriveInfo));
            }

            psObject.Properties.Add(new PSNoteProperty("PSProvider", ProviderInfo));
            return(psObject);
        }