Example #1
0
        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();
            }
        }
Example #2
0
 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();
     }
 }
Example #3
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            // If no end point is created so far, return.
            if (this.RelayContext.Endpoint == null)
            {
                this.DisplayMessage("Please set up a username in order to add contacts.", "Error");
                return;
            }

            if (string.IsNullOrEmpty(NameBox.Text))
            {
                this.DisplayMessage("Please enter a name for this contact.", "Error");
                return;
            }

            // If no end point is created so far, return.
            string recipientId = this.UsernameBox.Text;

            if (string.IsNullOrEmpty(recipientId))
            {
                this.DisplayMessage("Please enter a username.", "Error");
                return;
            }

            ((ApplicationBarIconButton)ApplicationBar.Buttons[0]).IsEnabled = false;
            ProgressBar.IsVisible = true;
            NameBox.IsEnabled     = false;
            UsernameBox.IsEnabled = false;

            Person fromContacts = ((ObservableCollection <Person>)settings["ContactsList"]).Where(X => X.username == UsernameBox.Text).FirstOrDefault();
            Person fromRequests = ((ObservableCollection <Person>)settings["RequestList"]).Where(X => X.username == UsernameBox.Text).FirstOrDefault();

            if (contactID != -1 && fromContacts != null)
            {
                ((Person)((ObservableCollection <Person>)settings["ContactsList"])[contactID]).name = NameBox.Text;
                NavigationService.GoBack();
            }
            else if (!string.IsNullOrEmpty(acceptNameString) && !string.IsNullOrEmpty(acceptIDString) && fromRequests != null)
            {
                SendAccept(this.RelayContext.Endpoint, acceptIDString);
            }
            else
            {
                // Send the message.
                if (((string)settings["MyUsername"]).Equals(UsernameBox.Text))
                {
                    this.DisplayMessage("Can't request yourself as a contact.", "Error");
                    return;
                }
                else if (fromContacts != null)
                {
                    this.DisplayMessage("Contact already exists.", "Error");
                    return;
                }
                else if (fromRequests != null)
                {
                    this.DisplayMessage("You have already requested this person as a contact, or you have a pending request from them.", "Error");
                    return;
                }

                if (!string.IsNullOrEmpty(recipientId))
                {
                    RendezvousService.LookupNameAsync(HawaiiClient.HawaiiApplicationId, recipientId, this.OnCompleteLookupName);
                }
                else
                {
                    this.DisplayMessage("No username found. Enter a username and try again.", "Error");
                }
            }
        }