Menu

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

Download this file

88 lines (76 with data), 3.9 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
using System;
using System.Collections.Generic;
using System.Text;
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 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, Syncronizer sync)
{
this.UserProperties = new UserPropertiesHolder();
this.Update(item, sync);
}
#endregion
internal void Update(ContactItem outlookContactItem, Syncronizer 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;
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(Syncronizer sync)
{
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 = Syncronizer.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;
}
}
}
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.