Exemplo n.º 1
0
        public CancelDelegate ListGames(ResultCallback cb)
        {
            KerbalMonitor.CountDeadKerbals();
            WebClient client = new WebClient();

            client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => {
                bool result = false;
                try {
                    if (e.Cancelled)
                    {
                        Logging.Log("ListGames cancelled");
                    }
                    else if (e.Error != null)
                    {
                        Logging.LogException(e.Error);
                    }
                    else
                    {
                        string json = e.Result;
                        Logging.Log("ListGames: " + json);
                        Hashtable ht = MiniJSON.jsonDecode(json) as Hashtable;
                        checkError(ht);
                        gameList = new Dictionary <string, GameListEntry>();
                        foreach (DictionaryEntry de in ht)
                        {
                            gameList.Add(de.Key.ToString(), new GameListEntry(de.Value as Hashtable));
                        }
                        Logging.LogFormat("Listed {0} games", gameList.Count);
                        result = true;
                    }
                } catch (Exception exc) {
                    /* Job failed, but we still have to exit job state */
                    Logging.LogException(exc);
                }
                cb.Invoke(result);
            };
            client.DownloadStringAsync(Page("/"));
            return(client.CancelAsync);
        }
Exemplo n.º 2
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);
        }