/// <summary>Delete the specified <see cref="IHostfileEntry"/>.</summary> /// <param name="hostfileEntry">A <see cref="IHostfileEntry"/>.</param> /// <returns>True if the specified <see cref="IHostfileEntry"/> was successfully deleted; otherwise false.</returns> public bool DeleteChild(IHostfileEntry hostfileEntry) { if (this.Childs != null && this.Childs.Count > 0) { this.Childs.Remove(hostfileEntry.UniqueIdentifier); } return(false); }
/// <summary>Add a child to the top of this <see cref="HostFile"/> instance.</summary> /// <param name="child">The child entry.</param> /// <returns>True if the specified <paramref name="child"/> was added to the list of childs; otherwise false.</returns> public bool AddChildToTop(IHostfileEntry child) { if (this.Childs != null) { this.Childs.AddChildToTop(child); return(true); } return(false); }
/// <summary>Add a child to this <see cref="HostFile"/> instance.</summary> /// <param name="child">The child entry.</param> /// <returns>True if the specified <paramref name="child"/> was added to the list of childs; otherwise false.</returns> public bool AddChild(IHostfileEntry child) { if (this.Childs != null) { this.Childs.Add(child); this.OnPropertyChanged("Childs"); return(true); } return(false); }
/// <summary>Initializes a new instance of the <see cref="HostfileEntry"/> class. </summary> /// <param name="type">The entry type (e.g. <see cref="HostfileEntryType.Host"/>).</param> /// <param name="parent">The parent.</param> /// <param name="name">The name of this <see cref="HostfileEntry"/> instance.</param> /// <param name="propertyChangedCallBack">This event is fired whenever a property of this object changes.</param> protected HostfileEntry(HostfileEntryType type, IHostfileEntry parent, string name, EventHandler propertyChangedCallBack) { if (type.Equals(HostfileEntryType.NotSet) || name == null) { throw new ArgumentException("name"); } this.EntryType = type; this.Name = name; this.Parent = parent; this.PropertyChangedCallBack = propertyChangedCallBack; }
/// <summary>Initializes a new instance of the <see cref="HostfileEntry"/> class. </summary> /// <param name="type">The entry type (e.g. <see cref="HostfileEntryType.Host"/>).</param> /// <param name="parent">The parent.</param> /// <param name="name">The name of this <see cref="HostfileEntry"/> instance.</param> /// <param name="description">A description text.</param> /// <param name="childs">The childs.</param> /// <param name="propertyChangedCallBack">This event is fired whenever a property of this object changes.</param> protected HostfileEntry(HostfileEntryType type, IHostfileEntry parent, string name, string description, HostfileEntryCollection childs, EventHandler propertyChangedCallBack) { if (type.Equals(HostfileEntryType.NotSet) || string.IsNullOrEmpty(name)) { throw new ArgumentException("name"); } this.EntryType = type; this.Name = name; this.Description = description; this.Parent = parent; this.Childs = childs; this.PropertyChangedCallBack = propertyChangedCallBack; }
/// <summary> /// Move the specified <paramref name="hostfileEntry"/> down. /// </summary> /// <param name="hostfileEntry">A <see cref="IHostfileEntry"/> object.</param> /// <returns>True if the specified <paramref name="hostfileEntry"/> was successfully moved down; otherwise false.</returns> public bool MoveDown(IHostfileEntry hostfileEntry) { if (hostfileEntry != null) { if (hostfileEntry.HasParent) { hostfileEntry.MoveDown(); } else { this.HostFileInstance.MoveDown(hostfileEntry.UniqueIdentifier); } } return(false); }
/// <summary>Remove the specified <paramref name="hostfileEntry"/>.</summary> /// <param name="hostfileEntry">A <see cref="IHostfileEntry"/> object.</param> /// <returns>True if the specified <paramref name="hostfileEntry"/> was successfully removed; otherwise false.</returns> public bool Remove(IHostfileEntry hostfileEntry) { if (hostfileEntry != null) { if (hostfileEntry.HasParent) { hostfileEntry.Delete(); } else { this.HostFileInstance.Remove(hostfileEntry.UniqueIdentifier); } } return(false); }
/// <summary>Delete the specified <see cref="IHostfileEntry"/>.</summary> /// <param name="hostfileEntry">A <see cref="IHostfileEntry"/>.</param> /// <returns>True if the specified <see cref="IHostfileEntry"/> was successfully deleted; otherwise false.</returns> public bool DeleteChild(IHostfileEntry hostfileEntry) { if (this.Childs != null && this.Childs.Count > 0) { this.Childs.Remove(hostfileEntry.UniqueIdentifier); } return false; }
/// <summary>Add a child to the top of this <see cref="HostFile"/> instance.</summary> /// <param name="child">The child entry.</param> /// <returns>True if the specified <paramref name="child"/> was added to the list of childs; otherwise false.</returns> public bool AddChildToTop(IHostfileEntry child) { if (this.Childs != null) { this.Childs.AddChildToTop(child); return true; } return false; }
/// <summary>Remove the specified <paramref name="hostfileEntry"/>.</summary> /// <param name="hostfileEntry">A <see cref="IHostfileEntry"/> object.</param> /// <returns>True if the specified <paramref name="hostfileEntry"/> was successfully removed; otherwise false.</returns> public bool Remove(IHostfileEntry hostfileEntry) { if (hostfileEntry != null) { if (hostfileEntry.HasParent) { hostfileEntry.Delete(); } else { this.HostFileInstance.Remove(hostfileEntry.UniqueIdentifier); } } return false; }
/// <summary> /// Move the specified <paramref name="hostfileEntry"/> up. /// </summary> /// <param name="hostfileEntry">A <see cref="IHostfileEntry"/> object.</param> /// <returns>True if the specified <paramref name="hostfileEntry"/> was successfully moved up; otherwise false.</returns> public bool MoveUp(IHostfileEntry hostfileEntry) { if (hostfileEntry != null) { if (hostfileEntry.HasParent) { hostfileEntry.MoveUp(); } else { this.HostFileInstance.MoveUp(hostfileEntry.UniqueIdentifier); } } return false; }
/// <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); }
/// <summary>Get a <see cref="HostFile"/> object for the host file with the specified <paramref name="hostFilePath"/>.</summary> /// <param name="hostFilePath">The host file path.</param> /// <returns>An initialized <see cref="HostFile"/> object.</returns> private HostFile GetHostfile(string hostFilePath) { List <string> lines = this.DataAccess.GetHostfileContent(hostFilePath); HostFile hostFile = HostFile.CreateHostFile(hostFilePath); HostfileLineByLineNavigator navigator = new HostfileLineByLineNavigator(lines); HostfileEntryCollection collection = new HostfileEntryCollection(hostFile.PropertyChangedCallBack); foreach (HostfileLine line in navigator) { if (line.IsMultiLineComment) { /* multi line comment */ if (collection.GetElementBy(HostfileEntryType.Comment, line.MultiLineCommentText) == null) { collection.Add(new Comment(line.MultiLineCommentText, hostFile.PropertyChangedCallBack)); } } else if (line.IsToggleModeOption) { string value = line.Values.FirstOrDefault(); if (value != null) { /* group toggle-mode */ if (value.Equals("group", StringComparison.OrdinalIgnoreCase)) { hostFile.ExclusiveGroupToggleModeIsEnabled = true; } /* host toggle-mode */ if (value.Equals("host", StringComparison.OrdinalIgnoreCase)) { hostFile.ExclusiveHostToggleModeIsEnabled = true; } } } else if (line.IsGlobalComment) { /* single comment */ collection.Add(new Comment(line.Values.FirstOrDefault(), hostFile.PropertyChangedCallBack)); } else if (line.IsGroupStart) { /* host group */ HostGroup group = new HostGroup(line.GroupName, line.DescriptionText, hostFile.PropertyChangedCallBack); collection.Add(group); } else if (line.IsHost) { /* host */ IHostfileEntry parentItem = line.IsMemberOfHostGroup ? collection.GetElementBy( HostfileEntryType.HostGroup, line.GroupName) : null; HostGroup parentGroup = parentItem != null ? parentItem as HostGroup : null; Host host = new Host(parentGroup, line.Values.FirstOrDefault(), line.DescriptionText, hostFile.PropertyChangedCallBack) { IsActive = line.IsActive }; /* domains */ string domainString = line.Values.LastOrDefault(); if (string.IsNullOrEmpty(domainString) == false) { List <string> domainNames = domainString.Split(' ').Select(domain => domain.Trim()).ToList(); foreach (string domainName in domainNames) { host.Childs.Add(new Domain(host, domainName, hostFile.PropertyChangedCallBack)); } } if (parentGroup != null) { parentGroup.Childs.Add(host); } else { collection.Add(host); } } } /* attach entry collection to host file */ hostFile.Childs = collection; return(hostFile); }
/// <summary>Initializes a new instance of the <see cref="ActivatableHostfileEntry"/> class.</summary> /// <param name="entryType">The entry type.</param> /// <param name="parent">The parent <see cref="IHostfileEntry"/>.</param> /// <param name="name">The name of the enntry.</param> /// <param name="description">The description text.</param> /// <param name="childs">The childs.</param> /// <param name="propertyChangedCallBack">This event is fired whenever a property of this object changes.</param> protected ActivatableHostfileEntry(HostfileEntryType entryType, IHostfileEntry parent, string name, string description, HostfileEntryCollection childs, EventHandler propertyChangedCallBack) : base(entryType, parent, name, description, childs, propertyChangedCallBack) { this.IsActivatable = true; }
/// <summary>Add a child to the top of this <see cref="HostFile"/> instance.</summary> /// <param name="child">The child entry.</param> /// <returns>True if the specified <paramref name="child"/> was added to the list of childs; otherwise false.</returns> public bool AddChildToTop(IHostfileEntry child) { if (this.Childs != null) { this.Childs.AddChildToTop(child); this.OnPropertyChanged("Childs"); return true; } return false; }