Azure Easy Tables init(?) 在应用程序的一部分上失败,但在另一部分上成功。发生了什么?

Azure Easy Tables init(?) fails on one portion of app but succeeds on another. What's happening?

我正在开发 Xamarin.Android 应用程序。我正在连接到 Azure 移动应用程序,并且我是 EasyTable 中的 getting/storing 数据。

现在这是我的用户 'login' 和注册代码。这只是测试查询,所以不要介意明显不安全的登录:

public async Task Initialize()
        {
            MobileService = new MobileServiceClient(myappwebsiteinazurestring);

            string path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "UserSync.db");
            var store = new MobileServiceSQLiteStore(path);
            store.DefineTable<Users_Table>();
            await MobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
            userTable = MobileService.GetSyncTable<Users_Table>();
        }

        public async Task SyncUsers()
        {
            await userTable.PullAsync("Users_Table", userTable.CreateQuery());
            await MobileService.SyncContext.PushAsync();
        }

        public async Task<List<Users_Table>> loginUser(string username, string password)
        {
            List<Users_Table> userLogin = await userTable
                .Where(user => user.Username == username && user.Password == password)
                .ToListAsync();
            await MobileService.SyncContext.PushAsync();
            return userLogin;
        }

这是用于登录和初始化的。下面是寄存器部分:

 public async Task AddUser(Users_Table user)
        {
            var InsUser = new Users_Table
            {
                Name = user.Name,
                Username = user.Username,
                Password = user.Password,
                LicensePlate = user.LicensePlate,
                Email = user.Email,
                Exp = user.Exp
            };

            await userTable.InsertAsync(InsUser);
            await SyncUsers();

        }

现在一切都很好。以下是我如何从我的应用中调用它们:

 private async void LoginButton_Click(object sender, EventArgs e)
        {

            EditText username = FindViewById<EditText>(Resource.Id.LoginEditTextUsername);
            EditText password = FindViewById<EditText>(Resource.Id.LoginEditTextPassword);

            var prog = new ProgressDialog(this);
            prog.SetMessage("Logging in...");
            prog.Show();
            AzureDataService az = new AzureDataService();
            List<Users_Table> user = new List<Users_Table>();

            try
            {
                await az.Initialize();
                user = await az.loginUser(username.Text, password.Text);
            }
            catch (Exception ex)
            {

                Toast.MakeText(this.ApplicationContext, "Error: " + ex.Message + "\n" + ex.Source, ToastLength.Long).Show();
                return;
            }

以及注册:

 private async void CreateProfile()
        {
            EditText regUsername = FindViewById<EditText>(Resource.Id.RegisterLayoutUsername);
            EditText regPassword = FindViewById<EditText>(Resource.Id.RegisterLayoutPassword);
            EditText regConfirmPassword = FindViewById<EditText>(Resource.Id.RegisterLayoutConfirmPassword);
            EditText regPlateNumber = FindViewById<EditText>(Resource.Id.RegisterLayoutPlateNumber);
            EditText regEmail = FindViewById<EditText>(Resource.Id.RegisterLayoutEmail);
            EditText regName = FindViewById<EditText>(Resource.Id.RegisterLayoutName);

            var user = new Users_Table
            {
                Username = regUsername.Text,
                Password = regPassword.Text,
                LicensePlate = parseLicensePlate(regPlateNumber.Text),
                Name = regName.Text,
                Email = regEmail.Text,
                Exp = 0
            };

            try
            {
                var pd = new ProgressDialog(this);
                pd.SetMessage("Creating Profile...");
                pd.Show();
                AzureDataService az = new AzureDataService();
                await az.Initialize();
                await az.AddUser(user);
                pd.Dismiss();
            }

一旦我使用 apk 在任何设备上测试它,登录就会失败。该应用程序收到空值 Users_Table,因此显示 username/password 错误消息。

然而,奇怪的是:注册没有问题。一旦我成功注册了一个新用户,现有用户和新创建的用户的登录也会通过。这就像在注册方法中发生了一些事情,它启动了与任何东西的连接。

有人遇到过这种情况吗?发生什么事了?

我通过在任何进程之前添加 syncusers() 使其工作,例如像这样进行登录:

    public async Task<List<Users_Table>> loginUser(string username, string password)
    {



        await SyncUsers();//here
        List<Users_Table> userLogin = await userTable
            .Where(user => user.Username == username && user.Password == password)
            .ToListAsync();
        await MobileService.SyncContext.PushAsync();
        return userLogin;
    }