Exemplo n.º 1
0
        public Result(Hashtable ht, string ourName)
        {
            if (ht.ContainsKey(ourName))
            {
                Hashtable data = ht[ourName] as Hashtable;
                date = new YDate(data["date"] as Hashtable);
                switch (data["first"] as string)
                {
                case "first":
                    first = First.FIRST;
                    break;

                case "was_leader":
                    first = First.WAS_LEADER;
                    break;

                case "unknown":
                    first = First.UNKNOWN;
                    break;

                case "not_first":
                    first = First.NOT_FIRST;
                    break;

                default:
                    throw new Exception(String.Format("Bad 'first' value {0}", data["first"] as string));
                }
            }
            else
            {
                date  = null;
                first = First.UNKNOWN;
            }
        }
Exemplo n.º 2
0
 public int CompareTo(YDate other)
 {
     if (other.year != year)
     {
         return(year.CompareTo(other.year));
     }
     return(day.CompareTo(other.day));
 }
Exemplo n.º 3
0
 public Game(Hashtable ht)
 {
     mindate = new YDate(ht["mindate"] as Hashtable);
     players = new Dictionary <string, Player>();
     foreach (DictionaryEntry de in ht["players"] as Hashtable)
     {
         players.Add(de.Key.ToString(), new Player(de.Value as Hashtable));
     }
 }
Exemplo n.º 4
0
 public GameListEntry(Hashtable ht)
 {
     mindate = new YDate(ht["mindate"] as Hashtable);
     players = new List <string>();
     foreach (object obj in ht["players"] as ArrayList)
     {
         players.Add(obj as string);
     }
 }
Exemplo n.º 5
0
 public Game(Dictionary <string, object> ht)
 {
     mindate = new YDate(ht["mindate"] as Dictionary <string, object>);
     players = new Dictionary <string, Player>();
     foreach (KeyValuePair <string, object> de in ht["players"] as Dictionary <string, object> )
     {
         players.Add(de.Key.ToString(), new Player(de.Value as Dictionary <string, object>));
     }
 }
Exemplo n.º 6
0
 public GameListEntry(Dictionary <string, object> ht)
 {
     mindate = new YDate(ht["mindate"] as Dictionary <string, object>);
     players = new List <string>();
     foreach (object obj in ht["players"] as List <object> )
     {
         players.Add(obj as string);
     }
 }
Exemplo n.º 7
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            YDate other = obj as YDate;

            if (other == null)
            {
                throw new ArgumentException("Object is not a YDate");
            }
            return(CompareTo(other));
        }
Exemplo n.º 8
0
 public void Load(ConfigNode node)
 {
     if (node == null)
     {
         Reset();
         return;
     }
     if (node.HasValue("year") && node.HasValue("day"))
     {
         completed = new YDate(node);
     }
     if (node.HasValue("reported"))
     {
         reported = bool.Parse(node.GetValue("reported"));
     }
     if (node.HasValue("result"))
     {
         result = (Result.First) int.Parse(node.GetValue("result"));
     }
 }
Exemplo n.º 9
0
        public CancelDelegate SyncTail(ResultCallback cb)
        {
            WebClient client = new WebClient();

            client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => {
                bool result = false;
                try {
                    if (e.Cancelled)
                    {
                        Logging.Log("Sync cancelled");
                    }
                    else if (e.Error != null)
                    {
                        Logging.LogException(e.Error);
                    }
                    else
                    {
                        string json = e.Result;
                        Logging.Log("Sync: " + json);
                        Hashtable ht = MiniJSON.jsonDecode(json) as Hashtable;
                        checkError(ht);
                        game   = new Game(ht);
                        result = true;
                    }
                } catch (Exception exc) {
                    /* Job failed, but we still have to exit job state */
                    Logging.LogException(exc);
                }
                cb.Invoke(result);
            };
            YDate date = new YDate(Planetarium.GetUniversalTime());
            int   kia  = KerbalMonitor.CountDeadKerbals();

            client.DownloadStringAsync(Page("/sync", "game={0}&player={1}&year={2:D}&day={3:D}&kia={4:D}", inGame, ourName, date.year, date.day, kia));
            return(client.CancelAsync);
        }
Exemplo n.º 10
0
 public Player(Hashtable ht)
 {
     date   = new YDate(ht["date"] as Hashtable);
     leader = (bool)ht["leader"];
 }
Exemplo n.º 11
0
 private void Reset()
 {
     completed = null;
     reported  = false;
     result    = Result.First.UNKNOWN;
 }
Exemplo n.º 12
0
 public Player(Dictionary <string, object> ht)
 {
     date   = new YDate(ht["date"] as Dictionary <string, object>);
     leader = (bool)ht["leader"];
 }