DotCMIS: more quick fixes

git-svn-id: https://svn.apache.org/repos/asf/chemistry/dotcmis/trunk@1510564 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/DotCMIS/Properties/AssemblyInfo.cs b/DotCMIS/Properties/AssemblyInfo.cs
index fe4c90a..ed5b1ed 100644
--- a/DotCMIS/Properties/AssemblyInfo.cs
+++ b/DotCMIS/Properties/AssemblyInfo.cs
@@ -1,4 +1,5 @@
-using System.Reflection;

+using System;

+using System.Reflection;

 using System.Runtime.CompilerServices;

 using System.Runtime.InteropServices;

 

@@ -19,6 +20,8 @@
 // COM, set the ComVisible attribute to true on that type.

 [assembly: ComVisible(false)]

 

+[assembly: CLSCompliant(true)]

+

 // The following GUID is for the ID of the typelib if this project is exposed to COM

 [assembly: Guid("ac118463-00ec-4e63-8c93-b45760f9abcf")]

 

diff --git a/DotCMIS/binding/binding-caches.cs b/DotCMIS/binding/binding-caches.cs
index 5e69e3f..dbdfa4f 100644
--- a/DotCMIS/binding/binding-caches.cs
+++ b/DotCMIS/binding/binding-caches.cs
@@ -593,7 +593,7 @@
 

             cache = new Cache("Repository Info Cache");

             cache.Initialize(new string[] { 

-                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount });

+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString() });

         }

 

         public void Put(IRepositoryInfo repositoryInfo)

@@ -643,8 +643,8 @@
 

             cache = new Cache("Type Definition Cache");

             cache.Initialize(new string[] {

-                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount, // repository

-                typeof(LruCacheLevel).FullName + " " + LruCacheLevel.MaxEntries + "=" + typeCount // type

+                typeof(DictionaryCacheLevel).FullName + " " + DictionaryCacheLevel.Capacity + "=" + repCount.ToString(), // repository

+                typeof(LruCacheLevel).FullName + " " + LruCacheLevel.MaxEntries + "=" + typeCount.ToString() // type

         });

         }

 

diff --git a/DotCMIS/binding/webservices/webservices.cs b/DotCMIS/binding/webservices/webservices.cs
index 2aeabde..18f9e24 100644
--- a/DotCMIS/binding/webservices/webservices.cs
+++ b/DotCMIS/binding/webservices/webservices.cs
@@ -257,29 +257,30 @@
                 elements.Add(transportElement);

 

                 binding = new CustomBinding(elements);

+                TimeSpan timeout;

 

                 string openTimeOut = session.GetValue(SessionParameter.WebServicesOpenTimeout) as string;

-                if (openTimeOut != null)

+                if (openTimeOut != null && TimeSpan.TryParse(openTimeOut, out timeout))

                 {

-                    binding.OpenTimeout = TimeSpan.Parse(openTimeOut);

+                    binding.OpenTimeout = timeout;

                 }

 

                 string closeTimeOut = session.GetValue(SessionParameter.WebServicesCloseTimeout) as string;

-                if (closeTimeOut != null)

+                if (closeTimeOut != null && TimeSpan.TryParse(closeTimeOut, out timeout))

                 {

-                    binding.CloseTimeout = TimeSpan.Parse(closeTimeOut);

+                    binding.CloseTimeout = timeout;

                 }

 

                 string sendTimeOut = session.GetValue(SessionParameter.WebServicesSendTimeout) as string;

-                if (sendTimeOut != null)

+                if (sendTimeOut != null && TimeSpan.TryParse(sendTimeOut, out timeout))

                 {

-                    binding.SendTimeout = TimeSpan.Parse(sendTimeOut);

+                    binding.SendTimeout = timeout;

                 }

 

                 string receiveTimeOut = session.GetValue(SessionParameter.WebServicesReceiveTimeout) as string;

-                if (receiveTimeOut != null)

+                if (receiveTimeOut != null && TimeSpan.TryParse(receiveTimeOut, out timeout))

                 {

-                    binding.ReceiveTimeout = TimeSpan.Parse(receiveTimeOut);

+                    binding.ReceiveTimeout = timeout;

                 }

             }

 

