コード例 #1
0
        public void Real(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                         string url, string user, string password, string repositoryId)
        {
            // Create temporary folder for configuration and data files.
            string tempFolder          = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            string configurationFolder = Path.Combine(tempFolder, "configuration");

            Directory.CreateDirectory(tempFolder);
            Directory.CreateDirectory(configurationFolder);

            // Create XML config file.
            string customConfigPath = Path.Combine(configurationFolder, "config.xml");
            string logPath          = Path.Combine(configurationFolder, "debug_log.txt");
            string localDataPath    = Path.Combine(tempFolder, "data");
            string customConfig     = File.ReadAllText(@"../../config.xml");

            // Replace variables in template
            customConfig.Replace("{LOG}", logPath);
            customConfig.Replace("{LOCAL_FOLDER}", localDataPath);
            customConfig.Replace("{REMOTE_FOLDER}", remoteFolderPath);
            customConfig.Replace("{URL}", url);
            customConfig.Replace("{USER}", user);
            customConfig.Replace("{PASSWORD}", password);
            customConfig.Replace("{REPOSITORY}", repositoryId);

            File.WriteAllText(customConfigPath, customConfig);

            Process process = Process.Start(CONSOLE_EXE, "-p -c " + customConfigPath);

            if (null == process)
            {
                Assert.Fail("Could not start process, maybe an existing process has been reused?");
            }

            process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
            process.ErrorDataReceived  += (s, e) => Console.WriteLine(e.Data);

            //Clean(canonicalName, localPath, remoteFolderPath, url, user, password, repositoryId);
            // TODO clean the remote folder and delete/create local folder

            // Create random small file.
            string filename       = LocalFilesystemActivityGenerator.GetNextFileName();
            string remoteFilePath = (remoteFolderPath + "/" + filename).Replace("//", "/");

            LocalFilesystemActivityGenerator.CreateRandomFile(localDataPath, 3);

            Thread.Sleep(10 * 1000); // Wait for 10 seconds so that sync gets a chance to sync things.

            // Check that file is present server-side.
            IDocument doc = (IDocument)CreateSession(url, user, password, repositoryId).GetObjectByPath(remoteFilePath, true);

            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);

            // Exit the process to avoid any possible interference with subsequent tests.
            process.Kill();
        }
コード例 #2
0
ファイル: CmisSyncTests.cs プロジェクト: to2y/CmisSync
        public void ClientSideBigFileAddition(string canonical_name, string localPath, string remoteFolderPath,
                                              string url, string user, string password, string repositoryId)
        {
            // Prepare checkout directory.
            string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name);

            CleanDirectory(localDirectory);
            Console.WriteLine("Synced to clean state.");

            IActivityListener activityListener = new Mock <IActivityListener>().Object;
            RepoInfo          repoInfo         = new RepoInfo(
                canonical_name,
                ".",
                remoteFolderPath,
                url,
                user,
                password,
                repositoryId,
                5000);

            using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener))
            {
                using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(
                           repoInfo,
                           activityListener,
                           cmis))
                {
                    synchronizedFolder.Sync();
                    Console.WriteLine("Synced to clean state.");

                    // Create random big file.
                    LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 1000); // 1 MB ... no that big to not load servers too much.

                    // Sync again.
                    synchronizedFolder.Sync();
                    Console.WriteLine("Second sync done.");

                    // Check that file is present server-side.
                    // TODO

                    // Clean.
                    Console.WriteLine("Clean all.");
                    Clean(localDirectory, synchronizedFolder);
                }
            }
        }
コード例 #3
0
ファイル: CmisSyncTests.cs プロジェクト: to2y/CmisSync
        public void ClientSideDirectoryAndSmallFilesAddition(string canonical_name, string localPath, string remoteFolderPath,
                                                             string url, string user, string password, string repositoryId)
        {
            // Prepare checkout directory.
            string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name);

            CleanDirectory(localDirectory);
            Console.WriteLine("Synced to clean state.");

            IActivityListener activityListener = new Mock <IActivityListener>().Object;
            RepoInfo          repoInfo         = new RepoInfo(
                canonical_name,
                CMISSYNCDIR,
                remoteFolderPath,
                url,
                user,
                password,
                repositoryId,
                5000);

            using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener))
            {
                using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(
                           repoInfo,
                           activityListener,
                           cmis))
                {
                    synchronizedFolder.Sync();
                    Console.WriteLine("Synced to clean state.");

                    // Create directory and small files.
                    LocalFilesystemActivityGenerator.CreateDirectoriesAndFiles(localDirectory);

                    // Sync again.
                    synchronizedFolder.Sync();
                    Console.WriteLine("Second sync done.");

                    // Clean.
                    Console.WriteLine("Clean all.");
                    Clean(localDirectory, synchronizedFolder);
                }
            }
        }
