chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1065064 - in /incubator/chemistry/dotcmis/trunk: ./ DotCMIS/ DotCMIS/binding/ DotCMIS/binding/atompub/ DotCMIS/client/ DotCMISUnitTest/
Date Sat, 29 Jan 2011 16:41:20 GMT
Author: fmui
Date: Sat Jan 29 16:41:19 2011
New Revision: 1065064

URL: http://svn.apache.org/viewvc?rev=1065064&view=rev
Log:
implemented enumerators

Added:
    incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs
    incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs
    incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs
Modified:
    incubator/chemistry/dotcmis/trunk/DotCMIS.suo
    incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj
    incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs
    incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs
    incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs
    incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs
    incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs
    incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj
    incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user
    incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS.suo
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS.suo?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj Sat Jan 29 16:41:19 2011
@@ -59,6 +59,7 @@
     <Compile Include="client\client-objectfactory.cs" />
     <Compile Include="client\client-objects.cs" />
     <Compile Include="client\client-types.cs" />
+    <Compile Include="client\client-utils.cs" />
     <Compile Include="const.cs" />
     <Compile Include="data\data-impl.cs" />
     <Compile Include="data\data-intf.cs" />

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs Sat Jan 29 16:41:19 2011
@@ -256,7 +256,7 @@ namespace DotCMIS.Binding.AtomPub
     {
         public ContentTypeCacheLevel()
         {
-            EnableKeyFallback(null);
+            EnableKeyFallback(NullKey);
         }
 
         public override object this[string key]

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs Sat Jan 29 16:41:19 2011
@@ -352,7 +352,7 @@ namespace DotCMIS.Binding
 
     internal abstract class AbstractDictionaryCacheLevel : ICacheLevel
     {
-        private static string NullKey = "";
+        protected static string NullKey = "";
 
         private IDictionary<string, object> dict;
         private bool fallbackEnabled = false;

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs Sat Jan 29 16:41:19 2011
@@ -26,6 +26,7 @@ using DotCMIS.Exceptions;
 using System.Threading;
 using DotCMIS.Enums;
 using DotCMIS.Data.Extensions;
+using DotCMIS.Binding.Services;
 
 namespace DotCMIS.Client
 {
@@ -332,11 +333,51 @@ namespace DotCMIS.Client
             return ObjectFactory.ConvertTypeDefinition(typeDefinition);
         }
 
-        public IItemIterable<IObjectType> GetTypeChildren(string typeId, bool includePropertyDefinitions)
-        { throw new CmisNotSupportedException("Client not implemented!"); }
+        public IItemEnumerable<IObjectType> GetTypeChildren(string typeId, bool includePropertyDefinitions)
+        {
+            IRepositoryService repositoryService = Binding.GetRepositoryService();
+
+            PageFetcher<IObjectType>.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount)
+            {
+                // fetch the data
+                ITypeDefinitionList tdl = repositoryService.GetTypeChildren(RepositoryId, typeId, includePropertyDefinitions, maxNumItems, skipCount, null);
+
+                // convert type definitions
+                IList<IObjectType> page = new List<IObjectType>(tdl.List.Count);
+                foreach (ITypeDefinition typeDefinition in tdl.List)
+                {
+                    page.Add(ObjectFactory.ConvertTypeDefinition(typeDefinition));
+                }
+
+                return new PageFetcher<IObjectType>.Page<IObjectType>(page, tdl.NumItems, tdl.HasMoreItems);
+            };
+
+            return new CollectionEnumerable<IObjectType>(new PageFetcher<IObjectType>(DefaultContext.MaxItemsPerPage, fetchPageDelegate));
+        }
 
         public IList<ITree<IObjectType>> GetTypeDescendants(string typeId, int depth, bool includePropertyDefinitions)
-        { throw new CmisNotSupportedException("Client not implemented!"); }
+        {
+            IList<ITypeDefinitionContainer> descendants = Binding.GetRepositoryService().GetTypeDescendants(
+            RepositoryId, typeId, depth, includePropertyDefinitions, null);
+
+            return ConvertTypeDescendants(descendants);
+        }
+
+        private IList<ITree<IObjectType>> ConvertTypeDescendants(IList<ITypeDefinitionContainer> descendantsList)
+        {
+            IList<ITree<IObjectType>> result = new List<ITree<IObjectType>>();
+
+            foreach (ITypeDefinitionContainer container in descendantsList)
+            {
+                Tree<IObjectType> tree = new Tree<IObjectType>();
+                tree.Item = ObjectFactory.ConvertTypeDefinition(container.TypeDefinition);
+                tree.Children = ConvertTypeDescendants(container.Children);
+
+                result.Add(tree);
+            }
+
+            return result;
+        }
 
         // navigation
 
@@ -347,9 +388,7 @@ namespace DotCMIS.Client
 
         public IFolder GetRootFolder(IOperationContext context)
         {
-            string rootFolderId = RepositoryInfo.RootFolderId;
-
-            ICmisObject rootFolder = GetObject(CreateObjectId(rootFolderId), context);
+            ICmisObject rootFolder = GetObject(CreateObjectId(RepositoryInfo.RootFolderId), context);
             if (!(rootFolder is IFolder))
             {
                 throw new CmisRuntimeException("Root folder object is not a folder!");
@@ -358,10 +397,10 @@ namespace DotCMIS.Client
             return (IFolder)rootFolder;
         }
 
-        public IItemIterable<IDocument> GetCheckedOutDocs()
+        public IItemEnumerable<IDocument> GetCheckedOutDocs()
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IItemIterable<IDocument> GetCheckedOutDocs(IOperationContext context)
+        public IItemEnumerable<IDocument> GetCheckedOutDocs(IOperationContext context)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
         public ICmisObject GetObject(IObjectId objectId)
@@ -382,59 +421,59 @@ namespace DotCMIS.Client
 
         // discovery
 
-        public IItemIterable<IQueryResult> Query(string statement, bool searchAllVersions)
+        public IItemEnumerable<IQueryResult> Query(string statement, bool searchAllVersions)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IItemIterable<IQueryResult> query(string statement, bool searchAllVersions, IOperationContext context)
+        public IItemEnumerable<IQueryResult> Query(string statement, bool searchAllVersions, IOperationContext context)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems)
+        public IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems,
+        public IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems,
                 IOperationContext context)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
         // create
 
