示例#1
0
 protected override void GetItem(string path)
 {
     using (EnterContext(path))
     {
         DirectoryEntryInfo info = GetEntryInfoFromPSPath(path);
         WriteEntryInfo(info);
     }
 }
示例#2
0
        public bool Equals(DirectoryEntryInfo other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Entry.Path.Equals(other.Entry.Path, StringComparison.OrdinalIgnoreCase) &&
                   Entry.Username.Equals(other.Entry.Username, StringComparison.OrdinalIgnoreCase));
        }
示例#3
0
        public bool Equals(DirectoryEntryInfo other)
        {
            if (other == null)
            {
                return false;
            }

            return Entry.Path.Equals(other.Entry.Path, StringComparison.OrdinalIgnoreCase) &&
                   Entry.Username.Equals(other.Entry.Username, StringComparison.OrdinalIgnoreCase);
        }
示例#4
0
 protected override bool IsItemContainer(string path)
 {
     using (EnterContext(path))
     {
         using (DirectoryEntryInfo info = GetEntryInfoFromPSPath(path))
         {
             return(info.IsContainer);
         }
     }
 }
示例#5
0
 public void GetProperty(string path, Collection <string> providerSpecificPickList)
 {
     using (EnterContext(path))
     {
         using (DirectoryEntryInfo info = GetEntryInfoFromPSPath(path))
         {
             PSObject properties = info.GetProperty(providerSpecificPickList, ParamRawSet);
             WritePropertyObject(properties, path);
         }
     }
 }
示例#6
0
        private void GetPathItems(DirectoryEntryInfo parent, bool recurse, bool nameOnly, ReturnContainers returnContainers)
        {
            foreach (DirectoryEntryInfo child in parent.GetChildren())
            {
                WriteEntryInfo(child, nameOnly);

                if (recurse)
                {
                    GetPathItems(child, recurse, nameOnly, returnContainers);
                }
            }
        }
示例#7
0
        protected override void NewItem(string path, string itemTypeName, object newItemValue)
        {
            using (EnterContext(path))
            {
                string parentPath, childName;
                SplitPath(path, out parentPath, out childName);

                using (DirectoryEntry parent = GetEntryFromPSPath(parentPath))
                {
                    DirectoryEntry child = DirectoryEntryType.NewItem(parent, childName, itemTypeName);
                    child.CommitChanges();

                    DirectoryEntryInfo info = GetEntryInfo(child);
                    WriteEntryInfo(info);
                }
            }
        }
示例#8
0
        private void GetPathItems(string path, bool recurse, bool nameOnly, ReturnContainers returnContainers)
        {
            using (EnterContext(path))
            {
                DirectoryEntryInfo parent = GetEntryInfoFromPSPath(path);

                if (parent.IsContainer)
                {
                    using (parent)
                    {
                        GetPathItems(parent, recurse, nameOnly, returnContainers);
                    }
                }
                else
                {
                    WriteEntryInfo(parent, nameOnly);
                }
            }
        }
示例#9
0
 public void SetProperty(string path, PSObject value)
 {
     using (EnterContext(path))
     {
         using (DirectoryEntryInfo info = GetEntryInfoFromPSPath(path))
         {
             if (ParamAddSet)
             {
                 info.AddPropertyValue(value, ParamRawSet);
             }
             else if (ParamRemoveSet)
             {
                 info.RemovePropertyValue(value, ParamRawSet);
             }
             else
             {
                 info.SetProperty(value, ParamRawSet);
             }
         }
     }
 }
示例#10
0
        private void WriteEntryInfo(DirectoryEntryInfo info, bool nameOnly)
        {
            try
            {
                object value = info;

                if (nameOnly)
                {
                    value = info.Name;
                }

                WriteItemObject(value, info.FullName, info.IsContainer);
            }
            finally
            {
                if (nameOnly)
                {
                    info.Dispose();
                }
            }
        }
示例#11
0
        private void AddItemProperty(PSObject retval, DirectoryEntryProperty dep)
        {
            if (dep.CanRead)
            {
                string name  = dep.Name;
                object value = dep.GetValue();

                if (dep is IDistinguishedNameProperty)
                {
                    String      stringValue = value as String;
                    ICollection listValue   = value as ICollection;

                    if (listValue != null)
                    {
                        List <DirectoryEntryInfo> infoList = new List <DirectoryEntryInfo>();

                        foreach (string dn in listValue)
                        {
                            DirectoryEntry     entry = CurrentProvider.GetEntry(dn);
                            DirectoryEntryInfo info  = CurrentProvider.GetEntryInfo(entry);

                            infoList.Add(info);
                        }

                        value = infoList;
                    }
                    else if (stringValue != null)
                    {
                        DirectoryEntry     entry = CurrentProvider.GetEntry(stringValue);
                        DirectoryEntryInfo info  = CurrentProvider.GetEntryInfo(entry);

                        value = info;
                    }
                }

                retval.Members.Add(new PSNoteProperty(name, value));
            }
        }
示例#12
0
        private string[] GetDistinguishedNames(object value)
        {
            DirectoryEntryInfo info = value as DirectoryEntryInfo;

            if (info != null)
            {
                return(new string[] { info.DistinguishedName });
            }

            IEnumerable paths = (value as IEnumerable);

            if (value is string)
            {
                paths = new object[] { value };
            }

            if (paths != null)
            {
                return(GetDistinguishedNames(paths));
            }

            return(new string[0]);
        }
示例#13
0
        private string[] GetDistinguishedNames(IEnumerable paths)
        {
            List <PSObject> items = new List <PSObject>();

            foreach (string p in paths)
            {
                items.AddRange(CurrentProvider.InvokeProvider.Item.Get(p));
            }

            List <String> names = new List <string>(items.Count);

            foreach (PSObject itm in items)
            {
                using (DirectoryEntryInfo info = (itm.BaseObject as DirectoryEntryInfo))
                {
                    if (info != null)
                    {
                        names.Add(info.DistinguishedName);
                    }
                }
            }

            return(names.ToArray());
        }
示例#14
0
        private void GetPathItems(DirectoryEntryInfo parent, bool recurse, bool nameOnly, ReturnContainers returnContainers)
        {
            foreach (DirectoryEntryInfo child in parent.GetChildren())
            {
                WriteEntryInfo(child, nameOnly);

                if (recurse)
                {
                    GetPathItems(child, recurse, nameOnly, returnContainers);
                }
            }
        }
示例#15
0
 private void WriteEntryInfo(DirectoryEntryInfo info)
 {
     WriteEntryInfo(info, false);
 }
示例#16
0
 private void WriteEntryInfo(DirectoryEntryInfo info)
 {
     WriteEntryInfo(info, false);
 }
示例#17
0
        private void WriteEntryInfo(DirectoryEntryInfo info, bool nameOnly)
        {
            try
            {
                object value = info;

                if (nameOnly)
                {
                    value = info.Name;
                }

                WriteItemObject(value, info.FullName, info.IsContainer);
            }
            finally
            {
                if (nameOnly)
                {
                    info.Dispose();
                }
            }
        }
示例#18
0
        protected DirectoryEntryInfo[] NewUsers(int count)
        {
            DirectoryEntryInfo[] users = new DirectoryEntryInfo[count];

            for (int i = 0; i < count; i++)
            {
                users[i] = GetItem<DirectoryEntryInfo>(NewUser());
            }

            return users;
        }