/// <summary> /// /// </summary> /// <param name="obj"></param> private void SubmitButtonClick(object obj) { try { evtDone.Reset(); successVerification = false; if (String.IsNullOrWhiteSpace(VerificationText)) { MessageBoxInfoVisibility = true; MessageBoxInfoText = Application.Current.FindResource("CodeVerificationErrorNoCode").ToString(); return; } dynamic deviceRegistrationResponse = webAPI.RegisterDevice(new WEBApiJSON.DeviceRegistrationRequest() { installation = pbData.InstallationUUID, nickname = System.Windows.Forms.SystemInformation.ComputerName, software_version = Assembly.GetAssembly(typeof(PasswordBoss.PBApp)).GetName().Version.ToString(), verification = VerificationText }, email); if (deviceRegistrationResponse == null) { MessageBoxInfoVisibility = true; MessageBoxInfoText = Application.Current.FindResource("CodeVerificationErrorDeviceRegistration").ToString(); return; } else { if (deviceRegistrationResponse.error != null) { VerificationErrorMessage = Application.Current.FindResource("IncorrectVerificationCodeDescription").ToString(); VerificationApiErrorVisibility = true; return; } } pbData.DeviceUUID = deviceRegistrationResponse.devices[0].uuid.ToString(); Guid g; if (!Guid.TryParse(pbData.DeviceUUID, out g)) { MessageBoxInfoVisibility = true; MessageBoxInfoText = "Invalid device ID"; return; } if (!pbData.CreateProfile(email, mastePassword)) { MessageBoxInfoVisibility = true; MessageBoxInfoText = Application.Current.FindResource("ErrorSecureDatabaseCreating").ToString(); } if (pbData.AddDevice( new DTO.Device() { InstallationId = pbData.InstallationUUID, UUID = pbData.DeviceUUID, Nickname = System.Windows.Forms.SystemInformation.ComputerName }) == null) { MessageBoxInfoVisibility = true; MessageBoxInfoText = "Failed to save device data"; return; } // Account created, can delete pre-registrate message history pbData.TryToClearMessageHistory(); IPBSync sync = resolver.GetInstanceOf <IPBSync>(); sync.OnSyncFinished += sync_OnSyncFinished; Task.Factory.StartNew(() => { try { if (!sync.Sync(3, ProgressInfo)) { logger.Error("Initial sync failed"); } else { if (masterPasswordDiffers) { //Treba reci da se pass razlikuje lokalno i na cloud-u i pitati da li zeli promijeniti lokalni pass na onaj sa cloud-a //Ako kaze da onda treba uraditi pbData.ChangeMasterPassword(newPass) masterPasswordDiffers = true; } } } catch (Exception ex) { logger.Error(ex.Message); } finally { evSyncDone.Set(); } }); evSyncDone.WaitOne(); evtDone.WaitOne(); sync.OnSyncFinished -= sync_OnSyncFinished; if (_finishVerification) { ConfirmMasterPasswordViewModel.SetDefaultSettings(pbData); successVerification = true; } } catch (Exception ex) { logger.Debug(ex.ToString()); } }
private void PerformInitialSync() { try { //TODO register device //if not default device goto verification dynamic deviceRegistrationResponse = webApi.RegisterDevice( new WEBApiJSON.DeviceRegistrationRequest() { /*application_language = "en-us", device_language = "en-us",*/ installation = pbData.InstallationUUID, nickname = Environment.MachineName, software_version = Assembly.GetExecutingAssembly().GetName().Version.ToString() }, pbData.ActiveUser); if (deviceRegistrationResponse == null) { MessageBox.Show("Error in device registration"); return; } else { if (deviceRegistrationResponse.error != null) { MessageBox.Show(deviceRegistrationResponse.error.message.ToString()); if (deviceRegistrationResponse.error.code.ToString() == "403") { //todo send verification post dynamic verificationRequestResponse = webApi.RequestVerificationCode(pbData.ActiveUser); var verificationScreen = resolver.GetInstanceOf <VerificationRequired>(); Navigator.NavigationService.Navigate(verificationScreen); } return; } } pbData.DeviceUUID = deviceRegistrationResponse.devices[0].uuid.ToString(); Guid g; if (!Guid.TryParse(pbData.DeviceUUID, out g)) { MessageBox.Show("Invalid device ID"); return; } logger.Debug("Adding device"); if (pbData.AddDevice( new DTO.Device() { InstallationId = pbData.InstallationUUID, UUID = pbData.DeviceUUID, Nickname = System.Windows.Forms.SystemInformation.ComputerName }) == null) { MessageBox.Show("Failed to save device data"); return; } evDone.Reset(); IPBSync sync = resolver.GetInstanceOf <IPBSync>(); //sync.OnGetMergePassword(GetMergePassword); sync.OnSyncFinished += sync_OnSyncFinished; Task.Factory.StartNew(() => { try { if (!sync.Sync(3, ProgressInfo)) { logger.Error("Initial sync failed"); } else { if (masterPasswordDiffers) { //Treba reci da se pass razlikuje lokalno i na cloud-u i pitati da li zeli promijeniti lokalni pass na onaj sa cloud-a //Ako kaze da onda treba uraditi pbData.ChangeMasterPassword(newPass) masterPasswordDiffers = true; } } } catch (Exception ex) { logger.Error(ex.Message); } finally { evSyncDone.Set(); } }); evSyncDone.WaitOne(); evDone.WaitOne(); } catch (Exception ex) { logger.Error(ex.Message); } }
private void PerformInitialSync() { try { //if not default device goto verification string uuid = ""; if (!TryToRegisterDevice(pbData.ActiveUser, out uuid)) { return; } pbData.DeviceUUID = uuid; Guid g; if (!Guid.TryParse(pbData.DeviceUUID, out g)) { OnMessageRaised("Invalid device ID"); return; } logger.Debug("Adding device"); if (pbData.AddDevice( new DTO.Device() { InstallationId = pbData.InstallationUUID, UUID = pbData.DeviceUUID, Nickname = System.Windows.Forms.SystemInformation.ComputerName }) == null) { OnMessageRaised("Failed to save device data"); return; } evDone.Reset(); IPBSync sync = resolver.GetInstanceOf <IPBSync>(); //sync.OnGetMergePassword(GetMergePassword); sync.OnSyncFinished += sync_OnSyncFinished; Task.Factory.StartNew(() => { var sw = Stopwatch.StartNew(); try { if (!sync.Sync(3, ProgressInfo)) { logger.Error("Initial sync failed"); } else { } } catch (Exception ex) { logger.Error(ex.Message); } finally { var str = sw.Elapsed.ToString(); logger.Info("Sync elasped {0}", str); evSyncDone.Set(); } }); evSyncDone.WaitOne(); evDone.WaitOne(); } catch (Exception ex) { logger.Error(ex.Message); } }