Пример #1
0
        /// <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;
        }
Пример #2
0
 /// <summary>Create a new <see cref="HostFile"/> object.</summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="entries">The entries.</param>
 /// <returns>An initialized <see cref="HostFile"/> object instance.</returns>
 public static HostFile CreateHostFile(string filePath, HostfileEntryCollection entries)
 {
     return new HostFile { FilePath = filePath, Childs = entries };
 }
Пример #3
0
 /// <summary>Initializes a new instance of the <see cref="HostGroup"/> class.</summary>
 /// <param name="groupName">The group name.</param>
 /// <param name="groupDescription">The group description.</param>
 /// <param name="childs">The childs.</param>
 /// <param name="propertyChangedCallBack">This event is fired whenever a property of this object changes.</param>
 public HostGroup(string groupName, string groupDescription, HostfileEntryCollection childs, EventHandler propertyChangedCallBack)
     : base(HostfileEntryType.HostGroup, null, groupName, groupDescription, childs, propertyChangedCallBack)
 {
 }
Пример #4
0
        /// <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);
        }
Пример #5
0
 /// <summary>Initializes a new instance of the <see cref="HostGroup"/> class.</summary>
 /// <param name="groupName">The group name.</param>
 /// <param name="groupDescription">The group description.</param>
 /// <param name="childs">The childs.</param>
 /// <param name="propertyChangedCallBack">This event is fired whenever a property of this object changes.</param>
 public HostGroup(string groupName, string groupDescription, HostfileEntryCollection childs, EventHandler propertyChangedCallBack)
     : base(HostfileEntryType.HostGroup, null, groupName, groupDescription, childs, propertyChangedCallBack)
 {
 }
        /// <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;
        }
Пример #7
0
 /// <summary>Create a new <see cref="HostFile"/> object.</summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="entries">The entries.</param>
 /// <returns>An initialized <see cref="HostFile"/> object instance.</returns>
 public static HostFile CreateHostFile(string filePath, HostfileEntryCollection entries)
 {
     return(new HostFile {
         FilePath = filePath, Childs = entries
     });
 }
 /// <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;
 }