Menu

[r672]: / trunk / GoogleContactsSync / OutlookContactInfo.cs  Maximize  Restore  History

Download this file

108 lines (91 with data), 5.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
using System;
using Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;
namespace GoContactSyncMod
{
/// <summary>
/// Holds information about an Outlook contact during processing.
/// We can not always instantiate an unlimited number of Exchange Outlook objects (policy limitations),
/// so instead we copy the info we need for our processing into instances of OutlookContactInfo and only
/// get the real Outlook.ContactItem objects when needed to communicate with Outlook.
/// </summary>
class OutlookContactInfo
{
#region Internal classes
internal class UserPropertiesHolder
{
public string GoogleContactId;
public DateTime? LastSync;
}
#endregion
#region Properties
public string EntryID { get; set; }
public string FileAs { get; set; }
public string FullName { get; set; }
public string TitleFirstLastAndSuffix { get; set; } //Additional unique identifier
public string Email1Address { get; set; }
public string MobileTelephoneNumber { get; set; }
public string Categories { get; set; }
public string Company { get; set; }
public DateTime LastModificationTime { get; set; }
public UserPropertiesHolder UserProperties { get; set; }
#endregion
#region Construction
private OutlookContactInfo()
{
// Not public - we are always constructed from an Outlook.ContactItem (constructor below)
}
public OutlookContactInfo(ContactItem item, Synchronizer sync)
{
this.UserProperties = new UserPropertiesHolder();
this.Update(item, sync);
}
#endregion
internal void Update(ContactItem outlookContactItem, Synchronizer sync)
{
this.EntryID = outlookContactItem.EntryID;
this.FileAs = outlookContactItem.FileAs;
this.FullName = outlookContactItem.FullName;
this.Email1Address = ContactPropertiesUtils.GetOutlookEmailAddress1(outlookContactItem);
this.MobileTelephoneNumber = outlookContactItem.MobileTelephoneNumber;
this.Categories = outlookContactItem.Categories;
this.LastModificationTime = outlookContactItem.LastModificationTime;
this.Company = outlookContactItem.CompanyName;
this.TitleFirstLastAndSuffix = GetTitleFirstLastAndSuffix(outlookContactItem);
UserProperties userProperties = outlookContactItem.UserProperties;
UserProperty prop = userProperties[sync.OutlookPropertyNameId];
this.UserProperties.GoogleContactId = prop != null ? string.Copy((string)prop.Value) : null;
if (prop != null)
Marshal.ReleaseComObject(prop);
prop = userProperties[sync.OutlookPropertyNameSynced];
this.UserProperties.LastSync = prop != null ? (DateTime)prop.Value : (DateTime?)null;
if (prop != null)
Marshal.ReleaseComObject(prop);
Marshal.ReleaseComObject(userProperties);
}
internal ContactItem GetOriginalItemFromOutlook()
{
if (this.EntryID == null)
throw new ApplicationException("OutlookContactInfo cannot re-create the ContactItem from Outlook because EntryID is null, suggesting that this OutlookContactInfo was not created from an existing Outook contact.");
ContactItem outlookContactItem = Synchronizer.OutlookNameSpace.GetItemFromID(this.EntryID) as ContactItem;
if (outlookContactItem == null)
throw new ApplicationException("OutlookContactInfo cannot re-create the ContactItem from Outlook because there is no Outlook entry with this EntryID, suggesting that the existing Outook contact may have been deleted.");
return outlookContactItem;
}
internal static string GetTitleFirstLastAndSuffix(ContactItem outlookContactItem)
{
return GetTitleFirstLastAndSuffix(outlookContactItem.Title, outlookContactItem.FirstName, outlookContactItem.MiddleName, outlookContactItem.LastName, outlookContactItem.Suffix);
}
internal static string GetTitleFirstLastAndSuffix(Google.Contacts.Contact googleContact)
{
return GetTitleFirstLastAndSuffix(googleContact.Name.NamePrefix, googleContact.Name.GivenName, googleContact.Name.AdditionalName, googleContact.Name.FamilyName, googleContact.Name.NameSuffix);
}
private static string GetTitleFirstLastAndSuffix(string title, string firstName, string middleName, string lastName, string suffix)
{
string ret = title + " " + firstName + " " + middleName + " " + lastName + " " + suffix;
if (string.IsNullOrEmpty(ret.Trim()))
ret = null;
return ret;
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.