~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/NU-AddressBook/.svn/text-base/Group.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com 
20
 
 |
21
 
 |  Author: Brady Anderson <banderso@novell.com>
22
 
        /***********************************************************************
23
 
        * This source file implements the Group class.
24
 
        * Groups are implemented as Node objects contained within an 
25
 
        * AddressBook (collection).  Relationship objects are used to link
26
 
        * Contacts to a Group
27
 
        *
28
 
        ***********************************************************************/
29
 
 |***************************************************************************/
30
 
 
31
 
 
32
 
 
33
 
 
34
 
using System;
35
 
using System.IO;
36
 
using System.Collections;
37
 
using Simias;
38
 
using Simias.Storage;
39
 
 
40
 
namespace Novell.AddressBook
41
 
{
42
 
        /// <summary>
43
 
        /// Summary description for Group.
44
 
        /// A Group is equivalent to a Node in the collection store.
45
 
        /// </summary>
46
 
        public class Group : Node
47
 
        {
48
 
                #region Class Members
49
 
                internal        AddressBook             addressBook = null;
50
 
//              private         IEnumerator             thisEnum = null;
51
 
                internal        ArrayList               addressList;
52
 
                private         Stream                  logoStream = null;
53
 
 
54
 
                #endregion
55
 
 
56
 
                #region Properties
57
 
 
58
 
                /// <summary>
59
 
                /// Description of the Group
60
 
                /// !NOTE! Doc incomplete
61
 
                /// </summary>
62
 
                public string Description
63
 
                {
64
 
                        get
65
 
                        {
66
 
                                try
67
 
                                {
68
 
                                        return(
69
 
                                                this.Properties.GetSingleProperty(
70
 
                                                        Common.groupDescriptionProperty).ToString());
71
 
                                }
72
 
                                catch{}
73
 
                                return("");
74
 
                        }
75
 
 
76
 
                        set
77
 
                        {
78
 
                                try
79
 
                                {
80
 
                                        if (value != null)
81
 
                                        {
82
 
                                                this.Properties.ModifyProperty(
83
 
                                                        Common.groupDescriptionProperty, 
84
 
                                                        (string) value);
85
 
                                        }
86
 
                                        else
87
 
                                        {
88
 
                                                this.Properties.DeleteProperties(
89
 
                                                        Common.groupDescriptionProperty);
90
 
                                        }
91
 
                                }
92
 
                                catch{}
93
 
                        }
94
 
                }
95
 
 
96
 
                /// <summary>
97
 
                /// Url: Specifies the a url to the Group's web page
98
 
                ///
99
 
                /// Type Value: Single text value
100
 
                ///
101
 
                /// Example: http://www.eatatjoes.com
102
 
                ///
103
 
                /// </summary>
104
 
                public string Url
105
 
                {
106
 
                        get
107
 
                        {
108
 
                                try
109
 
                                {
110
 
                                        return(
111
 
                                                this.Properties.GetSingleProperty(
112
 
                                                        Common.urlProperty).ToString());
113
 
                                }
114
 
                                catch{}
115
 
                                return("");
116
 
                        }
117
 
 
118
 
                        set
119
 
                        {
120
 
                                try
121
 
                                {
122
 
                                        if (value != null)
123
 
                                        {
124
 
                                                this.Properties.ModifyProperty(
125
 
                                                        Common.urlProperty, 
126
 
                                                        (string) value);
127
 
                                        }
128
 
                                        else
129
 
                                        {
130
 
                                                this.Properties.DeleteProperties(
131
 
                                                        Common.urlProperty);
132
 
                                        }
133
 
                                }
134
 
                                catch{}
135
 
                        }
136
 
                }
137
 
 
138
 
                /// <summary>
139
 
                /// NOTE: latest notes about the Group
140
 
                ///
141
 
                /// Type Value: single value - text
142
 
                ///
143
 
                /// Example: blah, blah, blah...
144
 
                ///
145
 
                /// </summary>
146
 
                public string Note
147
 
                {
148
 
                        get
149
 
                        {
150
 
                                try
151
 
                                {
152
 
                                        return(
153
 
                                                this.Properties.GetSingleProperty(
154
 
                                                        Common.noteProperty).ToString());
155
 
                                }
156
 
                                catch{}
157
 
                                return("");
158
 
                        }
159
 
 
160
 
                        set
161
 
                        {
162
 
                                try
163
 
                                {
164
 
                                        if (value != null)
165
 
                                        {
166
 
                                                this.Properties.ModifyProperty(
167
 
                                                        Common.noteProperty, 
168
 
                                                        (string) value);
169
 
                                        }
170
 
                                        else
171
 
                                        {
172
 
                                                this.Properties.DeleteProperties(
173
 
                                                        Common.noteProperty);
174
 
                                        }
175
 
                                }
176
 
                                catch{}
177
 
                        }
178
 
                }
179
 
 
180
 
                /// <summary>
181
 
                /// Blog: Specifies the Group's blog url
182
 
                ///
183
 
                /// Type Value: Single text value
184
 
                ///
185
 
                /// Example: http://simiasteam.blogdomain.com
186
 
                ///
187
 
                /// </summary>
188
 
                public string Blog
189
 
                {
190
 
                        get
191
 
                        {
192
 
                                try
193
 
                                {
194
 
                                        return(
195
 
                                                this.Properties.GetSingleProperty(
196
 
                                                        Common.blogProperty).ToString());
197
 
                                }
198
 
                                catch{}
199
 
                                return("");
200
 
                        }
201
 
 
202
 
                        set
203
 
                        {
204
 
                                try
205
 
                                {
206
 
                                        if (value != null)
207
 
                                        {
208
 
                                                this.Properties.ModifyProperty(
209
 
                                                        Common.blogProperty, 
210
 
                                                        (string) value);
211
 
                                        }
212
 
                                        else
213
 
                                        {
214
 
                                                this.Properties.DeleteProperties(Common.blogProperty);
215
 
                                        }
216
 
                                }
217
 
                                catch{}
218
 
                        }
219
 
                }
220
 
 
221
 
                /// <summary>
222
 
                /// Calendar: Specifies the Group's calendar url
223
 
                ///
224
 
                /// Type Value: Single text value
225
 
                ///
226
 
                /// Example: http://simiasteam.company.com/groupname/ical
227
 
                ///
228
 
                /// </summary>
229
 
                public string Calendar
230
 
                {
231
 
                        get
232
 
                        {
233
 
                                try
234
 
                                {
235
 
                                        return(
236
 
                                                this.Properties.GetSingleProperty(
237
 
                                                        Common.calProperty).ToString());
238
 
                                }
239
 
                                catch{}
240
 
                                return("");
241
 
                        }
242
 
 
243
 
                        set
244
 
                        {
245
 
                                try
246
 
                                {
247
 
                                        if (value != null)
248
 
                                        {
249
 
                                                this.Properties.ModifyProperty(
250
 
                                                        Common.calProperty, 
251
 
                                                        (string) value);
252
 
                                        }
253
 
                                        else
254
 
                                        {
255
 
                                                this.Properties.DeleteProperties(Common.calProperty);
256
 
                                        }
257
 
                                }
258
 
                                catch{}
259
 
                        }
260
 
                }
261
 
                #endregion
262
 
 
263
 
                #region Constructors
264
 
 
265
 
                internal Group(AddressBook addressBook, Node cNode) : base(cNode)
266
 
                {
267
 
                        this.addressList = new ArrayList();
268
 
                        this.ToObject();
269
 
                }
270
 
 
271
 
                /// <summary>
272
 
                /// Simple Group constructor
273
 
                /// </summary>
274
 
                public Group() : base("")
275
 
                {
276
 
                        this.addressList = new ArrayList();
277
 
                }
278
 
 
279
 
                /// <summary>
280
 
                /// Group constructor that names the group upon construction
281
 
                /// </summary>
282
 
                public Group(string groupName) : base(groupName)
283
 
                {
284
 
                        this.addressList = new ArrayList();
285
 
                }
286
 
 
287
 
                #endregion
288
 
 
289
 
                #region Private Methods
290
 
 
291
 
                internal void Add(AddressBook addressBook)
292
 
                {
293
 
                        try
294
 
                        {
295
 
                                this.addressBook = addressBook;
296
 
                                if (this.Name != null && this.Name != "")
297
 
                                {
298
 
                                        // Add a relationship that will reference the parent Node.
299
 
                                        Relationship parentChild = new
300
 
                                                Relationship( addressBook.ID, this.ID );
301
 
                                        this.Properties.AddProperty( Common.groupToAddressBook, parentChild );
302
 
 
303
 
                                        if (this.addressList.Count > 0)
304
 
                                        {
305
 
                                                foreach(Address cAddress in this.addressList)
306
 
                                                {
307
 
                                                        Relationship addressAndContact = new
308
 
                                                                Relationship(addressBook.ID, this.ID );
309
 
                                                        cAddress.Properties.AddProperty( Common.addressToGroup, addressAndContact );
310
 
                                                }
311
 
                                        }
312
 
                                        return;
313
 
                                }
314
 
                        }
315
 
                        catch{}
316
 
                        throw new ApplicationException(
317
 
                                                Common.addressBookExceptionHeader + "Group - missing \"Name\" property");
318
 
                }
319
 
 
320
 
                /// <summary>
321
 
                /// Retrieves a group from the collection store and deserializes
322
 
                /// to the properties in the Group object.
323
 
                /// <remarks>
324
 
                /// An exception is thrown if the contact can't be find by the
325
 
                /// specified ID
326
 
                /// </remarks>
327
 
                /// <returns>None</returns>
328
 
                /// </summary>
329
 
                internal void ToObject()
330
 
                {
331
 
                        try
332
 
                        {
333
 
                                // Load up the addresses
334
 
                                this.addressList.Clear();
335
 
                                Relationship parentChild =
336
 
                                        new Relationship( this.addressBook.ID, this.ID );
337
 
                                ICSList results =
338
 
                                        this.addressBook.Search( Common.addressToGroup, parentChild );
339
 
                                foreach ( ShallowNode cShallow in results )
340
 
                                {
341
 
                                        Node cNode = new Node(this.addressBook, cShallow);
342
 
                                        if (this.addressBook.IsType(cNode, Common.addressProperty) == true)
343
 
                                        {
344
 
                                                this.addressList.Add(new Group(this.addressBook, cNode));
345
 
                                        }
346
 
                                }
347
 
                        }
348
 
                        catch{}
349
 
                }
350
 
                #endregion
351
 
 
352
 
                #region Public Methods
353
 
 
354
 
                /// <summary>
355
 
                /// Commits any changes to the Group object.
356
 
                /// </summary>
357
 
                public void Commit()
358
 
                {
359
 
                        if (this.addressBook != null)
360
 
                        {
361
 
                                this.addressBook.SetType(this, Common.groupType);
362
 
 
363
 
                                int nodesToCommit = 1 + this.addressList.Count;
364
 
 
365
 
                                Node[] commitList = new Node[nodesToCommit];
366
 
                                int     i = 0;
367
 
                                commitList[i++] = this;
368
 
 
369
 
                                if (this.addressList.Count > 0)
370
 
                                {
371
 
                                        Novell.AddressBook.Address.PrepareToCommit(this);
372
 
                                        foreach(Address cAddr in this.addressList)
373
 
                                        {
374
 
                                                this.addressBook.SetType(cAddr, Common.addressProperty);
375
 
                                                commitList[i++] = cAddr;
376
 
                                        }
377
 
                                }
378
 
 
379
 
                                this.addressBook.Commit(commitList);
380
 
                        }
381
 
                }
382
 
 
383
 
                /// <summary>
384
 
                /// Deletes the current Group object.
385
 
                /// </summary>
386
 
                public Node[] Delete(bool commit)
387
 
                {
388
 
                        Node[] nodeList = new Node[1 + this.addressList.Count];
389
 
                        int     idx = 0;
390
 
 
391
 
                        foreach(Address cAddress in this.addressList)
392
 
                        {
393
 
                                nodeList[idx++] = cAddress;
394
 
                        }
395
 
                        this.addressList.Clear();
396
 
 
397
 
                        try
398
 
                        {
399
 
                                if (this.addressBook != null &&
400
 
                                        this.addressBook != null)
401
 
                                {
402
 
                                        nodeList[idx++] = this;
403
 
 
404
 
                                        if (commit == true)
405
 
                                        {
406
 
                                                this.addressBook.Commit(
407
 
                                                        this.addressBook.Delete(nodeList));
408
 
                                        }
409
 
                                        else
410
 
                                        {
411
 
                                                this.addressBook.Delete(nodeList);
412
 
                                        }
413
 
                                }
414
 
                        }
415
 
                        catch{}
416
 
 
417
 
                        // Return the list of nodes that were deleted
418
 
                        return(nodeList);
419
 
                }
420
 
 
421
 
                /// <summary>
422
 
                /// Deletes the current Group object.
423
 
                /// </summary>
424
 
                public void Delete()
425
 
                {
426
 
                        this.Delete(true);
427
 
                }
428
 
 
429
 
                /// <summary>
430
 
                /// Adds a contact to the group
431
 
                /// </summary>
432
 
                /// <remarks>
433
 
                /// If for any reason the contact cannot be added
434
 
                /// an exception is raised.
435
 
                /// </remarks>
436
 
                public void AddContact(Contact cContact)
437
 
                {
438
 
                        try
439
 
                        {
440
 
                                // Add a relationship that will reference the contact Node.
441
 
                                Relationship parentChild = new
442
 
                                        Relationship( this.ID, cContact.ID );
443
 
                                this.Properties.AddProperty( Common.groupToContact, parentChild );
444
 
                                return;
445
 
                        }
446
 
                        catch{}
447
 
                        throw new ApplicationException(Common.addressBookExceptionHeader + "Failed adding Contact");
448
 
                }
449
 
 
450
 
                /// <summary>
451
 
                /// Gets the list of contacts attached to this Group.
452
 
                /// </summary>
453
 
                public IABList GetContactList()
454
 
                {
455
 
                        IABList cList = new IABList();
456
 
 
457
 
                        try
458
 
                        {
459
 
                                MultiValuedList mList = this.Properties.GetProperties(Common.groupToContact);
460
 
                                foreach(Property p in mList)
461
 
                                {
462
 
                                        if (p != null)
463
 
                                        {
464
 
                                                Simias.Storage.Relationship relationship = 
465
 
                                                        (Simias.Storage.Relationship) p.Value;
466
 
 
467
 
                                                Node cContactNode = 
468
 
                                                        this.addressBook.GetNodeByID(relationship.NodeID);
469
 
                                                if (this.addressBook.IsType(cContactNode, Common.contactType) == true)
470
 
                                                {
471
 
                                                        cList.Add(this.addressBook.GetContact(cContactNode.ID));
472
 
                                                }
473
 
 
474
 
                                        }
475
 
                                }
476
 
 
477
 
                                /*
478
 
                                Relationship parentChild =
479
 
                                        new Relationship( this.ID, this.ID );
480
 
                                ICSList results =
481
 
                                        this.addressBook.collection.Search( Common.groupToContact, parentChild );
482
 
                                foreach ( ShallowNode cShallow in results )
483
 
                                {
484
 
                                        Node cNode = new Node(this.addressBook.collection, cShallow);
485
 
                                        if (this.addressBook.collection.IsType(cNode, Common.contactType) == true)
486
 
                                        {
487
 
                                                cList.Add(new Contact(this.addressBook, cNode));
488
 
                                        }
489
 
                                }
490
 
                                */
491
 
                        }
492
 
                        catch{}
493
 
                        return(cList);
494
 
                }
495
 
 
496
 
                /// <summary>
497
 
                /// Remove contact from group
498
 
                /// </summary>
499
 
                /// <remarks>
500
 
                /// </remarks>
501
 
                public void RemoveContact(Contact cContact)
502
 
                {
503
 
                        try
504
 
                        {
505
 
                                MultiValuedList mList = this.Properties.GetProperties(Common.groupToContact);
506
 
                                foreach(Property p in mList)
507
 
                                {
508
 
                                        if (((Relationship) p.Value).NodeID == cContact.ID)
509
 
                                        {
510
 
                                                p.Delete();
511
 
                                                break;
512
 
                                        }
513
 
                                }
514
 
                        }
515
 
                        catch{}
516
 
                        return;
517
 
                }
518
 
 
519
 
                /// <summary>
520
 
                /// Adds a vCard ADR property to the Group.
521
 
                /// </summary>
522
 
                /// <remarks>
523
 
                /// vCard ADR is a structured property consisting of:
524
 
                /// Street, Region, Locality, Country and Extended Address
525
 
                ///
526
 
                /// Each Group may have one preferred ADR.
527
 
                ///
528
 
                /// If for any reason the ADR cannot be created an exception is raised.
529
 
                /// </remarks>
530
 
                public void AddAddress(Address addr)
531
 
                {
532
 
                        try
533
 
                        {
534
 
                                addr.Add(this);
535
 
                                return;
536
 
                        }
537
 
                        catch{}
538
 
                        throw new ApplicationException(Common.addressBookExceptionHeader + "Failed adding Address");
539
 
                }
540
 
 
541
 
                /// <summary>
542
 
                /// Gets a list of addresses attached to this Group.
543
 
                /// </summary>
544
 
                public IABList GetAddresses()
545
 
                {
546
 
                        IABList cList = new IABList();
547
 
 
548
 
                        try
549
 
                        {
550
 
                                foreach(Address addr in this.addressList)
551
 
                                {
552
 
                                        cList.Add(addr);
553
 
                                }
554
 
                        }
555
 
                        catch{}
556
 
                        return(cList);
557
 
                }
558
 
 
559
 
                /// <summary>
560
 
                /// Gets the preferred address for this Group.
561
 
                /// </summary>
562
 
                public Address GetPreferredAddress()
563
 
                {
564
 
                        foreach(Address addr in this.addressList)
565
 
                        {
566
 
                                if (addr.Preferred == true)
567
 
                                {
568
 
                                        return(addr);
569
 
                                }
570
 
                        }
571
 
 
572
 
                        return(null);
573
 
                }
574
 
 
575
 
                /// <summary>
576
 
                /// Deletes an Address record in a Group.
577
 
                /// A Group may contain 0 to many address records
578
 
                /// </summary>
579
 
                public void DeleteAddress(string addressID)
580
 
                {
581
 
                        try
582
 
                        {
583
 
                                foreach(Address addr in this.addressList)
584
 
                                {
585
 
                                        if (addr.ID == addressID)
586
 
                                        {
587
 
                                                addr.Delete();
588
 
                                                return;
589
 
                                        }
590
 
                                }
591
 
                        }
592
 
                        catch{}
593
 
 
594
 
                        // FIXME - log this condition
595
 
                        return;
596
 
                }
597
 
 
598
 
                /// <summary>
599
 
                /// Retrieve a vCard ADR property based on an address ID.
600
 
                /// </summary>
601
 
                /// <param name="addressID">Address ID</param>
602
 
                /// <remarks>
603
 
                /// vCard Address is a structured property consisting of:
604
 
                /// Post Office Box, Extended Address, Street Address, Locality,
605
 
                /// Region, Postal Code and Country
606
 
                ///
607
 
                /// Each contact may have one preferred Address.
608
 
                ///
609
 
                /// If for any reason the Address can't be retrieved an an exception is raised.
610
 
                /// </remarks>
611
 
                /// <returns>An Address object with a valid postal code property.</returns>
612
 
                public Address GetAddress(string addressID)
613
 
                {
614
 
                        try
615
 
                        {
616
 
                                foreach(Address cAddress in this.addressList)
617
 
                                {
618
 
                                        if (cAddress.ID == addressID)
619
 
                                        {
620
 
                                                return(cAddress);
621
 
                                        }
622
 
                                }
623
 
                        }
624
 
                        catch{}
625
 
 
626
 
                        // FIXME - log this condition
627
 
                        return(null);
628
 
                }
629
 
 
630
 
                /// <summary>
631
 
                /// Export the Group logo via a binary Stream object.
632
 
                /// </summary>
633
 
                /// <remarks>
634
 
                /// vCard LOGO is a single valued binary property
635
 
                ///
636
 
                /// An exception is raised if the Group does not contain
637
 
                /// a logo property.
638
 
                ///
639
 
                /// NOTE: The caller is expected to close the returned
640
 
                /// stream object when finished.
641
 
                /// </remarks>
642
 
                /// <returns>A binary stream object which the caller can read from.</returns>
643
 
                public Stream ExportLogo()
644
 
                {
645
 
                        if (this.addressBook != null)
646
 
                        {
647
 
                                try
648
 
                                {
649
 
                                        Property p = this.Properties.GetSingleProperty(Common.groupToLogo);
650
 
                                        if (p != null)
651
 
                                        {
652
 
                                                Simias.Storage.Relationship relationship =
653
 
                                                        (Simias.Storage.Relationship) p.Value;
654
 
 
655
 
                                                Node cLogoNode =
656
 
                                                        this.addressBook.GetNodeByID(relationship.NodeID);
657
 
 
658
 
                                                if (cLogoNode != null)
659
 
                                                {
660
 
                                                        StoreFileNode sfn = new StoreFileNode(cLogoNode);
661
 
                                                        
662
 
                                                        return(new
663
 
                                                                FileStream(
664
 
                                                                        sfn.GetFullPath(this.addressBook),
665
 
                                                                        FileMode.Open,
666
 
                                                                        FileAccess.Read,
667
 
                                                                        FileShare.Read ));
668
 
                                                }
669
 
                                        }
670
 
                                }
671
 
                                catch{}
672
 
                                throw new ApplicationException(Common.addressBookExceptionHeader + "Logo property does not exist");
673
 
                        }
674
 
                        else
675
 
                        {
676
 
                                if(this.logoStream != null)
677
 
                                {
678
 
                                        return(this.logoStream);
679
 
                                }
680
 
 
681
 
                                throw new ApplicationException(Common.addressBookExceptionHeader + "Logo property does not exist");
682
 
                        }
683
 
                }
684
 
 
685
 
                /// <summary>
686
 
                /// Imports a logo photo from a a file name.
687
 
                /// </summary>
688
 
                /// <param name="fileName">Source Filename</param>
689
 
                /// <remarks>
690
 
                /// vCard PHOTO is a single valued binary property
691
 
                /// </remarks>
692
 
                /// <returns>true if the photo was successfully imported.</returns>
693
 
                public bool ImportLogo(string fileName)
694
 
                {
695
 
                        bool    results = false;
696
 
                        Stream  srcStream = null;
697
 
 
698
 
                        try
699
 
                        {
700
 
                                srcStream = new FileStream(fileName, FileMode.Open);
701
 
                                results = this.ImportLogo(srcStream);
702
 
                                // BUGBUG store the source file name in the store - where it came from
703
 
                        }
704
 
                        catch{}
705
 
                        finally
706
 
                        {
707
 
                                if (srcStream != null)
708
 
                                {
709
 
                                        srcStream.Close();
710
 
                                }
711
 
                        }
712
 
 
713
 
                        return(results);
714
 
                }
715
 
 
716
 
                /// <summary>
717
 
                /// Imports a logo photo from a stream object.
718
 
                /// </summary>
719
 
                /// <param name="srcStream">Source Stream</param>
720
 
                /// <remarks>
721
 
                /// vCard LOGO is a single valued binary property
722
 
                /// </remarks>
723
 
                /// <returns>true if the logo photo was successfully imported.</returns>
724
 
                public bool     ImportLogo(Stream srcStream)
725
 
                {
726
 
                        bool                    finished = false;
727
 
                        StoreFileNode   sfn = null;
728
 
                        //NodeStream            photoStream = null;
729
 
                        //Stream                        dstStream = null;
730
 
 
731
 
                        if (this.addressBook != null)
732
 
                        {
733
 
                                try
734
 
                                {
735
 
                                        // See if a photo stream already exists for this contact node.
736
 
                                        // If one is found - delete it
737
 
                                        Property p =
738
 
                                                this.Properties.GetSingleProperty(Common.groupToLogo);
739
 
                                        if (p != null)
740
 
                                        {
741
 
                                                Simias.Storage.Relationship relationship =
742
 
                                                        (Simias.Storage.Relationship) p.Value;
743
 
 
744
 
                                                Node cLogoNode = 
745
 
                                                        this.addressBook.GetNodeByID(relationship.NodeID);
746
 
                                                if (cLogoNode != null)
747
 
                                                {
748
 
                                                        this.addressBook.Delete(cLogoNode);
749
 
                                                        this.addressBook.Commit(cLogoNode);
750
 
                                                }
751
 
                                        }
752
 
                                }
753
 
                                catch{}
754
 
 
755
 
                                // Create the new node
756
 
                                try
757
 
                                {
758
 
                                        sfn =
759
 
                                                new StoreFileNode(
760
 
                                                                Common.logoProperty, 
761
 
                                                                srcStream);
762
 
 
763
 
                                        Relationship parentChild = new
764
 
                                                Relationship(
765
 
                                                        this.addressBook.ID,
766
 
                                                        sfn.ID);
767
 
 
768
 
                                        this.Properties.ModifyProperty(Common.groupToLogo, parentChild);
769
 
                                        this.addressBook.Commit(sfn);
770
 
                                        this.addressBook.Commit(this);
771
 
                                        finished = true;
772
 
                                }
773
 
                                catch{}
774
 
                        }
775
 
                        else
776
 
                        {
777
 
                                BinaryReader    bReader = null;
778
 
                                BinaryWriter    bWriter = null;
779
 
 
780
 
                                // Copy the logo photo into the cached stream
781
 
                                try
782
 
                                {
783
 
                                        // Create the new stream in the file system
784
 
                                        this.logoStream = new MemoryStream();
785
 
                                        bWriter = new BinaryWriter(this.logoStream);
786
 
 
787
 
                                        // Copy the source stream
788
 
                                        bReader = new BinaryReader(srcStream);
789
 
                                        bReader.BaseStream.Position = 0;
790
 
                                        bWriter.BaseStream.Position = 0;
791
 
 
792
 
                                        //bWriter.Write(bReader.BaseStream, 0, bReader.BaseStream.Length);
793
 
                                        
794
 
                                        // BUGBUG better algo for copying
795
 
                                        int i = 0;
796
 
                                        while(true)
797
 
                                        {
798
 
                                                i = bReader.BaseStream.ReadByte();
799
 
                                                if(i == -1)
800
 
                                                {
801
 
                                                        break;
802
 
                                                }
803
 
 
804
 
                                                bWriter.BaseStream.WriteByte((byte) i);
805
 
                                        }
806
 
 
807
 
                                        bWriter.BaseStream.Position = 0;
808
 
                                        finished = true;
809
 
                                }
810
 
                                catch{}
811
 
                                finally
812
 
                                {
813
 
                                        if (bReader != null)
814
 
                                        {
815
 
                                                bReader.Close();
816
 
                                        }
817
 
                                }
818
 
                        }
819
 
 
820
 
                        return(finished);
821
 
                }
822
 
 
823
 
                #endregion
824
 
        }
825
 
}