diff --git a/DotCMIS/client/client-caches.cs b/DotCMIS/client/client-caches.cs
index 17d5e87..c204857 100644
--- a/DotCMIS/client/client-caches.cs
+++ b/DotCMIS/client/client-caches.cs
@@ -73,8 +73,7 @@
 

         public void Initialize(ISession session, IDictionary<string, string> parameters)

         {

-            Lock();

-            try

+            lock (cacheLock)

             {

                 // cache size

                 cacheSize = 1000;

@@ -142,24 +141,15 @@
 

                 InitializeInternals();

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         private void InitializeInternals()

         {

-            Lock();

-            try

+            lock (cacheLock)

             {

                 objectCache = new LRUCache<string, IDictionary<string, ICmisObject>>(cacheSize, TimeSpan.FromMilliseconds(cacheTtl));

                 pathToIdCache = new LRUCache<string, string>(pathToIdSize, TimeSpan.FromMilliseconds(pathToIdTtl));

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public void Clear()

@@ -169,34 +159,23 @@
 

         public bool ContainsId(string objectId, string cacheKey)

         {

-            Lock();

-            try

+            lock (cacheLock)

             {

                 return objectCache.Get(objectId) != null;

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public bool ContainsPath(string path, string cacheKey)

         {

-            Lock();

-            try

+            lock (cacheLock)

             {

                 return pathToIdCache.Get(path) != null;

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public ICmisObject GetById(string objectId, string cacheKey)

         {

-            Lock();

-            try

+            lock (cacheLock)

             {

                 IDictionary<string, ICmisObject> cacheKeyDict = objectCache.Get(objectId);

                 if (cacheKeyDict == null)

@@ -212,16 +191,11 @@
 

                 return null;

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public ICmisObject GetByPath(string path, string cacheKey)

         {

-            Lock();

-            try

+            lock (cacheLock)

             {

                 string id = pathToIdCache.Get(path);

                 if (id == null)

@@ -231,10 +205,6 @@
 

                 return GetById(id, cacheKey);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public void Put(ICmisObject cmisObject, string cacheKey)

@@ -245,8 +215,7 @@
                 return;

             }

 

-            Lock();

-            try

+            lock (cacheLock)

             {

                 IDictionary<string, ICmisObject> cacheKeyDict = objectCache.Get(cmisObject.Id);

                 if (cacheKeyDict == null)

@@ -264,10 +233,6 @@
                     pathToIdCache.Add(path, cmisObject.Id);

                 }

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public void PutPath(string path, ICmisObject cmisObject, string cacheKey)

@@ -278,16 +243,11 @@
                 return;

             }

 

-            Lock();

-            try

+            lock (cacheLock)

             {

                 Put(cmisObject, cacheKey);

                 pathToIdCache.Add(path, cmisObject.Id);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public void Remove(string objectId)

@@ -297,30 +257,15 @@
                 return;

             }

 

-            Lock();

-            try

+            lock (cacheLock)

             {

                 objectCache.Remove(objectId);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public int CacheSize

         {

             get { return cacheSize; }

         }

-

-        protected void Lock()

-        {

-            Monitor.Enter(cacheLock);

-        }

-

-        protected void Unlock()

-        {

-            Monitor.Exit(cacheLock);

-        }

     }

 }

diff --git a/DotCMIS/client/client-impl.cs b/DotCMIS/client/client-impl.cs
index 7b62ee5..dbf8f42 100644
--- a/DotCMIS/client/client-impl.cs
+++ b/DotCMIS/client/client-impl.cs
@@ -202,27 +202,17 @@
         {

             get

             {

-                Lock();

-                try

+                lock (sessionLock)

                 {

                     return context;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

             set

             {

-                Lock();

-                try

+                lock (sessionLock)

                 {

                     context = (value == null ? FallbackContext : value);

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -252,8 +242,7 @@
 

         public void Connect()

         {

-            Lock();

-            try

+            lock (sessionLock)

             {

                 Binding = CmisBindingHelper.CreateBinding(parameters, AuthenticationProvider);

 

@@ -265,10 +254,6 @@
 

                 RepositoryInfo = Binding.GetRepositoryService().GetRepositoryInfo(repositoryId, null);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         protected ICache CreateCache()

@@ -337,16 +322,11 @@
 

         public void Clear()

         {

-            Lock();

-            try

+            lock (sessionLock)

             {

                 Cache = CreateCache();

                 Binding.ClearAllCaches();

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         // session context

@@ -654,18 +634,13 @@
         public IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems,

                 IOperationContext context)

         {

-            Lock();

-            try

+            lock (sessionLock)

             {

                 IObjectList objectList = Binding.GetDiscoveryService().GetContentChanges(RepositoryId, ref changeLogToken, includeProperties,

                     context.FilterString, context.IncludePolicies, context.IncludeAcls, maxNumItems, null);

 

                 return ObjectFactory.ConvertChangeEvents(changeLogToken, objectList);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         // create

@@ -960,15 +935,5 @@
                 Binding.GetPolicyService().RemovePolicy(RepositoryId, id, objectId.Id, null);

             }

         }

-

-        protected void Lock()

-        {

-            Monitor.Enter(sessionLock);

-        }

-

-        protected void Unlock()

-        {

-            Monitor.Exit(sessionLock);

-        }

     }

 }

diff --git a/DotCMIS/client/client-objects.cs b/DotCMIS/client/client-objects.cs
index e0bce61..53142eb 100644
--- a/DotCMIS/client/client-objects.cs
+++ b/DotCMIS/client/client-objects.cs
@@ -44,15 +44,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return objectType;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -80,7 +75,7 @@
         private IList<IRelationship> relationships;

         private IDictionary<ExtensionLevel, IList<ICmisExtensionElement>> extensions;

 

-        private object objectLock = new object();

+        protected object objectLock = new object();

 

         protected void Initialize(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context)

         {

@@ -176,8 +171,7 @@
 

         protected string GetPropertyQueryName(string propertyId)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 IPropertyDefinition propDef = objectType[propertyId];

                 if (propDef == null)

@@ -187,25 +181,16 @@
 

                 return propDef.QueryName;

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         // --- object ---

 

         public void Delete(bool allVersions)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 Session.Delete(this, allVersions);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public ICmisObject UpdateProperties(IDictionary<string, object> properties)

@@ -233,8 +218,7 @@
 

             string newObjectId = null;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 string objectId = ObjectId;

                 string changeToken = ChangeToken;

@@ -255,10 +239,6 @@
 

                 newObjectId = objectId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             if (refresh)

             {

@@ -306,15 +286,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return new List<IProperty>(properties.Values);

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -327,8 +302,7 @@
                     throw new ArgumentNullException("propertyId");

                 }

 

-                Lock();

-                try

+                lock (objectLock)

                 {

                     IProperty property;

                     if (properties.TryGetValue(propertyId, out property))

@@ -337,10 +311,6 @@
                     }

                     return null;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -358,15 +328,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return allowableActions;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -376,15 +341,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return renditions;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -418,15 +378,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return acl;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -434,30 +389,20 @@
 

         public void ApplyPolicy(params IObjectId[] policyId)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 Session.ApplyPolicy(this, policyId);

             }

-            finally

-            {

-                Unlock();

-            }

 

             Refresh();

         }

 

         public void RemovePolicy(params IObjectId[] policyId)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 Session.RemovePolicy(this, policyId);

             }

-            finally

-            {

-                Unlock();

-            }

 

             Refresh();

         }

@@ -466,15 +411,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return policies;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -484,15 +424,10 @@
         {

             get

             {

-                Lock();

-                try

+                lock (objectLock)

                 {

                     return relationships;

                 }

-                finally

-                {

-                    Unlock();

-                }

             }

         }

 

@@ -515,8 +450,7 @@
 

         public void Refresh()

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 IOperationContext oc = CreationContext;

 

@@ -527,36 +461,17 @@
                 // reset this object

                 Initialize(Session, ObjectType, objectData, CreationContext);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public void RefreshIfOld(long durationInMillis)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 if (((DateTime.UtcNow - RefreshTimestamp).Ticks / 10000) > durationInMillis)

                 {

                     Refresh();

                 }

             }

-            finally

-            {

-                Unlock();

-            }

-        }

-

-        protected void Lock()

-        {

-            Monitor.Enter(objectLock);

-        }

-

-        protected void Unlock()

-        {

-            Monitor.Exit(objectLock);

         }

     }

 

@@ -773,8 +688,7 @@
         {

             string newObjectId = null;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 string objectId = ObjectId;

                 bool? contentCopied;

@@ -782,10 +696,6 @@
                 Binding.GetVersioningService().CheckOut(RepositoryId, ref objectId, null, out contentCopied);

                 newObjectId = objectId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             if (newObjectId == null)

             {

@@ -805,8 +715,7 @@
         {

             String newObjectId = null;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 string objectId = ObjectId;

 

@@ -821,10 +730,6 @@
 

                 newObjectId = objectId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             if (newObjectId == null)

             {

@@ -845,16 +750,11 @@
             string objectId;

             string versionSeriesId;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 objectId = ObjectId;

                 versionSeriesId = VersionSeriesId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             IList<IObjectData> versions = Binding.GetVersioningService().GetAllVersions(RepositoryId, objectId, versionSeriesId,

                 context.FilterString, context.IncludeAllowableActions, null);

@@ -890,16 +790,11 @@
             string objectId;

             string versionSeriesId;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 objectId = ObjectId;

                 versionSeriesId = VersionSeriesId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             if (versionSeriesId == null)

             {

@@ -977,8 +872,7 @@
         {

             string newObjectId = null;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 string objectId = ObjectId;

                 string changeToken = ChangeToken;

@@ -987,10 +881,6 @@
 

                 newObjectId = objectId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             if (refresh)

             {

@@ -1025,8 +915,7 @@
         {

             string newObjectId = null;

 

-            Lock();

-            try

+            lock (objectLock)

             {

                 string objectId = ObjectId;

                 string changeToken = ChangeToken;

@@ -1035,10 +924,6 @@
 

                 newObjectId = objectId;

             }

-            finally

-            {

-                Unlock();

-            }

 

             if (refresh)

             {

@@ -1165,8 +1050,7 @@
             {

                 IList<IObjectType> result = new List<IObjectType>();

 

-                Lock();

-                try

+                lock (objectLock)

                 {

                     IList<string> otids = GetPropertyValue(PropertyIds.AllowedChildObjectTypeIds) as IList<string>;

                     if (otids == null)

@@ -1179,10 +1063,6 @@
                         result.Add(Session.GetTypeDefinition(otid));

                     }

                 }

-                finally

-                {

-                    Unlock();

-                }

 

                 return result;

             }

@@ -1359,8 +1239,7 @@
             {

                 string path;

 

-                Lock();

-                try

+                lock (objectLock)

                 {

                     // get the path property

                     path = GetPropertyValue(PropertyIds.Path) as string;

@@ -1382,10 +1261,6 @@
                         }

                     }

                 }

-                finally

-                {

-                    Unlock();

-                }

 

                 // we still don't know the path ... it's not a CMIS compliant repository

                 if (path == null)

@@ -1460,8 +1335,7 @@
 

         public ICmisObject GetSource(IOperationContext context)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 IObjectId sourceId = SourceId;

                 if (sourceId == null)

@@ -1471,10 +1345,6 @@
 

                 return Session.GetObject(sourceId, context);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public IObjectId SourceId

@@ -1498,8 +1368,7 @@
 

         public ICmisObject GetTarget(IOperationContext context)

         {

-            Lock();

-            try

+            lock (objectLock)

             {

                 IObjectId targetId = TargetId;

                 if (targetId == null)

@@ -1509,10 +1378,6 @@
 

                 return Session.GetObject(targetId, context);

             }

-            finally

-            {

-                Unlock();

-            }

         }

 

         public IObjectId TargetId

diff --git a/DotCMIS/client/client-utils.cs b/DotCMIS/client/client-utils.cs
index 5c9a67e..9043995 100644
--- a/DotCMIS/client/client-utils.cs
+++ b/DotCMIS/client/client-utils.cs
@@ -436,7 +436,7 @@
         private long? totalNumItems = null;

         private bool? hasMoreItems = null;

 

-        protected T current;

+        protected T Current;

 

         public AbstractEnumerator(long skipCount, PageFetcher<T> pageFetcher)

         {

@@ -444,8 +444,8 @@
             this.pageFetcher = pageFetcher;

         }

 

-        T IEnumerator<T>.Current { get { return current; } }

-        object IEnumerator.Current { get { return current; } }

+        T IEnumerator<T>.Current { get { return Current; } }

+        object IEnumerator.Current { get { return Current; } }

 

         public void Reset()

         {

@@ -633,7 +633,7 @@
                 return false;

             }

 

-            current = items[IncrementSkipOffset()];

+            Current = items[IncrementSkipOffset()];

 

             return true;

         }

@@ -678,7 +678,7 @@
                 return false;

             }

 

-            current = items[IncrementSkipOffset()];

+            Current = items[IncrementSkipOffset()];

 

             return true;

         }

diff --git a/DotCMIS/enums.cs b/DotCMIS/enums.cs
index 02a1467..0b32e25 100644
--- a/DotCMIS/enums.cs
+++ b/DotCMIS/enums.cs
@@ -308,6 +308,7 @@
 

     // --- attribute class ---

 

+    [AttributeUsage(AttributeTargets.Field)]

     public class CmisValueAttribute : System.Attribute

     {

         public CmisValueAttribute(string value)