コード例 #4
0
ファイル: CmisSyncTests.cs プロジェクト: lefty01/CmisSync
        public void ClientSideSmallFileAddition(string canonical_name, string localPath, string remoteFolderPath,
                                                string url, string user, string password, string repositoryId)
        {
            // Prepare checkout directory.
            string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name);

            CleanDirectory(localDirectory);
            // Mock.
            ActivityListener activityListener = new Mock <ActivityListener>().Object;
            // Sync.
            RepoInfo repoInfo = new RepoInfo(
                canonical_name,
                ".",
                remoteFolderPath,
                url,
                user,
                password,
                repositoryId,
                5000);

            CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(
                repoInfo,
                activityListener,
                new CmisRepo(repoInfo, activityListener)
                );
            synchronizedFolder.Sync();
            Console.WriteLine("Synced to clean state.");

            // Create random small file.
            LocalFilesystemActivityGenerator.CreateRandomFile(localDirectory, 3);

            // Sync again.
            synchronizedFolder.Sync();
            Console.WriteLine("Second sync done.");

            // Check that file is present server-side.
            // TODO

            // Clean.
            Clean(localDirectory, synchronizedFolder);
        }
コード例 #5
0
        public void LocalFileCreationWithOnlyWatcher(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                                                     string url, string user, string password, string repositoryId)
        {
            // Prepare remote folder.
            ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath);

            // Month-long sync interval, meaning that in fact only the watcher can trigger syncs.
            sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId, CmisSyncProcess.MONTH_LONG_SYNC_INTERVAL);

            // Wait a few seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            ////////////////////////////////////////////// Local file creation

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.doc";

            LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb);

            // Check that file is present server-side.
            Thread.Sleep(20 * 1000);
            IDocument doc = null;

            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength);
            Assert.AreEqual("application/msword", doc.ContentStreamMimeType);
            // TODO compare date Assert.AreEqual(, doc.);
            string docId = doc.Id;
        }
