Пример #1
0
        private bool TryDeleteObjectOnServer(IObjectId remoteId, MappedObjectType type) {
            try {
                if (type == MappedObjectType.Folder) {
                    (remoteId as IFolder).DeleteTree(false, UnfileObject.DeleteSinglefiled, true);
                } else {
                    this.Session.Delete(remoteId, true);
                }
            } catch (CmisPermissionDeniedException) {
                return false;
            }

            return true;
        }
        private static bool VerifyMappedObject(
            IMappedObject o,
            MappedObjectType type,
            string remoteId,
            string name,
            string parentId,
            string changeToken,
            bool extendedAttributeAvailable,
            DateTime? lastLocalModification,
            DateTime? lastRemoteModification,
            byte[] checksum,
            long contentSize,
            bool ignored)
        {
            Assert.That(o.RemoteObjectId, Is.EqualTo(remoteId), "Object remote Id is wrong");
            Assert.That(o.Name, Is.EqualTo(name), "Object name is wrong");
            Assert.That(o.ParentId, Is.EqualTo(parentId), "Object parent Id is wrong");
            Assert.That(o.LastChangeToken, Is.EqualTo(changeToken), "Object change token is wrong");
            Assert.That(o.Type, Is.EqualTo(type), "Object type is wrong");
            Assert.That(o.Ignored, Is.EqualTo(ignored), "Object ignore flag is wrong");
            if (extendedAttributeAvailable) {
                Assert.That(o.Guid, Is.Not.EqualTo(Guid.Empty), "Given Guid must not be empty");
            } else {
                Assert.That(o.Guid, Is.EqualTo(Guid.Empty), "Given Guid must be empty");
            }

            if (lastLocalModification != null) {
                Assert.That(o.LastLocalWriteTimeUtc, Is.EqualTo(lastLocalModification), "Last local modification date is wrong");
            }

            if (lastRemoteModification != null) {
                Assert.That(o.LastRemoteWriteTimeUtc, Is.EqualTo(lastRemoteModification), "Last remote modification date is wrong");
            }

            if (checksum != null) {
                Assert.That(o.ChecksumAlgorithmName, Is.EqualTo("SHA-1"));
                Assert.That(o.LastChecksum, Is.EqualTo(checksum), "Given checksum is not equal to last saved checksum");
            }

            if (type == MappedObjectType.File) {
                Assert.That(o.LastContentSize, Is.GreaterThanOrEqualTo(0), "Last content size is wrong");
                Assert.That(o.LastContentSize, Is.EqualTo(contentSize), "Last content size is wrong");
            }

            if (type == MappedObjectType.Folder) {
                Assert.That(o.LastContentSize, Is.EqualTo(-1), "Folder content size is wrong");
            }

            return true;
        }
 public static void VerifySavedMappedObject(
     this Mock<IMetaDataStorage> db,
     MappedObjectType type,
     string remoteId,
     string name,
     string parentId,
     string changeToken,
     Times times,
     bool extendedAttributeAvailable = true,
     DateTime? lastLocalModification = null,
     DateTime? lastRemoteModification = null,
     byte[] checksum = null,
     long contentSize = -1,
     bool ignored = false)
 {
     db.Verify(
         s =>
         s.SaveMappedObject(It.Is<IMappedObject>(o => VerifyMappedObject(o, type, remoteId, name, parentId, changeToken, extendedAttributeAvailable, lastLocalModification, lastRemoteModification, checksum, contentSize, ignored))),
         times);
 }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MappedObject"/> class.
        /// </summary>
        /// <param name="name">Name of the Directory/Folder.</param>
        /// <param name="remoteId">Remote identifier.</param>
        /// <param name="type">Object type.</param>
        /// <param name="parentId">Parent identifier.</param>
        /// <param name="changeToken">Change token.</param>
        /// <param name="contentSize">Size of the content. Only exists on Documents.</param>
        /// <param name="readOnly">Readonly flag of the mapped object.</param>
        public MappedObject(string name, string remoteId, MappedObjectType type, string parentId, string changeToken, long contentSize = -1, bool readOnly = false) {
            if (string.IsNullOrEmpty(name)) {
                throw new ArgumentNullException("name", "Given name is null or empty");
            }

            if (string.IsNullOrEmpty(remoteId)) {
                throw new ArgumentNullException("remoteId");
            }

            if (type == MappedObjectType.Unkown) {
                throw new ArgumentException("Given type is unknown but must be set to a known type", "type");
            } else {
                this.Type = type;
            }

            this.Name = name;
            this.RemoteObjectId = remoteId;
            this.ParentId = parentId;
            this.LastChangeToken = changeToken;
            this.LastContentSize = contentSize;
            this.ActualOperation = OperationType.No;
            this.Retries = new Dictionary<OperationType, int>();
            this.IsReadOnly = readOnly;
        }
 private bool VerifySavedObject(IMappedObject obj, MappedObjectType type, string id, string name, string parentId, string changeToken, DateTime modifiedTime)
 {
     Assert.That(obj.Type, Is.EqualTo(type));
     Assert.That(obj.RemoteObjectId, Is.EqualTo(id));
     Assert.That(obj.ParentId, Is.EqualTo(parentId));
     Assert.That(obj.Name, Is.EqualTo(name));
     Assert.That(obj.LastChangeToken, Is.EqualTo(changeToken));
     Assert.That(obj.LastRemoteWriteTimeUtc, Is.EqualTo(modifiedTime));
     Assert.That(obj.LastLocalWriteTimeUtc, Is.EqualTo(modifiedTime));
     return true;
 }