Exemplo n.º 1
0
        private static void GenrateFreeServersConfig()
        {
            try
            {
                var rootObject = new RootObject()
                {
                    configs = new List<ServerConfig>(),
                    index = -1,
                    strategy = "com.shadowsocks.strategy.balancing",
                    global = false,
                    enabled = true,
                    shareOverLan = false,
                    isDefault = false,
                    localPort = 1080,
                    pacUrl = null,
                    useOnlinePac = false,
                    availabilityStatistics = false
                };

                var serverList = rootObject.configs;

                try
                {
                    GetIshadowsocksServers(serverList);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                try
                {
                    GetFreeShadowsocksServers(serverList);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("Serialize the config to file.");
                var path = "server.txt";
                WriteServersToFile(rootObject, path);

                Console.WriteLine("Update the gui-config.json");

                File.Delete(configfile);

                File.Move(path, configfile);

                Console.WriteLine("Successful! Enjoy yourself!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Sorry,Run Error:{0}", ex.Message);
            }
        }
Exemplo n.º 2
0
        private static void WriteServersToFile(RootObject rootObject, string path)
        {
            //var str = JsonHelper.FormatJson(JsonHelper.Serialize(rootObject));
            var str = JsonConvert.SerializeObject(rootObject, Formatting.Indented);

            using (var file = new StreamWriter(path, false, Encoding.UTF8))
            {
                file.Write(str);
            }
        }