-        public IObjectId CreateDocument(IDictionary<string, string> properties, IObjectId folderId, IContentStream contentStream,
+        public IObjectId CreateDocument(IDictionary<string, object> properties, IObjectId folderId, IContentStream contentStream,
                 VersioningState? versioningState, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateDocument(IDictionary<string, string> properties, IObjectId folderId, IContentStream contentStream,
+        public IObjectId CreateDocument(IDictionary<string, object> properties, IObjectId folderId, IContentStream contentStream,
                 VersioningState? versioningState)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, string> properties, IObjectId folderId,
+        public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, object> properties, IObjectId folderId,
                 VersioningState? versioningState, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, string> properties, IObjectId folderId,
+        public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, object> properties, IObjectId folderId,
                 VersioningState? versioningState)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateFolder(IDictionary<string, string> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
+        public IObjectId CreateFolder(IDictionary<string, object> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
                 IList<IAce> removeAces)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateFolder(IDictionary<string, string> properties, IObjectId folderId)
+        public IObjectId CreateFolder(IDictionary<string, object> properties, IObjectId folderId)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreatePolicy(IDictionary<string, string> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
+        public IObjectId CreatePolicy(IDictionary<string, object> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
                 IList<IAce> removeAces)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreatePolicy(IDictionary<string, string> properties, IObjectId folderId)
+        public IObjectId CreatePolicy(IDictionary<string, object> properties, IObjectId folderId)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateRelationship(IDictionary<string, string> properties, IList<IPolicy> policies, IList<IAce> addAces,
+        public IObjectId CreateRelationship(IDictionary<string, object> properties, IList<IPolicy> policies, IList<IAce> addAces,
                 IList<IAce> removeAces)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IObjectId CreateRelationship(IDictionary<string, string> properties)
+        public IObjectId CreateRelationship(IDictionary<string, object> properties)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
-        public IItemIterable<IRelationship> GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes,
+        public IItemEnumerable<IRelationship> GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes,
                 RelationshipDirection? relationshipDirection, IObjectType type, IOperationContext context)
         { throw new CmisNotSupportedException("Client not implemented!"); }
 
@@ -462,335 +501,4 @@ namespace DotCMIS.Client
             Monitor.Exit(sessionLock);
         }
     }
-
-    /// <summary>
-    /// Operation context implementation.
-    /// </summary>
-    public class OperationContext : IOperationContext
-    {
-        public const string PropertiesStar = "*";
-        public const string RenditionNone = "cmis:none";
-
-        private HashSet<string> filter;
-        private bool includeAllowableActions;
-        private bool includeAcls;
-        private IncludeRelationshipsFlag? includeRelationships;
-        private bool includePolicies;
-        private HashSet<string> renditionFilter;
-        private bool includePathSegments;
-        private string orderBy;
-        private bool cacheEnabled;
-        private string cacheKey;
-        private int maxItemsPerPage;
-
-        public OperationContext()
-        {
-            filter = null;
-            includeAcls = false;
-            includeAllowableActions = true;
-            includePolicies = false;
-            includeRelationships = IncludeRelationshipsFlag.None;
-            renditionFilter = null;
-            includePathSegments = true;
-            orderBy = null;
-            cacheEnabled = false;
-            maxItemsPerPage = 100;
-
-            GenerateCacheKey();
-        }
-
-        public OperationContext(IOperationContext source)
-        {
-            filter = new HashSet<string>(source.Filter);
-            includeAcls = source.IncludeAcls;
-            includeAllowableActions = source.IncludeAllowableActions;
-            includePolicies = source.IncludePolicies;
-            includeRelationships = source.IncludeRelationships;
-            renditionFilter = new HashSet<string>(source.RenditionFilter);
-            includePathSegments = source.IncludePathSegments;
-            orderBy = source.OrderBy;
-            cacheEnabled = source.CacheEnabled;
-            maxItemsPerPage = source.MaxItemsPerPage;
-
-            GenerateCacheKey();
-        }
-
-        public OperationContext(HashSet<string> filter, bool includeAcls, bool includeAllowableActions,
-            bool includePolicies, IncludeRelationshipsFlag includeRelationships, HashSet<string> renditionFilter,
-            bool includePathSegments, String orderBy, bool cacheEnabled, int maxItemsPerPage)
-        {
-            this.filter = filter;
-            this.includeAcls = includeAcls;
-            this.includeAllowableActions = includeAllowableActions;
-            this.includePolicies = includePolicies;
-            this.includeRelationships = includeRelationships;
-            this.renditionFilter = renditionFilter;
-            this.includePathSegments = includePathSegments;
-            this.orderBy = orderBy;
-            this.cacheEnabled = cacheEnabled;
-            this.maxItemsPerPage = maxItemsPerPage;
-
-            GenerateCacheKey();
-        }
-
-        public HashSet<string> Filter
-        {
-            get { return new HashSet<string>(filter); }
-            set
-            {
-                if (value != null)
-                {
-                    HashSet<string> tempSet = new HashSet<string>();
-                    foreach (string oid in value)
-                    {
-                        if (oid == null) { continue; }
-
-                        string toid = oid.Trim();
-                        if (toid.Length == 0) { continue; }
-                        if (toid == PropertiesStar)
-                        {
-                            tempSet = new HashSet<string>();
-                            tempSet.Add(PropertiesStar);
-                            break;
-                        }
-                        if (toid.IndexOf(',') > -1)
-                        {
-                            throw new ArgumentException("Query id must not contain a comma!");
-                        }
-
-                        tempSet.Add(toid);
-                    }
-
-                    if (tempSet.Count == 0) { filter = null; }
-                    else { filter = tempSet; }
-                }
-                else
-                {
-                    filter = null;
-                }
-
-                GenerateCacheKey();
-            }
-        }
-
-        public string FilterString
-        {
-            get
-            {
-                if (filter == null) { return null; }
-
-                if (filter.Contains(PropertiesStar))
-                {
-                    return PropertiesStar;
-                }
-
-                this.filter.Add(PropertyIds.ObjectId);
-                this.filter.Add(PropertyIds.BaseTypeId);
-                this.filter.Add(PropertyIds.ObjectTypeId);
-
-                StringBuilder sb = new StringBuilder();
-
-                foreach (String oid in filter)
-                {
-                    if (sb.Length > 0) { sb.Append(','); }
-                    sb.Append(oid);
-                }
-
-                return sb.ToString();
-            }
-
-            set
-            {
-                if (value == null || value.Trim().Length == 0)
-                {
-                    Filter = null;
-                    return;
-                }
-
-                string[] ids = value.Split(',');
-                HashSet<string> tempSet = new HashSet<string>();
-                foreach (string qid in ids)
-                {
-                    tempSet.Add(qid);
-                }
-
-                Filter = tempSet;
-            }
-        }
-
-        public bool IncludeAllowableActions
-        {
-            get { return includeAllowableActions; }
-            set { includeAllowableActions = value; GenerateCacheKey(); }
-        }
-
-        public bool IncludeAcls
-        {
-            get { return includeAcls; }
-            set { includeAcls = value; GenerateCacheKey(); }
-        }
-
-        public IncludeRelationshipsFlag? IncludeRelationships
-        {
-            get { return includeRelationships; }
-            set { includeRelationships = value; GenerateCacheKey(); }
-        }
-
-        public bool IncludePolicies
-        {
-            get { return includePolicies; }
-            set { includePolicies = value; GenerateCacheKey(); }
-        }
-
-        public HashSet<string> RenditionFilter
-        {
-            get { return new HashSet<string>(renditionFilter); }
-            set
-            {
-                HashSet<string> tempSet = new HashSet<string>();
-                if (value != null)
-                {
-                    foreach (String rf in value)
-                    {
-                        if (rf == null) { continue; }
-
-                        String trf = rf.Trim();
-                        if (trf.Length == 0) { continue; }
-                        if (trf.IndexOf(',') > -1)
-                        {
-                            throw new ArgumentException("Rendition must not contain a comma!");
-                        }
-
-                        tempSet.Add(trf);
-                    }
-
-                    if (tempSet.Count == 0)
-                    {
-                        tempSet.Add(RenditionNone);
-                    }
-                }
-                else
-                {
-                    tempSet.Add(RenditionNone);
-                }
-
-                renditionFilter = tempSet;
-
-                GenerateCacheKey();
-            }
-        }
-
-        public string RenditionFilterString
-        {
-            get
-            {
-                if (renditionFilter == null) { return null; }
-
-                StringBuilder sb = new StringBuilder();
-                foreach (string rf in renditionFilter)
-                {
-                    if (sb.Length > 0) { sb.Append(','); }
-                    sb.Append(rf);
-                }
-
-                return sb.ToString();
-            }
-
-            set
-            {
-                if (value == null || value.Trim().Length == 0)
-                {
-                    RenditionFilter = null;
-                    return;
-                }
-
-                string[] renditions = value.Split(',');
-                HashSet<string> tempSet = new HashSet<string>();
-                foreach (string rend in renditions)
-                {
-                    tempSet.Add(rend);
-                }
-
-                RenditionFilter = tempSet;
-            }
-        }
-
-        public bool IncludePathSegments
-        {
-            get { return includePathSegments; }
-            set { includePathSegments = value; GenerateCacheKey(); }
-        }
-
-        public string OrderBy
-        {
-            get { return orderBy; }
-            set { orderBy = value; GenerateCacheKey(); }
-        }
-
-        public bool CacheEnabled
-        {
-            get { return cacheEnabled; }
-            set { cacheEnabled = value; GenerateCacheKey(); }
-        }
-
-        public string CacheKey
-        {
-            get { return cacheKey; }
-        }
-
-        public int MaxItemsPerPage
-        {
-            get { return maxItemsPerPage; }
-            set { maxItemsPerPage = value; }
-        }
-
-        protected void GenerateCacheKey()
-        {
-            if (!cacheEnabled)
-            {
-                cacheKey = null;
-            }
-
-            StringBuilder sb = new StringBuilder();
-
-            sb.Append(includeAcls ? "1" : "0");
-            sb.Append(includeAllowableActions ? "1" : "0");
-            sb.Append(includePolicies ? "1" : "0");
-            sb.Append("|");
-            sb.Append(filter == null ? "" : FilterString);
-            sb.Append("|");
-            sb.Append(includeRelationships == null ? "" : includeRelationships.GetCmisValue());
-
-            sb.Append("|");
-            sb.Append(renditionFilter == null ? "" : RenditionFilterString);
-
-            cacheKey = sb.ToString();
-        }
-    }
-
-    /// <summary>
-    /// Object id implementation.
-    /// </summary>
-    public class ObjectId : IObjectId
-    {
-        private string id;
-        public string Id
-        {
-            get { return id; }
-            set
-            {
-                if (value == null || value.Length == 0)
-                {
-                    throw new ArgumentException("Id must be set!");
-                }
-
-                id = value;
-            }
-        }
-
-        public ObjectId(string id)
-        {
-            Id = id;
-        }
-    }
 }

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs Sat Jan 29 16:41:19 2011
@@ -60,15 +60,15 @@ namespace DotCMIS.Client
         // types
 
         IObjectType GetTypeDefinition(string typeId);
-        IItemIterable<IObjectType> GetTypeChildren(string typeId, bool includePropertyDefinitions);
+        IItemEnumerable<IObjectType> GetTypeChildren(string typeId, bool includePropertyDefinitions);
         IList<ITree<IObjectType>> GetTypeDescendants(string typeId, int depth, bool includePropertyDefinitions);
 
         // navigation
 
         IFolder GetRootFolder();
         IFolder GetRootFolder(IOperationContext context);
-        IItemIterable<IDocument> GetCheckedOutDocs();
-        IItemIterable<IDocument> GetCheckedOutDocs(IOperationContext context);
+        IItemEnumerable<IDocument> GetCheckedOutDocs();
+        IItemEnumerable<IDocument> GetCheckedOutDocs(IOperationContext context);
         ICmisObject GetObject(IObjectId objectId);
         ICmisObject GetObject(IObjectId objectId, IOperationContext context);
         ICmisObject GetObjectByPath(string path);
@@ -76,33 +76,33 @@ namespace DotCMIS.Client
 
         // discovery
 
-        IItemIterable<IQueryResult> Query(string statement, bool searchAllVersions);
-        IItemIterable<IQueryResult> query(string statement, bool searchAllVersions, IOperationContext context);
-        IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems);
-        IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems,
+        IItemEnumerable<IQueryResult> Query(string statement, bool searchAllVersions);
+        IItemEnumerable<IQueryResult> Query(string statement, bool searchAllVersions, IOperationContext context);
+        IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems);
+        IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems,
                 IOperationContext context);
 
         // create
 
