/// <summary>Toggle the active state of the specified <paramref name="activatableHostfileEntry"/>.</summary> /// <param name="activatableHostfileEntry">A <see cref="IHostfileEntry"/> object.</param> /// <returns>True if the active state of the specified <see cref="IHostfileEntry"/> was successfully toggled; otherwise false.</returns> public bool ToggleActiveState(ActivatableHostfileEntry activatableHostfileEntry) { /* abort if parameter is null */ if (activatableHostfileEntry == null) { return(false); } /* toggle host status */ if (activatableHostfileEntry.HasParent) { activatableHostfileEntry.ToggleActiveState(); return(true); } /* toggle group status */ return(this.HostFileInstance.ToggleActiveState(activatableHostfileEntry.UniqueIdentifier)); }
/// <summary>Toggle the active state of the <see cref="IHostfileEntry"/> with the specified <paramref name="uniqueIdentifier"/>.</summary> /// <param name="uniqueIdentifier">The unique identifier of an <see cref="IHostfileEntry"/> object.</param> /// <returns>True if the active state of the <see cref="IHostfileEntry"/> with the specified <paramref name="uniqueIdentifier"/> was successfully toggled; otherwise false.</returns> public bool ToggleActiveState(Guid uniqueIdentifier) { /* abort if there are no childs in this host file */ if (this.Childs == null || this.Childs.Count == 0) { return(false); } /* get the host file entry with the specified unique identifier */ IHostfileEntry hostFileEntry = this.Childs.GetElementBy(uniqueIdentifier); if (hostFileEntry == null || hostFileEntry.IsActivatable == false) { /* abort if the host file entry was not found or is not activatable */ return(false); } /* cast the current host file entry to an activatable hostfile entry */ ActivatableHostfileEntry activatableHostfileEntry = hostFileEntry as ActivatableHostfileEntry; if (activatableHostfileEntry == null) { /* abort if the host file entry is not an ActivatableHostfileEntry */ return(false); } /* variables */ bool isGroup = activatableHostfileEntry.EntryType.Equals(HostfileEntryType.HostGroup); bool isHost = activatableHostfileEntry.EntryType.Equals(HostfileEntryType.Host); /* new states */ bool previousState = activatableHostfileEntry.IsActive; bool newState = !previousState; /* no exclusive toggle mode: groups */ if (isGroup && this.ExclusiveGroupToggleModeIsEnabled == false) { activatableHostfileEntry.IsActive = newState; return(true); } /* no exclusive toggle mode: hosts */ if (isHost && this.ExclusiveHostToggleModeIsEnabled == false) { activatableHostfileEntry.IsActive = newState; return(true); } /* just deactivate the current entry */ if (newState == false && this.ExclusiveGroupToggleModeIsEnabled == false && this.ExclusiveHostToggleModeIsEnabled == false) { activatableHostfileEntry.IsActive = false; return(true); } /* deactivate the current entry and all other groups */ if (newState == false && isGroup && this.ExclusiveGroupToggleModeIsEnabled) { foreach (HostGroup entry in this.Childs.Groups) { entry.IsActive = false; } return(true); } /* deactivate the current entry and all other hosts */ if (newState == false && isHost && this.ExclusiveHostToggleModeIsEnabled) { foreach (Host entry in this.Childs.Hosts) { entry.IsActive = false; } return(true); } /* toggle states: groups only */ if (isGroup && this.ExclusiveGroupToggleModeIsEnabled) { foreach (HostGroup entry in this.Childs.Groups) { entry.IsActive = entry.UniqueIdentifier.Equals(uniqueIdentifier) ? true : false; } } /* toggle states: hosts only */ if (isHost && this.ExclusiveHostToggleModeIsEnabled) { foreach (Host entry in this.Childs.Hosts) { entry.IsActive = entry.UniqueIdentifier.Equals(uniqueIdentifier) ? true : false; } } return(true); }