Exemplo n.º 1
0
        public void ProcessResponse(WebResponse response)
        {
            StreamReader sr = new StreamReader(response.GetResponseStream());

            if (onMessage != null && severity >= 7)
                onMessage(this,"[{0}] Reading response...",DateTime.Now);

            string data = sr.ReadToEnd ();

            response.Close ();

            Log.Write("Response: ");
            Log.WriteLine (data.ToString()+"\n");

            if (onMessage != null && severity >= 7)
                onMessage(this,"[{0}] Processing response...",DateTime.Now);

            using (JsonTextReader reader = new JsonTextReader(new StringReader(data)))
            {
            string text = "";

                Stack<string> level = new Stack<string>();
                //Stack<string> token = new Stack<string>();

                while(reader.Read())
                {
                    switch (reader.TokenClass.Name)
                    {
                        case "Member":
                            Log.Write("[{0}] {1} : ",level.Count,text = reader.Text);
                            break;
                        case "Array":
                        case "Object":
                            if (text == "")
                                Log.WriteLine("[{0}] {1} ()",level.Count,reader.TokenClass);
                            else
                                Log.WriteLine("({0})",reader.TokenClass);
                            level.Push(text);
              text = "";
                            break;
                        case "EndArray":
                        case "EndObject":
                            Log.WriteLine("[{0}] {1} ({2})",level.Count-1,reader.TokenClass,level.Pop());
                            break;
                        case "BOF":
                        case "EOF":
                            break;
                        default :
                            Log.WriteLine("{0} ({1})",reader.Text,reader.TokenClass);
                            break;
                    }
                }

                if (onMessage != null && severity >= 7)
                    onMessage(this,"[{0}] Processing complete!\n",DateTime.Now);

                if (onMessage != null && severity >= 6)
                    onMessage(this,"\n[{0}] {1} RPC call(s) remaining today",
                              DateTime.Now, cache.rpcLimit - cache.rpcCount);

                Log.WriteLine("-------------------------");
            Log.Flush();  // if we crash when we Deserialize, we still get the log!
            }

              JavaScriptSerializer js = new JavaScriptSerializer();

              r = js.Deserialize<Response>(data);

              if (r.error != null) return;

              // Cache what we need from status, if no errors
              cache.time = r.result.status.server.time;
              cache.rpcCount = r.result.status.empire.rpc_count;
              cache.rpcLimit = r.result.status.server.rpc_limit;
              cache.home_planet_id = r.result.status.empire.home_planet_id;

              // Update or add planet names to session cache
              foreach (KeyValuePair<string,string> p in r.result.status.empire.planets)
              {
            if (myColony.ContainsKey(p.Key)) {
              myColony[p.Key].name = p.Value;
            } else {
              Colony colony = new Colony(p.Key,p.Value);
              myColony.Add(p.Key,colony);
              cache.colony.Add(colony);
            }
              }
        }
Exemplo n.º 2
0
 public void Add(Colony c)
 {
     colony.Add(c);
 }
Exemplo n.º 3
0
 public Colony(Colony c)
 {
 }