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)); } } ); }
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))); } }
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(); } }
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)); } } ); }
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(); } } }
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(); } } } }
void IPscxErrorHandler.WriteGetHostEntryError(string host, Exception exc) { WriteError(PscxErrorRecord.GetHostEntryError(host, exc)); }
void IPscxErrorHandler.WriteInvalidIPAddressError(string invalidIPAddress) { WriteError(PscxErrorRecord.InvalidIPAddress(invalidIPAddress)); }