コード例 #6
0
        public void Real(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                         string url, string user, string password, string repositoryId)
        {
            // Clear the remote folder.
            ClearRemoteCMISFolder(url, user, password, repositoryId, remoteFolderPath);

            // Create temporary folder for configuration and data files.
            string tempFolder = Path.Combine(Path.GetTempPath(), "CmisSync_test_" + Path.GetRandomFileName());

            Console.Write("Test folder: " + tempFolder);
            string configurationFolder = Path.Combine(tempFolder, "configuration");
            string localDataFolder     = Path.Combine(tempFolder, "data");

            Directory.CreateDirectory(tempFolder);
            Directory.CreateDirectory(configurationFolder);
            Directory.CreateDirectory(localDataFolder);

            // Create XML config file.
            string customConfigPath = Path.Combine(configurationFolder, "config.xml");
            string logPath          = Path.Combine(configurationFolder, "debug_log.txt");
            string customConfig     = File.ReadAllText(@"../../config.xml");

            // Replace variables in template
            customConfig = customConfig.Replace("{LOG}", logPath);
            customConfig = customConfig.Replace("{LOCAL_FOLDER}", localDataFolder);
            customConfig = customConfig.Replace("{REMOTE_FOLDER}", remoteFolderPath);
            customConfig = customConfig.Replace("{URL}", url);
            customConfig = customConfig.Replace("{USER}", user);
            customConfig = customConfig.Replace("{PASSWORD}", password);
            customConfig = customConfig.Replace("{REPOSITORY}", repositoryId);
            // Write config file.
            File.WriteAllText(customConfigPath, customConfig);

            // Start CmiSync.
            string arguments = "-p -c " + customConfigPath;

            Console.Write("Executing: " + CONSOLE_EXE + " " + arguments);
            Process process = Process.Start(CONSOLE_EXE, arguments);

            if (null == process)
            {
                Assert.Fail("Could not start process, maybe an existing process has been reused?");
            }
            process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
            process.ErrorDataReceived  += (s, e) => Console.WriteLine(e.Data);

            ////////////////////////////////////////////// File creation

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.doc";

            LocalFilesystemActivityGenerator.CreateFile(Path.Combine(localDataFolder, filename), sizeKb);

            // Wait a few seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            // Check that file is present server-side.
            IDocument doc = null;

            try {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e) {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength);
            Assert.AreEqual("application/msword", doc.ContentStreamMimeType);
            // TODO compare date Assert.AreEqual(, doc.);
            string docId = doc.Id;

            ////////////////////////////////////////////// File append

            // Append to file
            string dataToAppend = "let's add a bit more data to that file";

            byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend);
            using (var fileStream = new FileStream(Path.Combine(localDataFolder, filename), FileMode.Append, FileAccess.Write, FileShare.None))
                using (var bw = new BinaryWriter(fileStream))
                {
                    bw.Write(bytes);
                }

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(10 * 1000);

            try
            {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(1024 * sizeKb + dataToAppend.Length, doc.ContentStreamLength);


            ////////////////////////////////////////////// Folder creation

            // Create local folder.
            string foldername = "folder 1";

            Directory.CreateDirectory(Path.Combine(localDataFolder, foldername));

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(10 * 1000);

            IFolder folder = null;

            try
            {
                folder = (IFolder)CreateSession(url, user, password, repositoryId)
                         .GetObjectByPath(remoteFolderPath + "/" + foldername, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Folder failed to get synced to the server.", e);
            }


            ////////////////////////////////////////////// File rename

            // Rename the document
            string newFilename = "moved_" + filename;

            File.Move(Path.Combine(localDataFolder, filename), Path.Combine(localDataFolder, newFilename));
            filename = newFilename;

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(10 * 1000);

            // Check that the remote document has been renamed, and still has the same object id.
            doc = null;
            try
            {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            string newDocId = doc.Id;

            //FIXME            Assert.AreEqual(docId, newDocId, "The remote document's id has changed when the local file was renamed: " + docId + " -> " + newDocId);

            ////////////////////////////////////////////// File delete

            // Delete the file.
            File.Delete(Path.Combine(localDataFolder, filename));

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(10 * 1000);

            // Check that file is not present server-side.
            doc = null;
            try
            {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);

                // Should have failed.
                Assert.Fail("Deleted document still exists on server: " + doc);
            }
            catch (CmisObjectNotFoundException e)
            {
                // That's the correct outcome
            }



            // Exit the process to avoid any possible interference with subsequent tests.
            process.Kill(); // TODO does not always get killed.
        }
コード例 #7
0
ファイル: CmisSyncTests.cs プロジェクト: to2y/CmisSync
        public void SyncWhileModifyingFolders(string canonical_name, string localPath, string remoteFolderPath,
                                              string url, string user, string password, string repositoryId)
        {
            // Prepare checkout directory.
            string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name);

            CleanDirectory(localDirectory);
            Console.WriteLine("Synced to clean state.");

            // Mock.
            IActivityListener activityListener = new Mock <IActivityListener>().Object;
            // Sync.
            RepoInfo repoInfo = new RepoInfo(
                canonical_name,
                CMISSYNCDIR,
                remoteFolderPath,
                url,
                user,
                password,
                repositoryId,
                5000);

            using (CmisRepo cmis = new CmisRepo(repoInfo, activityListener))
            {
                using (CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(
                           repoInfo,
                           activityListener,
                           cmis))
                {
                    synchronizedFolder.Sync();
                    Console.WriteLine("Synced to clean state.");

                    // Sync a few times in a different thread.
                    bool             syncing = true;
                    BackgroundWorker bw      = new BackgroundWorker();
                    bw.DoWork += new DoWorkEventHandler(
                        delegate(Object o, DoWorkEventArgs args)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            Console.WriteLine("Sync D" + i.ToString());
                            synchronizedFolder.Sync();
                        }
                    }
                        );
                    bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                        delegate(object o, RunWorkerCompletedEventArgs args)
                    {
                        syncing = false;
                    }
                        );
                    bw.RunWorkerAsync();

                    // Keep creating/removing a file as long as sync is going on.
                    while (syncing)
                    {
                        //Console.WriteLine("Create/remove.");
                        LocalFilesystemActivityGenerator.CreateDirectoriesAndFiles(localDirectory);
                        CleanAll(localDirectory);
                    }

                    // Clean.
                    Console.WriteLine("Clean all.");
                    Clean(localDirectory, synchronizedFolder);
                }
            }
        }
