Esempio n. 1
0
        public void ConstructorTakesTransmissionManager()
        {
            var manager = new ActiveActivitiesManager();
            var agg     = new ActivityListenerAggregator(Mock.Of <IActivityListener>(), manager);

            Assert.That(agg.TransmissionManager, Is.EqualTo(manager));
        }
Esempio n. 2
0
        private void SetUpMocks()
        {
            this.newParentPath = Path.Combine(Path.GetTempPath(), this.newParentName);
            this.newPath       = Path.Combine(this.newParentPath, this.newName);
            this.manager       = new ActiveActivitiesManager();
            this.session       = new Mock <ISession>();
            this.session.SetupTypeSystem();
            this.storage = new Mock <IMetaDataStorage>();
            var newParentObj = new MappedObject(
                this.newParentName,
                this.newParentId,
                MappedObjectType.Folder,
                null,
                this.changeToken)
            {
                Guid = this.newParentUuid
            };

            this.storage.AddMappedFolder(newParentObj);
            this.fsFactory    = new Mock <IFileSystemInfoFactory>();
            this.changeSolver = new Mock <LocalObjectChangedRemoteObjectChanged>(
                this.session.Object,
                this.storage.Object,
                this.manager,
                this.fsFactory.Object);
            this.renameSolver = new Mock <LocalObjectRenamedRemoteObjectRenamed>(
                this.session.Object,
                this.storage.Object,
                this.changeSolver.Object);
            this.session.AddRemoteObjects(Mock.Of <IFolder>(o => o.Id == this.oldParentId), Mock.Of <IFolder>(o => o.Id == this.newParentId));
            this.underTest = new LocalObjectMovedRemoteObjectRenamed(this.session.Object, this.storage.Object, this.changeSolver.Object, this.renameSolver.Object);
        }
Esempio n. 3
0
        /// <summary>
        /// Uploads the file content to the remote document.
        /// </summary>
        /// <returns>The SHA-1 hash of the uploaded file content.</returns>
        /// <param name="localFile">Local file.</param>
        /// <param name="doc">Remote document.</param>
        /// <param name="transmissionManager">Transmission manager.</param>
        protected static byte[] UploadFile(IFileInfo localFile, IDocument doc, ActiveActivitiesManager transmissionManager)
        {
            byte[]                hash              = null;
            IFileUploader         uploader          = FileTransmission.ContentTaskUtils.CreateUploader();
            FileTransmissionEvent transmissionEvent = new FileTransmissionEvent(FileTransmissionType.UPLOAD_MODIFIED_FILE, localFile.FullName);

            transmissionManager.AddTransmission(transmissionEvent);
            transmissionEvent.ReportProgress(new TransmissionProgressEventArgs {
                Started = true
            });
            using (var hashAlg = new SHA1Managed()) {
                try {
                    using (var file = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) {
                        uploader.UploadFile(doc, file, transmissionEvent, hashAlg);
                        hash = hashAlg.Hash;
                    }
                } catch (Exception ex) {
                    transmissionEvent.ReportProgress(new TransmissionProgressEventArgs {
                        FailedException = ex
                    });
                    throw;
                }
            }

            transmissionEvent.ReportProgress(new TransmissionProgressEventArgs {
                Completed = true
            });
            return(hash);
        }
 public LocalObjectRenamedOrMovedRemoteObjectDeleted(
     ISession session,
     IMetaDataStorage storage,
     ActiveActivitiesManager manager,
     ISolver secondSolver = null) : base(session, storage)
 {
     this.secondSolver = secondSolver ?? new LocalObjectAdded(session, storage, manager);
 }
