private void OnCompleteLookupName(NameRegistrationResult result) { NameRegistration nameRegistration = (NameRegistration)result.NameRegistration; if (result.Status == Status.Success) { this.Dispatcher.BeginInvoke( delegate { System.Diagnostics.Debug.WriteLine("Found the name!: " + nameRegistration.Id); hID = nameRegistration.Id; SendRequest(this.RelayContext.Endpoint, nameRegistration.Id); }); } else { this.Dispatcher.BeginInvoke( delegate { ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = true; ProgressBar.IsVisible = false; NameBox.IsEnabled = true; UsernameBox.IsEnabled = true; }); this.DisplayMessage("Name lookup failed. Check your wifi/cellular connection.", "Error"); } }
public void OnCompleteAssociateId(NameRegistrationResult result) { System.Diagnostics.Debug.WriteLine(this.RelayContext.Endpoint.RegistrationId); if (result.Status == Status.Success) { NameRegistration nameRegistration = (NameRegistration)result.StateObject; this.Dispatcher.BeginInvoke( delegate { this.NameRegistrationContext = new NameRegistrationContext(nameRegistration); settings["MyUsername"] = nameRegistration.Name; ((ObservableCollection <Person>)settings["ContactsList"]).Add(new Person { name = "Me", username = nameRegistration.Name, hawaiiID = this.RelayContext.Endpoint.RegistrationId, reqSent = true, accepted = true }); foreach (MyProject search in ((ObservableCollection <MyProject>)settings["ProjectList"])) { search.creator = ((ObservableCollection <Person>)settings["ContactsList"])[0]; foreach (MyTask searchTask in search.tasks) { searchTask.assignedTo = ((ObservableCollection <Person>)settings["ContactsList"])[0]; } foreach (MyTask searchTask in search.doneTasks) { searchTask.assignedTo = ((ObservableCollection <Person>)settings["ContactsList"])[0]; } } }); DisplayMessage("You have successfully registered the name " + nameRegistration.Name, "Success!"); this.Dispatcher.BeginInvoke( delegate { ProgressBar.IsVisible = false; NavigationService.GoBack(); }); } else { this.DisplayMessage("Associating a registration id with a name failed. Check your wifi/cellular connection.", "Error"); error(); } }
private void OnCompleteRegisterName(NameRegistrationResult result) { if (result.Status == Status.Success) { this.Dispatcher.BeginInvoke( delegate { this.NameRegistrationContext = new NameRegistrationContext(result.NameRegistration); // Store the secret key in isolated storage. RendezvousStorage.SetSecretKey(result.NameRegistration.Name, result.NameRegistration.SecretKey); string name = result.NameRegistration.Name; string registrationId = this.RelayContext.Endpoint.RegistrationId; System.Diagnostics.Debug.WriteLine("Registered a name!: " + name + registrationId); if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(registrationId)) { string secretKey = result.NameRegistration.SecretKey; if (string.IsNullOrEmpty(secretKey)) { this.DisplayMessage("You are not the owner of this name or the name ownership details are lost. You can't perform this operation.", "Error"); error(); return; } NameRegistration nameRegistration = new NameRegistration() { Name = name, Id = registrationId, SecretKey = secretKey }; RendezvousService.AssociateIdAsync(HawaiiClient.HawaiiApplicationId, nameRegistration, this.OnCompleteAssociateId, nameRegistration); } }); } else { this.DisplayMessage("Name registration failed. Check your wifi/cellular connection.", "Error"); error(); } }
private void OnCompleteCreateEndPoint(EndpointResult result) { if (result.Status == Status.Success) { // Set the newly created endpoint available in result as active(my) endpoint. this.RelayContext.Endpoint = result.EndPoint; this.Dispatcher.BeginInvoke( delegate { string name = UsernameTextBox.Text; RendezvousService.RegisterNameAsync(HawaiiClient.HawaiiApplicationId, name, this.OnCompleteRegisterName); }); NameRegistration nameRegistration = (NameRegistration)result.StateObject; } else { // Display a message box, in case of any error creating a new endpoint. DisplayMessage("Error creating endpoint.", "Error"); error(); } }
/// <summary> /// Initializes a new instance of the NameRegistrationContext class. /// </summary> /// <param name="nameRegistration">Specifies a name registration object.</param> public NameRegistrationContext(NameRegistration nameRegistration) { this.Name = nameRegistration.Name; this.RegistrationId = nameRegistration.Id; this.SecretKey = nameRegistration.SecretKey; }