Example #1
0
        /// <summary>
        /// Wraps the item in a PSObject and attaches some notes to the
        /// object that deal with path information.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private PSObject WrapOutputInPSObject(
            FileInfo item,
            string path)
        {
            PSObject result = new PSObject(item);

            // Now get the parent path and child name
            if (path != null)
            {
                // Get the parent path
                string parentPath = Directory.GetParent(path).FullName;
                result.AddOrSetProperty("PSParentPath", parentPath);

                // Get the child name
                string childName = item.Name;
                result.AddOrSetProperty("PSChildName", childName);
            }
            return result;
        }
        public void TestGetProperty()
        {
			FileSystemProvider fileSystemProvider = new FileSystemProvider();
			ProviderInfo providerInfoToSet = GetProvider();
			fileSystemProvider.SetProviderInformation(providerInfoToSet);
			fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());
			PSObject pso=new PSObject();
			pso.AddOrSetProperty("IsReadOnly",false);
			fileSystemProvider.SetProperty(testPath, pso);
			fileSystemProvider.GetProperty(testPath, new Collection<string>(){"IsReadOnly"});
			FileInfo fileSystemObject1 = new FileInfo(testPath);
			PSObject psobject1=PSObject.AsPSObject(fileSystemObject1);
			foreach(PSPropertyInfo property in psobject1.Properties)
			{
				if(property.Name == "IsReadOnly")
				{
					Assert.Equal(property.Value,false);
				}
			}
        }
Example #3
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;
 }