-        IObjectId CreateDocument(IDictionary<string, string> properties, IObjectId folderId, IContentStream contentStream,
+        IObjectId CreateDocument(IDictionary<string, object> properties, IObjectId folderId, IContentStream contentStream,
                 VersioningState? versioningState, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces);
-        IObjectId CreateDocument(IDictionary<string, string> properties, IObjectId folderId, IContentStream contentStream,
+        IObjectId CreateDocument(IDictionary<string, object> properties, IObjectId folderId, IContentStream contentStream,
                 VersioningState? versioningState);
-        IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, string> properties, IObjectId folderId,
+        IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, object> properties, IObjectId folderId,
                 VersioningState? versioningState, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces);
-        IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, string> properties, IObjectId folderId,
+        IObjectId CreateDocumentFromSource(IObjectId source, IDictionary<string, object> properties, IObjectId folderId,
                 VersioningState? versioningState);
-        IObjectId CreateFolder(IDictionary<string, string> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
+        IObjectId CreateFolder(IDictionary<string, object> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
                 IList<IAce> removeAces);
-        IObjectId CreateFolder(IDictionary<string, string> properties, IObjectId folderId);
-        IObjectId CreatePolicy(IDictionary<string, string> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
+        IObjectId CreateFolder(IDictionary<string, object> properties, IObjectId folderId);
+        IObjectId CreatePolicy(IDictionary<string, object> properties, IObjectId folderId, IList<IPolicy> policies, IList<IAce> addAces,
                 IList<IAce> removeAces);
-        IObjectId CreatePolicy(IDictionary<string, string> properties, IObjectId folderId);
-        IObjectId CreateRelationship(IDictionary<string, string> properties, IList<IPolicy> policies, IList<IAce> addAces,
+        IObjectId CreatePolicy(IDictionary<string, object> properties, IObjectId folderId);
+        IObjectId CreateRelationship(IDictionary<string, object> properties, IList<IPolicy> policies, IList<IAce> addAces,
                 IList<IAce> removeAces);
-        IObjectId CreateRelationship(IDictionary<string, string> properties);
+        IObjectId CreateRelationship(IDictionary<string, object> properties);
 
-        IItemIterable<IRelationship> GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes,
+        IItemEnumerable<IRelationship> GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes,
                 RelationshipDirection? relationshipDirection, IObjectType type, IOperationContext context);
 
         // permissions
@@ -169,7 +169,7 @@ namespace DotCMIS.Client
     public interface ITree<T>
     {
         T Item { get; }
-        IList<ITree<T>> GetChildren();
+        IList<ITree<T>> Children { get; }
     }
 
     public interface IObjectType : ITypeDefinition
@@ -177,7 +177,7 @@ namespace DotCMIS.Client
         bool IsBaseType { get; }
         IObjectType GetBaseType();
         IObjectType GetParentType();
-        IItemIterable<IObjectType> GetChildren();
+        IItemEnumerable<IObjectType> GetChildren();
         IList<ITree<IObjectType>> GetDescendants(int depth);
     }
 
@@ -201,11 +201,11 @@ namespace DotCMIS.Client
     {
     }
 
-    public interface IItemIterable<T>
+    public interface IItemEnumerable<T> : IEnumerable<T>
     {
-        IItemIterable<T> SkipTo(long position);
-        IItemIterable<T> GetPage();
-        IItemIterable<T> GetPage(int maxNumItems);
+        IItemEnumerable<T> SkipTo(long position);
+        IItemEnumerable<T> GetPage();
+        IItemEnumerable<T> GetPage(int maxNumItems);
         long PageNumItems { get; }
         bool HasMoreItems { get; }
         long TotalNumItems { get; }
@@ -369,13 +369,13 @@ namespace DotCMIS.Client
         IList<ITree<IFileableCmisObject>> GetFolderTree(int depth, IOperationContext context);
         IList<ITree<IFileableCmisObject>> GetDescendants(int depth);
         IList<ITree<IFileableCmisObject>> GetDescendants(int depth, IOperationContext context);
-        IItemIterable<ICmisObject> GetChildren();
-        IItemIterable<ICmisObject> GetChildren(IOperationContext context);
+        IItemEnumerable<ICmisObject> GetChildren();
+        IItemEnumerable<ICmisObject> GetChildren(IOperationContext context);
         bool IsRootFolder { get; }
         IFolder FolderParent { get; }
         string Path { get; }
-        IItemIterable<IDocument> GetCheckedOutDocs();
-        IItemIterable<IDocument> GetCheckedOutDocs(IOperationContext context);
+        IItemEnumerable<IDocument> GetCheckedOutDocs();
+        IItemEnumerable<IDocument> GetCheckedOutDocs(IOperationContext context);
     }
 
     public interface IPolicyProperties

Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs Sat Jan 29 16:41:19 2011
@@ -25,6 +25,9 @@ using DotCMIS.Data;
 
 namespace DotCMIS.Client
 {
+    /// <summary>
+    /// Helper for all type implementations.
+    /// </summary>
     internal class ObjectTypeHelper
     {
         private ISession session;
@@ -62,7 +65,7 @@ namespace DotCMIS.Client
             return parentType;
         }
 
-        public IItemIterable<IObjectType> GetChildren()
+        public IItemEnumerable<IObjectType> GetChildren()
         {
             return session.GetTypeChildren(objectType.Id, true);
         }
@@ -73,6 +76,9 @@ namespace DotCMIS.Client
         }
     }
 
+    /// <summary>
+    /// Document type implementation.
+    /// </summary>
     public class DocumentType : DocumentTypeDefinition, IDocumentType
     {
         private ObjectTypeHelper helper;
@@ -87,7 +93,7 @@ namespace DotCMIS.Client
 
         public IObjectType GetBaseType() { return helper.GetBaseType(); }
 
-        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }
+        public IItemEnumerable<IObjectType> GetChildren() { return helper.GetChildren(); }
 
         public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }
 
