コード例 #1
0
ファイル: Program.cs プロジェクト: mouhong/XHost
        static void Run(string commandLine)
        {
            var cmdLine = CommandLine.Parse(commandLine);
            var command = CommandFactory.Find(cmdLine.CommandName);

            if (command == null)
                throw new InvalidOperationException("Unknown command: " + cmdLine.CommandName);

            var context = new CommandExecutionContext(HostsFile.Load());

            command.Execute(cmdLine, context);
        }
コード例 #2
0
        public void can_remove_multi_entries_separated_by_comma_space()
        {
            var commandLine = CommandLine.Parse("-remove test1.com, test2.com");

            var context = new CommandExecutionContext(new HostsFile(new MockTextFileWriter()));
            context.Hosts["test1.com"] = "192.168.1.2";
            context.Hosts["test2.com"] = "192.168.1.3";
            context.Hosts["test3.com"] = "129.168.1.4";

            var command = new RemoveEntryCommand();
            command.Execute(commandLine, context);

            Assert.Equal(1, context.Hosts.AllEntries().Count);
            AssertEntry(context.Hosts.AllEntries()[0], "129.168.1.4", "test3.com");
        }
コード例 #3
0
ファイル: FireCommand.cs プロジェクト: mouhong/XHost
        public void Execute(CommandLine commandLine, CommandExecutionContext context)
        {
            var entries = new Dictionary<string, string>
            {
                { "157.56.8.150", "nuget.org" },
                { "216.121.112.229", "ayende.com" },
                { "74.125.91.113", "groups.google.com" }
            };

            foreach (var entry in entries)
            {
                context.Hosts.Set(entry.Key, entry.Value);
            }

            context.Hosts.Save();

            Console.WriteLine("OK");
        }