コード例 #8
0
        public void Conflict(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                             string url, string user, string password, string repositoryId)
        {
            // Prepare remote folder and CmisSync process.
            ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath);

            sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId);

            ////////////////////////////////////////////// Initialization

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.txt";

            LocalFilesystemActivityGenerator.CreateTextFile(Path.Combine(sync.Folder(), filename), sizeKb);

            // Wait a few seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            sync.Suspend();

            // Wait for 10 seconds to be sure suspension happened.
            Thread.Sleep(10 * 1000);

            ////////////////////////////////////////////// Modify on remote side

            byte[]        content       = UTF8Encoding.UTF8.GetBytes("Modified from remote side");
            ContentStream contentStream = new ContentStream();

            contentStream.FileName = "file.txt";
            contentStream.MimeType = "text/plain";
            contentStream.Length   = content.Length;
            contentStream.Stream   = new MemoryStream(content);

            IDocument doc = null;

            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
                doc.SetContentStream(contentStream, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }

            // Modify on local side, by appending to file.
            string dataToAppend = "Modified on local side";

            byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend);
            using (var fileStream = new FileStream(Path.Combine(sync.Folder(), filename), FileMode.Append, FileAccess.Write, FileShare.None))
                using (var bw = new BinaryWriter(fileStream))
                {
                    bw.Write(bytes);
                }

            // Conflict
            sync.Resume();
            Thread.Sleep(10 * 1000);

            // TODO check that conflicts happened correctly.
        }
コード例 #9
0
        public void LocalFileAppend(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                                    string url, string user, string password, string repositoryId)
        {
            // Prepare remote folder and CmisSync process.
            ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath);

            sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId);

            // Local file creation

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.doc";

            LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb);

            // Check that file is present server-side.
            Thread.Sleep(20 * 1000);
            IDocument doc = null;

            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength);
            Assert.AreEqual("application/msword", doc.ContentStreamMimeType);
            // TODO compare date Assert.AreEqual(, doc.);
            string docId = doc.Id;

            // Local file append

            // Append to file
            string dataToAppend = "let's add a bit more data to that file";

            byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend);
            using (var fileStream = new FileStream(Path.Combine(sync.Folder(), filename), FileMode.Append, FileAccess.Write, FileShare.None))
                using (var bw = new BinaryWriter(fileStream))
                {
                    bw.Write(bytes);
                }

            // Check on server
            Thread.Sleep(10 * 1000);
            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.True(1 - (1024 * sizeKb + dataToAppend.Length) / doc.ContentStreamLength < 0.1); // Text file size can vary a bit
        }
コード例 #10
0
        public void _CurrentlyFailing_LocalFileMove(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                                                    string url, string user, string password, string repositoryId)
        {
            // Prepare remote folder and CmisSync process.
            ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath);

            sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId);

            ////////////////////////////////////////////// Local file creation

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.doc";

            LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb);

            // Wait a few seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            // Check that file is present server-side.
            IDocument doc = null;

            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength);
            Assert.AreEqual("application/msword", doc.ContentStreamMimeType);
            // TODO compare date Assert.AreEqual(, doc.);
            string docId = doc.Id;

            ////////////////////////////////////////////// Local folder creation

            // Create local folder.
            string foldername = "folder 1";

            Directory.CreateDirectory(Path.Combine(sync.Folder(), foldername));

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            IFolder folder = null;

            try
            {
                folder = (IFolder)session.GetObjectByPath(remoteFolderPath + "/" + foldername, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Folder failed to get synced to the server.", e);
            }

            // Move local file to other folder

            string destinationFilename = foldername + Path.DirectorySeparatorChar + filename;

            File.Move(Path.Combine(sync.Folder(), filename), Path.Combine(sync.Folder(), destinationFilename));

            // Check that the remote document has been renamed, and still has the same object id.
            Thread.Sleep(20 * 1000);
            doc = null;
            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + foldername + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get moved on server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            string newDocId = doc.Id;

            // Current status: Fails.
            Assert.AreEqual(docId, newDocId, "The remote document's id has changed when the local file was moved: " + docId + " -> " + newDocId);
        }