@@ -96,6 +102,9 @@ namespace DotCMIS.Client
         public bool IsBaseType { get { return helper.IsBaseType; } }
     }
 
+    /// <summary>
+    /// Folder type implementation.
+    /// </summary>
     public class FolderType : FolderTypeDefinition, IFolderType
     {
         private ObjectTypeHelper helper;
@@ -108,7 +117,7 @@ namespace DotCMIS.Client
 
         public IObjectType GetBaseType() { return helper.GetBaseType(); }
 
-        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }
+        public IItemEnumerable<IObjectType> GetChildren() { return helper.GetChildren(); }
 
         public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }
 
@@ -117,6 +126,9 @@ namespace DotCMIS.Client
         public bool IsBaseType { get { return helper.IsBaseType; } }
     }
 
+    /// <summary>
+    /// Relationship type implementation.
+    /// </summary>
     public class RelationshipType : RelationshipTypeDefinition, IRelationshipType
     {
         private ObjectTypeHelper helper;
@@ -131,7 +143,7 @@ namespace DotCMIS.Client
 
         public IObjectType GetBaseType() { return helper.GetBaseType(); }
 
-        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }
+        public IItemEnumerable<IObjectType> GetChildren() { return helper.GetChildren(); }
 
         public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }
 
@@ -182,6 +194,9 @@ namespace DotCMIS.Client
         }
     }
 
