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 SaveObjectThrowsExceptionIfObjectIsInvalid()
        {
            var storage = new FileTransmissionStorage(this.engine);
            var obj     = new Mock <IFileTransmissionObject>();

            // argument cannot be null
            Assert.Throws <ArgumentNullException>(() => storage.SaveObject(null));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.LocalPath cannot be null
            Assert.Throws <ArgumentNullException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.LocalPath cannot be empty string
            obj.Setup(m => m.LocalPath).Returns(string.Empty);
            Assert.Throws <ArgumentException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.RemoteObjectId cannot be null
            obj.Setup(m => m.LocalPath).Returns("/LocalPath");
            Assert.Throws <ArgumentNullException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // IFileTransmissionObject.RemoteObjectId cannot be empty string
            obj.Setup(m => m.RemoteObjectId).Returns(string.Empty);
            Assert.Throws <ArgumentException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));

            // argument should be FileTransmissionObject
            obj.Setup(m => m.RemoteObjectId).Returns("RemoteObjectId");
            Assert.Throws <ArgumentException>(() => storage.SaveObject(obj.Object));
            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));
        }
        public void RemoveObjectThrowsExceptionIfRemoteObjectIdIsInvalid()
        {
            var storage = new FileTransmissionStorage(this.engine);

            Assert.Throws <ArgumentNullException>(() => storage.RemoveObjectByRemoteObjectId(null));
            Assert.Throws <ArgumentException>(() => storage.RemoveObjectByRemoteObjectId(string.Empty));
            Assert.DoesNotThrow(() => storage.RemoveObjectByRemoteObjectId("RemoteObjectId"));
        }
        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 SaveObjectBehaviorOverride()
        {
            var storage = new FileTransmissionStorage(this.engine);

            this.remoteFile.Setup(m => m.Id).Returns("RemoteObjectId");

            for (int i = 1; i <= 10; ++i)
            {
                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));
                Assert.That(storage.GetObjectList().First(foo => foo.LocalPath == this.localFile.Object.FullName && foo.RemoteObjectId == "RemoteObjectId"), Is.Not.Null);
                Assert.That(storage.GetObjectByRemoteObjectId("RemoteObjectId"), Is.Not.Null);
            }
        }
        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()));
            }
        }
        public void ConstructorTakesDbEngineAndChunkSize([Values(1, 1024, 12345)] long chunkSize)
        {
            var underTest = new FileTransmissionStorage(this.engine, chunkSize);

            Assert.That(underTest.ChunkSize, Is.EqualTo(chunkSize));
        }
        public void ConstructorTakesDbEngine()
        {
            var underTest = new FileTransmissionStorage(this.engine);

            Assert.That(underTest.ChunkSize, Is.GreaterThan(0));
        }
        public void GetObjectListReturnsZeroSizeListFromEmptyStorage()
        {
            var storage = new FileTransmissionStorage(this.engine);

            Assert.That(storage.GetObjectList().Count, Is.EqualTo(0));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Repository"/> class.
        /// </summary>
        /// <param name="repoInfo">Repo info.</param>
        /// <param name="activityListener">Activity listener.</param>
        /// <param name="inMemory">If set to <c>true</c> in memory.</param>
        /// <param name="queue">Event Queue.</param>
        protected Repository(RepoInfo repoInfo, ActivityListenerAggregator activityListener, bool inMemory, ICountingQueue queue) : base(repoInfo)
        {
            if (activityListener == null)
            {
                throw new ArgumentNullException("activityListener");
            }

            this.fileSystemFactory = new FileSystemInfoFactory();
            this.activityListener  = activityListener;

            this.rootFolderMonitor = new RepositoryRootDeletedDetection(this.fileSystemFactory.CreateDirectoryInfo(this.LocalPath));
            this.rootFolderMonitor.RepoRootDeleted += this.RootFolderAvailablilityChanged;

            if (!this.fileSystemFactory.CreateDirectoryInfo(this.LocalPath).IsExtendedAttributeAvailable())
            {
                throw new ExtendedAttributeException("Extended Attributes are not available on the local path: " + this.LocalPath);
            }

            this.Queue = queue;
            this.Queue.EventManager.AddEventHandler(rootFolderMonitor);
            this.Queue.EventManager.AddEventHandler(new DebugLoggingHandler());

            // Create Database connection
            this.db = new DBreezeEngine(new DBreezeConfiguration {
                DBreezeDataFolderName = inMemory ? string.Empty : repoInfo.GetDatabasePath(),
                Storage = inMemory ? DBreezeConfiguration.eStorage.MEMORY : DBreezeConfiguration.eStorage.DISK
            });

            // Create session dependencies
            this.sessionFactory = SessionFactory.NewInstance();
            this.authProvider   = AuthProviderFactory.CreateAuthProvider(repoInfo.AuthenticationType, repoInfo.Address, this.db);

            // Initialize storage
            this.storage = new MetaDataStorage(this.db, new PathMatcher(this.LocalPath, this.RepoInfo.RemotePath), inMemory);
            this.fileTransmissionStorage = new FileTransmissionStorage(this.db, RepoInfo.ChunkSize);

            // Add ignore file/folder filter
            this.ignoredFoldersFilter = new IgnoredFoldersFilter {
                IgnoredPaths = new List <string>(repoInfo.GetIgnoredPaths())
            };
            this.ignoredFileNameFilter = new IgnoredFileNamesFilter {
                Wildcards = ConfigManager.CurrentConfig.IgnoreFileNames
            };
            this.ignoredFolderNameFilter = new IgnoredFolderNameFilter {
                Wildcards = ConfigManager.CurrentConfig.IgnoreFolderNames
            };
            this.invalidFolderNameFilter = new InvalidFolderNameFilter();
            var symlinkFilter = new SymlinkFilter();

            this.filters         = new FilterAggregator(this.ignoredFileNameFilter, this.ignoredFolderNameFilter, this.invalidFolderNameFilter, this.ignoredFoldersFilter, symlinkFilter);
            this.reportingFilter = new ReportingFilter(
                this.Queue,
                this.ignoredFoldersFilter,
                this.ignoredFileNameFilter,
                this.ignoredFolderNameFilter,
                this.invalidFolderNameFilter,
                symlinkFilter);
            this.Queue.EventManager.AddEventHandler(this.reportingFilter);
            this.alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(this.storage, this.fileSystemFactory);
            this.Queue.EventManager.AddEventHandler(this.alreadyAddedFilter);

            // Add handler for repo config changes
            this.Queue.EventManager.AddEventHandler(new GenericSyncEventHandler <RepoConfigChangedEvent>(0, this.RepoInfoChanged));

            // Add periodic sync procedures scheduler
            this.Scheduler = new SyncScheduler(this.Queue, repoInfo.PollInterval);
            this.Queue.EventManager.AddEventHandler(this.Scheduler);

            // Add File System Watcher
            #if __COCOA__
            this.WatcherProducer = new CmisSync.Lib.Producer.Watcher.MacWatcher(LocalPath, Queue);
            #else
            this.WatcherProducer = new NetWatcher(new FileSystemWatcher(this.LocalPath), this.Queue, this.storage);
            #endif
            this.WatcherConsumer = new WatcherConsumer(this.Queue);
            this.Queue.EventManager.AddEventHandler(this.WatcherConsumer);

            // Add transformer
            this.transformer = new ContentChangeEventTransformer(this.Queue, this.storage, this.fileSystemFactory);
            this.Queue.EventManager.AddEventHandler(this.transformer);

            // Add local fetcher
            var localFetcher = new LocalObjectFetcher(this.storage.Matcher, this.fileSystemFactory);
            this.Queue.EventManager.AddEventHandler(localFetcher);

            this.ignoredStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), this.storage);

            this.Queue.EventManager.AddEventHandler(new EventManagerInitializer(this.Queue, this.storage, this.fileTransmissionStorage, this.ignoredStorage, this.RepoInfo, this.filters, activityListener, this.fileSystemFactory));

            this.Queue.EventManager.AddEventHandler(new DelayRetryAndNextSyncEventHandler(this.Queue));

            this.connectionScheduler = new ConnectionScheduler(this.RepoInfo, this.Queue, this.sessionFactory, this.authProvider);

            this.Queue.EventManager.AddEventHandler(this.connectionScheduler);
            this.Queue.EventManager.AddEventHandler(
                new GenericSyncEventHandler <SuccessfulLoginEvent>(
                    10000,
                    delegate(ISyncEvent e) {
                this.RepoStatusFlags.Connected = true;
                this.Status = this.RepoStatusFlags.Status;

                return(false);
            }));
            this.Queue.EventManager.AddEventHandler(
                new GenericSyncEventHandler <ConfigurationNeededEvent>(
                    10000,
                    delegate(ISyncEvent e) {
                this.RepoStatusFlags.Warning = true;
                this.Status = this.RepoStatusFlags.Status;

                return(false);
            }));
            this.unsubscriber = this.Queue.CategoryCounter.Subscribe(this);
        }