Menu

[r144]: / trunk / GoogleAPI / src / gcontacts / contactentry.cs  Maximize  Restore  History

Download this file

780 lines (711 with data), 24.7 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/* Copyright (c) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Change history
* Oct 13 2008 Joe Feser joseph.feser@gmail.com
* Converted ArrayLists and other .NET 1.1 collections to use Generics
* Combined IExtensionElement and IExtensionElementFactory interfaces
*
*/
#define USE_TRACING
using System;
using Google.GData.Client;
using Google.GData.Extensions;
namespace Google.GData.Contacts {
//////////////////////////////////////////////////////////////////////
/// <summary>
/// Entry API customization class for defining entries in an Event feed.
/// </summary>
//////////////////////////////////////////////////////////////////////
public class ContactEntry : BaseContactEntry
{
/// <summary>
/// default contact term string for the contact relationship link
/// </summary>
public static string ContactTerm = "http://schemas.google.com/contact/2008#contact";
/// <summary>`
/// Category used to label entries that contain contact extension data.
/// </summary>
public static AtomCategory CONTACT_CATEGORY =
new AtomCategory(ContactEntry.ContactTerm, new AtomUri(BaseNameTable.gKind));
private ExtensionCollection<EMail> emails;
private ExtensionCollection<IMAddress> ims;
private ExtensionCollection<PhoneNumber> phonenumbers;
private ExtensionCollection<StructuredPostalAddress> structuredAddress;
private ExtensionCollection<Organization> organizations;
private ExtensionCollection<GroupMembership> groups;
private ExtensionCollection<CalendarLink> calendars;
private ExtensionCollection<Event> events;
private ExtensionCollection<ExternalId> externalIds;
private ExtensionCollection<Hobby> hobbies;
private ExtensionCollection<Jot> jots;
private ExtensionCollection<Language> languages;
private ExtensionCollection<Relation> relations;
private ExtensionCollection<UserDefinedField> userDefinedFiels;
private ExtensionCollection<Website> websites;
/// <summary>
/// Constructs a new ContactEntry instance with the appropriate category
/// to indicate that it is an event.
/// </summary>
public ContactEntry()
: base()
{
Tracing.TraceMsg("Created Contact Entry");
Categories.Add(CONTACT_CATEGORY);
this.AddExtension(new GroupMembership());
this.AddExtension(new Where());
ContactsKindExtensions.AddExtension(this);
// colletions
this.AddExtension(new CalendarLink());
this.AddExtension(new Event());
this.AddExtension(new ExternalId());
this.AddExtension(new Hobby());
this.AddExtension(new Jot());
this.AddExtension(new Language());
this.AddExtension(new Relation());
this.AddExtension(new UserDefinedField());
this.AddExtension(new Website());
// singletons
this.AddExtension(new BillingInformation());
this.AddExtension(new Birthday());
this.AddExtension(new DirectoryServer());
this.AddExtension(new Initials());
this.AddExtension(new MaidenName());
this.AddExtension(new Mileage());
this.AddExtension(new Nickname());
this.AddExtension(new Occupation());
this.AddExtension(new Priority());
this.AddExtension(new Sensitivity());
this.AddExtension(new ShortName());
this.AddExtension(new Subject());
}
/// <summary>
/// typed override of the Update method
/// </summary>
/// <returns></returns>
public new ContactEntry Update()
{
return base.Update() as ContactEntry;
}
/// <summary>
/// Location associated with the contact
/// </summary>
/// <returns></returns>
public String Location
{
get
{
Where w = FindExtension(GDataParserNameTable.XmlWhereElement, BaseNameTable.gNamespace) as Where;
return w != null ? w.ValueString : null;
}
set
{
Where w = null;
if (value != null)
{
w = new Where(null, null, value);
}
ReplaceExtension(GDataParserNameTable.XmlWhereElement, BaseNameTable.gNamespace, w);
}
}
/// <summary>
/// convienience accessor to find the primary Email
/// there is no setter, to change this use the Primary Flag on
/// an individual object
/// </summary>
public EMail PrimaryEmail
{
get
{
foreach (EMail e in this.Emails)
{
if (e.Primary)
{
return e;
}
}
return null;
}
}
/// <summary>
/// convienience accessor to find the primary Phonenumber
/// there is no setter, to change this use the Primary Flag on
/// an individual object
/// </summary>
public PhoneNumber PrimaryPhonenumber
{
get
{
foreach (PhoneNumber p in this.Phonenumbers)
{
if (p.Primary)
{
return p;
}
}
return null;
}
}
/// <summary>
/// convienience accessor to find the primary PostalAddress
/// there is no setter, to change this use the Primary Flag on
/// an individual object
/// </summary>
public StructuredPostalAddress PrimaryPostalAddress
{
get
{
foreach (StructuredPostalAddress p in this.PostalAddresses)
{
if (p.Primary)
{
return p;
}
}
return null;
}
}
/// <summary>
/// convienience accessor to find the primary IMAddress
/// there is no setter, to change this use the Primary Flag on
/// an individual object
/// </summary>
public IMAddress PrimaryIMAddress
{
get
{
foreach (IMAddress im in this.IMs)
{
if (im.Primary)
{
return im;
}
}
return null;
}
}
/// <summary>
/// returns the groupmembership info on this object
/// </summary>
/// <returns></returns>
public ExtensionCollection<GroupMembership> GroupMembership
{
get
{
if (this.groups == null)
{
this.groups = new ExtensionCollection<GroupMembership>(this);
}
return this.groups;
}
}
/// <summary>
/// getter/setter for the email extension element
/// </summary>
public ExtensionCollection<EMail> Emails
{
get
{
if (this.emails == null)
{
this.emails = new ExtensionCollection<EMail>(this);
}
return this.emails;
}
}
/// <summary>
/// getter/setter for the IM extension element
/// </summary>
public ExtensionCollection<IMAddress> IMs
{
get
{
if (this.ims == null)
{
this.ims = new ExtensionCollection<IMAddress>(this);
}
return this.ims;
}
}
/// <summary>
/// returns the phonenumber collection
/// </summary>
public ExtensionCollection<PhoneNumber> Phonenumbers
{
get
{
if (this.phonenumbers == null)
{
this.phonenumbers = new ExtensionCollection<PhoneNumber>(this);
}
return this.phonenumbers;
}
}
/// <summary>
/// Postal address split into components. It allows to store the address in locale independent format.
/// The fields can be interpreted and used to generate formatted, locale dependent address
/// </summary>
public ExtensionCollection<StructuredPostalAddress> PostalAddresses
{
get
{
if (this.structuredAddress == null)
{
this.structuredAddress = new ExtensionCollection<StructuredPostalAddress>(this);
}
return this.structuredAddress;
}
}
/// <summary>
/// returns the phonenumber collection
/// </summary>
public ExtensionCollection<Organization> Organizations
{
get
{
if (this.organizations == null)
{
this.organizations = new ExtensionCollection<Organization>(this);
}
return this.organizations;
}
}
/// <summary>
/// getter for the CalendarLink collections
/// </summary>
public ExtensionCollection<CalendarLink> Calendars
{
get
{
if (this.calendars == null)
{
this.calendars = new ExtensionCollection<CalendarLink>(this);
}
return this.calendars;
}
}
/// <summary>
/// getter for the Events collections
/// </summary>
public ExtensionCollection<Event> Events
{
get
{
if (this.events == null)
{
this.events = new ExtensionCollection<Event>(this);
}
return this.events;
}
}
/// <summary>
/// getter for the externalids collections
/// </summary>
public ExtensionCollection<ExternalId> ExternalIds
{
get
{
if (this.externalIds == null)
{
this.externalIds = new ExtensionCollection<ExternalId>(this);
}
return this.externalIds;
}
}
/// <summary>
/// getter for the Hobby collections
/// </summary>
public ExtensionCollection<Hobby> Hobbies
{
get
{
if (this.hobbies == null)
{
this.hobbies = new ExtensionCollection<Hobby>(this);
}
return this.hobbies;
}
}
/// <summary>
/// getter for the Jot collections
/// </summary>
public ExtensionCollection<Jot> Jots
{
get
{
if (this.jots == null)
{
this.jots = new ExtensionCollection<Jot>(this);
}
return this.jots;
}
}
/// <summary>
/// getter for the languages collections
/// </summary>
public ExtensionCollection<Language> Languages
{
get
{
if (this.languages == null)
{
this.languages = new ExtensionCollection<Language>(this);
}
return this.languages;
}
}
/// <summary>
/// getter for the Relation collections
/// </summary>
public ExtensionCollection<Relation> Relations
{
get
{
if (this.relations == null)
{
this.relations = new ExtensionCollection<Relation>(this);
}
return this.relations;
}
}
/// <summary>
/// getter for the UserDefinedField collections
/// </summary>
public ExtensionCollection<UserDefinedField> UserDefinedFields
{
get
{
if (this.userDefinedFiels == null)
{
this.userDefinedFiels = new ExtensionCollection<UserDefinedField>(this);
}
return this.userDefinedFiels;
}
}
/// <summary>
/// getter for the website collections
/// </summary>
public ExtensionCollection<Website> Websites
{
get
{
if (this.websites == null)
{
this.websites = new ExtensionCollection<Website>(this);
}
return this.websites;
}
}
/// <summary>
/// retrieves the Uri of the Photo Link. To set this, you need to create an AtomLink object
/// and add/replace it in the atomlinks colleciton.
/// </summary>
/// <returns></returns>
public Uri PhotoUri
{
get
{
AtomLink link = this.Links.FindService(GDataParserNameTable.ServicePhoto, null);
return link == null ? null : new Uri(link.HRef.ToString());
}
}
/// <summary>
/// if a photo is present on this contact, it will have an etag associated with it,
/// that needs to be used when you want to delete or update that picture.
/// </summary>
/// <returns>the etag value as a string</returns>
public string PhotoEtag
{
get
{
AtomLink link = this.PhotoLink;
if (link != null)
{
foreach (XmlExtension x in link.ExtensionElements)
{
if (x.XmlNameSpace == GDataParserNameTable.gNamespace && x.XmlName == GDataParserNameTable.XmlEtagAttribute)
{
return x.Node.Value;
}
}
}
return null;
}
set
{
AtomLink link = this.PhotoLink;
if (link != null)
{
foreach (XmlExtension x in link.ExtensionElements)
{
if (x.XmlNameSpace == GDataParserNameTable.gNamespace && x.XmlName == GDataParserNameTable.XmlEtagAttribute)
{
x.Node.Value = value;
}
}
}
}
}
private AtomLink PhotoLink
{
get
{
AtomLink link = this.Links.FindService(GDataParserNameTable.ServicePhoto, null);
return link;
}
}
/// <summary>
/// returns the Name object
/// </summary>
public Name Name
{
get
{
return FindExtension(GDataParserNameTable.NameElement, BaseNameTable.gNamespace) as Name;
}
set
{
ReplaceExtension(GDataParserNameTable.NameElement, BaseNameTable.gNamespace, value);
}
}
/// <summary>
/// Contacts billing information.
/// </summary>
/// <returns></returns>
public string BillingInformation
{
get
{
return GetStringValue<BillingInformation>(ContactsNameTable.BillingInformationElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<BillingInformation>(value, ContactsNameTable.BillingInformationElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Contact's birthday.
/// </summary>
/// <returns></returns>
public string Birthday
{
get
{
Birthday b = FindExtension(ContactsNameTable.BirthdayElement, ContactsNameTable.NSContacts) as Birthday;
if (b != null)
{
return b.When;
}
return null;
}
set
{
Birthday b = null;
if (value != null)
{
b = new Birthday(value);
}
ReplaceExtension(ContactsNameTable.BirthdayElement, ContactsNameTable.NSContacts, b);
}
}
/// <summary>
/// Directory server associated with the contact.
/// </summary>
/// <returns></returns>
public string DirectoryServer
{
get
{
return GetStringValue<DirectoryServer>(ContactsNameTable.DirectoryServerElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<DirectoryServer>(value, ContactsNameTable.DirectoryServerElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Contacts initals
/// </summary>
/// <returns></returns>
public string Initials
{
get
{
return GetStringValue<Initials>(ContactsNameTable.InitialsElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<Initials>(value, ContactsNameTable.InitialsElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Maiden name associated with the contact.
/// </summary>
/// <returns></returns>
public string MaidenName
{
get
{
return GetStringValue<MaidenName>(ContactsNameTable.MaidenNameElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<MaidenName>(value, ContactsNameTable.MaidenNameElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Mileage associated with the contact.
/// </summary>
/// <returns></returns>
public string Mileage
{
get
{
return GetStringValue<Mileage>(ContactsNameTable.MileageElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<Mileage>(value, ContactsNameTable.MileageElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Nickname associated with the contact.
/// </summary>
/// <returns></returns>
public string Nickname
{
get
{
return GetStringValue<Nickname>(ContactsNameTable.NicknameElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<Nickname>(value, ContactsNameTable.NicknameElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Occupation associated with the contact.
/// </summary>
/// <returns></returns>
public string Occupation
{
get
{
return GetStringValue<Occupation>(ContactsNameTable.OccupationElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<Occupation>(value, ContactsNameTable.OccupationElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Priority ascribed to the contact.
/// </summary>
/// <returns></returns>
public string Priority
{
get
{
Priority b = FindExtension(ContactsNameTable.PriorityElement, ContactsNameTable.NSContacts) as Priority;
if (b != null)
{
return b.Relation;
}
return null;
}
set
{
Priority b = null;
if (value != null)
{
b = new Priority(value);
}
ReplaceExtension(ContactsNameTable.PriorityElement, ContactsNameTable.NSContacts, b);
}
}
/// <summary>
/// Sensitivity ascribed to the contact.
/// </summary>
/// <returns></returns>
public string Sensitivity
{
get
{
Sensitivity b = FindExtension(ContactsNameTable.SensitivityElement, ContactsNameTable.NSContacts) as Sensitivity;
if (b != null)
{
return b.Relation;
}
return null;
}
set
{
Sensitivity b = null;
if (value != null)
{
b = new Sensitivity(value);
}
ReplaceExtension(ContactsNameTable.SensitivityElement, ContactsNameTable.NSContacts, b);
}
}
/// <summary>
/// Contact's short name.
/// </summary>
/// <returns></returns>
public string ShortName
{
get
{
return GetStringValue<ShortName>(ContactsNameTable.ShortNameElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<ShortName>(value, ContactsNameTable.ShortNameElement,
ContactsNameTable.NSContacts);
}
}
/// <summary>
/// Subject associated with the contact.
/// </summary>
/// <returns></returns>
public string Subject
{
get
{
return GetStringValue<Subject>(ContactsNameTable.SubjectElement,
ContactsNameTable.NSContacts);
}
set
{
SetStringValue<Subject>(value, ContactsNameTable.SubjectElement,
ContactsNameTable.NSContacts);
}
}
}
}
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.