Added: chemistry/portcmis/PortCMIS/enum/Enums.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMIS/enum/Enums.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMIS/enum/Enums.cs (added) +++ chemistry/portcmis/PortCMIS/enum/Enums.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,395 @@ +/* +* 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.Reflection; + +namespace PortCMIS.Enums +{ + public enum BaseTypeId + { + [CmisValue("cmis:document")] + CmisDocument, + [CmisValue("cmis:folder")] + CmisFolder, + [CmisValue("cmis:relationship")] + CmisRelationship, + [CmisValue("cmis:policy")] + CmisPolicy, + [CmisValue("cmis:item")] + CmisItem, + [CmisValue("cmis:secondary")] + CmisSecondary + } + + public enum CapabilityContentStreamUpdates + { + [CmisValue("anytime")] + Anyime, + [CmisValue("pwconly")] + PWCOnly, + [CmisValue("none")] + None + } + + public enum CapabilityChanges + { + [CmisValue("none")] + None, + [CmisValue("objectidsonly")] + ObjectIdsOnly, + [CmisValue("properties")] + Properties, + [CmisValue("all")] + All + } + + public enum CapabilityRenditions + { + [CmisValue("none")] + None, + [CmisValue("read")] + Read + } + + public enum CapabilityQuery + { + [CmisValue("none")] + None, + [CmisValue("metadataonly")] + MetadataOnly, + [CmisValue("fulltextonly")] + FulltextOnly, + [CmisValue("bothseparate")] + BothSeparate, + [CmisValue("bothcombined")] + BothCombined + } + + public enum CapabilityJoin + { + [CmisValue("none")] + None, + [CmisValue("inneronly")] + InnerOnly, + [CmisValue("innerandouter")] + InnerAndOuter + } + + public enum CapabilityAcl + { + [CmisValue("none")] + None, + [CmisValue("discover")] + Discover, + [CmisValue("manage")] + Manage + } + + public enum CapabilityOrderBy + { + [CmisValue("none")] + None, + [CmisValue("common")] + Common, + [CmisValue("custom")] + Custom + } + + public enum SupportedPermissions + { + [CmisValue("basic")] + Basic, + [CmisValue("repository")] + Repository, + [CmisValue("both")] + Both + } + + public enum AclPropagation + { + [CmisValue("repositorydetermined")] + RepositoryDetermined, + [CmisValue("objectonly")] + ObjectOnly, + [CmisValue("propagate")] + Propagate + } + + public enum ContentStreamAllowed + { + [CmisValue("notallowed")] + NotAllowed, + [CmisValue("allowed")] + Allowed, + [CmisValue("required")] + Required + } + + public enum PropertyType + { + [CmisValue("boolean")] + Boolean, + [CmisValue("id")] + Id, + [CmisValue("integer")] + Integer, + [CmisValue("datetime")] + DateTime, + [CmisValue("decimal")] + Decimal, + [CmisValue("html")] + Html, + [CmisValue("string")] + String, + [CmisValue("uri")] + Uri + } + + public enum Cardinality + { + [CmisValue("single")] + Single, + [CmisValue("multi")] + Multi + } + + public enum Updatability + { + [CmisValue("readonly")] + ReadOnly, + [CmisValue("readwrite")] + ReadWrite, + [CmisValue("whencheckedout")] + WhenCheckedOut, + [CmisValue("oncreate")] + OnCreate + } + + public enum DateTimeResolution + { + [CmisValue("year")] + Year, + [CmisValue("date")] + Date, + [CmisValue("time")] + Time + } + + public enum DecimalPrecision + { + [CmisValue("32")] + Bits32, + [CmisValue("64")] + Bits64 + } + + public enum IncludeRelationships + { + [CmisValue("none")] + None, + [CmisValue("source")] + Source, + [CmisValue("target")] + Target, + [CmisValue("both")] + Both + } + + public enum VersioningState + { + [CmisValue("none")] + None, + [CmisValue("major")] + Major, + [CmisValue("minor")] + Minor, + [CmisValue("checkedout")] + CheckedOut + } + + public enum UnfileObject + { + [CmisValue("unfile")] + Unfile, + [CmisValue("deletesinglefiled")] + DeleteSinglefiled, + [CmisValue("delete")] + Delete + } + + public enum RelationshipDirection + { + [CmisValue("source")] + Source, + [CmisValue("target")] + Target, + [CmisValue("either")] + Either + } + + public enum ReturnVersion + { + [CmisValue("this")] + This, + [CmisValue("latest")] + Latest, + [CmisValue("latestmajor")] + LatestMajor + } + + public enum ChangeType + { + [CmisValue("created")] + Created, + [CmisValue("updated")] + Updated, + [CmisValue("deleted")] + Deleted, + [CmisValue("security")] + Security + } + + public enum DateTimeFormat + { + [CmisValue("simple")] + Simple, + [CmisValue("extended")] + Extended + } + + public enum Action + { + [CmisValue("canDeleteObject")] + CanDeleteObject, + [CmisValue("canUpdateProperties")] + CanUpdateProperties, + [CmisValue("canGetFolderTree")] + CanGetFolderTree, + [CmisValue("canGetProperties")] + CanGetProperties, + [CmisValue("canGetObjectRelationships")] + CanGetObjectRelationships, + [CmisValue("canGetObjectParents")] + CanGetObjectParents, + [CmisValue("canGetFolderParent")] + CanGetFolderParent, + [CmisValue("canGetDescendants")] + CanGetDescendants, + [CmisValue("canMoveObject")] + CanMoveObject, + [CmisValue("canDeleteContentStream")] + CanDeleteContentStream, + [CmisValue("canCheckOut")] + CanCheckOut, + [CmisValue("canCancelCheckOut")] + CanCancelCheckOut, + [CmisValue("canCheckIn")] + CanCheckIn, + [CmisValue("canSetContentStream")] + CanSetContentStream, + [CmisValue("canGetAllVersions")] + CanGetAllVersions, + [CmisValue("canAddObjectToFolder")] + CanAddObjectToFolder, + [CmisValue("canRemoveObjectFromFolder")] + CanRemoveObjectFromFolder, + [CmisValue("canGetContentStream")] + CanGetContentStream, + [CmisValue("canApplyPolicy")] + CanApplyPolicy, + [CmisValue("canGetAppliedPolicies")] + CanGetAppliedPolicies, + [CmisValue("canRemovePolicy")] + CanRemovePolicy, + [CmisValue("canGetChildren")] + CanGetChildren, + [CmisValue("canCreateDocument")] + CanCreateDocument, + [CmisValue("canCreateFolder")] + CanCreateFolder, + [CmisValue("canCreateRelationship")] + CanCreateRelationship, + [CmisValue("canCreateItem")] + CanCreateItem, + [CmisValue("canDeleteTree")] + CanDeleteTree, + [CmisValue("canGetRenditions")] + CanGetRenditions, + [CmisValue("canGetAcl")] + CanGetAcl, + [CmisValue("canApplyAcl")] + CanApplyAcl + } + + public enum CmisVersion + { + [CmisValue("1.0")] + Cmis_1_0, + [CmisValue("1.1")] + Cmis_1_1 + } + + // --- attribute class --- + + [AttributeUsage(AttributeTargets.Field)] + public class CmisValueAttribute : System.Attribute + { + public CmisValueAttribute(string value) + { + Value = value; + } + public string Value + { + get; + private set; + } + } + + public static class CmisValue + { + public static string GetCmisValue(this Enum value) + { + FieldInfo fieldInfo = value.GetType().GetRuntimeField(value.ToString()); + CmisValueAttribute[] cmisValueAttr = fieldInfo.GetCustomAttributes(typeof(CmisValueAttribute), false) as CmisValueAttribute[]; + return cmisValueAttr.Length > 0 ? cmisValueAttr[0].Value : null; + } + + public static T GetCmisEnum<T>(this string value) + { + Type type = typeof(T); + Type underlyingType = Nullable.GetUnderlyingType(type); + if (underlyingType != null) + { + type = underlyingType; + } + + foreach (FieldInfo fieldInfo in type.GetRuntimeFields()) + { + CmisValueAttribute[] cmisValueAttr = fieldInfo.GetCustomAttributes(typeof(CmisValueAttribute), false) as CmisValueAttribute[]; + if (cmisValueAttr != null && cmisValueAttr.Length > 0 && cmisValueAttr[0].Value == value) + { + return (T)Enum.Parse(type, fieldInfo.Name); + } + } + return default(T); + } + } +}
Added: chemistry/portcmis/PortCMIS/exceptions/Exceptions.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMIS/exceptions/Exceptions.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMIS/exceptions/Exceptions.cs (added) +++ chemistry/portcmis/PortCMIS/exceptions/Exceptions.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,342 @@ +/* +* 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; + +namespace PortCMIS.Exceptions +{ + /// <summary> + /// Base exception for all CMIS exceptions. + /// </summary> + public abstract class CmisBaseException : Exception + { + public CmisBaseException() : base() { Code = null; } + public CmisBaseException(string message) : base(message) { Code = null; } + public CmisBaseException(string message, Exception inner) : base(message, inner) { Code = null; } + public CmisBaseException(string message, long? code) + : this(message) + { + Code = code; + } + public CmisBaseException(string message, string errorContent) + : this(message) + { + ErrorContent = errorContent; + } + public CmisBaseException(string message, string errorContent, Exception inner) + : this(message, inner) + { + ErrorContent = errorContent; + } + public long? Code { get; protected set; } + public string ErrorContent { get; protected set; } + + public abstract string GetExtensionName(); + } + + public class CmisConnectionException : CmisBaseException + { + public CmisConnectionException() : base() { } + public CmisConnectionException(string message) : base(message) { } + public CmisConnectionException(string message, Exception inner) : base(message, inner) { } + public CmisConnectionException(string message, long? code) : base(message) { } + public CmisConnectionException(string message, string errorContent) : base(message) { } + public CmisConnectionException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "connection"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisConstraintException : CmisBaseException + { + public CmisConstraintException() : base() { } + public CmisConstraintException(string message) : base(message) { } + public CmisConstraintException(string message, Exception inner) : base(message, inner) { } + public CmisConstraintException(string message, long? code) : base(message) { } + public CmisConstraintException(string message, string errorContent) : base(message) { } + public CmisConstraintException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "constraint"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisContentAlreadyExistsException : CmisBaseException + { + public CmisContentAlreadyExistsException() : base() { } + public CmisContentAlreadyExistsException(string message) : base(message) { } + public CmisContentAlreadyExistsException(string message, Exception inner) : base(message, inner) { } + public CmisContentAlreadyExistsException(string message, long? code) : base(message) { } + public CmisContentAlreadyExistsException(string message, string errorContent) : base(message) { } + public CmisContentAlreadyExistsException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "contentAlreadyExists"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisFilterNotValidException : CmisBaseException + { + public CmisFilterNotValidException() : base() { } + public CmisFilterNotValidException(string message) : base(message) { } + public CmisFilterNotValidException(string message, Exception inner) : base(message, inner) { } + public CmisFilterNotValidException(string message, long? code) : base(message) { } + public CmisFilterNotValidException(string message, string errorContent) : base(message) { } + public CmisFilterNotValidException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "filterNotValid"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisInvalidArgumentException : CmisBaseException + { + public CmisInvalidArgumentException() : base() { } + public CmisInvalidArgumentException(string message) : base(message) { } + public CmisInvalidArgumentException(string message, Exception inner) : base(message, inner) { } + public CmisInvalidArgumentException(string message, long? code) : base(message) { } + public CmisInvalidArgumentException(string message, string errorContent) : base(message) { } + public CmisInvalidArgumentException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "invalidArgument"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisNameConstraintViolationException : CmisBaseException + { + public CmisNameConstraintViolationException() : base() { } + public CmisNameConstraintViolationException(string message) : base(message) { } + public CmisNameConstraintViolationException(string message, Exception inner) : base(message, inner) { } + public CmisNameConstraintViolationException(string message, long? code) : base(message) { } + public CmisNameConstraintViolationException(string message, string errorContent) : base(message) { } + public CmisNameConstraintViolationException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "nameConstraintViolation"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisNotSupportedException : CmisBaseException + { + public CmisNotSupportedException() : base() { } + public CmisNotSupportedException(string message) : base(message) { } + public CmisNotSupportedException(string message, Exception inner) : base(message, inner) { } + public CmisNotSupportedException(string message, long? code) : base(message) { } + public CmisNotSupportedException(string message, string errorContent) : base(message) { } + public CmisNotSupportedException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "notSupported"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisObjectNotFoundException : CmisBaseException + { + public CmisObjectNotFoundException() : base() { } + public CmisObjectNotFoundException(string message) : base(message) { } + public CmisObjectNotFoundException(string message, Exception inner) : base(message, inner) { } + public CmisObjectNotFoundException(string message, long? code) : base(message) { } + public CmisObjectNotFoundException(string message, string errorContent) : base(message) { } + public CmisObjectNotFoundException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "objectNotFound"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisPermissionDeniedException : CmisBaseException + { + public CmisPermissionDeniedException() : base() { } + public CmisPermissionDeniedException(string message) : base(message) { } + public CmisPermissionDeniedException(string message, Exception inner) : base(message, inner) { } + public CmisPermissionDeniedException(string message, long? code) : base(message) { } + public CmisPermissionDeniedException(string message, string errorContent) : base(message) { } + public CmisPermissionDeniedException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "permissionDenied"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisRuntimeException : CmisBaseException + { + public CmisRuntimeException() : base() { } + public CmisRuntimeException(string message) : base(message) { } + public CmisRuntimeException(string message, Exception inner) : base(message, inner) { } + public CmisRuntimeException(string message, long? code) : base(message) { } + public CmisRuntimeException(string message, string errorContent) : base(message) { } + public CmisRuntimeException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "runtime"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisStorageException : CmisBaseException + { + public CmisStorageException() : base() { } + public CmisStorageException(string message) : base(message) { } + public CmisStorageException(string message, Exception inner) : base(message, inner) { } + public CmisStorageException(string message, long? code) : base(message) { } + public CmisStorageException(string message, string errorContent) : base(message) { } + public CmisStorageException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "storage"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisStreamNotSupportedException : CmisBaseException + { + public CmisStreamNotSupportedException() : base() { } + public CmisStreamNotSupportedException(string message) : base(message) { } + public CmisStreamNotSupportedException(string message, Exception inner) : base(message, inner) { } + public CmisStreamNotSupportedException(string message, long? code) : base(message) { } + public CmisStreamNotSupportedException(string message, string errorContent) : base(message) { } + public CmisStreamNotSupportedException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "streamNotSupported"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisUpdateConflictException : CmisBaseException + { + public CmisUpdateConflictException() : base() { } + public CmisUpdateConflictException(string message) : base(message) { } + public CmisUpdateConflictException(string message, Exception inner) : base(message, inner) { } + public CmisUpdateConflictException(string message, long? code) : base(message) { } + public CmisUpdateConflictException(string message, string errorContent) : base(message) { } + public CmisUpdateConflictException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "updateConflict"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisVersioningException : CmisBaseException + { + public CmisVersioningException() : base() { } + public CmisVersioningException(string message) : base(message) { } + public CmisVersioningException(string message, Exception inner) : base(message, inner) { } + public CmisVersioningException(string message, long? code) : base(message) { } + public CmisVersioningException(string message, string errorContent) : base(message) { } + public CmisVersioningException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public const string ExceptionName = "versioning"; + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisUnauthorizedException : CmisRuntimeException + { + public CmisUnauthorizedException() : base() { } + public CmisUnauthorizedException(string message) : base(message) { } + public CmisUnauthorizedException(string message, Exception inner) : base(message, inner) { } + public CmisUnauthorizedException(string message, long? code) : base(message) { } + public CmisUnauthorizedException(string message, string errorContent) : base(message) { } + public CmisUnauthorizedException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisProxyAuthenticationException : CmisRuntimeException + { + public CmisProxyAuthenticationException() : base() { } + public CmisProxyAuthenticationException(string message) : base(message) { } + public CmisProxyAuthenticationException(string message, Exception inner) : base(message, inner) { } + public CmisProxyAuthenticationException(string message, long? code) : base(message) { } + public CmisProxyAuthenticationException(string message, string errorContent) : base(message) { } + public CmisProxyAuthenticationException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisServiceUnavailableException : CmisRuntimeException + { + public CmisServiceUnavailableException() : base() { } + public CmisServiceUnavailableException(string message) : base(message) { } + public CmisServiceUnavailableException(string message, Exception inner) : base(message, inner) { } + public CmisServiceUnavailableException(string message, long? code) : base(message) { } + public CmisServiceUnavailableException(string message, string errorContent) : base(message) { } + public CmisServiceUnavailableException(string message, string errorContent, Exception inner) : base(message, errorContent, inner) { } + + public override string GetExtensionName() + { + return ExceptionName; + } + } + + public class CmisInvalidServerData : InvalidOperationException + { + public CmisInvalidServerData() : base() { } + public CmisInvalidServerData(string message) : base(message) { } + public CmisInvalidServerData(string message, Exception inner) : base(message, inner) { } + } +} Added: chemistry/portcmis/PortCMIS/portcmis.snk URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMIS/portcmis.snk?rev=1691890&view=auto ============================================================================== Binary file - no diff available. Propchange: chemistry/portcmis/PortCMIS/portcmis.snk ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: chemistry/portcmis/PortCMIS/utils/Cache.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMIS/utils/Cache.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMIS/utils/Cache.cs (added) +++ chemistry/portcmis/PortCMIS/utils/Cache.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,134 @@ +/* +* 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 System.Threading.Tasks; + +namespace PortCMIS.Utils +{ + /// <summary> + /// LRU cache implementation. Not thread safe! + /// </summary> + internal class LRUCache<K, V> + { + private int capacity; + private TimeSpan ttl; + private Dictionary<K, LinkedListNode<LRUCacheItem<K, V>>> cacheDict = new Dictionary<K, LinkedListNode<LRUCacheItem<K, V>>>(); + private LinkedList<LRUCacheItem<K, V>> lruList = new LinkedList<LRUCacheItem<K, V>>(); + + public LRUCache(int capacity, TimeSpan ttl) + { + this.capacity = capacity; + this.ttl = ttl; + } + + public V Get(K key) + { + LinkedListNode<LRUCacheItem<K, V>> node; + if (cacheDict.TryGetValue(key, out node)) + { + lruList.Remove(node); + + if (node.Value.IsExpired) + { + cacheDict.Remove(node.Value.Key); + return default(V); + } + + lruList.AddLast(node); + + return node.Value.Value; + } + + return default(V); + } + + public V GetLatest() + { + if (lruList.Count == 0) + { + return default(V); + } + + return lruList.First().Value; + } + + public void Add(K key, V val) + { + Remove(key); + + if (cacheDict.Count >= capacity) + { + RemoveFirst(); + } + + LRUCacheItem<K, V> cacheItem = new LRUCacheItem<K, V>(key, val, DateTime.UtcNow + ttl); + LinkedListNode<LRUCacheItem<K, V>> node = new LinkedListNode<LRUCacheItem<K, V>>(cacheItem); + + lruList.AddLast(node); + cacheDict.Add(key, node); + } + + protected void RemoveFirst() + { + LinkedListNode<LRUCacheItem<K, V>> node = lruList.First; + lruList.RemoveFirst(); + cacheDict.Remove(node.Value.Key); + } + + public void Remove(K key) + { + LinkedListNode<LRUCacheItem<K, V>> node; + if (cacheDict.TryGetValue(key, out node)) + { + lruList.Remove(node); + cacheDict.Remove(node.Value.Key); + } + } + + public int Count + { + get { return lruList.Count; } + } + } + + internal class LRUCacheItem<K, V> + { + public LRUCacheItem(K key, V value, DateTime expiration) + { + Key = key; + Value = value; + Expiration = expiration; + } + + public K Key { get; private set; } + + public V Value { get; private set; } + + public DateTime Expiration { get; private set; } + + public bool IsExpired + { + get { return Value == null || DateTime.UtcNow > Expiration; } + } + } +} Added: chemistry/portcmis/PortCMIS/utils/Logger.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMIS/utils/Logger.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMIS/utils/Logger.cs (added) +++ chemistry/portcmis/PortCMIS/utils/Logger.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,150 @@ +/* +* 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.IO; +using System.Text; + +namespace PortCMIS.Utils +{ + /// <summary> + /// Simplistic logginh. + /// </summary> + public class Logger + { + + public enum LogLevel + { + Error, Warn, Info, Debug, Trace + } + + public static LogLevel Level { get; set; } + public static bool ToDebug { get; set; } + public static bool ToWriter { get; set; } + public static TextWriter Writer { private get; set; } + + public static bool IsErrorEnabled { get { return true; } } + public static bool IsWarnEnabled { get { return Level == LogLevel.Warn || Level == LogLevel.Info || Level == LogLevel.Debug || Level == LogLevel.Trace; } } + public static bool IsInfoEnabled { get { return Level == LogLevel.Info || Level == LogLevel.Debug || Level == LogLevel.Trace; } } + public static bool IsDebugEnabled { get { return Level == LogLevel.Debug || Level == LogLevel.Trace; } } + public static bool IsTraceEnabled { get { return Level == LogLevel.Trace; } } + + static Logger() + { + Level = LogLevel.Info; +#if DEBUG + ToDebug = true; +#else + ToDebug = false; +#endif + ToWriter = false; + } + + private static object loggerLock = new object(); + + public static void Error(string message, Exception e = null) + { + lock (loggerLock) + { + Write("ERROR", message, e); + } + } + + public static void Warn(string message, Exception e = null) + { + lock (loggerLock) + { + if (IsWarnEnabled) + { + Write("WARN", message, e); + } + } + } + + public static void Info(string message, Exception e = null) + { + lock (loggerLock) + { + if (IsInfoEnabled) + { + Write("INFO", message, e); + } + } + } + + public static void Debug(string message, Exception e = null) + { + lock (loggerLock) + { + if (IsDebugEnabled) + { + Write("DEBUG", message, e); + } + } + } + + public static void Trace(string message, Exception e = null) + { + lock (loggerLock) + { + if (IsTraceEnabled) + { + Write("Trace", message, e); + } + } + } + + private static void Write(string levelname, string message, Exception e) + { + if (!ToDebug && !ToWriter) + { + return; + } + + DateTime now = DateTime.Now; + + StringBuilder sb = new StringBuilder(); + sb.Append(now.ToString("o")); + sb.Append(' '); + sb.Append(levelname); + sb.Append(": "); + sb.Append(message); + if (e != null) + { + sb.AppendLine(); + sb.AppendLine(" "); + sb.AppendLine(e.ToString()); + sb.AppendLine(" "); + sb.AppendLine(e.StackTrace); + } + + if (ToDebug) + { + System.Diagnostics.Debug.WriteLine(sb.ToString()); + } + + if (ToWriter && Writer != null) + { + Writer.WriteLine(sb.ToString()); + Writer.Flush(); + } + } + + } +} Added: chemistry/portcmis/PortCMISTests/ContentStreamTest.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/ContentStreamTest.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/ContentStreamTest.cs (added) +++ chemistry/portcmis/PortCMISTests/ContentStreamTest.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,24 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using PortCMIS.Client.Impl; + +namespace PortCMISTests +{ + [TestClass] + public class ContentStreamHashTest + { + [TestMethod] + public void TestContentStreamHash() + { + ContentStreamHash hash1 = new ContentStreamHash("{MD5} 12345 67890 ABC"); + Assert.AreEqual("{MD5} 12345 67890 ABC", hash1.PropertyValue); + Assert.AreEqual("md5", hash1.Algorithm); + Assert.AreEqual("1234567890abc", hash1.Hash); + + ContentStreamHash hash2 = new ContentStreamHash("sHa1", " 12345 67890 ABC"); + Assert.AreEqual("{sha1}1234567890abc", hash2.PropertyValue); + Assert.AreEqual("sha1", hash2.Algorithm); + Assert.AreEqual("1234567890abc", hash2.Hash); + } + } +} Added: chemistry/portcmis/PortCMISTests/JsonTest.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/JsonTest.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/JsonTest.cs (added) +++ chemistry/portcmis/PortCMISTests/JsonTest.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,68 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.IO; +using PortCMIS.Binding.Browser.Json; +using System.Numerics; + +namespace PortCMISTests +{ + [TestClass] + public class JsonTest + { + [TestMethod] + public void TestBasicJson() + { + JsonParser jp = new JsonParser(); + + // --- + string json1 = "{ \"test\":\"test-value\" }"; + JsonObject jo1 = (JsonObject) jp.Parse(new StringReader(json1)); + + Assert.AreEqual("test-value", jo1["test"]); + + StringWriter writer = new StringWriter(); + jo1.WriteJsonString(writer); + Assert.AreEqual("{\"test\":\"test-value\"}", writer.ToString()); + + // --- + string json2 = "{ \"s\":\"test\", \"i\":42, \"b\":true, \"d\":123.456, \"n\":null}"; + JsonObject jo2 = (JsonObject)jp.Parse(new StringReader(json2)); + + Assert.AreEqual("test", jo2["s"]); + Assert.AreEqual(new BigInteger(42), jo2["i"]); + Assert.AreEqual(true, jo2["b"]); + Assert.AreEqual(new Decimal(123.456), jo2["d"]); + Assert.IsNull(jo2["n"]); + } + + [TestMethod] + public void TestArray() + { + JsonParser jp = new JsonParser(); + + string json = "[ \"a\" , \"b\" , \"c\" , \"d\" , \"e\" , \"f\" , \"g\" , \"h\" , \"i\" ]"; + + JsonArray ja1 = (JsonArray)jp.Parse(new StringReader(json)); + + Assert.AreEqual(9, ja1.Count); + for (char c = 'a'; c <= 'i'; c++) + { + Assert.AreEqual(c.ToString(), ja1[c - 'a']); + } + } + + [TestMethod] + public void TestNestedJson() + { + JsonParser jp = new JsonParser(); + + string json1 = "{ \"level1\":\"one\", \"nested\":{ \"level2\":\"two\"} }"; + JsonObject jo1 = (JsonObject)jp.Parse(new StringReader(json1)); + + Assert.AreEqual("one", jo1["level1"]); + Assert.AreEqual(2, jo1.Count); + Assert.AreEqual("two", ((JsonObject)jo1["nested"])["level2"]); + Assert.AreEqual(1, ((JsonObject)jo1["nested"]).Count); + } + } +} Added: chemistry/portcmis/PortCMISTests/PortCMISTests.csproj URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/PortCMISTests.csproj?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/PortCMISTests.csproj (added) +++ chemistry/portcmis/PortCMISTests/PortCMISTests.csproj Mon Jul 20 08:48:57 2015 @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{217BE2A3-7F09-49DD-B69C-7D900AAC15F1}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>PortCMISTests</RootNamespace> + <AssemblyName>PortCMISTests</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> + <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> + <IsCodedUITest>False</IsCodedUITest> + <TestProjectType>UnitTest</TestProjectType> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Numerics" /> + </ItemGroup> + <Choose> + <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> + <ItemGroup> + <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> + </ItemGroup> + </When> + <Otherwise> + <ItemGroup> + <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> + </ItemGroup> + </Otherwise> + </Choose> + <ItemGroup> + <Compile Include="framework\DefaultTestValues.cs" /> + <Compile Include="JsonTest.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="QueryStatementTest.cs" /> + <Compile Include="SimpleCmisTest.cs" /> + <Compile Include="framework\TestFramework.cs" /> + <Compile Include="ContentStreamTest.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\PortCMIS\PortCMIS.csproj"> + <Project>{a3ab61be-057d-4dd4-824c-ac174322c5d2}</Project> + <Name>PortCMIS</Name> + </ProjectReference> + </ItemGroup> + <Choose> + <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> + <ItemGroup> + <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <Private>False</Private> + </Reference> + <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <Private>False</Private> + </Reference> + </ItemGroup> + </When> + </Choose> + <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Added: chemistry/portcmis/PortCMISTests/Properties/AssemblyInfo.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/Properties/AssemblyInfo.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/Properties/AssemblyInfo.cs (added) +++ chemistry/portcmis/PortCMISTests/Properties/AssemblyInfo.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PortCMISTests")] +[assembly: AssemblyDescription("Tests for PortCMIS")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Apache Software Foundation")] +[assembly: AssemblyProduct("PortCMISTests")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8497530d-e638-4654-9ea5-4afd396212f3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.0.1.0")] +[assembly: AssemblyFileVersion("0.0.1.0")] Added: chemistry/portcmis/PortCMISTests/QueryStatementTest.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/QueryStatementTest.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/QueryStatementTest.cs (added) +++ chemistry/portcmis/PortCMISTests/QueryStatementTest.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,150 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using PortCMIS.Binding; +using PortCMIS.Client; +using PortCMIS.Client.Impl; +using System; +using System.Collections.Generic; + +namespace PortCMISTests +{ + [TestClass] + public class QueryStatementTest + { + [TestMethod] + public void TestStaticQueries() + { + Session session = new Session(new Dictionary<string, string>(), null, null, null); + String query; + IQueryStatement st; + + query = "SELECT cmis:name FROM cmis:folder"; + st = new QueryStatement(session, query); + Assert.AreEqual(query, st.ToQueryString()); + + query = "SELECT * FROM cmis:document WHERE cmis:createdBy = \'admin\' AND abc:int = 42"; + st = new QueryStatement(session, query); + Assert.AreEqual(query, st.ToQueryString()); + + query = "SELECT * FROM cmis:document WHERE abc:test = 'x?z'"; + st = new QueryStatement(session, query); + st.SetString(1, "y"); + Assert.AreEqual(query, st.ToQueryString()); + } + + [TestMethod] + public void TestWherePlacholder() + { + Session session = new Session(new Dictionary<string, string>(), null, null, null); + String query; + IQueryStatement st; + + // strings + query = "SELECT * FROM cmis:document WHERE abc:string = ?"; + st = new QueryStatement(session, query); + st.SetString(1, "test"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:string = 'test'", st.ToQueryString()); + + query = "SELECT * FROM cmis:document WHERE abc:string = ?"; + st = new QueryStatement(session, query); + st.SetString(1, "te'st"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:string = 'te\\'st'", st.ToQueryString()); + + // likes + query = "SELECT * FROM cmis:document WHERE abc:string LIKE ?"; + st = new QueryStatement(session, query); + st.SetStringLike(1, "%test%"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:string LIKE '%test%'", st.ToQueryString()); + + query = "SELECT * FROM cmis:document WHERE abc:string LIKE ?"; + st = new QueryStatement(session, query); + st.SetStringLike(1, "\\_test\\%blah\\\\blah"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:string LIKE '\\_test\\%blah\\\\\\\\blah'", + st.ToQueryString()); + + // contains + + // *, ? and - are treated as text search operators: 1st level escaping: + // none, 2nd level escaping: none + // \*, \? and \- are used as literals, 1st level escaping: none, 2nd + // level escaping: \\*, \\?, \\- + // ' and " are used as literals, 1st level escaping: \', \", 2nd level + // escaping: \\\', \\\", + // \ plus any other character, 1st level escaping \\ plus character, 2nd + // level: \\\\ plus character + + query = "SELECT * FROM cmis:document WHERE CONTAINS(?)"; + st = new QueryStatement(session, query); + st.SetStringContains(1, "John's"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('John\\\\\\'s')", st.ToQueryString()); + st.SetStringContains(1, "foo -bar"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('foo -bar')", st.ToQueryString()); + st.SetStringContains(1, "foo*"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('foo*')", st.ToQueryString()); + st.SetStringContains(1, "foo?"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('foo?')", st.ToQueryString()); + st.SetStringContains(1, "foo\\-bar"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\-bar')", st.ToQueryString()); + st.SetStringContains(1, "foo\\*"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\*')", st.ToQueryString()); + st.SetStringContains(1, "foo\\?"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('foo\\\\?')", st.ToQueryString()); + st.SetStringContains(1, "\"Cool\""); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('\\\\\\\"Cool\\\\\\\"')", st.ToQueryString()); + st.SetStringContains(1, "c:\\MyDcuments"); + Assert.AreEqual("SELECT * FROM cmis:document WHERE CONTAINS('c:\\\\MyDcuments')", st.ToQueryString()); + + // ids + query = "SELECT * FROM cmis:document WHERE abc:id = ?"; + st = new QueryStatement(session, query); + st.SetId(1, new ObjectId("123")); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:id = '123'", st.ToQueryString()); + + // booleans + query = "SELECT * FROM cmis:document WHERE abc:bool = ?"; + st = new QueryStatement(session, query); + st.SetBoolean(1, true); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:bool = TRUE", st.ToQueryString()); + + // numbers + query = "SELECT * FROM cmis:document WHERE abc:int = ? AND abc:int2 = 123"; + st = new QueryStatement(session, query); + st.SetInteger(1, 42); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:int = 42 AND abc:int2 = 123", st.ToQueryString()); + + // dateTime + query = "SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP ?"; + DateTime cal = new DateTime(2012, 2, 2, 3, 4, 5, DateTimeKind.Utc); + + st = new QueryStatement(session, query); + st.SetDateTime(1, cal); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP '2012-02-02T03:04:05.000Z'", + st.ToQueryString()); + + st = new QueryStatement(session, query); + st.SetDateTime(1, DateTimeHelper.ConvertDateTimeToMillis(cal)); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP '2012-02-02T03:04:05.000Z'", + st.ToQueryString()); + + // dateTime Timestamp + query = "SELECT * FROM cmis:document WHERE abc:dateTime = ?"; + + st = new QueryStatement(session, query); + st.SetDateTimeTimestamp(1, cal); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP '2012-02-02T03:04:05.000Z'", + st.ToQueryString()); + + st = new QueryStatement(session, query); + st.SetDateTimeTimestamp(1, DateTimeHelper.ConvertDateTimeToMillis(cal)); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:dateTime = TIMESTAMP '2012-02-02T03:04:05.000Z'", + st.ToQueryString()); + + query = "SELECT * FROM cmis:document WHERE abc:dateTime IN (?)"; + + st = new QueryStatement(session, query); + st.SetDateTimeTimestamp(1, cal, cal); + Assert.AreEqual("SELECT * FROM cmis:document WHERE abc:dateTime " + + "IN (TIMESTAMP '2012-02-02T03:04:05.000Z',TIMESTAMP '2012-02-02T03:04:05.000Z')", st.ToQueryString()); + } + + } +} Added: chemistry/portcmis/PortCMISTests/SimpleCmisTest.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/SimpleCmisTest.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/SimpleCmisTest.cs (added) +++ chemistry/portcmis/PortCMISTests/SimpleCmisTest.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,238 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using PortCMIS.Client.Impl; +using System.Collections.Generic; +using PortCMIS; +using PortCMIS.Client; +using PortCMIS.Exceptions; +using PortCMIS.Data; +using System.IO; +using PortCMIS.Enums; +using System.Text; +using PortCMIS.Utils; +using PortCMISTests.Framework; + +namespace PortCMISTests +{ + [TestClass] + public class SimpleCmisTest : TestFramework + { + public static ISession Session { get; set; } + + private TestContext testContextInstance; + /// <summary> + ///Gets or sets the test context which provides + ///information about and functionality for the current test run. + ///</summary> + public TestContext TestContext + { + get + { + return testContextInstance; + } + set + { + testContextInstance = value; + } + } + + + [ClassInitialize] + public static void CreateSession(TestContext testContext) + { + Logger.Level = Logger.LogLevel.Debug; + Session = Connect(); + } + + [TestMethod] + public void TestRepositoryInfo() + { + Assert.IsNotNull(Session); + Assert.IsNotNull(Session.RepositoryInfo); + Assert.IsNotNull(Session.RepositoryInfo.Id); + + TestContext.WriteLine("Repository ID: " + Session.RepositoryInfo.Id); + } + + [TestMethod] + public void TestRootFolder() + { + IOperationContext oc = Session.CreateOperationContext(); + oc.FilterString = "*"; + oc.IncludeAllowableActions = true; + + IFolder root = Session.GetRootFolder(oc); + Assert.IsNotNull(root); + Assert.IsNotNull(root.Id); + Assert.IsNotNull(root.Name); + Assert.AreEqual(root.BaseTypeId, BaseTypeId.CmisFolder); + Assert.IsNotNull(root.AllowableActions); + Assert.IsNotNull(root.AllowableActions.Actions); + Assert.IsTrue(root.AllowableActions.Actions.Count > 0); + Assert.IsTrue(root.AllowableActions.Actions.Contains(PortCMIS.Enums.Action.CanGetProperties)); + Assert.IsFalse(root.AllowableActions.Actions.Contains(PortCMIS.Enums.Action.CanGetFolderParent)); + Assert.IsFalse(root.AllowableActions.Actions.Contains(PortCMIS.Enums.Action.CanMoveObject)); + + foreach (ICmisObject child in root.GetChildren(oc)) + { + Assert.IsNotNull(child); + Assert.IsNotNull(child.Id); + Assert.IsNotNull(child.Name); + Assert.IsNotNull(child.BaseTypeId); + Assert.IsNotNull(child.ObjectType); + Assert.IsNotNull(child.Properties); + Assert.IsTrue(child.Properties.Count > 9); + Assert.AreEqual(child.Name, child[PropertyIds.Name].Value); + + Assert.IsNotNull(child.AllowableActions); + Assert.IsNotNull(child.AllowableActions.Actions); + Assert.IsTrue(child.AllowableActions.Actions.Count > 0); + Assert.IsTrue(child.AllowableActions.Actions.Contains(PortCMIS.Enums.Action.CanGetProperties)); + } + } + + [TestMethod] + public void TestCreate() + { + try + { + ICmisObject obj = Session.GetObjectByPath("/porttest"); + obj.Delete(true); + } + catch (CmisConstraintException) + { + IFolder folder = Session.GetObjectByPath("/porttest") as IFolder; + folder.DeleteTree(true, UnfileObject.Delete, true); + } + catch (CmisObjectNotFoundException) + { + // ignore + } + + // create folder + IDictionary<string, object> props = new Dictionary<string, object>(); + props[PropertyIds.Name] = "porttest"; + props[PropertyIds.ObjectTypeId] = "cmis:folder"; + + IFolder root = Session.GetRootFolder(); + IFolder newFolder = root.CreateFolder(props); + Assert.IsNotNull(newFolder); + + // create document + props = new Dictionary<string, object>(); + props[PropertyIds.Name] = "test.txt"; + props[PropertyIds.ObjectTypeId] = "cmis:document"; + + byte[] contentBytes = Encoding.UTF8.GetBytes("Hello World"); + + ContentStream content = new ContentStream(); + content.MimeType = "text/plain"; + content.Stream = new MemoryStream(contentBytes); + + IDocument newDoc = newFolder.CreateDocument(props, content, VersioningState.None); + Assert.IsNotNull(newDoc); + + // get content + IContentStream newContent = newDoc.GetContentStream(); + Assert.IsNotNull(newContent); + Assert.IsNotNull(newContent.Stream); + + MemoryStream memStream = new MemoryStream(); + newContent.Stream.CopyTo(memStream); + byte[] newContentBytes = memStream.ToArray(); + + Assert.AreEqual(contentBytes.Length, newContentBytes.Length); + for (int i = 0; i < contentBytes.Length; i++) + { + Assert.AreEqual(contentBytes[i], newContentBytes[i]); + } + + IOperationContext ctxt = Session.CreateOperationContext(); + ctxt.FilterString = "*"; + ICmisObject newObj = Session.GetObject(newDoc, ctxt); + + Assert.IsTrue(newObj is IDocument); + IDocument newDoc2 = (IDocument)newObj; + + Assert.AreEqual(newDoc.Name, newDoc2.Name); + Assert.AreEqual(contentBytes.Length, newDoc2.ContentStreamLength); + } + + [TestMethod] + public void TestUpdateProperties() + { + string name1 = "port-test-folder1"; + string name2 = "port-test-folder2"; + string name3 = "port-test-folder3"; + + IOperationContext oc = Session.CreateOperationContext(); + oc.CacheEnabled = false; + + IFolder newFolder = null; + try + { + // create folder + IDictionary<string, object> props = new Dictionary<string, object>(); + props[PropertyIds.Name] = name1; + props[PropertyIds.ObjectTypeId] = "cmis:folder"; + + IFolder root = Session.GetRootFolder(); + newFolder = root.CreateFolder(props); + Assert.IsNotNull(newFolder); + + IFolder newFolder2 = (IFolder)Session.GetObject(newFolder, oc); + Assert.IsNotNull(newFolder2); + Assert.IsNotNull(name1, newFolder2.Name); + + IDictionary<string, object> updateProps = new Dictionary<string, object>(); + updateProps[PropertyIds.Name] = name2; + + newFolder2.UpdateProperties(updateProps); + + IFolder newFolder3 = (IFolder)Session.GetObject(newFolder, oc); + Assert.IsNotNull(newFolder3); + Assert.IsNotNull(name2, newFolder3.Name); + + newFolder3.Rename(name3); + + IFolder newFolder4 = (IFolder)Session.GetObject(newFolder, oc); + Assert.IsNotNull(newFolder4); + Assert.IsNotNull(name3, newFolder4.Name); + } + finally + { + if (newFolder != null) + { + newFolder.DeleteTree(true, UnfileObject.Delete, true); + } + } + } + + [TestMethod] + public void TestQuery() + { + if (Session.RepositoryInfo.Capabilities.QueryCapability == CapabilityQuery.None) + { + return; + } + + foreach (IQueryResult qr in Session.Query("SELECT * FROM cmis:document", false)) + { + Assert.IsNotNull(qr); + Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.ObjectId)); + Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.Name)); + } + + int count = 0; + foreach (IQueryResult qr in Session.Query("SELECT * FROM cmis:folder", false)) + { + Assert.IsNotNull(qr); + Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.ObjectId)); + Assert.IsNotNull(qr.GetPropertyValueByQueryName(PropertyIds.Name)); + count++; + } + + Assert.IsTrue(count > 0); + } + } +} Added: chemistry/portcmis/PortCMISTests/framework/DefaultTestValues.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/framework/DefaultTestValues.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/framework/DefaultTestValues.cs (added) +++ chemistry/portcmis/PortCMISTests/framework/DefaultTestValues.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,45 @@ +/* +* 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 PortCMIS; +using PortCMIS.Client; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PortCMISTests.Framework +{ + public class DefaultTestValues + { + public const string DefaultDocumentType = "cmis:document"; + public const string DefaulFolderType = "cmis:folder"; + public const string TestRootFolder = "/"; + + public static IDictionary<string, string> SessionParameters = new Dictionary<string, string>() + { + {SessionParameter.BindingType , BindingType.Browser}, + {SessionParameter.BrowserUrl , "http://localhost:8080/inmemory/browser"}, + {SessionParameter.RepositoryId , "A1"}, + {SessionParameter.User , "user"}, + {SessionParameter.Password , "password"} + }; + } +} Added: chemistry/portcmis/PortCMISTests/framework/TestFramework.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISTests/framework/TestFramework.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISTests/framework/TestFramework.cs (added) +++ chemistry/portcmis/PortCMISTests/framework/TestFramework.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,91 @@ +/* +* 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 Microsoft.VisualStudio.TestTools.UnitTesting; +using PortCMIS.Client; +using PortCMIS.Client.Impl; +using PortCMIS.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PortCMISTests.Framework +{ + public class TestFramework + { + public static string DefaultDocumentType { get; set; } + public static string DefaultFolderType { get; set; } + public static IFolder TestFolder { get; set; } + + public static ISession Connect() + { + IDictionary<string, string> parameters = DefaultTestValues.SessionParameters; + + DefaultDocumentType = DefaultTestValues.DefaultDocumentType; + DefaultFolderType = DefaultTestValues.DefaulFolderType; + + SessionFactory factory = SessionFactory.NewInstance(); + + ISession session = null; + if (parameters.ContainsKey(SessionParameter.RepositoryId)) + { + session = factory.CreateSession(parameters); + } + else + { + session = factory.GetRepositories(parameters)[0].CreateSession(); + } + + Assert.IsNotNull(session); + Assert.IsNotNull(session.Binding); + Assert.IsNotNull(session.RepositoryInfo); + Assert.IsNotNull(session.RepositoryInfo.Id); + + string testRootFolderPath = DefaultTestValues.TestRootFolder; + if (testRootFolderPath == null) + { + TestFolder = session.GetRootFolder(); + } + else + { + TestFolder = session.GetObjectByPath(testRootFolderPath) as IFolder; + } + + Assert.IsNotNull(TestFolder); + Assert.IsNotNull(TestFolder.Id); + + foreach (ICmisObject cmisObject in TestFolder.GetChildren()) + { + IFolder folder = cmisObject as IFolder; + if (folder == null) + { + cmisObject.Delete(true); + } + else + { + folder.DeleteTree(true, null, true); + } + } + + return session; + } + } +} Added: chemistry/portcmis/PortCMISWin/PortCMISWin.csproj URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISWin/PortCMISWin.csproj?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISWin/PortCMISWin.csproj (added) +++ chemistry/portcmis/PortCMISWin/PortCMISWin.csproj Mon Jul 20 08:48:57 2015 @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{C9C05283-55A0-4F84-9476-E0E438927A08}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>PortCMISWin</RootNamespace> + <AssemblyName>PortCMISWin</AssemblyName> + <DefaultLanguage>en-US</DefaultLanguage> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <TargetFrameworkProfile>Profile32</TargetFrameworkProfile> + <TargetFrameworkVersion>v4.6</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <!-- A reference to the entire .NET Framework is automatically included --> + <ProjectReference Include="..\PortCMIS\PortCMIS.csproj"> + <Project>{a3ab61be-057d-4dd4-824c-ac174322c5d2}</Project> + <Name>PortCMIS</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <TargetPlatform Include="WindowsPhoneApp, Version=8.1" /> + <TargetPlatform Include="Windows, Version=8.1" /> + </ItemGroup> + <ItemGroup> + <Compile Include="binding\WindowsBindingIntf.cs" /> + <Compile Include="binding\WindowsHttp.cs" /> + <Compile Include="client\ClientImpl.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Added: chemistry/portcmis/PortCMISWin/PortCMISWin.nuspec URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISWin/PortCMISWin.nuspec?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISWin/PortCMISWin.nuspec (added) +++ chemistry/portcmis/PortCMISWin/PortCMISWin.nuspec Mon Jul 20 08:48:57 2015 @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<package > + <metadata> + <id>$id$</id> + <version>0.0.1.0</version> + <title>PortCMIS for Store Apps</title> + <authors>Apache Software Foundation</authors> + <owners>Apache Software Foundation</owners> + <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl> + <requireLicenseAcceptance>false</requireLicenseAcceptance> + <description>CMIS Client Library for .Net</description> + <releaseNotes>Initial release.</releaseNotes> + <copyright>Copyright 2015</copyright> + <tags>CMIS</tags> + </metadata> +</package> \ No newline at end of file Added: chemistry/portcmis/PortCMISWin/Properties/AssemblyInfo.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISWin/Properties/AssemblyInfo.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISWin/Properties/AssemblyInfo.cs (added) +++ chemistry/portcmis/PortCMISWin/Properties/AssemblyInfo.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,30 @@ +using System.Resources; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PortCMIS for Store Apps")] +[assembly: AssemblyDescription("CMIS Client Library for .Net")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Apache Software Foundation")] +[assembly: AssemblyProduct("PortCMISWin")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: NeutralResourcesLanguage("en")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.0.1.0")] +[assembly: AssemblyFileVersion("0.0.1.0")] Added: chemistry/portcmis/PortCMISWin/binding/WindowsBindingIntf.cs URL: http://svn.apache.org/viewvc/chemistry/portcmis/PortCMISWin/binding/WindowsBindingIntf.cs?rev=1691890&view=auto ============================================================================== --- chemistry/portcmis/PortCMISWin/binding/WindowsBindingIntf.cs (added) +++ chemistry/portcmis/PortCMISWin/binding/WindowsBindingIntf.cs Mon Jul 20 08:48:57 2015 @@ -0,0 +1,74 @@ +/* +* 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 PortCMIS.Client; +using Windows.Security.Credentials; +using Windows.Web.Http; +using Windows.Web.Http.Filters; + +namespace PortCMIS.Binding +{ + public interface IWindowsAuthenticationProvider : IAuthenticationProvider + { + void PrepareHttpClientFilter(HttpBaseProtocolFilter httpClientFilter); + void PrepareHttpRequestMessage(HttpRequestMessage httpRequestMessage); + void HandleResponse(HttpResponseMessage httpResponseMessage); + } + + public abstract class AbstractWindowsAuthenticationProvider : IWindowsAuthenticationProvider + { + public IBindingSession Session { get; set; } + public HttpCookieManager CookieManager { get; private set; } + public string User { get { return Session.GetValue(SessionParameter.User) as string; } } + public string Password { get { return Session.GetValue(SessionParameter.Password) as string; } } + + public virtual void PrepareHttpClientFilter(HttpBaseProtocolFilter httpClientFilter) + { + httpClientFilter.CacheControl.ReadBehavior = HttpCacheReadBehavior.MostRecent; + httpClientFilter.CacheControl.WriteBehavior = HttpCacheWriteBehavior.NoCache; + + httpClientFilter.MaxConnectionsPerServer = 20; + + httpClientFilter.UseProxy = true; + + CookieManager = httpClientFilter.CookieManager; + } + + public virtual void PrepareHttpRequestMessage(HttpRequestMessage httpRequestMessage) + { + } + + public virtual void HandleResponse(HttpResponseMessage httpResponseMessage) + { + } + } + + public class StandardWindowsAuthenticationProvider : AbstractWindowsAuthenticationProvider + { + public override void PrepareHttpClientFilter(HttpBaseProtocolFilter httpClientFilter) + { + base.PrepareHttpClientFilter(httpClientFilter); + + if (User != null) + { + httpClientFilter.ServerCredential = new PasswordCredential("cmis", User, Password); + } + } + } +}