Esempio n. 5
0
 private void InitMocks(bool dateSyncEnabled = true)
 {
     this.session = new Mock <ISession>();
     this.session.SetupTypeSystem();
     this.storage   = new Mock <IMetaDataStorage>();
     this.manager   = new ActiveActivitiesManager();
     this.underTest = new LocalObjectChangedRemoteObjectChanged(this.session.Object, this.storage.Object, this.manager);
 }
        public void AddSingleTransmissionIncreasesListCountByOne()
        {
            var manager = new ActiveActivitiesManager();

            Assert.IsTrue(manager.AddTransmission(new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path")));

            Assert.That(manager.ActiveTransmissions.Count, Is.EqualTo(1));
        }
Esempio n. 7
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        static void Main(string[] args)
        {
            // Only allow one instance of DataSpace Sync (on Windows)
            if (!programMutex.WaitOne(0, false))
            {
                System.Console.WriteLine("DataSpaceSync is already running.");
                Environment.Exit(-1);
            }

            if (File.Exists(ConfigManager.CurrentConfigFile))
            {
                ConfigMigration.Migrate();
            }

            log4net.Config.XmlConfigurator.Configure(ConfigManager.CurrentConfig.GetLog4NetConfig());
            CmisSync.Lib.Utils.EnsureNeededDependenciesAreAvailable();
            if (args.Length != 0)
            {
                foreach (string arg in args)
                {
                    // Check, if the user would like to read console logs
                    if (arg.Equals("-v") || arg.Equals("--verbose"))
                    {
                        verbose = true;
                    }
                }
            }

            // Add Console Logging if user wants to
            if (verbose)
            {
                BasicConfigurator.Configure();
            }

            Logger.Info("Starting.");

            List <Repository> repositories = new List <Repository>();
            var transmissionManager        = new ActiveActivitiesManager();

            foreach (RepoInfo repoInfo in ConfigManager.CurrentConfig.Folders)
            {
                string path = repoInfo.LocalPath;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                Repository repo = new Repository(repoInfo, new ActivityListenerAggregator(new ActivityListener(), transmissionManager));
                repositories.Add(repo);
                repo.Initialize();
            }

            while (true)
            {
                System.Threading.Thread.Sleep(100);
            }
        }
Esempio n. 8
0
        private void RunSolveFile(string fileName, string fileId, string parentId, string lastChangeToken, bool extendedAttributes, Mock <IFileInfo> fileInfo, out Mock <IDocument> documentMock, bool returnLastModificationDate = false)
        {
            var parentDirInfo = this.SetupParentFolder(parentId);

            var parents = new List <IFolder>();

            parents.Add(Mock.Of <IFolder>(f => f.Id == parentId));

            string path            = Path.Combine(Path.GetTempPath(), fileName);
            var    futureRemoteDoc = Mock.Of <IDocument>(
                f =>
                f.Name == fileName &&
                f.Id == fileId &&
                f.Parents == parents &&
                f.ChangeToken == lastChangeToken);
            var futureRemoteDocId = Mock.Of <IObjectId>(
                o =>
                o.Id == fileId);

            this.session.Setup(s => s.CreateDocument(
                                   It.Is <IDictionary <string, object> >(p => (string)p["cmis:name"] == fileName),
                                   It.Is <IObjectId>(o => o.Id == parentId),
                                   It.Is <IContentStream>(stream => SetupFutureRemoteDocStream(Mock.Get(futureRemoteDoc), stream)),
                                   null,
                                   null,
                                   null,
                                   null)).Returns(futureRemoteDocId);
            this.session.Setup(s => s.GetObject(It.Is <IObjectId>(o => o == futureRemoteDocId), It.IsAny <IOperationContext>())).Returns(futureRemoteDoc);
            Mock.Get(futureRemoteDoc).Setup(
                doc =>
                doc.SetContentStream(It.IsAny <IContentStream>(), It.IsAny <bool>(), It.IsAny <bool>()))
            .Callback <IContentStream, bool, bool>(
                (s, o, r) =>
            {
                using (var temp = new MemoryStream())
                {
                    s.Stream.CopyTo(temp);
                }
            });
            if (returnLastModificationDate)
            {
                Mock.Get(futureRemoteDoc).Setup(doc => doc.LastModificationDate).Returns(new DateTime());
            }

            fileInfo.Setup(d => d.FullName).Returns(path);
            fileInfo.Setup(d => d.Name).Returns(fileName);
            fileInfo.Setup(d => d.Exists).Returns(true);
            fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributes);

            fileInfo.Setup(d => d.Directory).Returns(parentDirInfo);
            var transmissionManager = new ActiveActivitiesManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.queue.Object, transmissionManager);

            solver.Solve(fileInfo.Object, null);
            documentMock = Mock.Get(futureRemoteDoc);
            Assert.That(transmissionManager.ActiveTransmissions, Is.Empty);
        }
