private static AccountCollection MakeAllAccountsNotActive(AccountCollection accounts)
		{
			var accountCollection = new AccountCollection();
			foreach (var a in accounts.AccountList)
			{
				a.ActiveAccount = false;
				accountCollection.AccountList.Add(a);
			}
			return accountCollection;
		}
        private static AccountCollection MakeAllAccountsNotActive(AccountCollection accounts)
        {
            var accountCollection = new AccountCollection();

            foreach (var a in accounts.AccountList)
            {
                a.ActiveAccount = false;
                accountCollection.AccountList.Add(a);
            }
            return(accountCollection);
        }
Exemplo n.º 3
0
		async void LoadAccountsIntoPicker()
		{
			AccountManagement.AccountManager accountManger = new AccountManagement.AccountManager();
			accounts = await accountManager.LoadAccountsAsync();
			selectedAccount = await accountManager.GetActiveAccountAsync();
			if (accounts != null)
			{
				foreach (var a in accounts.AccountList)
					accountPicker.Items.Add(a.DisplayName);
			}
			else
			{
				await Navigation.PushModalAsync(new LacunaExpress.Pages.AccountPages.Login());
			}
		}
        public async Task <bool> CreateAndAddAccountAsync(string username, string password, string server, bool setAsActive)
        {
            string json     = Empire.Login(1, username, password);
            var    s        = new Server();
            var    response = await s.GetHttpResultAsync(server, Empire.url, json);

            if (response.result != null)
            {
                var account = new AccountModel(username, password, server, response.result.session_id, setAsActive);
                account.SessionRenewed = DateTime.Now;
                account.ActiveAccount  = setAsActive;
                account.Colonies       = response.result.status.empire.colonies;
                account.Stations       = response.result.status.empire.stations;
                account.AllBodies      = response.result.status.empire.planets;
                account.Capital        = response.result.status.empire.colonies[response.result.status.empire.home_planet_id];

                account.Colonies.OrderBy(x => x.Value);
                account.Stations.OrderBy(x => x.Value);
                account.AllBodies.OrderBy(x => x.Value);
                var accounts = await LoadAccountsAsync();

                if (accounts != null)
                {
                    var accountCollection = new AccountCollection();
                    if (setAsActive)
                    {
                        accountCollection = MakeAllAccountsNotActive(accounts);
                    }
                    accountCollection.AccountList.Add(account);
                    await Storage.SaveTextAsync(AccountFile, Newtonsoft.Json.JsonConvert.SerializeObject(accountCollection));

                    return(true);
                }
                else
                {
                    var accountCollection = new AccountCollection();
                    account.ActiveAccount = true;
                    accountCollection.AccountList.Add(account);
                    await Storage.SaveTextAsync(AccountFile, Newtonsoft.Json.JsonConvert.SerializeObject(accountCollection));

                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
		public async Task<bool> CreateAndAddAccountAsync(string username, string password, string server, bool setAsActive)
		{
			string json = Empire.Login(1, username, password);
			var s = new Server();
			var response = await s.GetHttpResultAsync(server, Empire.url, json);
			if (response.result != null)
			{
				var account = new AccountModel(username, password, server, response.result.session_id, setAsActive);
				account.SessionRenewed = DateTime.Now;
				account.ActiveAccount = setAsActive;
				account.Colonies = response.result.status.empire.colonies;
				account.Stations = response.result.status.empire.stations;
				account.AllBodies = response.result.status.empire.planets;
				account.Capital = response.result.status.empire.colonies[response.result.status.empire.home_planet_id];

				account.Colonies.OrderBy(x => x.Value);
				account.Stations.OrderBy(x => x.Value);
				account.AllBodies.OrderBy(x => x.Value);
				var accounts = await LoadAccountsAsync();
				if (accounts != null)
				{
					var accountCollection = new AccountCollection();
					if (setAsActive)
					{
						accountCollection = MakeAllAccountsNotActive(accounts);
					}
					accountCollection.AccountList.Add(account);
					await Storage.SaveTextAsync(AccountFile, Newtonsoft.Json.JsonConvert.SerializeObject(accountCollection));
					return true;
				}
				else
				{
					var accountCollection = new AccountCollection();
					account.ActiveAccount = true;
					accountCollection.AccountList.Add(account);
					await Storage.SaveTextAsync(AccountFile, Newtonsoft.Json.JsonConvert.SerializeObject(accountCollection));
					return true;
				}

			}
			else
				return false;

		}