コード例 #11
0
        public void LocalFileRename(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                                    string url, string user, string password, string repositoryId)
        {
            // Prepare remote folder and CmisSync process.
            ISession session = ClearRemoteCMISFolderAndGetSession(url, user, password, repositoryId, remoteFolderPath);

            sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId);

            ////////////////////////////////////////////// Local file creation

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.doc";

            LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb);

            // Wait a few seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            // Check that file is present server-side.
            IDocument doc = null;

            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength);
            Assert.AreEqual("application/msword", doc.ContentStreamMimeType);
            // TODO compare date Assert.AreEqual(, doc.);
            string docId = doc.Id;

            ////////////////////////////////////////////// Local file rename

            // Rename the document
            string newFilename = "moved_" + filename;

            File.Move(Path.Combine(sync.Folder(), filename), Path.Combine(sync.Folder(), newFilename));
            filename = newFilename;

            // Check that the remote document has been renamed, and still has the same object id.
            Thread.Sleep(10 * 1000);
            doc = null;
            try
            {
                doc = (IDocument)session.GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            string newDocId = doc.Id;

            // Current status: The following line sometimes fails, sometimes succeeds. Probably a race condition.
            Assert.AreEqual(docId, newDocId, "The remote document's id has changed when the local file was renamed: " + docId + " -> " + newDocId);
        }
