示例#1
0
 public ContractMonitor()
 {
     foreach (ConfigNode cn in GameDatabase.Instance.GetConfigNodes("RISMilestone"))
     {
         RISMilestone stone = new RISMilestone(cn);
         stones.Add(stone);
     }
 }
示例#2
0
 public void CheckCompletion(RISMilestone stone)
 {
     ContractConfigurator.ContractType type = ContractConfigurator.ContractType.GetContractType(stone.ccName);
     if (type == null)
     {
         Logging.LogWarningFormat("Failed to get CC Type {0} for Milestone {1}", stone.ccName, stone.name);
         return;
     }
     if (type.ActualCompletions() > 0)
     {
         stone.completed = new YDate(Planetarium.GetUniversalTime());
     }
 }
示例#3
0
        public CancelDelegate Resolve(List <RISMilestone> stones, ResultCallback cb)
        {
            WebClient      client = new WebClient();
            CancelDelegate cd     = () => {};
            RISMilestone   stone  = stones[0];

            stones.RemoveAt(0);
            Logging.LogFormat("Resolving {0}", stone.name);
            client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => {
                bool result = false;
                try {
                    if (e.Cancelled)
                    {
                        Logging.Log("Resolve(Sync) cancelled");
                    }
                    else if (e.Error != null)
                    {
                        Logging.LogException(e.Error);
                    }
                    else
                    {
                        string json = e.Result;
                        Logging.Log("Resolve: " + json);
                        Hashtable ht = MiniJSON.jsonDecode(json) as Hashtable;
                        checkError(ht);
                        Result r = new Result(ht, ourName);
                        stone.Resolve(r.first);
                        result = true;
                    }
                } catch (Exception exc) {
                    /* Job failed, but we still have to exit job state */
                    Logging.LogException(exc);
                }
                if (result && stones.Count > 0)
                {
                    cd += Resolve(stones, cb);
                    return;
                }
                cb.Invoke(result);
            };
            client.DownloadStringAsync(Page("/result", "game={0}&contract={1}", inGame, stone.name));
            cd += client.CancelAsync;
            return(cd);
        }
示例#4
0
        public CancelDelegate Report(RISMilestone stone, ResultCallback cb)
        {
            WebClient client = new WebClient();

            Logging.LogFormat("Reporting {0} completed at {1}", stone.name, stone.completed.ToString());
            client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) => {
                bool result = false;
                try {
                    if (e.Cancelled)
                    {
                        Logging.Log("Report(Sync) cancelled");
                    }
                    else if (e.Error != null)
                    {
                        Logging.LogException(e.Error);
                    }
                    else
                    {
                        string json = e.Result;
                        Logging.Log("Report: " + json);
                        Hashtable ht = MiniJSON.jsonDecode(json) as Hashtable;
                        checkError(ht);
                        Result r = new Result(ht, ourName);
                        if (r.date != null)
                        {
                            stone.reported = true;
                        }
                        stone.Resolve(r.first);
                        result = true;
                    }
                } catch (Exception exc) {
                    /* Job failed, but we still have to exit job state */
                    Logging.LogException(exc);
                }
                cb.Invoke(result);
            };
            client.DownloadStringAsync(Page("/completed", "game={0}&player={1}&year={2:D}&day={3:D}&contract={4}",
                                            inGame, ourName, stone.completed.year, stone.completed.day, stone.name));
            return(client.CancelAsync);
        }
示例#5
0
        public CancelDelegate Sync(ResultCallback cb)
        {
            RISMilestone   stone = monitor.CheckAll();
            CancelDelegate cd    = () => {};

            if (stone != null)
            {
                cd += Report(stone, (bool ok) => {
                    if (ok)
                    {
                        cd += Sync(cb);
                    }
                    else
                    {
                        cb.Invoke(false);
                    }
                });
                return(cd);
            }
            cd += SyncTail((bool ok) => {
                if (ok)
                {
                    List <RISMilestone> toResolve = monitor.ToResolve();
                    if (toResolve.Count > 0)
                    {
                        cd += Resolve(toResolve, cb);
                    }
                    else
                    {
                        cb.Invoke(true);
                    }
                }
                else
                {
                    cb.Invoke(false);
                }
            });
            return(cd);
        }