0

저는 Xamarin.Android 앱을 만들고 있습니다. Azure Mobile App에 연결하고 있고 EasyTable에 데이터를 저장/저장하고 있습니다.Azure Easy Tables init (?)은 한 부분에서 실패하지만 다른 부분에서는 성공합니다. 무슨 일이야?

사용자 로그인 및 등록에 대한 내 코드는 다음과 같습니다. 이것은 단지 테스트 쿼리이므로 확실한 보안되지 않은 로그인은 신경 쓰지 않아도됩니다.

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와 모든 장치에서이 테스트를하면 로그인이 실패합니다. 앱에 null 사용자 _ 테이블이 수신되어 사용자 이름/비밀번호가 잘못되었다는 메시지가 표시됩니다.

그러나 이상한 일은 다음과 같습니다. 레지스터가 문제없이 통과합니다. 그리고 새로운 사용자를 성공적으로 등록하면 로그인은 기존 사용자와 새로 생성 된 사용자를 위해 진행됩니다. 등록 방법에서 뭔가가 발생하면 연결이 킥 스타트됩니다.

누구에게이 경험이 있습니까? 무슨 일이야?

답변

0

나는 그렇게 같이 예를 들어 로그인을하고, 모든 프로세스 전에 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; 
    } 
관련 문제