Inheritance: IFileTransmissionObject
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="CmisSync.Lib.Storage.Database.Entities.FileTransmissionObject"/>.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="CmisSync.Lib.Storage.Database.Entities.FileTransmissionObject"/>.</param>
        /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current
        /// <see cref="CmisSync.Lib.Storage.Database.Entities.FileTransmissionObject"/>; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (this == obj)
            {
                return(true);
            }

            // If parameter cannot be casted to FileTransmissionObject return false.
            FileTransmissionObject o = obj as FileTransmissionObject;

            if (o == null)
            {
                return(false);
            }

            return(this.Type.Equals(o.Type) &&
                   object.Equals(this.LocalPath, o.LocalPath) &&
                   ((this.LastChecksum == null && o.LastChecksum == null) || (this.LastChecksum != null && o.LastChecksum != null && this.LastChecksum.SequenceEqual(o.LastChecksum))) &&
                   object.Equals(this.ChecksumAlgorithmName, o.ChecksumAlgorithmName) &&
                   object.Equals(this.LastLocalWriteTimeUtc, o.LastLocalWriteTimeUtc) &&
                   object.Equals(this.RemoteObjectId, o.RemoteObjectId) &&
                   object.Equals(this.LastChangeToken, o.LastChangeToken) &&
                   object.Equals(this.LastRemoteWriteTimeUtc, o.LastRemoteWriteTimeUtc));
        }
        public void ConstructorTakesData() {
            var remoteFile = new Mock<IDocument>();
            remoteFile.Setup(m => m.Paths).Returns(new List<string>() { "/RemoteFile" });
            remoteFile.Setup(m => m.Id).Returns("RemoteId");
            remoteFile.Setup(m => m.ChangeToken).Returns("ChangeToken");
            remoteFile.Setup(m => m.LastModificationDate).Returns(LocalFile.Object.LastWriteTimeUtc);
            remoteFile.Setup(m => m.VersionSeriesCheckedOutId).Returns("RemotePWCId");
            var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, LocalFile.Object, remoteFile.Object);
            Assert.AreEqual(TransmissionType.UPLOAD_NEW_FILE, obj.Type);
            Assert.AreEqual(LocalFile.Object.FullName, obj.LocalPath);
            Assert.AreEqual(LocalFile.Object.Length, obj.LastContentSize);
            Assert.AreEqual(null, obj.LastChecksum);
            Assert.AreEqual(null, obj.ChecksumAlgorithmName);
            Assert.AreEqual(LocalFile.Object.LastWriteTimeUtc, obj.LastLocalWriteTimeUtc);
            Assert.AreEqual("RemoteId", obj.RemoteObjectId);
            Assert.AreEqual("ChangeToken", obj.LastChangeToken);
            Assert.AreEqual("RemotePWCId", obj.RemoteObjectPWCId);
            Assert.AreEqual(LocalFile.Object.LastWriteTimeUtc, obj.LastRemoteWriteTimeUtc);
            var obj2 = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, LocalFile.Object, remoteFile.Object);
            Assert.IsTrue(obj.Equals(obj2));

            obj.ChecksumAlgorithmName = "SHA1";
            Assert.AreEqual("SHA1", obj.ChecksumAlgorithmName);
            obj.LastChecksum = new byte[32];
            using (var random = RandomNumberGenerator.Create()) {
                random.GetBytes(obj.LastChecksum);
            }

            Assert.IsFalse(obj.Equals(obj2));

            obj2.ChecksumAlgorithmName = "SHA1";
            obj2.LastChecksum = new byte[32];
            using (var random = RandomNumberGenerator.Create()) {
                random.GetBytes(obj.LastChecksum);
            }

            Assert.IsFalse(obj.Equals(obj2));

            Buffer.BlockCopy(obj2.LastChecksum, 0, obj.LastChecksum, 0, 32);
            Assert.IsTrue(obj.Equals(obj2));
        }
