예제 #1
0
        public bool Read()
        {
            HostEntries.Clear();

            try
            {
                var hostFile = File.ReadAllLines(HostFilePath);
                var hostHead = HostHead.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var line in hostFile)
                {
                    if (hostHead.Contains(line) || string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    var entry = new HostEntry(line);
                    HostEntries.Add(entry);
                }

                return(HostEntries.Count > 0);
            }
            catch (Exception)
            {
                //TODO
                throw;
            }
        }
예제 #2
0
        public void AddNewItem()
        {
            var newEntry = new NewEntry();

            newEntry.ShowDialog();

            if (newEntry.DialogResult != DialogResult.OK)
            {
                return;
            }

            var newHost = new HostEntry()
            {
                UrlAddress = newEntry.UrlAddress,
                IpAddress  = newEntry.IpAddress,
                Enabled    = newEntry.IsEnabled
            };

            objectListView1.AddObject(newHost);

            Hosts.HostEntries = objectListView1.Objects.Cast <HostEntry>().ToList();
        }