+    /// <summary>
+    /// Policy type implementation.
+    /// </summary>
     public class PolicyType : PolicyTypeDefinition, IPolicyType
     {
         private ObjectTypeHelper helper;
@@ -194,7 +209,7 @@ namespace DotCMIS.Client
 
         public IObjectType GetBaseType() { return helper.GetBaseType(); }
 
-        public IItemIterable<IObjectType> GetChildren() { return helper.GetChildren(); }
+        public IItemEnumerable<IObjectType> GetChildren() { return helper.GetChildren(); }
 
         public IList<ITree<IObjectType>> GetDescendants(int depth) { return helper.GetDescendants(depth); }
 

Added: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs?rev=1065064&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs Sat Jan 29 16:41:19 2011
@@ -0,0 +1,682 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using DotCMIS.Enums;
+using System.Collections;
+
+namespace DotCMIS.Client
+{
+    /// <summary>
+    /// Operation context implementation.
+    /// </summary>
+    public class OperationContext : IOperationContext
+    {
+        public const string PropertiesStar = "*";
+        public const string RenditionNone = "cmis:none";
+
+        private HashSet<string> filter;
+        private bool includeAllowableActions;
+        private bool includeAcls;
+        private IncludeRelationshipsFlag? includeRelationships;
+        private bool includePolicies;
+        private HashSet<string> renditionFilter;
+        private bool includePathSegments;
+        private string orderBy;
+        private bool cacheEnabled;
+        private string cacheKey;
+        private int maxItemsPerPage;
+
+        public OperationContext()
+        {
+            filter = null;
+            includeAcls = false;
+            includeAllowableActions = true;
+            includePolicies = false;
+            includeRelationships = IncludeRelationshipsFlag.None;
+            renditionFilter = null;
+            includePathSegments = true;
+            orderBy = null;
+            cacheEnabled = false;
+            maxItemsPerPage = 100;
+
+            GenerateCacheKey();
+        }
+
+        public OperationContext(IOperationContext source)
+        {
+            filter = new HashSet<string>(source.Filter);
+            includeAcls = source.IncludeAcls;
+            includeAllowableActions = source.IncludeAllowableActions;
+            includePolicies = source.IncludePolicies;
+            includeRelationships = source.IncludeRelationships;
+            renditionFilter = new HashSet<string>(source.RenditionFilter);
+            includePathSegments = source.IncludePathSegments;
+            orderBy = source.OrderBy;
+            cacheEnabled = source.CacheEnabled;
+            maxItemsPerPage = source.MaxItemsPerPage;
+
+            GenerateCacheKey();
+        }
+
+        public OperationContext(HashSet<string> filter, bool includeAcls, bool includeAllowableActions,
+            bool includePolicies, IncludeRelationshipsFlag includeRelationships, HashSet<string> renditionFilter,
+            bool includePathSegments, String orderBy, bool cacheEnabled, int maxItemsPerPage)
+        {
+            this.filter = filter;
+            this.includeAcls = includeAcls;
+            this.includeAllowableActions = includeAllowableActions;
+            this.includePolicies = includePolicies;
+            this.includeRelationships = includeRelationships;
+            this.renditionFilter = renditionFilter;
+            this.includePathSegments = includePathSegments;
+            this.orderBy = orderBy;
+            this.cacheEnabled = cacheEnabled;
+            this.maxItemsPerPage = maxItemsPerPage;
+
+            GenerateCacheKey();
+        }
+
+        public HashSet<string> Filter
+        {
+            get { return new HashSet<string>(filter); }
+            set
+            {
+                if (value != null)
+                {
+                    HashSet<string> tempSet = new HashSet<string>();
+                    foreach (string oid in value)
+                    {
+                        if (oid == null) { continue; }
+
+                        string toid = oid.Trim();
+                        if (toid.Length == 0) { continue; }
+                        if (toid == PropertiesStar)
+                        {
+                            tempSet = new HashSet<string>();
+                            tempSet.Add(PropertiesStar);
+                            break;
+                        }
+                        if (toid.IndexOf(',') > -1)
+                        {
+                            throw new ArgumentException("Query id must not contain a comma!");
+                        }
+
+                        tempSet.Add(toid);
+                    }
+
+                    if (tempSet.Count == 0) { filter = null; }
+                    else { filter = tempSet; }
+                }
+                else
+                {
+                    filter = null;
+                }
+
+                GenerateCacheKey();
+            }
+        }
+
+        public string FilterString
+        {
+            get
+            {
+                if (filter == null) { return null; }
+
+                if (filter.Contains(PropertiesStar))
+                {
+                    return PropertiesStar;
+                }
+
+                this.filter.Add(PropertyIds.ObjectId);
+                this.filter.Add(PropertyIds.BaseTypeId);
+                this.filter.Add(PropertyIds.ObjectTypeId);
+
+                StringBuilder sb = new StringBuilder();
+
+                foreach (String oid in filter)
+                {
+                    if (sb.Length > 0) { sb.Append(','); }
+                    sb.Append(oid);
+                }
+
+                return sb.ToString();
+            }
+
+            set
+            {
+                if (value == null || value.Trim().Length == 0)
+                {
+                    Filter = null;
+                    return;
+                }
+
+                string[] ids = value.Split(',');
+                HashSet<string> tempSet = new HashSet<string>();
+                foreach (string qid in ids)
+                {
+                    tempSet.Add(qid);
+                }
+
+                Filter = tempSet;
+            }
+        }
+
+        public bool IncludeAllowableActions
+        {
+            get { return includeAllowableActions; }
+            set { includeAllowableActions = value; GenerateCacheKey(); }
+        }
+
+        public bool IncludeAcls
+        {
+            get { return includeAcls; }
+            set { includeAcls = value; GenerateCacheKey(); }
+        }
+
+        public IncludeRelationshipsFlag? IncludeRelationships
+        {
+            get { return includeRelationships; }
+            set { includeRelationships = value; GenerateCacheKey(); }
+        }
+
+        public bool IncludePolicies
+        {
+            get { return includePolicies; }
+            set { includePolicies = value; GenerateCacheKey(); }
+        }
+
+        public HashSet<string> RenditionFilter
+        {
+            get { return new HashSet<string>(renditionFilter); }
+            set
+            {
+                HashSet<string> tempSet = new HashSet<string>();
+                if (value != null)
+                {
+                    foreach (String rf in value)
+                    {
+                        if (rf == null) { continue; }
+
+                        String trf = rf.Trim();
+                        if (trf.Length == 0) { continue; }
+                        if (trf.IndexOf(',') > -1)
+                        {
+                            throw new ArgumentException("Rendition must not contain a comma!");
+                        }
+
+                        tempSet.Add(trf);
+                    }
+
+                    if (tempSet.Count == 0)
+                    {
+                        tempSet.Add(RenditionNone);
+                    }
+                }
+                else
+                {
+                    tempSet.Add(RenditionNone);
+                }
+
+                renditionFilter = tempSet;
+
+                GenerateCacheKey();
+            }
+        }
+
+        public string RenditionFilterString
+        {
+            get
+            {
+                if (renditionFilter == null) { return null; }
+
+                StringBuilder sb = new StringBuilder();
+                foreach (string rf in renditionFilter)
+                {
+                    if (sb.Length > 0) { sb.Append(','); }
+                    sb.Append(rf);
+                }
+
+                return sb.ToString();
+            }
+
+            set
+            {
+                if (value == null || value.Trim().Length == 0)
+                {
+                    RenditionFilter = null;
+                    return;
+                }
+
+                string[] renditions = value.Split(',');
+                HashSet<string> tempSet = new HashSet<string>();
+                foreach (string rend in renditions)
+                {
+                    tempSet.Add(rend);
+                }
+
+                RenditionFilter = tempSet;
+            }
+        }
+
+        public bool IncludePathSegments
+        {
+            get { return includePathSegments; }
+            set { includePathSegments = value; GenerateCacheKey(); }
+        }
+
+        public string OrderBy
+        {
+            get { return orderBy; }
+            set { orderBy = value; GenerateCacheKey(); }
+        }
+
+        public bool CacheEnabled
+        {
+            get { return cacheEnabled; }
+            set { cacheEnabled = value; GenerateCacheKey(); }
+        }
+
+        public string CacheKey
+        {
+            get { return cacheKey; }
+        }
+
+        public int MaxItemsPerPage
+        {
+            get { return maxItemsPerPage; }
+            set { maxItemsPerPage = value; }
+        }
+
+        protected void GenerateCacheKey()
+        {
+            if (!cacheEnabled)
+            {
+                cacheKey = null;
+            }
+
+            StringBuilder sb = new StringBuilder();
+
+            sb.Append(includeAcls ? "1" : "0");
+            sb.Append(includeAllowableActions ? "1" : "0");
+            sb.Append(includePolicies ? "1" : "0");
+            sb.Append("|");
+            sb.Append(filter == null ? "" : FilterString);
+            sb.Append("|");
+            sb.Append(includeRelationships == null ? "" : includeRelationships.GetCmisValue());
+
+            sb.Append("|");
+            sb.Append(renditionFilter == null ? "" : RenditionFilterString);
+
+            cacheKey = sb.ToString();
+        }
+    }
+
+    /// <summary>
+    /// Object id implementation.
+    /// </summary>
+    public class ObjectId : IObjectId
+    {
+        private string id;
+        public string Id
+        {
+            get { return id; }
+            set
+            {
+                if (value == null || value.Length == 0)
+                {
+                    throw new ArgumentException("Id must be set!");
+                }
+
+                id = value;
+            }
+        }
+
+        public ObjectId(string id)
+        {
+            Id = id;
+        }
+    }
+
+    /// <summary>
+    /// Tree implementation.
+    /// </summary>
+    public class Tree<T> : ITree<T>
+    {
+        public T Item { get; set; }
+        public IList<ITree<T>> Children { get; set; }
+    }
+
+    /// <summary>
+    /// Base class for IItemEnumerable's.
+    /// </summary>
+    public abstract class AbstractEnumerable<T> : IItemEnumerable<T>
+    {
+        private AbstractEnumerator<T> enumerator;
+        protected AbstractEnumerator<T> Enumerator
+        {
+            get
+            {
+                if (enumerator == null) { enumerator = CreateEnumerator(); }
+                return enumerator;
+            }
+        }
+
+        protected PageFetcher<T> PageFetcher { get; set; }
+        protected long SkipCount { get; private set; }
+
+        public AbstractEnumerable(PageFetcher<T> pageFetcher) :
+            this(0, pageFetcher) { }
+
+        protected AbstractEnumerable(long position, PageFetcher<T> pageFetcher)
+        {
+            this.PageFetcher = pageFetcher;
+            this.SkipCount = position;
+        }
+
+        protected abstract AbstractEnumerator<T> CreateEnumerator();
+
+        IEnumerator<T> IEnumerable<T>.GetEnumerator()
+        {
+            return Enumerator;
+        }
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return Enumerator;
+        }
+
+        public IItemEnumerable<T> SkipTo(long position)
+        {
+            return new CollectionEnumerable<T>(position, PageFetcher);
+        }
+
+        public IItemEnumerable<T> GetPage()
+        {
+            return new CollectionPageEnumerable<T>(SkipCount, PageFetcher);
+        }
+
+        public IItemEnumerable<T> GetPage(int maxNumItems)
+        {
+            PageFetcher.MaxNumItems = maxNumItems;
+            return new CollectionPageEnumerable<T>(SkipCount, PageFetcher);
+        }
+
+        public long PageNumItems { get { return Enumerator.PageNumItems; } }
+
+        public bool HasMoreItems { get { return Enumerator.HasMoreItems; } }
+
+        public long TotalNumItems { get { return Enumerator.TotalNumItems; } }
+    }
+
+    /// <summary>
+    /// Abstract Enumerator implementation.
+    /// </summary>
+    public abstract class AbstractEnumerator<T> : IEnumerator<T>
+    {
+        private PageFetcher<T> pageFetcher;
+        private PageFetcher<T>.Page<T> page = null;
+        private long? totalNumItems = null;
+        private bool? hasMoreItems = null;
+
+        protected T current;
+
+        public AbstractEnumerator(long skipCount, PageFetcher<T> pageFetcher)
+        {
+            this.SkipCount = skipCount;
+            this.pageFetcher = pageFetcher;
+        }
+
+        T IEnumerator<T>.Current { get { return current; } }
+        object IEnumerator.Current { get { return current; } }
+
+        public void Reset()
+        {
+            throw new NotSupportedException();
+        }
+
+        public abstract bool MoveNext();
+
+        public void Dispose() { }
+
+        public long SkipCount { get; protected set; }
+
+        public int SkipOffset { get; protected set; }
+
+        public long Position { get { return SkipCount + SkipOffset; } }
+
+        public long PageNumItems
+        {
+            get
+            {
+                PageFetcher<T>.Page<T> page = GetCurrentPage();
+                if (page != null)
+                {
+                    IList<T> items = page.Items;
+                    if (items != null)
+                    {
+                        return items.Count;
+                    }
+                }
+                return 0;
+            }
+        }
+
+        public long TotalNumItems
+        {
+            get
+            {
+                if (totalNumItems == null)
+                {
+                    totalNumItems = -1;
+                    PageFetcher<T>.Page<T> page = GetCurrentPage();
+                    if (page != null)
+                    {
+                        totalNumItems = page.TotalNumItems;
+                    }
+                }
+                return (long)totalNumItems;
+            }
+        }
+
+        public bool HasMoreItems
+        {
+            get
+            {
+                if (hasMoreItems == null)
+                {
+                    hasMoreItems = false;
+                    PageFetcher<T>.Page<T> page = GetCurrentPage();
+                    if (page != null)
+                    {
+                        if (page.HasMoreItems.HasValue)
+                        {
+                            hasMoreItems = page.HasMoreItems;
+                        }
+                    }
+                }
+                return (bool)hasMoreItems;
+            }
+        }
+
+        protected int IncrementSkipOffset()
+        {
+            return SkipOffset++;
+        }
+
+        protected PageFetcher<T>.Page<T> GetCurrentPage()
+        {
+            if (page == null)
+            {
+                page = pageFetcher.FetchNextPage(SkipCount);
+            }
+            return page;
+        }
+
+        protected PageFetcher<T>.Page<T> IncrementPage()
+        {
+            SkipCount += SkipOffset;
+            SkipOffset = 0;
+            totalNumItems = null;
+            hasMoreItems = null;
+            page = pageFetcher.FetchNextPage(SkipCount);
+            return page;
+        }
+    }
+
+    /// <summary>
+    /// Page fetcher.
+    /// </summary>
+    public class PageFetcher<T>
+    {
+        public delegate Page<T> FetchPage(long maxNumItems, long skipCount);
+
+        private FetchPage fetchPageDelegate;
+
+        public PageFetcher(long maxNumItems, FetchPage fetchPageDelegate)
+        {
+            MaxNumItems = maxNumItems;
+            this.fetchPageDelegate = fetchPageDelegate;
+        }
+
+        public long MaxNumItems { get; set; }
+
+        public Page<T> FetchNextPage(long skipCount)
+        {
+            return fetchPageDelegate(MaxNumItems, skipCount);
+        }
+
+        public class Page<P>
+        {
+            public Page(IList<P> items, long? totalNumItems, bool? hasMoreItems)
+            {
+                Items = items;
+                TotalNumItems = totalNumItems;
+                HasMoreItems = hasMoreItems;
+            }
+
+            public IList<P> Items { get; private set; }
+            public long? TotalNumItems { get; private set; }
+            public bool? HasMoreItems { get; private set; }
+        }
+    }
+
+    /// <summary>
+    /// CMIS Collection Enumerable.
+    /// </summary>
+    public class CollectionEnumerable<T> : AbstractEnumerable<T>
+    {
+        public CollectionEnumerable(PageFetcher<T> pageFetcher) :
+            this(0, pageFetcher) { }
+
+        public CollectionEnumerable(long position, PageFetcher<T> pageFetcher) :
+            base(position, pageFetcher) { }
+
+        protected override AbstractEnumerator<T> CreateEnumerator()
+        {
+            return new CollectionEnumerator<T>(SkipCount, PageFetcher);
+        }
+    }
+
+    /// <summary>
+    /// Enumerator for iterating over all items in a CMIS Collection.
+    /// </summary>
+    public class CollectionEnumerator<T> : AbstractEnumerator<T>
+    {
+        public CollectionEnumerator(long skipCount, PageFetcher<T> pageFetcher) :
+            base(skipCount, pageFetcher) { }
+
+        public override bool MoveNext()
+        {
+            PageFetcher<T>.Page<T> page = GetCurrentPage();
+            if (page == null)
+            {
+                return false;
+            }
+
+            IList<T> items = page.Items;
+            if (items == null || items.Count == 0)
+            {
+                return false;
+            }
+
+            if (SkipOffset == items.Count)
+            {
+                page = IncrementPage();
+                items = page == null ? null : page.Items;
+            }
+
+            if (items == null || items.Count == 0 || SkipOffset == items.Count)
+            {
+                return false;
+            }
+
+            current = items[IncrementSkipOffset()];
+
+            return true;
+        }
+    }
+
+    /// <summary>
+    /// Enumerable for a CMIS Collection Page.
+    /// </summary>
+    public class CollectionPageEnumerable<T> : AbstractEnumerable<T>
+    {
+        public CollectionPageEnumerable(PageFetcher<T> pageFetcher) :
+            this(0, pageFetcher) { }
+
+        public CollectionPageEnumerable(long position, PageFetcher<T> pageFetcher) :
+            base(position, pageFetcher) { }
+
+        protected override AbstractEnumerator<T> CreateEnumerator()
+        {
+            return new CollectionPageEnumerator<T>(SkipCount, PageFetcher);
+        }
+    }
+
+    /// <summary>
+    /// Enumerator for iterating over a page of items in a CMIS Collection.
+    /// </summary>
+    public class CollectionPageEnumerator<T> : AbstractEnumerator<T>
+    {
+        public CollectionPageEnumerator(long skipCount, PageFetcher<T> pageFetcher) :
+            base(skipCount, pageFetcher) { }
+
+        public override bool MoveNext()
+        {
+            PageFetcher<T>.Page<T> page = GetCurrentPage();
+            if (page == null)
+            {
+                return false;
+            }
+
+            IList<T> items = page.Items;
+            if (items == null || items.Count == 0 || SkipOffset == items.Count)
+            {
+                return false;
+            }
+
+            current = items[IncrementSkipOffset()];
+
+            return true;
+        }
+    }
+}