示例#3
0
 public void InsertAndSelectFileTransmissionObjectData() {
     using (var tran = this.engine.GetTransaction()) {
         string key = "key";
         var remoteFile = new Mock<DotCMIS.Client.IDocument>();
         remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");
         remoteFile.Setup(m => m.Paths).Returns(new List<string>() { "/RemoteFile" });
         var data = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.file.Object, remoteFile.Object);
         tran.Insert<string, DbCustomSerializer<FileTransmissionObject>>("objects", key, data);
         Assert.That((tran.Select<string, DbCustomSerializer<FileTransmissionObject>>("objects", key).Value.Get as FileTransmissionObject).Equals(data));
     }
 }
        private void SaveRemotePWCDocument(IFileInfo localFile, IDocument remoteDocument, IDocument remotePWCDocument, byte[] checksum, Transmission transmissionEvent) {
            if (remotePWCDocument == null) {
                return;
            }

            var obj = new FileTransmissionObject(transmissionEvent.Type, localFile, remoteDocument) {
                ChecksumAlgorithmName = "SHA-1",
                RemoteObjectPWCId = remotePWCDocument.Id,
                LastChangeTokenPWC = remotePWCDocument.ChangeToken,
                LastChecksumPWC = checksum
            };
            this.TransmissionStorage.SaveObject(obj);
        }
 public void GetObjectByLocalPath() {
     var storage = new FileTransmissionStorage(this.engine);
     this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");
     var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
     Assert.DoesNotThrow(() => storage.SaveObject(obj));
     Assert.That(storage.GetObjectByLocalPath(this.localFile.Object.FullName).RemoteObjectId, Is.EqualTo("RemoteObjectId"));
     Assert.That(storage.GetObjectByLocalPath(this.localFile.Object.FullName + ".temp"), Is.Null);
 }
        public void GetObjectListOnPersistedStorage() {
            var conf = new DBreezeConfiguration {
                DBreezeDataFolderName = this.persistentDBreezePath,
                Storage = DBreezeConfiguration.eStorage.DISK
            };

            using (var engine = new DBreezeEngine(conf)) {
                var storage = new FileTransmissionStorage(engine);
                for (int i = 1; i <= 10; ++i) {
                    this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId" + i.ToString());
                    var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
                    Assert.DoesNotThrow(() => storage.SaveObject(obj));
                    Assert.That(storage.GetObjectList().Count, Is.EqualTo(i));
                    Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
                }
            }

            using (var engine = new DBreezeEngine(conf)) {
                var storage = new FileTransmissionStorage(engine);
                for (int i = 1; i <= 10; ++i) {
                    Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
                }

                Assert.That(storage.GetObjectList().Count, Is.EqualTo(10));
            }
        }
        public void ClearObjectList() {
            var storage = new FileTransmissionStorage(this.engine);

            for (int i = 1; i <= 10; ++i) {
                this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId" + i.ToString());
                var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
                Assert.DoesNotThrow(() => storage.SaveObject(obj));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(i));
                Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
            }

            storage.ClearObjectList();

            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));
        }
        public void RemoveObjectOnMultipleTimesForSameRemoteObjectId() {
            var storage = new FileTransmissionStorage(this.engine);

            this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");
            var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
            Assert.DoesNotThrow(() => storage.SaveObject(obj));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(1));

            for (int i = 1; i <= 10; ++i) {
                Assert.DoesNotThrow(() => storage.RemoveObjectByRemoteObjectId("RemoteObjectId"));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));
            }
        }
        public void RemoveObjectOnMultipleTimes() {
            var storage = new FileTransmissionStorage(this.engine);

            for (int i = 1; i <= 10; ++i) {
                this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId" + i.ToString());
                var obj = new FileTransmissionObject(TransmissionType.UPLOAD_NEW_FILE, this.localFile.Object, this.remoteFile.Object);
                Assert.DoesNotThrow(() => storage.SaveObject(obj));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(i));
                Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()), Is.Not.Null);
            }

            for (int i = 1; i <= 10; ++i) {
                Assert.DoesNotThrow(() => storage.RemoveObjectByRemoteObjectId("RemoteObjectId" + i.ToString()));
                Assert.That(storage.GetObjectList().Count, Is.EqualTo(10 - i));
                Assert.Throws<InvalidOperationException>(() => storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId" + i.ToString()));
            }
        }
        private void SaveCacheFile(IFileInfo target, IDocument remoteDocument, byte[] hash, long length, Transmission transmissionEvent) {
            if (this.TransmissionStorage == null) {
                return;
            }

            target.Refresh();
            IFileTransmissionObject obj = new FileTransmissionObject(transmissionEvent.Type, target, remoteDocument);
            obj.ChecksumAlgorithmName = "SHA-1";
            obj.LastChecksum = hash;
            obj.LastContentSize = length;

            this.TransmissionStorage.SaveObject(obj);
        }