Esempio n. 9
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public ControllerBase()
 {
     this.FoldersPath                = ConfigManager.CurrentConfig.GetFoldersPath();
     this.transmissionManager        = new ActiveActivitiesManager();
     this.activityListenerAggregator = new ActivityListenerAggregator(this, this.transmissionManager);
     this.transmissionManager.ActiveTransmissions.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
         this.OnTransmissionListChanged();
     };
 }
 public void SetUp()
 {
     this.session = new Mock <ISession>();
     this.session.SetupTypeSystem();
     this.storage             = new Mock <IMetaDataStorage>();
     this.transmissionManager = new ActiveActivitiesManager();
     this.changeSolver        = new Mock <LocalObjectChangedRemoteObjectChanged>(this.session.Object, this.storage.Object, this.transmissionManager, Mock.Of <IFileSystemInfoFactory>());
     this.renameSolver        = new Mock <LocalObjectRenamedRemoteObjectRenamed>(this.session.Object, this.storage.Object, this.changeSolver.Object);
 }
Esempio n. 11
0
 public void SetUp()
 {
     this.manager   = new ActiveActivitiesManager();
     this.session   = new Mock <ISession>();
     this.storage   = new Mock <IMetaDataStorage>();
     this.queue     = new Mock <ISyncEventQueue>();
     this.fsFactory = new Mock <IFileSystemInfoFactory>();
     this.underTest = new RemoteObjectChanged(this.session.Object, this.storage.Object, this.queue.Object, this.manager, this.fsFactory.Object);
 }
        public void ListedTransmissionIsEqualToAdded()
        {
            var manager = new ActiveActivitiesManager();
            var trans   = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path");

            Assert.That(manager.AddTransmission(trans), Is.True);

            Assert.That(manager.ActiveTransmissions[0], Is.EqualTo(trans));
            Assert.That(manager.ActiveTransmissionsAsList()[0], Is.EqualTo(trans));
        }
Esempio n. 13
0
 public void SetUp()
 {
     this.path      = Path.Combine(Path.GetTempPath(), this.objectName);
     this.manager   = new ActiveActivitiesManager();
     this.session   = new Mock <ISession>();
     this.storage   = new Mock <IMetaDataStorage>();
     this.queue     = new Mock <ISyncEventQueue>();
     this.fsFactory = new Mock <IFileSystemInfoFactory>(MockBehavior.Strict);
     this.underTest = new RemoteObjectAdded(this.session.Object, this.storage.Object, this.queue.Object, this.manager, this.fsFactory.Object);
 }
