コード例 #1
0
        public void DetectSymlinksCorrectly([Values(true, false)] bool exists, [Values(true, false)] bool isSymlink)
        {
            var    underTest = new SymlinkFilter();
            string path      = "path";
            string reason;
            var    fileInfo = new Mock <IFileSystemInfo>(MockBehavior.Strict);

            fileInfo.Setup(f => f.Exists).Returns(exists);
            fileInfo.Setup(f => f.IsSymlink).Returns(isSymlink);
            fileInfo.Setup(f => f.FullName).Returns(path);
            var result = underTest.IsSymlink(fileInfo.Object, out reason);

            Assert.That(result, Is.EqualTo(exists && isSymlink));
            Assert.That(reason, Is.Not.Null);
            if (result)
            {
                Assert.That(reason, Is.StringContaining(path));
                fileInfo.Verify(f => f.FullName, Times.Once());
            }
            else
            {
                Assert.That(reason, Is.EqualTo(string.Empty));
                fileInfo.Verify(f => f.FullName, Times.Never());
            }

            fileInfo.Verify(f => f.Exists, Times.AtMostOnce());
            fileInfo.Verify(f => f.IsSymlink, Times.AtMostOnce());
        }
コード例 #2
0
 public void SetUpFilter()
 {
     this.ignoreFoldersFilter     = Mock.Of <IgnoredFoldersFilter>();
     this.ignoreFileNamesFilter   = Mock.Of <IgnoredFileNamesFilter>();
     this.ignoreFolderNamesFilter = Mock.Of <IgnoredFolderNameFilter>();
     this.invalidFolderNameFilter = Mock.Of <InvalidFolderNameFilter>();
     this.symlinkFilter           = Mock.Of <SymlinkFilter>();
     this.queue = new Mock <ISyncEventQueue>();
 }
コード例 #3
0
        public void ConstructorSetAllFilter([Values(true, false, null)] bool?passSymlinkFilter)
        {
            SymlinkFilter symlinkFilter = passSymlinkFilter == true ? new SymlinkFilter() : null;
            var           filter        = passSymlinkFilter == false ? new FilterAggregator(this.arg0, this.arg1, this.arg2, this.arg3) : new FilterAggregator(this.arg0, this.arg1, this.arg2, this.arg3, symlinkFilter);

            Assert.That(filter.FileNamesFilter, Is.EqualTo(this.arg0));
            Assert.That(filter.FolderNamesFilter, Is.EqualTo(this.arg1));
            Assert.That(filter.InvalidFolderNamesFilter, Is.EqualTo(this.arg2));
            Assert.That(filter.IgnoredFolderFilter, Is.EqualTo(this.arg3));
            if (symlinkFilter != null)
            {
                Assert.That(filter.SymlinkFilter, Is.EqualTo(symlinkFilter));
            }
            else
            {
                Assert.That(filter.SymlinkFilter, Is.Not.Null);
            }
        }
コード例 #4
0
ファイル: Repository.cs プロジェクト: OpenDataSpace/CmisSync
        /// <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);
        }