Database to cache remote information from the CMIS server. Implemented with SQLite.
Inheritance: IDisposable
Esempio n. 1
0
        public void TestSpecialCharacter()
        {
            string oldPath = Path.Combine(RootPath, "a'b'c");
            string newPath = Path.Combine(RootPath, "'a'b'c'");

            using (Database database = new Database(DatabasePath))
            {
                CreateTestFile(oldPath, 10);
                database.AddFile(oldPath, "1", DateTime.Now, null, FakeHash);
                Assert.True(database.ContainsFile(oldPath));
                Assert.False(database.ContainsFile(newPath));
                database.MoveFile(oldPath, newPath);
                Assert.False(database.ContainsFile(oldPath));
                Assert.True(database.ContainsFile(newPath));
                database.RemoveFile(newPath);
                Assert.False(database.ContainsFile(oldPath));
                Assert.False(database.ContainsFile(newPath));
            }

            using (Database database = new Database(DatabasePath))
            {
                database.AddFolder(oldPath, "1", DateTime.Now);
                Assert.True(database.ContainsFolder(oldPath));
                Assert.False(database.ContainsFolder(newPath));
                database.MoveFolder(oldPath, newPath);
                Assert.False(database.ContainsFolder(oldPath));
                Assert.True(database.ContainsFolder(newPath));
                database.RemoveFolder(newPath);
                Assert.False(database.ContainsFolder(oldPath));
                Assert.False(database.ContainsFolder(newPath));
            }
        }
Esempio n. 2
0
 public void TestMoveFile()
 {
     using (Database database = new Database(DatabasePath))
     {
         string oldPath = Path.Combine(RootPath, "1.old");
         CreateTestFile(oldPath, 10);
         string newPath = Path.Combine(RootPath, "1.new");
         
         database.AddFile(oldPath, "1", DateTime.Now, null, FakeHash);
         Assert.True(database.ContainsFile(oldPath));
         Assert.False(database.ContainsFile(newPath));
         database.MoveFile(oldPath, newPath);
         Assert.False(database.ContainsFile(oldPath));
         Assert.True(database.ContainsFile(newPath));
     }
 }