Esempio n. 14
0
        public void Init()
        {
            this.subfolder = SubfolderBase + Guid.NewGuid().ToString();
            Console.WriteLine("Working on " + this.subfolder);

            // RepoInfo
            this.repoInfo = new RepoInfo {
                AuthenticationType = AuthenticationType.BASIC,
                LocalPath          = Path.Combine(config[1].ToString(), this.subfolder),
                RemotePath         = config[2].ToString() + "/" + this.subfolder,
                Address            = new XmlUri(new Uri(config[3].ToString())),
                User         = config[4].ToString(),
                RepositoryId = config[6].ToString()
            };
            this.repoInfo.RemotePath = this.repoInfo.RemotePath.Replace("//", "/");
            this.repoInfo.SetPassword(config[5].ToString());

            // FileSystemDir
            this.localRootDir = new DirectoryInfo(this.repoInfo.LocalPath);
            this.localRootDir.Create();

            // Repo
            var activityListener    = new Mock <IActivityListener>();
            var transmissionManager = new ActiveActivitiesManager();
            var activityAggregator  = new ActivityListenerAggregator(activityListener.Object, transmissionManager);
            var queue = new SingleStepEventQueue(new SyncEventManager());

            this.repo = new CmisRepoMock(this.repoInfo, activityAggregator, queue);

            // Session
            var cmisParameters = new Dictionary <string, string>();

            cmisParameters[SessionParameter.BindingType]  = BindingType.AtomPub;
            cmisParameters[SessionParameter.AtomPubUrl]   = this.repoInfo.Address.ToString();
            cmisParameters[SessionParameter.User]         = this.repoInfo.User;
            cmisParameters[SessionParameter.Password]     = this.repoInfo.GetPassword().ToString();
            cmisParameters[SessionParameter.RepositoryId] = this.repoInfo.RepositoryId;

            SessionFactory factory = SessionFactory.NewInstance();

            this.session = factory.CreateSession(cmisParameters);

            IFolder root = (IFolder)this.session.GetObjectByPath(config[2].ToString());

            foreach (var child in root.GetChildren())
            {
                if (child is IFolder && child.Name == this.subfolder)
                {
                    (child as IFolder).DeleteTree(true, null, true);
                }
            }

            root.Refresh();
            this.remoteRootDir = root.CreateFolder(this.subfolder);
        }
        public void AddingNonEqualTransmissionProducesNewEntryInList()
        {
            var manager = new ActiveActivitiesManager();
            var trans   = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path");
            var trans2  = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path2");

            Assert.That(manager.AddTransmission(trans), Is.True);
            Assert.That(manager.AddTransmission(trans2), Is.True);

            Assert.That(manager.ActiveTransmissions.Count, Is.EqualTo(2));
        }
Esempio n. 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Consumer.SituationSolver.LocalObjectChanged"/> class.
        /// </summary>
        /// <param name="session">Cmis session.</param>
        /// <param name="storage">Meta data storage.</param>
        /// <param name="transmissionManager">Transmission manager.</param>
        public LocalObjectChanged(
            ISession session,
            IMetaDataStorage storage,
            ActiveActivitiesManager transmissionManager) : base(session, storage)
        {
            if (transmissionManager == null)
            {
                throw new ArgumentNullException("Given transmission manager is null");
            }

            this.transmissionManager = transmissionManager;
        }
        public void AddingTheSameInstanceASecondTimeReturnsFalseAndIsNotListed()
        {
            var manager = new ActiveActivitiesManager();
            var trans   = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path");

            Assert.That(manager.AddTransmission(trans), Is.True);

            Assert.That(manager.AddTransmission(trans), Is.False);

            Assert.That(manager.ActiveTransmissions.Count, Is.EqualTo(1));
            Assert.That(manager.ActiveTransmissions[0], Is.EqualTo(trans));
        }
        public void AFinishedTransmissionIsRemovedFromList()
        {
            var manager = new ActiveActivitiesManager();
            var trans   = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path");

            manager.AddTransmission(trans);

            trans.ReportProgress(new TransmissionProgressEventArgs {
                Completed = true
            });

            Assert.That(manager.ActiveTransmissions, Is.Empty);
        }
        public void SetUp()
        {
            this.newLocalName  = string.Empty;
            this.newRemoteName = string.Empty;
            this.session       = new Mock <ISession>();
            this.session.SetupTypeSystem();
            this.storage = new Mock <IMetaDataStorage>();
            this.InitializeMappedFolderOnStorage();
            var transmissionManager = new ActiveActivitiesManager();
            var fsFactory           = Mock.Of <IFileSystemInfoFactory>();

            this.changeSolver = new Mock <LocalObjectChangedRemoteObjectChanged>(this.session.Object, this.storage.Object, transmissionManager, fsFactory);
            this.underTest    = new LocalObjectRenamedRemoteObjectRenamed(this.session.Object, this.storage.Object, this.changeSolver.Object);
        }