コード例 #12
0
        public void LongScenario(string ignoredCanonicalName, string ignoredLocalPath, string remoteFolderPath,
                                 string url, string user, string password, string repositoryId)
        {
            // Prepare remote folder and CmisSync process.
            ClearRemoteCMISFolder(url, user, password, repositoryId, remoteFolderPath);
            sync = new CmisSyncProcess(remoteFolderPath, url, user, password, repositoryId);

            ////////////////////////////////////////////// Local file creation

            // Create random small file.
            int    sizeKb   = 3;
            string filename = "file.doc";

            LocalFilesystemActivityGenerator.CreateFile(Path.Combine(sync.Folder(), filename), sizeKb);

            // Wait a few seconds so that sync gets a chance to sync things.
            Thread.Sleep(20 * 1000);

            // Check that file is present server-side.
            IDocument doc = null;

            try
            {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.AreEqual(sizeKb * 1024, doc.ContentStreamLength);
            Assert.AreEqual("application/msword", doc.ContentStreamMimeType);
            // TODO compare date Assert.AreEqual(, doc.);
            string docId = doc.Id;

            ////////////////////////////////////////////// Local file append

            // Append to file
            string dataToAppend = "let's add a bit more data to that file";

            byte[] bytes = Encoding.UTF8.GetBytes(dataToAppend);
            using (var fileStream = new FileStream(Path.Combine(sync.Folder(), filename), FileMode.Append, FileAccess.Write, FileShare.None))
                using (var bw = new BinaryWriter(fileStream))
                {
                    bw.Write(bytes);
                }

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(10 * 1000);

            try
            {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Document failed to get synced to the server.", e);
            }
            Assert.NotNull(doc);
            Assert.AreEqual(filename, doc.ContentStreamFileName);
            Assert.AreEqual(filename, doc.Name);
            Assert.True(1 - (1024 * sizeKb + dataToAppend.Length) / doc.ContentStreamLength < 0.1); // Text file size can vary a bit

            ////////////////////////////////////////////// Local folder creation

            // Create local folder.
            string foldername = "folder 1";

            Directory.CreateDirectory(Path.Combine(sync.Folder(), foldername));

            // Wait for 10 seconds so that sync gets a chance to sync things.
            Thread.Sleep(10 * 1000);

            IFolder folder = null;

            try
            {
                folder = (IFolder)CreateSession(url, user, password, repositoryId)
                         .GetObjectByPath(remoteFolderPath + "/" + foldername, true);
            }
            catch (CmisObjectNotFoundException e)
            {
                Assert.Fail("Folder failed to get synced to the server.", e);
            }

            ////////////////////////////////////////////// Local file delete

            // Delete the file.
            File.Delete(Path.Combine(sync.Folder(), filename));

            // Wait so that sync gets a chance to sync things.
            Thread.Sleep(15 * 1000);

            // Check that file is not present server-side.
            doc = null;
            try
            {
                doc = (IDocument)CreateSession(url, user, password, repositoryId)
                      .GetObjectByPath(remoteFolderPath + "/" + filename, true);

                // Should have failed.
                Assert.Fail("Deleted document still exists on server: " + doc);
            }
            catch (CmisObjectNotFoundException e)
            {
                // That's the correct outcome
            }

            ////////////////////////////////////////////// Remote file creation

            string[] remoteFilenames = { filename, "いろんなカタチが、見えてくる。", "مشاور", "コンサルティングपरामर्शदाता컨설턴트" };
            foreach (string remoteFilename in remoteFilenames)
            {
                // Create remote file
                IFolder remoteBaseFolder = (IFolder)CreateSession(url, user, password, repositoryId).GetObjectByPath(remoteFolderPath, true);
                IDictionary <string, object> properties = new Dictionary <string, object>();
                properties[PropertyIds.Name]         = remoteFilename;
                properties[PropertyIds.ObjectTypeId] = "cmis:document";

                byte[]        creationContent       = UTF8Encoding.UTF8.GetBytes("Hello World!");
                ContentStream creationContentStream = new ContentStream();
                creationContentStream.FileName = remoteFilename;
                creationContentStream.MimeType = "text/plain";
                creationContentStream.Length   = creationContent.Length;
                creationContentStream.Stream   = new MemoryStream(creationContent);

                remoteBaseFolder.CreateDocument(properties, creationContentStream, null);

                // Wait for 10 seconds so that sync gets a chance to sync things.
                Thread.Sleep(10 * 1000);

                // Check locally
                Assert.True(File.Exists(Path.Combine(sync.Folder(), (String)properties[PropertyIds.Name])));
            }

            ////////////////////////////////////////////// Remote file modification

            doc = (IDocument)CreateSession(url, user, password, repositoryId)
                  .GetObjectByPath(remoteFolderPath + "/" + filename, true);

            string contentString = "Hello World, edited.";

            byte[]        content       = UTF8Encoding.UTF8.GetBytes(contentString);
            ContentStream contentStream = new ContentStream();

            contentStream.FileName = filename;
            contentStream.MimeType = "text/plain";
            contentStream.Length   = content.Length;
            contentStream.Stream   = new MemoryStream(content);

            doc.SetContentStream(contentStream, true);

            // Wait so that sync gets a chance to sync things.
            Thread.Sleep(30 * 1000);

            // Check local file
            string remoteContent = File.ReadAllText(Path.Combine(sync.Folder(), filename));

            Assert.AreEqual(contentString, remoteContent);
        }
コード例 #13
0
ファイル: CmisSyncTests.cs プロジェクト: lefty01/CmisSync
        public void SyncWhileModifyingFolders(string canonical_name, string localPath, string remoteFolderPath,
                                              string url, string user, string password, string repositoryId)
        {
            // Prepare checkout directory.
            string localDirectory = Path.Combine(CMISSYNCDIR, canonical_name);

            //CleanDirectory(localDirectory);
            //Console.WriteLine("Synced to clean state.");

            // Mock.
            ActivityListener activityListener = new Mock <ActivityListener>().Object;
            // Sync.
            RepoInfo repoInfo = new RepoInfo(
                canonical_name,
                ".",
                remoteFolderPath,
                url,
                user,
                password,
                repositoryId,
                5000);

            CmisRepo.SynchronizedFolder synchronizedFolder = new CmisRepo.SynchronizedFolder(
                repoInfo,
                activityListener,
                new CmisRepo(repoInfo, activityListener)
                );

            // Sync a few times in a different thread.
            bool             syncing = true;
            BackgroundWorker bw      = new BackgroundWorker();

            bw.DoWork += new DoWorkEventHandler(
                delegate(Object o, DoWorkEventArgs args)
            {
                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("Sync.");
                    synchronizedFolder.Sync();
                }
            }
                );
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                delegate(object o, RunWorkerCompletedEventArgs args)
            {
                syncing = false;
            }
                );
            bw.RunWorkerAsync();

            // Keep creating/removing a file as long as sync is going on.
            while (syncing)
            {
                Console.WriteLine("Create/remove.");
                LocalFilesystemActivityGenerator.CreateDirectoriesAndFiles(localDirectory);
                DirectoryInfo localDirectoryInfo = new DirectoryInfo(localDirectory);
                foreach (FileInfo file in localDirectoryInfo.GetFiles())
                {
                    try
                    {
                        file.Delete();
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("Exception on testing side, ignoring");
                    }
                }
                foreach (DirectoryInfo directory in localDirectoryInfo.GetDirectories())
                {
                    try
                    {
                        directory.Delete();
                    }
                    catch (IOException e)
                    {
                        Console.WriteLine("Exception on testing side, ignoring");
                    }
                }
            }

            // Clean.
            Clean(localDirectory, synchronizedFolder);
        }