Menu

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

Download this file

138 lines (117 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Google.Apis.PeopleService.v1.Data;
using Microsoft.Office.Interop.Outlook;
using System;
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>
internal 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 oc, Synchronizer sync)
{
UserProperties = new UserPropertiesHolder();
Update(oc, sync);
}
#endregion
public override string ToString()
{
var name = FileAs;
if (!string.IsNullOrWhiteSpace(name))
{
return name.RemoveNewLines();
}
name = FullName;
if (!string.IsNullOrWhiteSpace(name))
{
return name.RemoveNewLines();
}
name = TitleFirstLastAndSuffix;
if (!string.IsNullOrWhiteSpace(name))
{
return name.RemoveNewLines();
}
name = Company;
if (!string.IsNullOrWhiteSpace(name))
{
return name.RemoveNewLines();
}
name = Email1Address;
if (!string.IsNullOrWhiteSpace(name))
{
return name.RemoveNewLines();
}
return string.Empty;
}
internal void Update(ContactItem oc, Synchronizer sync)
{
EntryID = oc.EntryID;
FileAs = oc.FileAs;
FullName = oc.FullName;
Email1Address = ContactPropertiesUtils.GetOutlookEmailAddress1(oc);
MobileTelephoneNumber = oc.MobileTelephoneNumber;
Categories = oc.Categories;
//some contacts can throw "Not a legal OleAut date." exception when accessing LastModificationTime
try
{
LastModificationTime = oc.LastModificationTime;
}
catch
{
LastModificationTime = DateTime.MinValue;
}
Company = oc.CompanyName;
TitleFirstLastAndSuffix = GetTitleFirstLastAndSuffix(oc);
UserProperties.GoogleContactId = ContactPropertiesUtils.GetOutlookGoogleId(oc);
UserProperties.LastSync = ContactPropertiesUtils.GetOutlookLastSync(oc);
}
internal ContactItem GetOriginalItemFromOutlook()
{
if (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.");
}
//"is" operator creates an implicit variable (COM leak), so unfortunately we need to avoid pattern matching
var o = Synchronizer.OutlookNameSpace.GetItemFromID(EntryID);
#pragma warning disable IDE0019 // Use pattern matching
var oc = o as ContactItem;
#pragma warning restore IDE0019 // Use pattern matching
if (oc == 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 oc;
}
internal static string GetTitleFirstLastAndSuffix(ContactItem oc)
{
return ContactPropertiesUtils.GetTitleFirstLastAndSuffix(oc.Title, oc.FirstName, oc.MiddleName, oc.LastName, oc.Suffix);
}
}
}
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.