Modified: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj Sat Jan 29 16:41:19 2011
@@ -44,7 +44,9 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="CRUDTest.cs" />
+    <Compile Include="EnumeratorTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SmokeTest.cs" />
     <Compile Include="TestFramework.cs" />
     <Compile Include="TypeTest.cs" />
   </ItemGroup>

Modified: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user Sat Jan 29 16:41:19 2011
@@ -3,7 +3,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
     <StartAction>Program</StartAction>
     <StartProgram>C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\nunit-console.exe</StartProgram>
-    <StartArguments>C:\projects\opencmis\DotCMIS\DotCMISUnitTest\bin\Debug\DotCMISUnitTest.dll</StartArguments>
-    <StartWorkingDirectory>C:\projects\opencmis\DotCMIS\DotCMISUnitTest\bin\Debug</StartWorkingDirectory>
+    <StartArguments>C:\projects\chemistry\dotcmis\trunk\DotCMISUnitTest\bin\Debug\DotCMISUnitTest.dll</StartArguments>
+    <StartWorkingDirectory>C:\projects\chemistry\dotcmis\trunk\DotCMISUnitTest\bin\Debug\</StartWorkingDirectory>
   </PropertyGroup>
 </Project>
\ No newline at end of file

Added: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs?rev=1065064&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs Sat Jan 29 16:41:19 2011
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System.Collections.Generic;
+using DotCMIS.Client;
+using NUnit.Framework;
+
+namespace DotCMISUnitTest
+{
+    [TestFixture]
+    class EnumeratorTest
+    {
+        private const int PageSize = 12;
+
+        private IList<int> source;
+        private IItemEnumerable<int> testEnumerable;
+
+        [SetUp]
+        public void Init()
+        {
+            source = new List<int>();
+            for (int i = 0; i < 100; i++)
+            {
+                source.Add(i);
+            }
+
+            PageFetcher<int>.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount)
+            {
+                IList<int> page = new List<int>();
+
+                for (int i = (int)skipCount; i < skipCount + maxNumItems; i++)
+                {
+                    if (source.Count <= i) { break; }
+                    page.Add(source[i]);
+                }
+
+                return new PageFetcher<int>.Page<int>(page, source.Count, skipCount + maxNumItems < source.Count);
+            };
+
+            testEnumerable = new CollectionEnumerable<int>(new PageFetcher<int>(PageSize, fetchPageDelegate));
+        }
+
+        [Test]
+        public void TestIteration()
+        {
+            Assert.AreEqual(source.Count, testEnumerable.TotalNumItems);
+            Assert.AreEqual(PageSize, testEnumerable.PageNumItems);
+
+            int i = 0;
+            foreach (int x in testEnumerable)
+            {
+                Assert.AreEqual(i, x);
+                i++;
+            }
+        }
+
+        [Test]
+        public void TestSkip()
+        {
+            int i = 42;
+            foreach (int x in testEnumerable.SkipTo(42))
+            {
+                Assert.AreEqual(i, x);
+                i++;
+            }
+
+            Assert.AreEqual(source.Count, i);
+        }
+
+        [Test]
+        public void TestOverSkip()
+        {
+            foreach (int x in testEnumerable.SkipTo(source.Count + 1))
+            {
+                Assert.Fail();
+            }
+        }
+
+        [Test]
+        public void TestPage()
+        {
+            int i = 0;
+            foreach (int x in testEnumerable.GetPage(8))
+            {
+                Assert.AreEqual(i, x);
+                i++;
+            }
+
+            Assert.AreEqual(8, i);
+        }
+
+        [Test]
+        public void TestBigPage()
+        {
+            int i = 0;
+            foreach (int x in testEnumerable.GetPage(source.Count * 2))
+            {
+                Assert.AreEqual(i, x);
+                i++;
+            }
+
+            Assert.AreEqual(source.Count, i);
+        }
+
+        [Test]
+        public void TestSkipAndPage()
+        {
+            int i = 42;
+            foreach (int x in testEnumerable.SkipTo(42).GetPage(20))
+            {
+                Assert.AreEqual(i, x);
+                i++;
+            }
+
+            Assert.AreEqual(62, i);
+        }
+    }
+}

