Exemplo n.º 1
0
        /// <summary>
        /// Sync and wait, several times until a particular condition is satisfied.
        /// </summary>
        /// <returns>
        /// True if the condition got satisfied, false if the condition did not get satisfied within the time limit.
        /// </returns>
        /// <param name='synchronizedFolder'>
        /// Folder to synchronize.
        /// </param>
        /// <param name='checkStop'>
        /// If returns <c>true</c> wait returns true, otherwise a retry will be executed until reaching maxTries.
        /// </param>
        /// <param name='maxTries'>
        /// Number of retries, until false is returned, if checkStop could not be true.
        /// </param>
        /// <param name='pollInterval'>
        /// Sleep interval duration in miliseconds between synchronization calls.
        /// </param>
        public static bool SyncAndWaitUntilCondition(CmisRepo.SynchronizedFolder synchronizedFolder, Func <bool> checkStop, int maxTries = 4, int pollInterval = 5000)
        {
            int i = 0;

            while (i < maxTries)
            {
                try
                {
                    synchronizedFolder.Sync();
                }
                catch (DotCMIS.Exceptions.CmisRuntimeException e)
                {
                    Console.WriteLine("{0} Exception caught and swallowed, retry.", e);
                    System.Threading.Thread.Sleep(pollInterval);
                    continue;
                }
                if (checkStop())
                {
                    return(true);
                }
                Console.WriteLine(String.Format("Retry Sync in {0}ms", pollInterval));
                System.Threading.Thread.Sleep(pollInterval);
                i++;
            }
            Console.WriteLine("Sync call was not successful");
            return(false);
        }
Exemplo n.º 2
0
        public void Sync(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,
                           cmis))
                {
                    synchronizedFolder.Sync();
                    Console.WriteLine("Synced to clean state.");

                    // Clean.
                    Console.WriteLine("Clean all.");
                    Clean(localDirectory, synchronizedFolder);
                }
            }
        }
Exemplo n.º 3
0
        public void Sync(string canonical_name, string localPath, string remoteFolderPath,
                         string url, string user, string password, string repositoryId)
        {
            // Clean.
            CleanDirectory(Path.Combine(CMISSYNCDIR, canonical_name));
            // 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();
        }
Exemplo n.º 4
0
        private void Clean(string localDirectory, CmisRepo.SynchronizedFolder synchronizedFolder)
        {
            // Sync deletions to server.
            synchronizedFolder.Sync();
            CleanAll(localDirectory);
            synchronizedFolder.Sync();

            // Remove checkout folder.
            Directory.Delete(localDirectory);
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        private void Clean(string localDirectory, CmisRepo.SynchronizedFolder synchronizedFolder)
        {
            DirectoryInfo directory = new DirectoryInfo(localDirectory);

            // Delete all local files/folders.
            foreach (FileInfo file in directory.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in directory.GetDirectories())
            {
                dir.Delete(true);
            }
            // Sync deletions to server.
            synchronizedFolder.Sync();
            // Remove checkout folder.
            directory.Delete(false); // Not recursive, should not contain anything at this point.
        }
Exemplo n.º 7
0
        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);
                }
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
                }
            }
        }
Exemplo n.º 10
0
        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);
        }