void INetworkObserver.OnHypeInstanceResolved(Instance instance) { Debug.WriteLine(String.Format("Hype instance resolved: {0}", instance.GetStringIdentifier())); // Creates a new contact to add to the contacts list Contact contact = new Contact() { Identifier = instance.GetStringIdentifier(), Name = "Description not available" }; IContactDelegate contactDelegate = GetContactDelegate(); // Instances should be strongly kept by some data structure. Their identifiers // are useful for keeping track of which instances are ready to communicate. Stores.Add(instance.GetStringIdentifier(), new Store(instance)); // Save the contact before reloading the contacts page (ContactPage) Contacts.Add(contact); // Notify the contacts delegate (if any) that a new contact is available, which may // cause the contact page to reload. if (contactDelegate != null) { contactDelegate.OnAddContact(contact); } }
void IMessageObserver.OnHypeMessageReceived(Message message, Instance instance) { Debug.WriteLine(String.Format("Hype Got a message from: {0}", instance.GetStringIdentifier())); IChatDelegate chatDelegate = GetChatDelegate(); Store store = Stores[instance.GetStringIdentifier()]; string text = System.Text.Encoding.UTF8.GetString(message.GetData().ToArray()); store.Add(text); // Notify the chat delegate, causing the the conversation to be updated if (chatDelegate != null) { chatDelegate.OnMessageReceived(message); } else { // Notify the contacts delegate so that an indicator of new contact is shown // at the front of the sender's contact. This is shown as a green circle. IContactDelegate contactDelegate = GetContactDelegate(); if (contactDelegate != null) { contactDelegate.NotifyNewMessage(GetContactIndex(instance.GetStringIdentifier())); } } }
void INetworkObserver.OnHypeInstanceLost(Instance instance, Error error) { Debug.WriteLine(String.Format("Hype lost instance: {0} [{1}]", instance.GetStringIdentifier(), error.GetDescription())); // Cleaning up is always a good idea. It's not possible to communicate with instances // that were previously lost. Stores.Remove(instance.GetStringIdentifier()); // Update the contact list by dropping the lost contact int index = GetContactIndex(instance.GetStringIdentifier()); Contacts.RemoveAt(index); // Notifying the contact delegate, which may cause the contacts page to reload. IContactDelegate contactDelegate = GetContactDelegate(); if (contactDelegate != null) { contactDelegate.OnRemoveContact(index); } }
public void SetContactDelegate(IContactDelegate contactDelegate) { this._contactDelegate = new WeakReference <IContactDelegate>(contactDelegate); }