Esempio n. 3
0
            /// <summary>
            ///  Constructor for Repo (at every launch of CmisSync)
            /// </summary>
            public SynchronizedFolder(RepoInfo repoInfo, RepoBase repoCmis, IActivityListener activityListener)
            {
                this.activityListener = activityListener;

                if (null == repoInfo || null == repoCmis)
                {
                    throw new ArgumentNullException("repoInfo");
                }

                this.repo = repoCmis;
                this.repoinfo = repoInfo;

                suspended = this.repoinfo.IsSuspended;

				Queue = repoCmis.Queue;

                // Database is the user's AppData/Roaming
                database = new Database(repoinfo.CmisDatabase);

                // Get path on remote repository.
                remoteFolderPath = repoInfo.RemotePath;

                cmisParameters = new Dictionary<string, string>();
                UpdateCmisParameters();
                if (Logger.IsInfoEnabled)
                {
                    foreach (string ignoredFolder in repoInfo.getIgnoredPaths())
                    {
                        Logger.Info("The folder \"" + ignoredFolder + "\" will be ignored");
                    }
                }
                repoCmis.EventManager.AddEventHandler(new GenericSyncEventHandler<RepoConfigChangedEvent>(10, RepoInfoChanged));

                syncWorker = new BackgroundWorker();
                syncWorker.WorkerSupportsCancellation = true;
                syncWorker.DoWork += new DoWorkEventHandler(
                    delegate(Object o, DoWorkEventArgs args)
                    {
                        bool syncFull = (bool)args.Argument;
                        try
                        {
                            Sync(syncFull);
                        }
                        catch (OperationCanceledException e)
                        {
                            Logger.Info(e.Message);
                        }
                        catch (CmisPermissionDeniedException e)
                        {
                            repo.OnSyncError(new PermissionDeniedException("Authentication failed.", e));
                        }
                        catch (Exception e)
                        {
                            repo.OnSyncError(new BaseException(e));
                        }
                        finally
                        {
                            SyncComplete(syncFull);
                        }
                    }
                );
            }
            /// <summary>
            ///  Constructor for Repo (at every launch of CmisSync)
            /// </summary>
            public SynchronizedFolder(RepoInfo repoInfo, RepoBase repoCmis)
            {
                if (null == repoInfo || null == repoCmis)
                {
                    throw new ArgumentNullException("repoInfo");
                }

                this.repo = repoCmis;
                this.repoinfo = repoInfo;

                // Database is the user's AppData/Roaming
                database = new Database(repoinfo.CmisDatabase);

                // Get path on remote repository.
                remoteFolderPath = repoInfo.RemotePath;

                cmisParameters = new Dictionary<string, string>();
                cmisParameters[SessionParameter.BindingType] = BindingType.AtomPub;
                cmisParameters[SessionParameter.AtomPubUrl] = repoInfo.Address.ToString();
                cmisParameters[SessionParameter.User] = repoInfo.User;
                cmisParameters[SessionParameter.Password] = repoInfo.Password.ToString();
                cmisParameters[SessionParameter.RepositoryId] = repoInfo.RepoID;
                cmisParameters[SessionParameter.ConnectTimeout] = "-1";

                foreach (string ignoredFolder in repoInfo.getIgnoredPaths())
                {
                    Logger.Info("The folder \"" + ignoredFolder + "\" will be ignored");
                }

                syncWorker = new BackgroundWorker();
                syncWorker.WorkerSupportsCancellation = true;
                syncWorker.DoWork += new DoWorkEventHandler(
                    delegate(Object o, DoWorkEventArgs args)
                    {
                        bool syncFull = (bool)args.Argument;
                        try
                        {
                            Sync(syncFull);
                        }
                        catch (OperationCanceledException e)
                        {
                            Logger.Info(e.Message);
                        }
                        catch (CmisPermissionDeniedException e)
                        {
                            repo.OnSyncError(new PermissionDeniedException("Authentication failed.", e));
                        }
                        catch (Exception e)
                        {
                            repo.OnSyncError(new BaseException(e));
                        }
                        finally
                        {
                            SyncComplete(syncFull);
                        }
                    }
                );
            }
Esempio n. 5
0
        public void TestMoveFolder()
        {
            using (Database database = new Database(DatabasePath))
            {
                Directory.CreateDirectory(Path.Combine(RootPath, "folder1/folder2"));

                string oldPath = Path.Combine(RootPath, "folder1/folder2", "1.test");
                CreateTestFile(oldPath, 10);
                string newPath = Path.Combine(RootPath, "sub1/folder2", "1.test");

                database.AddFile(oldPath, "1", DateTime.Now, null, FakeHash);
                database.AddFolder(Path.Combine(RootPath, "folder1"), "D1", DateTime.Now);
                database.AddFolder(Path.Combine(RootPath, "folder1/folder2"), "D12", DateTime.Now);
                Assert.True(database.ContainsFile(oldPath));
                Assert.True(database.ContainsFolder(Path.Combine(RootPath, "folder1")));
                Assert.True(database.ContainsFolder(Path.Combine(RootPath, "folder1/folder2")));
                Assert.False(database.ContainsFile(newPath));
                Assert.False(database.ContainsFolder(Path.Combine(RootPath, "sub1")));
                Assert.False(database.ContainsFolder(Path.Combine(RootPath, "sub1/folder2")));
                database.MoveFolder(Path.Combine(RootPath, "folder1"), Path.Combine(RootPath, "sub1"));
                Assert.False(database.ContainsFile(oldPath));
                Assert.False(database.ContainsFolder(Path.Combine(RootPath, "folder1")));
                Assert.False(database.ContainsFolder(Path.Combine(RootPath, "folder1/folder2")));
                Assert.True(database.ContainsFile(newPath));
                Assert.True(database.ContainsFolder(Path.Combine(RootPath, "sub1")));
                Assert.True(database.ContainsFolder(Path.Combine(RootPath, "sub1/folder2")));
            }
        }
