Menu

[r241]: / trunk / GoogleContactsSync / ConflictResolver.cs  Maximize  Restore  History

Download this file

184 lines (159 with data), 8.8 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using System.Text;
using Google.Contacts;
using Google.Documents;
using System.Reflection;
using Google.GData.Extensions;
namespace GoContactSyncMod
{
class ConflictResolver : IConflictResolver
{
private ConflictResolverForm _form;
public ConflictResolver()
{
_form = new ConflictResolverForm();
}
public ConflictResolver(ConflictResolverForm form)
{
_form = form;
}
#region IConflictResolver Members
public ConflictResolution Resolve(Microsoft.Office.Interop.Outlook.ContactItem outlookContact, Contact googleContact)
{
string name = googleContact.Title;
if (string.IsNullOrEmpty(name))
name = googleContact.Name.FullName;
if (string.IsNullOrEmpty(name) && googleContact.Organizations.Count > 0)
name = googleContact.Organizations[0].Name;
if (string.IsNullOrEmpty(name) && googleContact.Emails.Count > 0)
name = googleContact.Emails[0].Address;
_form.messageLabel.Text =
"Both the outlook contact and the google contact \"" + name +
"\" have been changed. Choose which you would like to keep.";
_form.OutlookItemTextBox.Text = "Name: " + outlookContact.FileAs + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.Email1Address))
_form.OutlookItemTextBox.Text += "Email1: " + outlookContact.Email1Address + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.Email2Address))
_form.OutlookItemTextBox.Text += "Email2: " + outlookContact.Email2Address + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.Email3Address))
_form.OutlookItemTextBox.Text += "Email3: " + outlookContact.Email3Address + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.MobileTelephoneNumber))
_form.OutlookItemTextBox.Text += "MobilePhone: " + outlookContact.MobileTelephoneNumber + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.HomeTelephoneNumber))
_form.OutlookItemTextBox.Text += "HomePhone: " + outlookContact.HomeTelephoneNumber + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.Home2TelephoneNumber))
_form.OutlookItemTextBox.Text += "HomePhone2: " + outlookContact.HomeTelephoneNumber + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.BusinessTelephoneNumber))
_form.OutlookItemTextBox.Text += "BusinessPhone: " + outlookContact.BusinessTelephoneNumber + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.Business2TelephoneNumber))
_form.OutlookItemTextBox.Text += "BusinessPhone2: " + outlookContact.BusinessTelephoneNumber + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.OtherTelephoneNumber))
_form.OutlookItemTextBox.Text += "OtherPhone: " + outlookContact.OtherTelephoneNumber + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.HomeAddress))
_form.OutlookItemTextBox.Text += "HomeAddress: " + outlookContact.HomeAddress + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.BusinessAddress))
_form.OutlookItemTextBox.Text += "BusinessAddress: " + outlookContact.BusinessAddress + "\r\n";
if (!string.IsNullOrEmpty(outlookContact.OtherAddress))
_form.OutlookItemTextBox.Text += "OtherAddress: " + outlookContact.OtherAddress + "\r\n";
_form.GoogleItemTextBox.Text = "Name: " + googleContact.Name.FullName + "\r\n";
for (int i = 0; i < googleContact.Emails.Count; i++)
{
string email = googleContact.Emails[i].Address;
if (!string.IsNullOrEmpty(email))
{
_form.GoogleItemTextBox.Text += "Email" + (i+1) + ": " + email + "\r\n";
}
}
foreach (PhoneNumber phone in googleContact.Phonenumbers)
{
if (!string.IsNullOrEmpty(phone.Value))
{
if (phone.Rel == ContactsRelationships.IsMobile)
_form.GoogleItemTextBox.Text += "MobilePhone: ";
if (phone.Rel == ContactsRelationships.IsHome)
_form.GoogleItemTextBox.Text += "HomePhone: ";
if (phone.Rel == ContactsRelationships.IsWork)
_form.GoogleItemTextBox.Text += "BusinessPhone: ";
if (phone.Rel == ContactsRelationships.IsOther)
_form.GoogleItemTextBox.Text += "OtherPhone: ";
_form.GoogleItemTextBox.Text += phone.Value + "\r\n";
}
}
foreach (StructuredPostalAddress address in googleContact.PostalAddresses)
{
if (!string.IsNullOrEmpty(address.FormattedAddress))
{
if (address.Rel == ContactsRelationships.IsHome)
_form.GoogleItemTextBox.Text += "HomeAddress: ";
if (address.Rel == ContactsRelationships.IsWork)
_form.GoogleItemTextBox.Text += "BusinessAddress: ";
if (address.Rel == ContactsRelationships.IsOther)
_form.GoogleItemTextBox.Text += "OtherAddress: ";
_form.GoogleItemTextBox.Text += address.FormattedAddress + "\r\n";
}
}
switch (_form.ShowDialog())
{
case System.Windows.Forms.DialogResult.Ignore:
// skip
return ConflictResolution.Skip;
case System.Windows.Forms.DialogResult.Cancel:
// cancel
return ConflictResolution.Cancel;
case System.Windows.Forms.DialogResult.No:
// google wins
return _form.AllCheckBox.Checked?ConflictResolution.GoogleWinsAlways:ConflictResolution.GoogleWins;
case System.Windows.Forms.DialogResult.Yes:
// outlook wins
return _form.AllCheckBox.Checked?ConflictResolution.OutlookWinsAlways:ConflictResolution.OutlookWins;
default:
throw new Exception();
}
}
//private string GetPropertyInfos(object myObject)
//{
// // get all public static properties of OutlookItem
// PropertyInfo[] propertyInfos;
// propertyInfos = myObject.GetType().GetProperties();
// // sort properties by name
// Array.Sort(propertyInfos,
// delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
// { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); });
// string ret = String.Empty;
// // write property names
// foreach (PropertyInfo propertyInfo in propertyInfos)
// {
// object value = propertyInfo.GetValue(myObject, null);
// if (value != null && !(value is string))
// ret += propertyInfo.Name + ": " + value + "\r\n";
// }
// return ret;
//}
public ConflictResolution Resolve(Microsoft.Office.Interop.Outlook.NoteItem outlookNote, Document googleNote)
{
string name = googleNote.Title;
_form.messageLabel.Text =
"Both the outlook note and the google note \"" + name +
"\" have been changed. Choose which you would like to keep.";
switch (_form.ShowDialog())
{
case System.Windows.Forms.DialogResult.Ignore:
// skip
return ConflictResolution.Skip;
case System.Windows.Forms.DialogResult.Cancel:
// cancel
return ConflictResolution.Cancel;
case System.Windows.Forms.DialogResult.No:
// google wins
return ConflictResolution.GoogleWins;
case System.Windows.Forms.DialogResult.Yes:
// outlook wins
return ConflictResolution.OutlookWins;
default:
throw new Exception();
}
}
#endregion
}
}
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.