Exemple #1
0
        public static PoolList LoadFromFile(string filename)
        {
            PoolList pl = new PoolList();

            pl.pools = new Dictionary <string, PoolInfo>();

            string json = File.ReadAllText(filename);

            JsonData data = json.FromJson <JsonData>();

            foreach (string pool in data.Keys)
            {
                JsonData jinfo = data[pool] as JsonData;
                PoolInfo pi    = new PoolInfo();

                if (!(jinfo.ContainsKey("url") && jinfo.ContainsKey("port") &&
                      jinfo.ContainsKey("emptypassword") && jinfo.ContainsKey("algorithm")))
                {
                    throw new Exception("Invalid entry.");
                }

                pi.Url           = jinfo["url"].GetString();
                pi.EmptyPassword = jinfo["emptypassword"].GetString();

                pi.DefaultAlgorithm = jinfo["algorithm"].GetString();
                pi.Port             = int.Parse(jinfo["port"].GetString());

                if (!AlgorithmHelper.ValidAlgorithm(pi.DefaultAlgorithm))
                {
                    throw new Exception("Invalid algorithm found in pools.json: " + pi.DefaultAlgorithm);
                }

                pl.pools.Add(pool, pi);
            }

            int counter = 0;

            pl.JsonPools = "{\"identifier\":\"" + "poolinfo";

            foreach (string pool in pl.pools.Keys)
            {
                counter++;
                pl.JsonPools += "\",\"pool" + counter.ToString() + "\":\"" + pool;
            }

            pl.JsonPools += "\"}\n";

            return(pl);
        }
 public bool TryGetPool(string pool, out PoolInfo info)
 {
     return(pools.TryGetValue(pool, out info));
 }