Esempio n. 6
0
 public void TestFailedOperationCounter()
 {
     using (Database database = new Database(DatabasePath))
     {
         string path = Path.Combine(RootPath,"1.test");
         string path2 = Path.Combine(RootPath,"2.test");
         CreateTestFile(path, 1);
         CreateTestFile(path2, 1);
         File.SetLastWriteTimeUtc(path,File.GetLastWriteTimeUtc(path).Subtract(TimeSpan.FromMinutes(1)));
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.UPLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 1);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
         database.SetOperationRetryCounter(path, 2, Database.OperationType.UPLOAD);
         database.SetOperationRetryCounter(path, 4, Database.OperationType.CHANGE);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 2);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 4);
         database.SetOperationRetryCounter(path, 3, Database.OperationType.DOWNLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 3);
         database.SetOperationRetryCounter(path, 5, Database.OperationType.DELETE);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 5);
         database.SetOperationRetryCounter(path, 0, Database.OperationType.DELETE);
         CreateTestFile(path, 1);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.UPLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 1);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
         database.SetOperationRetryCounter(path2, 2, Database.OperationType.UPLOAD);
         database.DeleteAllFailedOperations(path);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 0);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.UPLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 1);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
         Assert.True(database.GetOperationRetryCounter(path2, Database.OperationType.UPLOAD) == 2);
         Assert.True(database.GetOperationRetryCounter(path2, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path2, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path2, Database.OperationType.DELETE) == 0);
         database.DeleteAllFailedOperations();
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path2, Database.OperationType.UPLOAD) == 0);
         database.SetOperationRetryCounter(path, -1, Database.OperationType.UPLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.UPLOAD);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.CHANGE);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 1);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 1);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.DOWNLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 1);
         database.SetOperationRetryCounter(path, 1, Database.OperationType.DELETE);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 1);
         Console.WriteLine("bla");
         database.SetOperationRetryCounter(path, 2, Database.OperationType.UPLOAD);
         database.SetOperationRetryCounter(path, 3, Database.OperationType.CHANGE);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 2);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 3);
         database.SetOperationRetryCounter(path, 4, Database.OperationType.DOWNLOAD);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 4);
         database.SetOperationRetryCounter(path, 5, Database.OperationType.DELETE);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 5);
         database.DeleteAllFailedOperations();
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.UPLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DOWNLOAD) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.CHANGE) == 0);
         Assert.True(database.GetOperationRetryCounter(path, Database.OperationType.DELETE) == 0);
     }
 }
            /// <summary>
            ///  Constructor for Repo (at every launch of CmisSync)
            /// </summary>
            public SynchronizedFolder(RepoInfo repoInfo,
                IActivityListener listener, RepoBase repoCmis)
            {
                if (null == repoInfo || null == repoCmis)
                {
                    throw new ArgumentNullException("repoInfo");
                }

                this.repo = repoCmis;
                this.activityListener = listener;
                this.repoinfo = repoInfo;

                // Database is the user's AppData/Roaming
                database = new Database(repoinfo.CmisDatabase);

                // Get path on remote repository.
                remoteFolderPath = repoInfo.RemotePath;

                cmisParameters = new Dictionary<string, string>();
                cmisParameters[SessionParameter.BindingType] = BindingType.AtomPub;
                cmisParameters[SessionParameter.AtomPubUrl] = repoInfo.Address.ToString();
                cmisParameters[SessionParameter.User] = repoInfo.User;
                cmisParameters[SessionParameter.Password] = Crypto.Deobfuscate(repoInfo.Password); // Deobfuscate password.
                cmisParameters[SessionParameter.RepositoryId] = repoInfo.RepoID;
                cmisParameters[SessionParameter.ConnectTimeout] = "-1";

				foreach (string ignoredFolder in repoInfo.getIgnoredPaths())
				{
					Logger.Info("The folder \""+ignoredFolder+"\" will be ignored");
				}
            }