~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/NU-FsProvider/.svn/text-base/FsResultSet.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
 
 
25
 
using System;
26
 
using System.Collections;
27
 
using System.IO;
28
 
using Simias.Storage.Provider;
29
 
using System.Runtime.InteropServices;
30
 
 
31
 
namespace Simias.Storage.Provider.Fs
32
 
{
33
 
        /// <summary>
34
 
        /// Summary description for FsObjectIterator.
35
 
        /// </summary>
36
 
        public class FsResultSet : MarshalByRefObject, IResultSet
37
 
        {
38
 
                private bool AlreadyDisposed = false;
39
 
                int                     count;
40
 
                Queue           resultQ;
41
 
        
42
 
                /// <summary>
43
 
                /// Creates a resultset from the queue.
44
 
                /// </summary>
45
 
                /// <param name="queue"></param>
46
 
                public FsResultSet(Queue queue)
47
 
                {
48
 
                        resultQ = queue;
49
 
                        count = resultQ.Count;
50
 
                }
51
 
 
52
 
                #region IObjectIterator Members
53
 
 
54
 
                /// <summary>
55
 
                /// Method to return the next set of objects.
56
 
                /// All the objects that can fit in the buffer will be returned.
57
 
                /// returns false when no more objects exist.
58
 
                /// </summary>
59
 
                /// <param name="buffer">Buffer used to return the objects.</param>
60
 
                /// <returns>true - objects returned. false - no more objects</returns>
61
 
                public int GetNext(ref char[] buffer)
62
 
                {
63
 
                        if (AlreadyDisposed || resultQ.Count == 0)
64
 
                        {
65
 
                                return 0;
66
 
                        }
67
 
                        else
68
 
                        {
69
 
                                int length = buffer.Length;
70
 
                                int offset = 0;
71
 
                                string startListTag = "<" + XmlTags.ObjectListTag + ">";
72
 
                                string endListTag = "</" + XmlTags.ObjectListTag + ">";
73
 
                                if (length > startListTag.Length)
74
 
                                {
75
 
                                        int stringLen = startListTag.Length;
76
 
                                        startListTag.CopyTo(0, buffer, offset, stringLen);
77
 
                                        offset += stringLen;
78
 
                                        length -= stringLen;
79
 
                                        // Save space for the end tag.
80
 
                                        length -= endListTag.Length;
81
 
 
82
 
                                        while (resultQ.Count != 0 && length > 0)
83
 
                                        {
84
 
                                                string objectXml = (string)resultQ.Peek();
85
 
                                                stringLen = objectXml.Length;
86
 
                                                if (length > stringLen)
87
 
                                                {
88
 
                                                        resultQ.Dequeue();
89
 
                                                        objectXml.CopyTo(0, buffer, offset, stringLen);
90
 
                                                        offset += stringLen;
91
 
                                                        length -= stringLen;
92
 
                                                }
93
 
                                                else
94
 
                                                {
95
 
                                                        // We are out of space.
96
 
                                                        break;
97
 
                                                }
98
 
                                        }
99
 
                                        endListTag.CopyTo(0, buffer, offset, endListTag.Length);
100
 
                                }
101
 
                                if (length == 0)
102
 
                                {
103
 
                                        Dispose();
104
 
                                }
105
 
                                return buffer.Length - length;
106
 
                        }
107
 
                }
108
 
 
109
 
                /// <summary>
110
 
                /// Property to get the count of available objects.
111
 
                /// </summary>
112
 
                public int Count
113
 
                {
114
 
                        get
115
 
                        {
116
 
                                if (AlreadyDisposed)
117
 
                                {
118
 
                                        return 0;
119
 
                                }
120
 
                                else
121
 
                                {
122
 
                                        return count;
123
 
                                }
124
 
                        }
125
 
                }
126
 
 
127
 
 
128
 
 
129
 
                #endregion
130
 
 
131
 
                #region IDisposable Members
132
 
 
133
 
                /// <summary>
134
 
                /// Method to cleanup any file system resources held.
135
 
                /// </summary>
136
 
                public void Dispose()
137
 
                {
138
 
                        AlreadyDisposed = true;
139
 
                }
140
 
 
141
 
                #endregion
142
 
        }
143
 
}