static void DisplayContactPresence(IMessengerContactAdvanced contact) { object[] presenceProps = (object[])contact.PresenceProperties; if (contact.IsSelf) { Console.WriteLine("Local User Presence Info for {0}:", contact.FriendlyName); } else { Console.WriteLine("Contact Presence Info for {0}:", contact.FriendlyName); } // Status or Machine State. Console.WriteLine("\tStatus: {0}", (MISTATUS)presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE]); Console.WriteLine("\tStatus String: {0}", GetStatusString((MISTATUS)presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE])); // Status string if status is set to custom. Console.WriteLine("\tCustom Status String: {0}", presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_CUSTOM_STATUS_STRING]); // Presence or User state. Console.WriteLine("\tAvailability: {0}", presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_AVAILABILITY]); Console.WriteLine("\tAvailability String: {0}", GetAvailabilityString((int)presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_AVAILABILITY])); // Presence note. Console.WriteLine("\tPresence Note: \n'{0}'", presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_PRESENCE_NOTE]); Console.WriteLine("\tIs Blocked: {0}", presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_IS_BLOCKED]); // OOF message for contact, if specified. Console.WriteLine("\tIs OOF: {0}", presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_IS_OOF]); // Tooltip. Console.WriteLine("\tTool Tip: \n'{0}'\n", presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_TOOL_TIP]); }
static void InsertContactInfo(IMessengerContactAdvanced contact) { try { object[] presenceProps = (object[])contact.PresenceProperties; var statusString = GetStatusString((MISTATUS)presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE]); var availabilityString = GetAvailabilityString((int)presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_AVAILABILITY]).ToString(); var status = (int)((MISTATUS)presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE]); var customStatus = presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_CUSTOM_STATUS_STRING]; var customStatusString = (string)customStatus ?? string.Empty; var availability = (int)(presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_AVAILABILITY]); var presenceNote = presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_PRESENCE_NOTE].ToString(); var isBlocked = presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_IS_BLOCKED].ToString(); var isOutOfOffice = presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_IS_OOF].ToString(); var toolTip = presenceProps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_TOOL_TIP].ToString(); InsertRecordIntoDB( contact.FriendlyName, status, statusString, customStatusString, availability, availabilityString, presenceNote, isBlocked, isOutOfOffice, toolTip ); } catch (Exception ex) { Console.WriteLine(string.Format("Exception occurred inserting contact {0}", ex)); } }
static void Main(string[] args) { try { Console.WriteLine($"******* Program Started at {DateTime.Now}"); _messenger = new Messenger(); IMessengerContactAdvanced localUser = (IMessengerContactAdvanced)_messenger.GetContact(_messenger.MySigninName, _messenger.MyServiceId); IMessengerContacts _contacts = (IMessengerContacts)_messenger.MyContacts; IMessengerContactAdvanced _contact; Console.WriteLine("Contact list for the local user:"******"\t{0}", _contact.FriendlyName); DisplayContactPresence(_contact); InsertContactInfo((IMessengerContactAdvanced)_contact); } _messenger.OnContactStatusChange += new DMessengerEvents_OnContactStatusChangeEventHandler(_messenger_OnContactStatusChange); _messenger.OnMyStatusChange += new DMessengerEvents_OnMyStatusChangeEventHandler(_messenger_OnMyStatusChange); if (localUser != null) { DisplayContactPresence(localUser); } Console.WriteLine("\nPress Enter key to exit the application.\n"); Console.ReadLine(); _messenger.OnContactStatusChange -= new DMessengerEvents_OnContactStatusChangeEventHandler(_messenger_OnContactStatusChange); _messenger.OnMyStatusChange -= new DMessengerEvents_OnMyStatusChangeEventHandler(_messenger_OnMyStatusChange); System.Runtime.InteropServices.Marshal.ReleaseComObject(_messenger); _messenger = null; System.Runtime.InteropServices.Marshal.ReleaseComObject(localUser); localUser = null; } catch (Exception ex) { Console.WriteLine($"ERROR: An error occurred in status tracker.\n{ex}"); } finally { Console.WriteLine("******** Program Ended at {0}", DateTime.Now); } }
static void Log(IMessengerContactAdvanced contact) { var pps = contact.PresenceProperties; var emailAddress = contact.SigninName; if (!EmailAddresses.Contains(emailAddress, StringComparer.OrdinalIgnoreCase)) { return; } var status = ((MISTATUS)pps[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE]).ToString(); var path = Path.Combine(LogDir, $"{emailAddress}-{DateTime.Today.ToString("yyyyMMdd")}.txt"); if (IsStatusChanged(path, status)) { File.AppendAllText(path, string.Join(",", new[] { DateTime.Now.ToString("HHmmss"), status } + Environment.NewLine)); } }
private void GetContact(String singinName, String serviceId) { contact = messenger.GetContact(singinName, serviceId) as IMessengerContactAdvanced; messenger.OnContactStatusChange += new DMessengerEvents_OnContactStatusChangeEventHandler(OnContactStatusChange); }