Exemple #1
0
        private bool UpdateHosts(IIntegrationResult result, string host, string ip)
        {
            using (var fs = GetFileStream(result))
            {
                if (fs == null)
                {
                    return(false);
                }
                HostsCollection hosts;
                using (var sr = new StreamReader(fs, Encoding.UTF8))
                {
                    var text = sr.ReadToEnd();
                    hosts = new HostsCollection(text);

                    if (hosts[host] == ip)
                    {
                        return(true);
                    }
                    else
                    {
                        hosts[host] = ip;

                        string hostsContent = hosts.ToString();
                        var    contentBytes = Encoding.UTF8.GetBytes(hostsContent);
                        fs.Seek(0, SeekOrigin.Begin);
                        fs.SetLength(contentBytes.Length);
                        fs.Write(contentBytes, 0, contentBytes.Length);
                    }
                }
            }
            return(true);
        }
        public HtmlActionResult <HostsCollection> HostView()
        {
            IStateQuery     syslogState = base.GetSyslogState();
            List <Host>     hosts       = syslogState.GetHosts();
            HostsCollection coll        = new HostsCollection()
            {
                Hosts = hosts
            };

            return(new HtmlActionResult <HostsCollection>(Path.Combine(base.GetViewDirectory(), "Hosts.cshtml"), coll));
        }
        static void Main(String[] args)
        {
            String path = Directory.GetCurrentDirectory();

            if (args.Length > 0)
            {
                path = args[0];
            }

            String configPath = Path.Combine(path, "Tests.Runner.config");

            if (!File.Exists(configPath))
            {
                MessageBox.Show($"Config file '{configPath}' not found", "Usage", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            ExeConfigurationFileMap configMap = new ExeConfigurationFileMap()
            {
                ExeConfigFilename = configPath
            };

            HostsCollection _hosts = null;

            try
            {
                var config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
                if ((config.Sections["hosts"] is HostsSection hs))
                {
                    _hosts = hs.hosts;
                }
                else
                {
                    MessageBox.Show("Invalid configuration file (configPath)");
                    return;
                }
            }
Exemple #4
0
 public MainForm(HostsCollection hosts, String appRoot)
 {
     InitializeComponent();
     _hosts   = hosts;
     _appRoot = appRoot;
 }
 public ParsersImportControl()
 {
     Hosts = new HostsCollection();
     Urls  = new UrlCollection();
     InitializeComponent();
 }