Added: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs?rev=1065064&view=auto
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs (added)
+++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs Sat Jan 29 16:41:19 2011
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using DotCMIS.Client;
+using DotCMIS.Enums;
+
+namespace DotCMISUnitTest
+{
+    [TestFixture]
+    class SmokeTest : TestFramework
+    {
+        [Test]
+        public void TestSession()
+        {
+            Assert.NotNull(Session);
+            Assert.NotNull(Session.Binding);
+            Assert.NotNull(Session.RepositoryInfo);
+            Assert.NotNull(Session.RepositoryInfo.Id);
+            Assert.NotNull(Session.RepositoryInfo.RootFolderId);
+            Assert.NotNull(Session.DefaultContext);
+            Assert.NotNull(Session.ObjectFactory);
+
+            Assert.AreEqual("test", Session.CreateObjectId("test").Id);
+        }
+
+        [Test]
+        public void SmokeTestTypes()
+        {
+            // getTypeDefinition
+            IObjectType documentType = Session.GetTypeDefinition("cmis:document");
+            Assert.NotNull(documentType);
+            Assert.True(documentType is DocumentType);
+            Assert.AreEqual("cmis:document", documentType.Id);
+            Assert.AreEqual(BaseTypeId.CmisDocument, documentType.BaseTypeId);
+            Assert.True(documentType.IsBaseType);
+            Assert.Null(documentType.ParentTypeId);
+            Assert.NotNull(documentType.PropertyDefintions);
+            Assert.True(documentType.PropertyDefintions.Count >= 9);
+
+            IObjectType folderType = Session.GetTypeDefinition("cmis:folder");
+            Assert.NotNull(folderType);
+            Assert.True(folderType is FolderType);
+            Assert.AreEqual("cmis:folder", folderType.Id);
+            Assert.AreEqual(BaseTypeId.CmisFolder, folderType.BaseTypeId);
+            Assert.True(folderType.IsBaseType);
+            Assert.Null(folderType.ParentTypeId);
+            Assert.NotNull(folderType.PropertyDefintions);
+            Assert.True(folderType.PropertyDefintions.Count >= 9);
+
+            // getTypeChildren
+            Session.Clear();
+
+            IItemEnumerable<IObjectType> children = Session.GetTypeChildren(null, true);
+            Assert.NotNull(children);
+
+            int count;
+            count = 0;
+            foreach (IObjectType type in children)
+            {
+                Assert.NotNull(type);
+                Assert.NotNull(type.Id);
+                Assert.True(type.IsBaseType);
+                Assert.Null(type.ParentTypeId);
+                Assert.NotNull(type.PropertyDefintions);
+
+                Session.Clear();
+                IObjectType type2 = Session.GetTypeDefinition(type.Id);
+                AssertAreEqual(type, type2);
+
+                Session.GetTypeChildren(type.Id, true);
+
+                count++;
+            }
+
+            Assert.True(count >= 2);
+            Assert.True(count <= 4);
+
+            // getTypeDescendants
+            Session.Clear();
+
+            IList<ITree<IObjectType>> descendants = Session.GetTypeDescendants(null, -1, true);
+
+            count = 0;
+            foreach (ITree<IObjectType> tree in descendants)
+            {
+                Assert.NotNull(tree);
+                Assert.NotNull(tree.Item);
+
+                IObjectType type = tree.Item;
+                Assert.NotNull(type);
+                Assert.NotNull(type.Id);
+                Assert.True(type.IsBaseType);
+                Assert.Null(type.ParentTypeId);
+                Assert.NotNull(type.PropertyDefintions);
+
+                Session.Clear();
+                IObjectType type2 = Session.GetTypeDefinition(type.Id);
+                AssertAreEqual(type, type2);
+
+                Session.GetTypeDescendants(type.Id, 2, true);
+
+                count++;
+            }
+
+            Assert.True(count >= 2);
+            Assert.True(count <= 4);
+        }
+    }
+}

