File: TestBook.cs

package info (click to toggle)
evolution-sharp 0.17.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,892 kB
  • ctags: 875
  • sloc: sh: 8,987; cs: 2,700; ansic: 712; makefile: 183; xml: 28
file content (223 lines) | stat: -rw-r--r-- 7,763 bytes parent folder | download
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
using System;
using System.Collections;
using Gtk;
using GLib;
using Evolution;

namespace BookBindingsTest {
	public class BookBindingsTest {


				/// <summary>
				/// Tests the Creation, Modification, and Deleting of a Contact in EDS
				/// </summary>
				public static void TestContact()
				{
					Console.WriteLine("TestContact: Opening System Addressbook");				
					Book systemBook = Book.NewSystemAddressbook();
					systemBook.Open(true);
			
					// ***********************************************
					// Book.AddContact Test
					// ***********************************************
					Console.WriteLine("TestContact: Creating contact EDS Test Dude");
					Contact contact = new Contact();
					contact.FileAs = "EDS Test Dude";
					
					string[] jabberId = new string[1];
					jabberId[0] = "edstestdude@jabber.org";
					contact.ImJabber = jabberId;
					contact.Email1 = "edstestdude@jabber.org";
					Console.WriteLine("TestContact: contact.Id before Add: {0}", contact.Id);
					systemBook.AddContact(contact);
					Console.WriteLine("TestContact: contact.Id after Add: {0}", contact.Id);
					
					// ***********************************************
					// Book.CommitContact Test
					// ***********************************************
					Console.WriteLine("TestContact: Modifying contact EDS Test Dude");					
					contact.BusinessPhone = "800.555.1212";
					contact.Nickname = "Mr. EDSContact Test Dude";
					
					systemBook.CommitContact(contact);
					
					
					// ***********************************************
					// Book.RemoveContact Test
					// ***********************************************
					Console.WriteLine("TestContact: Removing contact EDS Test Dude");
					systemBook.RemoveContact(contact.Id);
				}


				/// <summary>
				/// Tests the Creation, Modification, and Deleting of a ContactList in EDS
				/// </summary>
				public static void TestContactList()
				{
					Console.WriteLine("TestContactList: Opening System Addressbook");				
					Book systemBook = Book.NewSystemAddressbook();
					systemBook.Open(true);
			
					// ***********************************************
					// Create a contact to add to a ContactList
					// ***********************************************
					
					Console.WriteLine("TestContactList: Creating contact EDS Test Dude");
					Contact contact = new Contact();
					contact.FileAs = "EDS Test Dude";
					contact.Email1 = "edstestdude@jabber.org";

					Console.WriteLine("TestContactList: contact.Id before Add: {0}", contact.Id);
					systemBook.AddContact(contact);
					Console.WriteLine("TestContactList: contact.Id after Add: {0}", contact.Id);
					
					
					// ***********************************************
					// Create a ContactList
					// ***********************************************
					Console.WriteLine("TestContactList: Creating contactlist EDS Test List");
					Contact contactList = new Contact();
					contactList.List = true;					
					contactList.FileAs = "EDS Test List";

					Console.WriteLine("TestContactList: contactList.Id before Add: {0}", contactList.Id);
					systemBook.AddContact(contactList);
					Console.WriteLine("TestContactList: contactList.Id after Add: {0}", contactList.Id);


					// ***********************************************
					// Add the Contact to the ContactList
					// ***********************************************
					VCardAttribute attr = new VCardAttribute("", "EMAIL");
					VCardAttributeParam param = new VCardAttributeParam("X-EVOLUTION-DEST-CONTACT-UID");

					param.AddValue(contact.Id);
					attr.AddParam(param);
					param = new VCardAttributeParam("X-EVOLUTION-DEST-NAME");
					param.AddValue(contact.FileAs);
					attr.AddParam(param);
					param = new VCardAttributeParam("X-EVOLUTION-DEST-EMAIL");
					param.AddValue(contact.Email1);
					attr.AddParam(param);
					param = new VCardAttributeParam("X-EVOLUTION-DEST-HTML-MAIL");
					param.AddValue("FALSE");
					attr.AddParam(param);
					
					attr.AddValue(contact.FileAs + " <" + contact.Email1 + ">");
					contactList.AddAttribute(attr);
					
					systemBook.CommitContact(contactList);
					
					// ***********************************************
					// Clean everything up
					// ***********************************************
					Console.WriteLine("TestContactList: Cleaning up objects");
					systemBook.RemoveContact(contact.Id);
					systemBook.RemoveContact(contactList.Id);
				}