Esempio n. 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Consumer.SituationSolver.RemoteObjectChanged"/> class.
        /// </summary>
        /// <param name="session">Cmis session.</param>
        /// <param name="storage">Meta data storage.</param>
        /// <param name="transmissonManager">Transmisson manager.</param>
        /// <param name="fsFactory">File System Factory.</param>
        public RemoteObjectChanged(
            ISession session,
            IMetaDataStorage storage,
            ActiveActivitiesManager transmissonManager,
            IFileSystemInfoFactory fsFactory = null) : base(session, storage)
        {
            if (transmissonManager == null)
            {
                throw new ArgumentNullException("Given transmission manager is null");
            }

            this.transmissonManager = transmissonManager;
            this.fsFactory          = fsFactory ?? new FileSystemInfoFactory();
        }
Esempio n. 21
0
 private void SetUpMocks()
 {
     this.manager = new ActiveActivitiesManager();
     this.session = new Mock <ISession>();
     this.session.SetupTypeSystem();
     this.storage      = new Mock <IMetaDataStorage>();
     this.fsFactory    = new Mock <IFileSystemInfoFactory>();
     this.changeSolver = new Mock <LocalObjectChangedRemoteObjectChanged>(
         this.session.Object,
         this.storage.Object,
         this.manager,
         this.fsFactory.Object);
     this.underTest = new LocalObjectChangedRemoteObjectRenamed(this.session.Object, this.storage.Object, this.changeSolver.Object);
 }
Esempio n. 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.ActivityListenerAggregator"/> class.
        /// </summary>
        /// <param name="overallListener">The activity listener to which aggregated activity will be sent.</param>
        /// <param name="transmissionManager">Transmission manager.</param>
        public ActivityListenerAggregator(IActivityListener overallListener, ActiveActivitiesManager transmissionManager)
        {
            if (overallListener == null)
            {
                throw new ArgumentNullException("Given listener is null");
            }

            if (transmissionManager == null)
            {
                throw new ArgumentNullException("Given transmission manager is null");
            }

            this.overall             = overallListener;
            this.TransmissionManager = transmissionManager;
        }
        public void AddingATransmissionFiresEvent()
        {
            var manager      = new ActiveActivitiesManager();
            var trans        = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path");
            int eventCounter = 0;

            manager.ActiveTransmissions.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            {
                eventCounter++;
                Assert.That(e.NewItems.Count, Is.EqualTo(1));
                Assert.That(e.NewItems[0], Is.EqualTo(trans));
            };
            manager.AddTransmission(trans);

            Assert.That(eventCounter, Is.EqualTo(1));
        }
        private void SetUpMocks()
        {
            this.manager = new ActiveActivitiesManager();
            this.session = new Mock <ISession>();
            this.session.SetupTypeSystem();
            this.storage      = new Mock <IMetaDataStorage>();
            this.fsFactory    = new Mock <IFileSystemInfoFactory>();
            this.changeSolver = new Mock <LocalObjectChangedRemoteObjectChanged>(
                this.session.Object,
                this.storage.Object,
                this.manager,
                this.fsFactory.Object);
            var changeSolverForRenameSolver = new Mock <LocalObjectChangedRemoteObjectChanged>(
                this.session.Object,
                this.storage.Object,
                this.manager,
                this.fsFactory.Object);

            this.renameSolver = new Mock <LocalObjectRenamedRemoteObjectChanged>(
                this.session.Object,
                this.storage.Object,
                changeSolverForRenameSolver.Object)
            {
                CallBase = true
            };
            this.underTest = new LocalObjectMovedRemoteObjectChanged(this.session.Object, this.storage.Object, this.renameSolver.Object, this.changeSolver.Object);
            var srcRemoteParent = Mock.Of <ICmisObject>(
                o =>
                o.Name == this.oldParentsName &&
                o.Id == this.oldParentsId);
            var targetRemoteParent = Mock.Of <ICmisObject>(
                o =>
                o.Name == this.newParentsName &&
                o.Id == this.newParentsId);

            this.session.AddRemoteObjects(srcRemoteParent, targetRemoteParent);
            this.parentUuid = Guid.NewGuid();
            var mappedParent = new MappedObject(this.newParentsName, this.newParentsId, MappedObjectType.Folder, "grandParentId", this.changeToken)
            {
                Guid = this.parentUuid
            };

            this.storage.AddMappedFolder(mappedParent);
        }