Modified: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs
URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs?rev=1065064&r1=1065063&r2=1065064&view=diff
==============================================================================
--- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs (original)
+++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs Sat Jan 29 16:41:19 2011
@@ -26,6 +26,7 @@ using DotCMIS.Data;
 using DotCMIS.Enums;
 using DotCMIS.Exceptions;
 using NUnit.Framework;
+using DotCMIS.Client;
 
 namespace DotCMISUnitTest
 {
@@ -33,7 +34,8 @@ namespace DotCMISUnitTest
     {
         private IRepositoryInfo repositoryInfo;
 
-        public ICmisBinding Binding { get; set; }
+        public ISession Session { get; set; }
+        public ICmisBinding Binding { get { return Session.Binding; } }
         public IRepositoryInfo RepositoryInfo
         {
             get
@@ -59,51 +61,59 @@ namespace DotCMISUnitTest
             DefaultDocumentType = "cmis:document";
             DefaultFolderType = "cmis:folder";
 
-            Binding = ConnectAtomPub();
+            Session = ConnectAtomPub();
         }
 
-        public ICmisBinding ConnectAtomPub()
+        public ISession ConnectAtomPub()
         {
-            Dictionary<string, string> parametersAtom = new Dictionary<string, string>();
+            Dictionary<string, string> parameters = new Dictionary<string, string>();
 
-            string baseUrlAtom = "http://localhost:8080/alfresco/opencmis-atom";
+            string baseUrlAtom = "http://localhost:8080/alfresco/service/cmis";
 
-            parametersAtom[SessionParameter.AtomPubUrl] = baseUrlAtom;
-            parametersAtom[SessionParameter.User] = "admin";
-            parametersAtom[SessionParameter.Password] = "admin";
+            parameters[SessionParameter.BindingType] = BindingType.AtomPub;
+            parameters[SessionParameter.AtomPubUrl] = baseUrlAtom;
+            parameters[SessionParameter.User] = "admin";
+            parameters[SessionParameter.Password] = "admin";
 
-            CmisBindingFactory factory = CmisBindingFactory.NewInstance();
-            ICmisBinding binding = factory.CreateCmisAtomPubBinding(parametersAtom);
+            SessionFactory factory = SessionFactory.NewInstance();
+            ISession session = factory.GetRepositories(parameters)[0].CreateSession();
 
-            Assert.NotNull(binding);
+            Assert.NotNull(session);
+            Assert.NotNull(session.Binding);
+            Assert.NotNull(session.RepositoryInfo);
+            Assert.NotNull(session.RepositoryInfo.Id);
 
-            return binding;
+            return session;
         }
 
-        public ICmisBinding ConnectWebServices()
+        public ISession ConnectWebServices()
         {
-            Dictionary<string, string> parametersWS = new Dictionary<string, string>();
+            Dictionary<string, string> parameters = new Dictionary<string, string>();
 
-            string baseUrlWS = "https://localhost:8443/alfresco/opencmis-ws";
+            string baseUrlWS = "http://localhost:8080/alfresco/cmis";
 
-            parametersWS[SessionParameter.WebServicesRepositoryService] = baseUrlWS + "/RepositoryService?wsdl";
-            parametersWS[SessionParameter.WebServicesAclService] = baseUrlWS + "/AclService?wsdl";
-            parametersWS[SessionParameter.WebServicesDiscoveryService] = baseUrlWS + "/DiscoveryService?wsdl";
-            parametersWS[SessionParameter.WebServicesMultifilingService] = baseUrlWS + "/MultifilingService?wsdl";
-            parametersWS[SessionParameter.WebServicesNavigationService] = baseUrlWS + "/NavigationService?wsdl";
-            parametersWS[SessionParameter.WebServicesObjectService] = baseUrlWS + "/ObjectService?wsdl";
-            parametersWS[SessionParameter.WebServicesPolicyService] = baseUrlWS + "/PolicyService?wsdl";
-            parametersWS[SessionParameter.WebServicesRelationshipService] = baseUrlWS + "/RelationshipService?wsdl";
-            parametersWS[SessionParameter.WebServicesVersioningService] = baseUrlWS + "/VersioningService?wsdl";
-            parametersWS[SessionParameter.User] = "admin";
-            parametersWS[SessionParameter.Password] = "admin";
+            parameters[SessionParameter.BindingType] = BindingType.WebServices;
+            parameters[SessionParameter.WebServicesRepositoryService] = baseUrlWS + "/RepositoryService?wsdl";
+            parameters[SessionParameter.WebServicesAclService] = baseUrlWS + "/AclService?wsdl";
+            parameters[SessionParameter.WebServicesDiscoveryService] = baseUrlWS + "/DiscoveryService?wsdl";
+            parameters[SessionParameter.WebServicesMultifilingService] = baseUrlWS + "/MultifilingService?wsdl";
+            parameters[SessionParameter.WebServicesNavigationService] = baseUrlWS + "/NavigationService?wsdl";
+            parameters[SessionParameter.WebServicesObjectService] = baseUrlWS + "/ObjectService?wsdl";
+            parameters[SessionParameter.WebServicesPolicyService] = baseUrlWS + "/PolicyService?wsdl";
+            parameters[SessionParameter.WebServicesRelationshipService] = baseUrlWS + "/RelationshipService?wsdl";
+            parameters[SessionParameter.WebServicesVersioningService] = baseUrlWS + "/VersioningService?wsdl";
+            parameters[SessionParameter.User] = "admin";
+            parameters[SessionParameter.Password] = "admin";
+
+            SessionFactory factory = SessionFactory.NewInstance();
+            ISession session = factory.GetRepositories(parameters)[0].CreateSession();
+
+            Assert.NotNull(session);
+            Assert.NotNull(session.Binding);
+            Assert.NotNull(session.RepositoryInfo);
+            Assert.NotNull(session.RepositoryInfo.Id);
 
-            CmisBindingFactory factory = CmisBindingFactory.NewInstance();
-            ICmisBinding binding = factory.CreateCmisWebServicesBinding(parametersWS);
-
-            Assert.NotNull(binding);
-
-            return binding;
+            return session;
         }
 
         public IObjectData GetFullObject(string objectId)
@@ -311,5 +321,28 @@ namespace DotCMISUnitTest
 
             return result;
         }
+
+        // ---- asserts ----
+
+        public void AssertAreEqual(IObjectType expected, IObjectType actual)
+        {
+            if (expected == null && actual == null)
+            {
+                return;
+            }
+
+            Assert.NotNull(expected);
+            Assert.NotNull(actual);
+
+            Assert.AreEqual(expected.Id, actual.Id);
+            Assert.AreEqual(expected.IsBaseType, actual.IsBaseType);
+            Assert.AreEqual(expected.BaseTypeId, actual.BaseTypeId);
+            Assert.AreEqual(expected.DisplayName, actual.DisplayName);
+            Assert.AreEqual(expected.Description, actual.Description);
+            Assert.AreEqual(expected.LocalName, actual.LocalName);
+            Assert.AreEqual(expected.LocalNamespace, actual.LocalNamespace);
+            Assert.AreEqual(expected.QueryName, actual.QueryName);
+            Assert.AreEqual(expected.PropertyDefintions.Count, actual.PropertyDefintions.Count);
+        }
     }
 }



Mime
View raw message