                private void OnContactsAdded (object o,
                                              Evolution.ContactsAddedArgs args)
                {
			Console.WriteLine ("Contacts added:");
			foreach (Contact contact in args.Contacts) {
				Console.WriteLine ("\nId: {0}", contact.Id);
				Console.WriteLine ("Fullname: {0}", contact.FullName);
				Console.WriteLine ("Photo: Mime-type: {0}", contact.Photo.MimeType);
				Console.WriteLine ("Photo: Uri: {0}", contact.Photo.Uri);
			}
                }

                private void OnContactsChanged (object o,
                                                Evolution.ContactsChangedArgs args)
                {

                }

                private void OnContactsRemoved (object o,
                                                Evolution.ContactsRemovedArgs args)
                {
			
		}

		public static void Main (string[] args)
		{
			Application.Init ();
	
			Console.WriteLine("Calling TestContact to test contact methods");
			BookBindingsTest.TestContact();

			Console.WriteLine("Calling TestContactList to test Contact List methods");			
			BookBindingsTest.TestContactList();

			SourceList slist = new SourceList ("/apps/evolution/addressbook/sources");
			if (slist != null) {
				SList group_list = slist.Groups;
				Console.WriteLine ("Group count: {0}", group_list.Count);
				foreach (SourceGroup group in group_list) {
					Console.WriteLine ("UID: {0}, Name: {1}", group.Uid, group.Name);
					SList src_list = group.Sources;
					foreach (Evolution.Source src in src_list) {
						Book bk = Book.NewSystemAddressbook ();
						//Book bk = new Book (src);
					       	bk.Open (true);

						Console.WriteLine ("UID: {0}, Name: {1}", src.Uid, src.Name);
						Evolution.BookQuery q = Evolution.BookQuery.AnyFieldContains ("");
						
						ArrayList dummy = new ArrayList ();
						BookView bk_view = bk.GetBookView (q, dummy, -1);

						BookBindingsTest t = new BookBindingsTest ();
						bk_view.ContactsChanged += t.OnContactsChanged;
						bk_view.ContactsAdded += t.OnContactsAdded;
						bk_view.ContactsRemoved += t.OnContactsRemoved;
							
						bk_view.Start ();
						
						Contact[] contactlist = bk.GetContacts (q);
						Console.WriteLine ("Contact count (range) : {0}", contactlist.Length);
												 
						
						if (contactlist != null) {
							foreach (Contact comp in contactlist) {
								Console.WriteLine ("Id: {0}", comp.Id);
								Console.WriteLine ("Fullname: {0}", comp.FullName);
								Console.WriteLine ("Photo: Mime-type: {0}", comp.Photo.MimeType);
								Console.WriteLine ("Photo: Uri: {0}", comp.Photo.Uri);
							}
						} else 
							Console.WriteLine ("No event strings found");

						Contact[] newcontacts;
						Contact[] updated;
						string[] removed;

						bk.GetChanges ("TestBook-testing", 
							       out newcontacts, 
							       out updated, 
							       out removed);
						if (newcontacts != null)
							Console.WriteLine ("Newly added: {0}", newcontacts.Length);

						if (updated != null)
							Console.WriteLine ("Updated : {0}", updated.Length);

						if (removed != null)
							Console.WriteLine ("removed added: {0}", removed.Length);
					}
					
				}
				
			}
			else
				Console.WriteLine ("slist is NULL");

			Application.Run ();
		}
	}
}