Esempio n. 25
0
        public void LocalFolderAddingFailsBecauseUtf8Character()
        {
            this.SetUpMocks();
            var transmissionManager = new ActiveActivitiesManager();
            var solver  = new LocalObjectAdded(this.session.Object, this.storage.Object, transmissionManager);
            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.Name).Returns(@"ä".Normalize(System.Text.NormalizationForm.FormD));
            var parentDirInfo = this.SetupParentFolder(parentId);

            dirInfo.Setup(d => d.Parent).Returns(parentDirInfo);
            this.session.Setup(s => s.CreateFolder(It.IsAny <IDictionary <string, object> >(), It.IsAny <IObjectId>())).Throws(new CmisConstraintException("Conflict"));
            Assert.Throws <InteractionNeededException>(() => solver.Solve(dirInfo.Object, null));

            this.storage.VerifyThatNoObjectIsManipulated();
            this.session.Verify(s => s.CreateFolder(It.Is <IDictionary <string, object> >(p => p.ContainsKey("cmis:name")), It.Is <IObjectId>(o => o.Id == this.parentId)), Times.Once());
            dirInfo.VerifyThatLocalFileObjectLastWriteTimeUtcIsNeverModified();
            dirInfo.VerifySet(d => d.Uuid = It.IsAny <Guid?>(), Times.Never());
        }
Esempio n. 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Consumer.SituationSolver.LocalObjectChanged"/> class.
        /// </summary>
        /// <param name="session">Cmis session.</param>
        /// <param name="storage">Meta data storage.</param>
        /// <param name="queue">Event queue for publishing upload transmission.</param>
        /// <param name="transmissionManager">Transmission manager.</param>
        /// <param name="serverCanModifyCreationAndModificationDate">If set to <c>true</c> server can modify creation and modification date.</param>
        public LocalObjectChanged(
            ISession session,
            IMetaDataStorage storage,
            ISyncEventQueue queue,
            ActiveActivitiesManager transmissionManager,
            bool serverCanModifyCreationAndModificationDate = false) : base(session, storage, serverCanModifyCreationAndModificationDate)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("Given queue is null");
            }

            if (transmissionManager == null)
            {
                throw new ArgumentNullException("Given transmission manager is null");
            }

            this.queue = queue;
            this.transmissionManager = transmissionManager;
        }
        public void AFinishedTransmissionFiresEvent()
        {
            var manager      = new ActiveActivitiesManager();
            var trans        = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, "path");
            int eventCounter = 0;

            manager.AddTransmission(trans);

            manager.ActiveTransmissions.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            {
                eventCounter++;
                Assert.That(e.NewItems, Is.Null);
                Assert.That(e.OldItems.Count, Is.EqualTo(1));
                Assert.That(e.OldItems[0], Is.EqualTo(trans));
            };
            trans.ReportProgress(new TransmissionProgressEventArgs {
                Completed = true
            });

            Assert.That(eventCounter, Is.EqualTo(1));
        }
Esempio n. 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Consumer.SituationSolver.RemoteObjectAdded"/> class.
        /// </summary>
        /// <param name="session">Cmis session.</param>
        /// <param name="storage">Meta data storage.</param>
        /// <param name="queue">Queue to report new transmissions to.</param>
        /// <param name="transmissonManager">Transmisson manager.</param>
        /// <param name="fsFactory">File system factory.</param>
        public RemoteObjectAdded(
            ISession session,
            IMetaDataStorage storage,
            ISyncEventQueue queue,
            ActiveActivitiesManager transmissonManager,
            IFileSystemInfoFactory fsFactory = null) : base(session, storage)
        {
            if (queue == null)
            {
                throw new ArgumentNullException("Given queue is null");
            }

            if (transmissonManager == null)
            {
                throw new ArgumentNullException("Given transmission manager is null");
            }

            this.fsFactory = fsFactory ?? new FileSystemInfoFactory();
            this.queue     = queue;
            this.manager   = transmissonManager;
        }
