Exemplo n.º 1
0
        public static async Task <List <Stars> > LoadStarsAsync()
        {
            if (Storage.Exists(StarMapFile))
            {
                var list = await Storage.LoadTextAsync(StarMapFile);

                return(JsonConvert.DeserializeObject <List <Stars> >(list));
            }
            else
            {
                return(null);
            }
        }
        public async Task <AccountModel> GetActiveAccountAsync()
        {
            if (Storage.Exists(AccountFile))
            {
                var accounts = await LoadAccountsAsync();

                if (accounts != null)
                {
                    foreach (var a in accounts.AccountList)
                    {
                        //a.ActiveAccount = true;
                        if (a.ActiveAccount)
                        {
                            if (a.SessionRenewed < DateTime.Now.AddHours(-2))
                            {
                                var    oldAccount = a;
                                string json       = Empire.Login(1, a.EmpireName, a.Password);
                                var    s          = new Server();
                                var    response   = await s.GetHttpResultAsync(a.Server, Empire.url, json);

                                s                = null;
                                a.SessionID      = response.result.session_id;
                                a.SessionRenewed = DateTime.Now;
                                ModifyAccountAsync(a, oldAccount);
                            }
                            return(a);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }