Exemple #1
0
 public void RemovePropertyValue(PSObject psobject, bool raw)
 {
     InvokeOnProperty(psobject, raw,
                      delegate(DirectoryEntryProperty dep, object value)
     {
         if (dep.CanRemove)
         {
             dep.RemoveValue(ConvertToPropertyType(dep, value));
         }
         else
         {
             CurrentProvider.WriteError(PscxErrorRecord.CannotRemoveItemProperty(dep.Name));
         }
     }
                      );
 }
Exemple #2
0
        protected override PSDriveInfo NewDrive(PSDriveInfo drive)
        {
            using (EnterContext())
            {
                if (drive is DirectoryServiceDriveInfo)
                {
                    return(drive);
                }

                string rootPath = drive.Root;

                if (string.IsNullOrEmpty(rootPath))
                {
                    WriteError(PscxErrorRecord.ArgumentNullOrEmpty("root"));
                    return(null);
                }

                return(CreateDrive(drive, ParsePSPathRoot(rootPath)));
            }
        }
Exemple #3
0
        private void OnGetHostEntryCompleted(IAsyncResult ar)
        {
            IPHostEntry     entry = null;
            SocketException error = null;

            try
            {
                try
                {
                    entry = Dns.EndGetHostEntry(ar);
                }
                catch (SocketException exc)
                {
                    error = exc;
                }

                if (entry != null)
                {
                    Send(entry);
                }
                else
                {
                    String    str     = ar.AsyncState as String;
                    IPAddress address = ar.AsyncState as IPAddress;

                    if ((address != null) || ((str != null) && IPAddress.TryParse(str, out address)))
                    {
                        Send(address, false);
                    }
                    else
                    {
                        errors.Enqueue(PscxErrorRecord.GetHostEntryError(ar.AsyncState.ToString(), error));
                    }
                }
            }
            finally
            {
                DecrementItemCount();
            }
        }
Exemple #4
0
        public void SetProperty(PSObject psobject, bool raw)
        {
            InvokeOnProperty(psobject, raw,
                             delegate(DirectoryEntryProperty dep, object value)
            {
                value = ConvertToPropertyType(dep, value);

                if (dep.CanSet)
                {
                    dep.SetValue(value);
                }
                else if (dep.CanAdd)
                {
                    dep.AddValue(value);
                }
                else
                {
                    CurrentProvider.WriteError(PscxErrorRecord.CannotSetItemProperty(dep.Name));
                }
            }
                             );
        }
Exemple #5
0
 internal override void Send(string hostOrAddress, bool tryResolve)
 {
     if (tryResolve)
     {
         IncrementItemCount();
         Dns.BeginGetHostEntry(hostOrAddress, OnGetHostEntryCompleted, hostOrAddress);
     }
     else
     {
         IPAddress address;
         if (IPAddress.TryParse(hostOrAddress, out address))
         {
             Send(address, false);
         }
         else
         {
             IncrementItemCount();
             errors.Enqueue(PscxErrorRecord.InvalidIPAddress(hostOrAddress));
             DecrementItemCount();
         }
     }
 }
Exemple #6
0
        protected override void RenameItem(string path, string newName)
        {
            using (EnterContext(path))
            {
                if (string.IsNullOrEmpty(ParsePSPathChild(path)))
                {
                    WriteError(PscxErrorRecord.CannotRenameRoot());
                    return;
                }

                if (ShouldProcess(path))
                {
                    using (DirectoryEntry entry = GetEntryFromPSPath(path))
                    {
                        string dn     = DirectoryUtils.GetDistinguishedName(entry);
                        string prefix = GetNamePrefix(dn);

                        entry.Rename(prefix + newName);
                        entry.CommitChanges();
                    }
                }
            }
        }
Exemple #7
0
 void IPscxErrorHandler.WriteGetHostEntryError(string host, Exception exc)
 {
     WriteError(PscxErrorRecord.GetHostEntryError(host, exc));
 }
Exemple #8
0
 void IPscxErrorHandler.WriteInvalidIPAddressError(string invalidIPAddress)
 {
     WriteError(PscxErrorRecord.InvalidIPAddress(invalidIPAddress));
 }