~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/NU-FsProvider/.svn/text-base/FsProvider.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: Russ Young
22
 
 |***************************************************************************/ 
23
 
 
24
 
using System;
25
 
using System.Text;
26
 
using System.Text.RegularExpressions;
27
 
using System.Xml;
28
 
using System.Diagnostics;
29
 
using System.Collections;
30
 
using System.Security.Policy;
31
 
using System.Threading;
32
 
using Simias.Storage.Provider;
33
 
using System.Runtime.InteropServices;
34
 
using System.Runtime.Remoting;
35
 
using System.Runtime.Remoting.Activation;
36
 
using System.Runtime.Remoting.Channels;
37
 
using System.Runtime.Remoting.Channels.Tcp;
38
 
using System.Runtime.Serialization.Formatters.Binary;
39
 
using System.IO;
40
 
 
41
 
namespace Simias.Storage.Provider.Fs
42
 
{
43
 
        #region FsDb class
44
 
        internal class FsDb
45
 
        {
46
 
                /// <summary>
47
 
                /// Queue used to keep track of Fs record IDs.
48
 
                /// When a node gets deleted the id is put on the queue
49
 
                /// so that a new object can reuse the ID.
50
 
                /// </summary>
51
 
                static Hashtable        dbTable = new Hashtable();
52
 
                int                                     refCount = 0;
53
 
                public IntPtr           pFWDB = IntPtr.Zero;
54
 
                string                          dbName;
55
 
                bool                            deleteDb = false;
56
 
 
57
 
                FsDb(string name)
58
 
                {
59
 
                        dbName = name;
60
 
                }
61
 
 
62
 
                public static FsDb GetFsDb(string name)
63
 
                {
64
 
                        FsDb FsDb;
65
 
                        lock(dbTable)
66
 
                        {
67
 
                                FsDb = (FsDb)dbTable[name];
68
 
                                if (FsDb == null)
69
 
                                {
70
 
                                        FsDb = new FsDb(name);
71
 
                                        dbTable.Add(name, FsDb);
72
 
                                }
73
 
                                FsDb.refCount++;
74
 
                        }
75
 
                        return (FsDb);
76
 
                }
77
 
 
78
 
                public void Release()
79
 
                {
80
 
                        lock(dbTable)
81
 
                        {
82
 
                                if (--refCount == 0)
83
 
                                {
84
 
                                        dbTable.Remove(dbName);
85
 
                                        if (deleteDb)
86
 
                                        {
87
 
                                                FsProvider.DeleteStore(dbName);
88
 
                                        }
89
 
                                }
90
 
                        }
91
 
                }
92
 
 
93
 
                public bool DeleteDb
94
 
                {
95
 
                        set {deleteDb = value;}
96
 
                }
97
 
        }
98
 
        #endregion
99
 
 
100
 
        /// <summary>
101
 
        /// Class that implements the Simias.Storage.Provider.IProvider interface 
102
 
        /// using the native file system.
103
 
        /// </summary>
104
 
        public class FsProvider : MarshalByRefObject, IProvider
105
 
        {
106
 
                #region Variables
107
 
                ProviderConfig                  conf;
108
 
                bool                                    AlreadyDisposed;
109
 
                FsDb                                    FsDb;
110
 
                string                                  DbPath;
111
 
                const string                    DbName = "Collection.db";
112
 
                const string                    version = "0.1";
113
 
                string                                  storePath;
114
 
                #endregion
115
 
                
116
 
                #region Constructor/Destructor
117
 
                /// <summary>
118
 
                /// 
119
 
                /// </summary>
120
 
                /// <param name="conf">The configuration object used to configure this instance.</param>
121
 
                public FsProvider(ProviderConfig conf)
122
 
                {
123
 
                        this.conf = conf;
124
 
                        storePath = System.IO.Path.GetFullPath(conf.Path);
125
 
                        DbPath = Path.Combine(storePath, DbName);
126
 
                        FsDb = FsDb.GetFsDb(DbPath);
127
 
                }
128
 
 
129
 
                /// <summary>
130
 
                /// 
131
 
                /// </summary>
132
 
                ~FsProvider()
133
 
                {
134
 
                        Dispose(true);
135
 
                }
136
 
                #endregion
137
 
 
138
 
                #region Transaction class
139
 
                class Transaction
140
 
                {
141
 
                        Mutex   mutex;
142
 
                        public string   path;
143
 
                        string  addPath;
144
 
                        string  delPath;
145
 
                        bool    deleteContainer = false;
146
 
 
147
 
                        internal Transaction(string dbPath, string container)
148
 
                        {
149
 
                                path = Path.Combine(dbPath, container);
150
 
                                addPath = Path.Combine(path, "add");
151
 
                                delPath = Path.Combine(path, "del");
152
 
                                mutex = new Mutex(false, "mutex_" + Path.GetFileName(path));
153
 
                        }
154
 
 
155
 
                        internal void Begin()
156
 
                        {
157
 
                                mutex.WaitOne();
158
 
                                if (!Directory.Exists(path))
159
 
                                {
160
 
                                        Directory.CreateDirectory(path);
161
 
                                }
162
 
                                if (!Directory.Exists(addPath))
163
 
                                {
164
 
                                        Directory.CreateDirectory(addPath);
165
 
                                }
166
 
                                if (!Directory.Exists(delPath))
167
 
                                {
168
 
                                        Directory.CreateDirectory(delPath);
169
 
                                }
170
 
                        }
171
 
 
172
 
                        internal void BeginRead()
173
 
                        {
174
 
                                mutex.WaitOne();
175
 
                        }
176
 
 
177
 
                        internal void EndRead()
178
 
                        {
179
 
                                mutex.ReleaseMutex();
180
 
                        }
181
 
 
182
 
                        internal void Commit()
183
 
                        {
184
 
                                try
185
 
                                {
186
 
                                        if (deleteContainer)
187
 
                                        {
188
 
                                                Directory.Delete(path, true);
189
 
                                        }
190
 
                                        else
191
 
                                        {
192
 
                                                // Commit the deletes.
193
 
                                                if (Directory.Exists(delPath))
194
 
                                                {
195
 
                                                        Directory.Delete(delPath, true);
196
 
                                                }
197
 
 
198
 
                                                // Commit the Adds.
199
 
                                                string [] files = Directory.GetFiles(addPath);
200
 
 
201
 
                                                foreach (string f in files)
202
 
                                                {
203
 
                                                        string filePath = Path.Combine(path, Path.GetFileName(f));
204
 
                                                        if (File.Exists(filePath))
205
 
                                                        {
206
 
                                                                File.Delete(filePath);
207
 
                                                        }
208
 
                                                        File.Move(f, filePath);
209
 
                                                }
210
 
                                                Directory.Delete(addPath, true);
211
 
                                        }
212
 
                                }
213
 
                                catch
214
 
                                {
215
 
                                }
216
 
                                mutex.ReleaseMutex();
217
 
                        }
218
 
 
219
 
                        internal void Abort()
220
 
                        {
221
 
                                try
222
 
                                {
223
 
                                        deleteContainer = false;
224
 
                                        // Abort the Adds.
225
 
                                        Directory.Delete(addPath, true);
226
 
 
227
 
                                        // Abort the Deletes.
228
 
                                        string [] files = Directory.GetFiles(delPath);
229
 
 
230
 
                                        foreach (string f in files)
231
 
                                        {
232
 
                                                string filePath = Path.Combine(path, Path.GetFileName(f));
233
 
                                                if (File.Exists(filePath))
234
 
                                                {
235
 
                                                        File.Delete(filePath);
236
 
                                                }
237
 
                                                File.Move(f, filePath);
238
 
                                        }
239
 
                                        Directory.Delete(delPath, true);
240
 
                                }
241
 
                                catch
242
 
                                {
243
 
                                }
244
 
                                mutex.ReleaseMutex();
245
 
                        }
246
 
 
247
 
                        internal void addObject(string file, XmlElement xmlObject)
248
 
                        {
249
 
                                removeObject(file);
250
 
                                string filePath = Path.Combine(addPath, file);
251
 
                                XmlTextWriter xmlWriter = new XmlTextWriter(filePath, System.Text.Encoding.UTF8);
252
 
                                //xmlWriter.Formatting = Formatting.Indented;
253
 
                                xmlObject.WriteTo(xmlWriter);
254
 
                                xmlWriter.Close();
255
 
                        }
256
 
 
257
 
                        internal void removeObject(string file)
258
 
                        {
259
 
                                string filePath = Path.Combine(path, file);
260
 
                                if (File.Exists(filePath))
261
 
                                {
262
 
                                        File.Move(filePath, Path.Combine(delPath, file));
263
 
                                }
264
 
                        }
265
 
 
266
 
                        internal void DeleteContainer()
267
 
                        {
268
 
                                deleteContainer = true;
269
 
                        }
270
 
                }
271
 
                #endregion
272
 
 
273
 
                #region Private Methods.
274
 
                internal static void DeleteStore(string path)
275
 
                {
276
 
                        Directory.Delete(path, true);
277
 
                        Provider.Delete(Path.GetDirectoryName(path));
278
 
                }
279
 
 
280
 
                /// <summary>
281
 
                /// Method Used to create a store Object.
282
 
                /// </summary>
283
 
                /// <param name="doc">XML document that describes the Objects</param>
284
 
                /// <param name="trans">The transaction object for this create.</param>
285
 
                private void CreateRecords(XmlDocument doc, Transaction trans)
286
 
                {
287
 
                        XmlElement root = doc.DocumentElement;
288
 
                        XmlNodeList objectList = root.SelectNodes(XmlTags.ObjectTag);
289
 
 
290
 
                        // Build the path to the collection and make sure it exists.
291
 
                        if (!Directory.Exists(trans.path))
292
 
                        {
293
 
                                Directory.CreateDirectory(trans.path);
294
 
                        }
295
 
 
296
 
                        foreach (XmlElement recordEl in objectList)
297
 
                        {
298
 
                                // Get the Name, ID, and type.
299
 
                                string name = recordEl.GetAttribute(XmlTags.NameAttr);
300
 
                                string id = recordEl.GetAttribute(XmlTags.IdAttr);
301
 
                                string type = recordEl.GetAttribute(XmlTags.TypeAttr);
302
 
                
303
 
                                // Make sure this is a valid record.
304
 
                                if (name != null && id != null && type != null)
305
 
                                {
306
 
                                        trans.addObject(id, recordEl);
307
 
                                }
308
 
                        }
309
 
                }
310
 
 
311
 
                /// <summary>
312
 
                /// Called to delete 1 or more Records.
313
 
                /// </summary>
314
 
                /// <param name="doc">Xml string describing Records to delete.</param>
315
 
                /// <param name="trans">The transaction object for this delete.</param>
316
 
                private void DeleteRecords(XmlDocument doc, Transaction trans)
317
 
                {
318
 
                        XmlElement root = doc.DocumentElement;
319
 
                        XmlNodeList objectList = root.SelectNodes(XmlTags.ObjectTag);
320
 
                        
321
 
                        foreach (XmlElement recordEl in objectList)
322
 
                        {
323
 
                                // Get ID.
324
 
                                string id = recordEl.GetAttribute(XmlTags.IdAttr);
325
 
                                trans.removeObject(id);
326
 
                        }
327
 
                }
328
 
 
329
 
 
330
 
                private void Dispose(bool inFinalize)
331
 
                {
332
 
                        if (!AlreadyDisposed)
333
 
                        {
334
 
                                // Close all of the handles that have been opened.
335
 
                                FsDb.Release();
336
 
 
337
 
                                if (!inFinalize)
338
 
                                {
339
 
                                        //GC.SuppressFinalize(this);
340
 
                                }
341
 
                                AlreadyDisposed = true;
342
 
                        }
343
 
                }
344
 
 
345
 
                #endregion
346
 
 
347
 
                #region IProvider Methods
348
 
 
349
 
                #region Store Calls
350
 
 
351
 
                /// <summary>
352
 
                /// Called to Create a new Collection Store at the specified location.
353
 
                /// </summary>
354
 
                public void CreateStore()
355
 
                {
356
 
                        lock (FsDb)
357
 
                        {
358
 
                                // Create the store
359
 
                                if (!Directory.Exists(DbPath))
360
 
                                {
361
 
                                        Directory.CreateDirectory(DbPath);
362
 
                                        // Set the version.
363
 
                                        conf.Version = version;
364
 
                                }
365
 
                        }
366
 
 
367
 
                        AlreadyDisposed = false;
368
 
                }
369
 
 
370
 
 
371
 
                /// <summary>
372
 
                /// Called to Delete the opened CollectionStore.
373
 
                /// </summary>
374
 
                public void DeleteStore()
375
 
                {
376
 
                        lock (FsDb)
377
 
                        {
378
 
                                FsDb.DeleteDb = true;
379
 
                        }
380
 
                }
381
 
 
382
 
 
383
 
                /// <summary>
384
 
                /// Called to Open an existing Collection store at the specified location.
385
 
                /// </summary>
386
 
                public void OpenStore()
387
 
                {
388
 
                        lock (FsDb)
389
 
                        {
390
 
                                // Open the store
391
 
                                if (!Directory.Exists(DbPath))
392
 
                                {
393
 
                                        throw new OpenException(DbPath);
394
 
                                }
395
 
                                // Make sure the version is correct.
396
 
                                if (conf.Version != version)
397
 
                                {
398
 
                                        throw new VersionException(DbPath, conf.Version, version);
399
 
                                }
400
 
                        }
401
 
                        
402
 
                        AlreadyDisposed = false;
403
 
                }
404
 
                
405
 
                #endregion
406
 
 
407
 
                #region Container Calls.
408
 
                
409
 
                /// <summary>
410
 
                /// Called to create a container to hold records.  This call does not need to
411
 
                /// be made.  If a record is created and the container does not exist. it will be created.
412
 
                /// </summary>
413
 
                /// <param name="name">The name of the container.</param>
414
 
                public void CreateContainer(string name)
415
 
                {
416
 
                        Transaction trans = new Transaction(DbPath, name);
417
 
                        trans.Begin();
418
 
            trans.Commit();
419
 
                }
420
 
 
421
 
                /// <summary>
422
 
                /// Called to Delete a record container.  
423
 
                /// This call is deep (all records contained are deleted).
424
 
                /// </summary>
425
 
                /// <param name="name">The name of the container.</param>
426
 
                public void DeleteContainer(string name)
427
 
                {
428
 
                        Transaction trans = new Transaction(DbPath, name);
429
 
                        trans.Begin();
430
 
                        trans.DeleteContainer();
431
 
                        trans.Commit();
432
 
                }
433
 
        
434
 
        #endregion
435
 
 
436
 
                #region Record Calls.
437
 
 
438
 
                /// <summary>
439
 
                /// Used to Create, Modify or Delete records from the store.
440
 
                /// </summary>
441
 
                /// <param name="container">The container to commit changes to.</param>
442
 
                /// <param name="createDoc">The records to create or modify.</param>
443
 
                /// <param name="deleteDoc">The records to delete.</param>
444
 
                public void CommitRecords(string container, XmlDocument createDoc, XmlDocument deleteDoc)
445
 
                {
446
 
                        Transaction trans = new Transaction(DbPath, container);
447
 
                        trans.Begin();
448
 
                        try
449
 
                        {
450
 
                                if (createDoc != null)
451
 
                                {
452
 
                                        CreateRecords(createDoc, trans);
453
 
                                }
454
 
                                if (deleteDoc != null)
455
 
                                {
456
 
                                        DeleteRecords(deleteDoc, trans);
457
 
                                }
458
 
                        }
459
 
                        catch 
460
 
                        {
461
 
                                trans.Abort();
462
 
                                return;
463
 
                        }
464
 
 
465
 
                        trans.Commit();
466
 
                }
467
 
                
468
 
                /// <summary>
469
 
                /// Called to ge a Record.  The record is returned as an XML string representation.  
470
 
                /// </summary>
471
 
                /// <param name="recordId">string that contains the ID of the Record to retrieve</param>
472
 
                /// <param name="container">The conaiter to get the record from.</param>
473
 
                /// <returns>XML string describing the Record</returns>
474
 
                public XmlDocument GetRecord(string recordId, string container)
475
 
                {
476
 
                        string recordPath = Path.Combine(DbPath, container);
477
 
                        recordPath = Path.Combine(recordPath, recordId);
478
 
                        XmlDocument doc = new XmlDocument();
479
 
                        XmlElement rootElement = doc.CreateElement(XmlTags.ObjectListTag);
480
 
                        doc.AppendChild(rootElement);
481
 
 
482
 
                        XmlTextReader xmlReader = new XmlTextReader(recordPath);
483
 
                        try
484
 
                        {
485
 
                                xmlReader.Read();
486
 
                                rootElement.InnerXml = xmlReader.ReadOuterXml();
487
 
                        }
488
 
                        finally
489
 
                        {
490
 
                                xmlReader.Close();
491
 
                        }
492
 
                        
493
 
                        return (doc);
494
 
                }
495
 
 
496
 
 
497
 
                #endregion
498
 
                
499
 
                #region Query Calls
500
 
 
501
 
                /// <summary>
502
 
                /// Method used to search for Records using the specified query.
503
 
                /// </summary>
504
 
                /// <param name="query">Query used for this search</param>
505
 
                /// <returns></returns>
506
 
                public IResultSet Search(Query query)
507
 
                {
508
 
                        IResultSet      resultSet = null;
509
 
                        string          pattern = null;
510
 
                        bool            valueCompare = false;
511
 
                        bool            isAttribute = false;
512
 
                        string          attribute = null;
513
 
                        
514
 
                        try
515
 
                        {
516
 
                                switch (query.Property)
517
 
                                {
518
 
                                        case BaseSchema.ObjectName:
519
 
                                                attribute = XmlTags.NameAttr;
520
 
                                                isAttribute = true;
521
 
                                                break;
522
 
                                        case BaseSchema.ObjectId:
523
 
                                                attribute = XmlTags.IdAttr;
524
 
                                                isAttribute = true;
525
 
                                                break;
526
 
                                        case BaseSchema.ObjectType:
527
 
                                                attribute = XmlTags.TypeAttr;
528
 
                                                isAttribute = true;
529
 
                                                break;
530
 
                                }
531
 
                        
532
 
                                switch (query.Operation)
533
 
                                {
534
 
                                        case SearchOp.Equal:
535
 
                                        case SearchOp.Not_Equal:
536
 
                                                if (isAttribute)
537
 
                                                {
538
 
                                                        pattern = string.Format("<{0}[^>]*{1}=\"{2}\"[^>]*", XmlTags.ObjectTag, attribute, query.Value);
539
 
                                                }
540
 
                                                else
541
 
                                                {
542
 
                                                        pattern = string.Format("<{0} name=\"{1}\" type=\"{2}\".*>{3}</{0}>", XmlTags.PropertyTag, query.Property, query.Type, query.Value);
543
 
                                                }
544
 
                                                break;
545
 
                                        case SearchOp.Begins:
546
 
                                                if (isAttribute)
547
 
                                                {
548
 
                                                        pattern = string.Format("<{0}[^>]*{1}=\"{2}", XmlTags.ObjectTag, attribute, query.Value);
549
 
                                                }
550
 
                                                else
551
 
                                                {
552
 
                                                        pattern = string.Format("<{0} name=\"{1}\" type=\"{2}\".*>{3}", XmlTags.PropertyTag, query.Property, query.Type, query.Value);
553
 
                                                }
554
 
                                                break;
555
 
                                        case SearchOp.Ends:
556
 
                                                if (isAttribute)
557
 
                                                {
558
 
                                                        pattern = string.Format("<{0}[^>]*{1}=\"[^\"]*{2}\"", XmlTags.ObjectTag, attribute, query.Value);
559
 
                                                }
560
 
                                                else
561
 
                                                {
562
 
                                                        pattern = string.Format("<{0} name=\"{1}\" type=\"{2}\".*>.*{3}</{0}>", XmlTags.PropertyTag, query.Property, query.Type, query.Value);
563
 
                                                }
564
 
                                                break;
565
 
                                        case SearchOp.Contains:
566
 
                                                if (isAttribute)
567
 
                                                {
568
 
                                                        pattern = string.Format("<{0}[^>]*{1}=\"[^\"]*{2}", XmlTags.ObjectTag, attribute, query.Value);
569
 
                                                }
570
 
                                                else
571
 
                                                {
572
 
                                                        pattern = string.Format("<{0} name=\"{1}\" type=\"{2}\".*>.*{3}.*</{0}>", XmlTags.PropertyTag, query.Property, query.Type, query.Value);
573
 
                                                }
574
 
                                                break;
575
 
                                        case SearchOp.Greater:
576
 
                                        case SearchOp.Less:
577
 
                                        case SearchOp.Greater_Equal:
578
 
                                        case SearchOp.Less_Equal:
579
 
                                                pattern = string.Format("<{0} name=\"{1}\" type=\"{2}\"[^>]*>", XmlTags.PropertyTag, query.Property, query.Type);
580
 
                                                valueCompare = true;
581
 
                                                break;
582
 
                                        case SearchOp.Exists:
583
 
                                                if (isAttribute)
584
 
                                                {
585
 
                                                        pattern = string.Format("<{0}[^>]*{1}=\"[^>]*", XmlTags.ObjectTag, attribute, query.Value);
586
 
                                                }
587
 
                                                else
588
 
                                                {
589
 
                                                        pattern = string.Format("<{0} name=\"{1}\" type=\"{2}\".*>", XmlTags.PropertyTag, query.Property, query.Type);
590
 
                                                }
591
 
                                                break;
592
 
                                }
593
 
 
594
 
                                if (pattern != null)
595
 
                                {
596
 
                                        Regex expression = new Regex(pattern, RegexOptions.IgnoreCase);
597
 
                                        string path;
598
 
                                        string[] files;
599
 
 
600
 
                                        if (query.CollectionId != null)
601
 
                                        {
602
 
                                                path = Path.Combine(DbPath, query.CollectionId);
603
 
                                                files = Directory.GetFiles(path);
604
 
                                        }
605
 
                                        else
606
 
                                        {
607
 
                                                path = DbPath;
608
 
                                                files = Directory.GetDirectories(path);
609
 
                                        }
610
 
                                
611
 
                                        Queue resultQ = new Queue();
612
 
 
613
 
                                        foreach(string sfile in files)
614
 
                                        {
615
 
                                                StreamReader sReader;
616
 
                                                // If we have a collection ID then search in the collection only
617
 
                                                // Else only search collections.
618
 
                                                try
619
 
                                                {
620
 
                                                        if (query.CollectionId != null)
621
 
                                                        {
622
 
                                                                sReader = File.OpenText(sfile);
623
 
                                                        }
624
 
                                                        else
625
 
                                                        {
626
 
                                                                sReader = File.OpenText(Path.Combine(sfile, Path.GetFileName(sfile)));
627
 
                                                        }
628
 
                                                }
629
 
                                                catch
630
 
                                                {
631
 
                                                        continue;
632
 
                                                }
633
 
                                                string xmlString = sReader.ReadToEnd();
634
 
                                                sReader.Close();
635
 
                                                Match match = expression.Match(xmlString);
636
 
                                                if (match != Match.Empty)
637
 
                                                {
638
 
                                                        if (valueCompare)
639
 
                                                        {
640
 
                                                                int diff;
641
 
                                                                bool found = false;
642
 
                                                                while (match != Match.Empty)
643
 
                                                                {
644
 
                                                                        int startIndex = match.Index + match.Length;
645
 
                                                                        int length = xmlString.IndexOf('<', match.Index + match.Length) - startIndex;
646
 
                                                                        string s1 = xmlString.Substring(startIndex, length);
647
 
                                                                                
648
 
                                                                        switch (query.Type)
649
 
                                                                        {
650
 
                                                                                case Syntax.Byte:
651
 
                                                                                case Syntax.DateTime:
652
 
                                                                                case Syntax.TimeSpan:
653
 
                                                                                case Syntax.UInt16:
654
 
                                                                                case Syntax.UInt32:
655
 
                                                                                case Syntax.UInt64:
656
 
                                                                                case Syntax.Char:
657
 
                                                                                {
658
 
                                                                                        ulong v1 = ulong.Parse(s1);
659
 
                                                                                        ulong v2 = ulong.Parse(query.Value);
660
 
                                                                                        diff = v1.CompareTo(v2);
661
 
                                                                                        break;
662
 
                                                                                }
663
 
                                                                                case Syntax.SByte:
664
 
                                                                                case Syntax.Int16:
665
 
                                                                                case Syntax.Int32:
666
 
                                                                                case Syntax.Int64:
667
 
                                                                                {
668
 
                                                                                        long v1 = long.Parse(s1);
669
 
                                                                                        long v2 = long.Parse(query.Value);
670
 
                                                                                        diff = v1.CompareTo(v2);
671
 
                                                                                        break;
672
 
                                                                                }
673
 
                                                                                case Syntax.Single:
674
 
                                                                                {
675
 
                                                                                        Double v1 = Double.Parse(s1);
676
 
                                                                                        Double v2 = Double.Parse(query.Value);
677
 
                                                                                        diff = v1.CompareTo(v2);
678
 
                                                                                        break;
679
 
                                                                                }
680
 
                                                                                default:
681
 
                                                                                        throw new SearchException(query.ToString());
682
 
                                                                        }
683
 
                                                                
684
 
                                                                        switch (query.Operation)
685
 
                                                                        {
686
 
                                                                                case SearchOp.Greater:
687
 
                                                                                        if (diff > 0) found = true;
688
 
                                                                                        break;
689
 
                                                                                case SearchOp.Less:
690
 
                                                                                        if (diff < 0) found = true;
691
 
                                                                                        break;
692
 
                                                                                case SearchOp.Greater_Equal:
693
 
                                                                                        if (diff > 0 || diff == 0) found = true;
694
 
                                                                                        break;
695
 
                                                                                case SearchOp.Less_Equal:
696
 
                                                                                        if (diff < 0 || diff == 0) found = true;
697
 
                                                                                        break;
698
 
                                                                        }
699
 
 
700
 
                                                                        if (found)
701
 
                                                                        {
702
 
                                                                                string sObject = xmlString.Substring(0, xmlString.IndexOf('>')) + "/>";
703
 
                                                                                resultQ.Enqueue(sObject);
704
 
                                                                                break;
705
 
                                                                        }
706
 
                                                                        else
707
 
                                                                        {
708
 
                                                                                match = match.NextMatch();
709
 
                                                                        }
710
 
                                                                }
711
 
                                                        }
712
 
                                                        else
713
 
                                                        {
714
 
                                                                // Save this file as a match.
715
 
                                                                string sObject = xmlString.Substring(0, xmlString.IndexOf('>')) + "/>";
716
 
                                                                resultQ.Enqueue(sObject);
717
 
                                                        }
718
 
                                                }
719
 
                                                else if (query.Operation == SearchOp.Not_Equal)
720
 
                                                {
721
 
                                                        // Save this as a miss.
722
 
                                                        string sObject = xmlString.Substring(0, xmlString.IndexOf('>')) + "/>";
723
 
                                                        resultQ.Enqueue(sObject);
724
 
                                                }
725
 
                                        }
726
 
                                        resultSet = new FsResultSet(resultQ);
727
 
                                }
728
 
                        }
729
 
                        catch
730
 
                        {
731
 
                                resultSet = new FsResultSet(new Queue());
732
 
                        }
733
 
                        
734
 
                        return (resultSet);
735
 
                }
736
 
 
737
 
 
738
 
                #endregion
739
 
 
740
 
                #region Properties
741
 
 
742
 
                /// <summary>
743
 
                /// Property to get the directory to where the store is rooted.
744
 
                /// </summary>
745
 
                public Uri StoreDirectory
746
 
                {
747
 
                        get {return new Uri(storePath);}
748
 
                }
749
 
 
750
 
                #endregion
751
 
 
752
 
                #endregion
753
 
 
754
 
                #region IDisposable Members
755
 
 
756
 
                /// <summary>
757
 
                /// Method used to cleanup unmanaged resources.
758
 
                /// </summary>
759
 
                public void Dispose()
760
 
                {
761
 
                        Dispose(false);
762
 
                }
763
 
 
764
 
                #endregion
765
 
        }
766
 
}