Exemplo n.º 1
0
        private void GetPresenceInfo(uint [] contacts, IDictionary <uint, SimplePresence> presence_info, bool raise_events)
        {
            string[] member_names;

            try {
                member_names = iconn_proxy.InspectHandles(HandleType.Contact, contacts);
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
                return;
            }

            for (int i = 0; i < contacts.Length; i++)
            {
                uint handle = contacts[i];
                if (presence_info.ContainsKey(handle))
                {
                    Console.WriteLine("Presence change for {0} with handle {1} is {2}",
                                      member_names[i],
                                      handle,
                                      presence_info[handle].Status);

                    lock (roster) {
                        if (!roster.ContainsKey(handle))
                        {
                            Contact c = CreateContact(member_names[i],
                                                      handle,
                                                      presence_info[handle].Type,
                                                      presence_info[handle].StatusMessage);
                            roster.Add(handle, c);
                            c.Initialize();
                        }
                        else
                        {
                            roster[handle].Update(member_names[i],
                                                  handle,
                                                  presence_info[handle].Type);
                            roster[handle].StatusMessage = presence_info[handle].StatusMessage;
                        }
                    }

                    if (raise_events)
                    {
                        OnContactStatusChanged(roster[handle],
                                               new ContactStatusEventArgs(presence_info[handle].Type));
                    }
                }
            }
        }