Esempio n. 29
0
        private Mock <IDirectoryInfo> RunSolveFolder(string folderName, string id, string parentId, string lastChangeToken, bool extendedAttributes, out Mock <IFolder> folderMock, Guid?existingGuid = null)
        {
            string path = Path.Combine(Path.GetTempPath(), folderName);
            var    futureRemoteFolder = Mock.Of <IFolder>(
                f =>
                f.Name == folderName &&
                f.Id == id &&
                f.ParentId == parentId &&
                f.ChangeToken == lastChangeToken);
            var futureRemoteFolderId = Mock.Of <IObjectId>(
                o =>
                o.Id == id);

            this.session.Setup(s => s.CreateFolder(It.Is <IDictionary <string, object> >(p => (string)p["cmis:name"] == folderName), It.Is <IObjectId>(o => o.Id == parentId))).Returns(futureRemoteFolderId);
            this.session.Setup(s => s.GetObject(It.Is <IObjectId>(o => o == futureRemoteFolderId), It.IsAny <IOperationContext>())).Returns(futureRemoteFolder);

            var dirInfo = new Mock <IDirectoryInfo>();

            dirInfo.Setup(d => d.FullName).Returns(path);
            dirInfo.Setup(d => d.Name).Returns(folderName);
            dirInfo.Setup(d => d.Exists).Returns(true);
            dirInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributes);
            if (existingGuid != null)
            {
                dirInfo.Setup(d => d.GetExtendedAttribute(It.IsAny <string>())).Returns(existingGuid.ToString());
            }

            var parentDirInfo = this.SetupParentFolder(parentId);

            dirInfo.Setup(d => d.Parent).Returns(parentDirInfo);
            var transmissionManager = new ActiveActivitiesManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.queue.Object, transmissionManager);

            solver.Solve(dirInfo.Object, null);

            folderMock = Mock.Get(futureRemoteFolder);
            return(dirInfo);
        }
Esempio n. 30
0
        public void PermissionDeniedLeadsToNoOperation()
        {
            string fileName           = "fileName";
            string parentId           = "parentId";
            bool   extendedAttributes = true;

            string path = Path.Combine(Path.GetTempPath(), fileName);

            this.session.Setup(s => s.CreateDocument(
                                   It.Is <IDictionary <string, object> >(p => (string)p["cmis:name"] == fileName),
                                   It.Is <IObjectId>(o => o.Id == parentId),
                                   It.IsAny <IContentStream>(),
                                   null,
                                   null,
                                   null,
                                   null)).Throws(new CmisPermissionDeniedException());

            Mock <IFileInfo> fileInfo = new Mock <IFileInfo>();

            fileInfo.Setup(f => f.Length).Returns(0);

            var parentDirInfo = this.SetupParentFolder(parentId);

            var parents = new List <IFolder>();

            parents.Add(Mock.Of <IFolder>(f => f.Id == parentId));
            fileInfo.Setup(d => d.FullName).Returns(path);
            fileInfo.Setup(d => d.Name).Returns(fileName);
            fileInfo.Setup(d => d.Exists).Returns(true);
            fileInfo.Setup(d => d.IsExtendedAttributeAvailable()).Returns(extendedAttributes);

            fileInfo.Setup(d => d.Directory).Returns(parentDirInfo);
            var transmissionManager = new ActiveActivitiesManager();
            var solver = new LocalObjectAdded(this.session.Object, this.storage.Object, this.queue.Object, transmissionManager);

            solver.Solve(fileInfo.Object, null);
            this.storage.Verify(s => s.SaveMappedObject(It.IsAny <IMappedObject>()), Times.Never());
        }