All the info for a particular CmisSync synchronized folder. Contains local info, as well as remote info to connect to the CMIS folder.
Ejemplo n.º 1
0
        /// <summary>
        /// Sets up a fetcher that can get remote CMIS folders.
        /// </summary>
        public Fetcher(RepoInfo repoInfo, IActivityListener activityListener)
        {
            string remote_path = repoInfo.RemotePath.Trim("/".ToCharArray());
            string address = repoInfo.Address.ToString();

            TargetFolder = repoInfo.TargetDirectory;

            RemoteUrl = new Uri(address + remote_path);

            Logger.Info("Fetcher | Cmis Fetcher constructor");
            TargetFolder = repoInfo.TargetDirectory;
            RemoteUrl = repoInfo.Address;

            // Check that the CmisSync root folder exists.
            if (!Directory.Exists(ConfigManager.CurrentConfig.FoldersPath))
            {
                Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Default Folder {0} does not exist", ConfigManager.CurrentConfig.FoldersPath));
                throw new DirectoryNotFoundException("Root folder don't exist !");
            }

            // Check that the folder is writable.
            if (!Utils.HasWritePermissionOnDir(ConfigManager.CurrentConfig.FoldersPath))
            {
                Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Default Folder {0} is not writable", ConfigManager.CurrentConfig.FoldersPath));
                throw new UnauthorizedAccessException("Root folder is not writable!");
            }

            // Check that the folder exists.
            if (Directory.Exists(repoInfo.TargetDirectory))
            {
                Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Repository Folder {0} already exist", repoInfo.TargetDirectory));
                throw new UnauthorizedAccessException("Repository folder already exists!");
            }

            // Create the local folder.
            Directory.CreateDirectory(repoInfo.TargetDirectory);

            // Use this folder configuration.
            this.cmisRepo = new CmisRepo(repoInfo, activityListener);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check whether the file is worth syncing or not.
        /// This optionally excludes blank files or files too large.
        /// </summary>
        private static bool IsFileWorthSyncing(string filepath, RepoInfo repoInfo)
        {
            if (File.Exists(filepath))
            {
                bool allowBlankFiles = true; //TODO: add a preference repoInfo.allowBlankFiles
                bool limitFilesize = false; //TODO: add preference for filesize limiting
                long filesizeLimit = 256 * 1024 * 1024; //TODO: add a preference for filesize limit

                FileInfo fileInfo = new FileInfo(filepath);

                //Check permissions
                if (fileInfo.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    Logger.DebugFormat("Skipping {0}: hidden file", filepath);
                    return false;
                }
                if (fileInfo.Attributes.HasFlag(FileAttributes.System))
                {
                    Logger.DebugFormat("Skipping {0}: system file", filepath);
                    return false;
                }

                //Check filesize
                if (!allowBlankFiles && fileInfo.Length <= 0)
                {
                    Logger.DebugFormat("Skipping {0}: blank file", filepath);
                    return false;
                }
                if (limitFilesize && fileInfo.Length > filesizeLimit)
                {
                    Logger.DebugFormat("Skipping {0}: file too large {1}mb", filepath, fileInfo.Length / (1024f * 1024f));
                    return false;
                }

            }
            else if (Directory.Exists(filepath))
            {
                return IsDirectoryWorthSyncing(filepath, repoInfo);
            }
            return true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get all the configured info about a synchronized folder.
        /// </summary>
        public RepoInfo GetRepoInfo(string folderName)
        {
            RepoInfo repoInfo = new RepoInfo(folderName, ConfigPath);

            repoInfo.User = GetFolderAttribute(folderName, "user");
            repoInfo.Password = GetFolderAttribute(folderName, "password");
            repoInfo.Address = GetUrlForFolder(folderName);
            repoInfo.RepoID = GetFolderAttribute(folderName, "repository");
            repoInfo.RemotePath = GetFolderAttribute(folderName, "remoteFolder");
            repoInfo.TargetDirectory = GetFolderAttribute(folderName, "path");
            
            double pollinterval = 0;
            double.TryParse(GetFolderAttribute(folderName, "pollinterval"), out pollinterval);
            if (pollinterval < 1) pollinterval = 5000;
            repoInfo.PollInterval = pollinterval;

            if (String.IsNullOrEmpty(repoInfo.TargetDirectory))
            {
                repoInfo.TargetDirectory = Path.Combine(FoldersPath, folderName);
            }
            LinkedList<string> ignoredFolders = getIgnoredFolders(folderName);
            foreach (string ignoredFolder in ignoredFolders)
            {
                repoInfo.addIgnorePath(ignoredFolder);
            }
            return repoInfo;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RepoBase(RepoInfo repoInfo, IActivityListener activityListener)
        {
            EventManager = new SyncEventManager();
            EventManager.AddEventHandler(new DebugLoggingHandler());
            EventManager.AddEventHandler(new GenericSyncEventHandler<RepoConfigChangedEvent>(0, RepoInfoChanged));
            Queue = new SyncEventQueue(EventManager);
            RepoInfo = repoInfo;
            LocalPath = repoInfo.TargetDirectory;
            Name = repoInfo.Name;
            RemoteUrl = repoInfo.Address;

            this.activityListener = activityListener;

            if (repoInfo.IsSuspended) Status = SyncStatus.Suspend;

            // Folder lock.
            // Disabled for now. Can be an interesting feature, but should be made opt-in, as
            // most users would be surprised to see this file appear.
            // folderLock = new FolderLock(LocalPath);

            Watcher = new Watcher(LocalPath);
            Watcher.EnableRaisingEvents = true;


            // Main loop syncing every X seconds.
            remote_timer.Elapsed += delegate
            {
                // Synchronize.
                SyncInBackground();
            };
            remote_timer.AutoReset = true;
            Logger.Info("Repo " + repoInfo.Name + " - Set poll interval to " + repoInfo.PollInterval + "ms");
            remote_timer.Interval = repoInfo.PollInterval;

            //Partial sync interval..
            local_timer.Elapsed += delegate
            {
                // Run partial sync.
                SyncInBackground(false);
            };
            local_timer.AutoReset = false;
            local_timer.Interval = delay_interval;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initialize (in the GUI and syncing mechanism) an existing CmisSync synchronized folder.
 /// </summary>
 /// <param name="repositoryInfo">Synchronized folder path</param>
 private void AddRepository(RepoInfo repositoryInfo)
 {
     RepoBase repo = null;
     repo = new CmisSync.Lib.Sync.CmisRepo(repositoryInfo, activityListenerAggregator);
     this.repositories.Add(repo);
     repo.Initialize();
 }
Ejemplo n.º 6
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);
                }
            }
        }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
                /// <summary>
                /// Get all the configured info about a synchronized folder.
                /// </summary>
                public RepoInfo GetRepoInfo()
                {
                    RepoInfo repoInfo = new RepoInfo(DisplayName, ConfigManager.CurrentConfig.ConfigPath);
                    repoInfo.User = UserName;
                    repoInfo.Password = new CmisSync.Auth.CmisPassword();
                    repoInfo.Password.ObfuscatedPassword = ObfuscatedPassword;
                    repoInfo.Address = RemoteUrl;
                    repoInfo.RepoID = RepositoryId;
                    repoInfo.RemotePath = RemotePath;
                    repoInfo.TargetDirectory = LocalPath;
                    if (PollInterval < 1) PollInterval = Config.DEFAULT_POLL_INTERVAL;
                    repoInfo.PollInterval = PollInterval;

                    foreach (IgnoredFolder ignoredFolder in IgnoredFolders)
                    {
                        repoInfo.addIgnorePath(ignoredFolder.Path);
                    }
                    return repoInfo;
                }
Ejemplo n.º 9
0
 /// <summary></summary>
 /// <param name="path"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromRemotePath(string path, RepoInfo repoInfo)
 {
     return new RemotePathSyncItem(path, repoInfo);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RepoBase(RepoInfo repoInfo)
        {
            RepoInfo = repoInfo;
            LocalPath = repoInfo.TargetDirectory;
            Name = repoInfo.Name;
            RemoteUrl = repoInfo.Address;

            Logger.Info("Repo " + repoInfo.Name + " - Set poll interval to " + repoInfo.PollInterval + "ms");
            this.remote_timer.Interval = repoInfo.PollInterval;

            SyncStatusChanged += delegate(SyncStatus status)
            {
                Status = status;
            };

            this.Watcher = new Watcher(LocalPath);

            // Main loop syncing every X seconds.
            this.remote_timer.Elapsed += delegate
            {
                // Synchronize.
                SyncInBackground();
            };
            
            ChangesDetected += delegate { };
        }
Ejemplo n.º 11
0
        public RemotePathSyncItem(string remoteFolderPath, string remoteDocumentName, string localFilename, bool isFolder, RepoInfo repoInfo, Database.Database database)
        {
            this.isFolder = isFolder;
            this.database = database;
            this.localRoot = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.remoteRelativePath = remoteFolderPath;
            if (remoteRelativePath.StartsWith(this.remoteRoot))
            {
                this.remoteRelativePath = remoteRelativePath.Substring(this.remoteRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }
            this.localRelativePath = localFilename;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Create from the path of a remote file, and the local filename to use.
        /// </summary>
        /// <param name="remoteRelativePath">Example: adir/a<file</param>
        /// <param name="localFilename">Example: afile.txt</param>
        public RemotePathSyncItem(string remoteRelativePath, string localFilename, RepoInfo repoInfo, Database.Database database)
        {
            this.isFolder = false;
            this.database = database;
            this.localRoot = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.remoteRelativePath = remoteRelativePath;
            if (remoteRelativePath.StartsWith(this.remoteRoot))
            {
                this.remoteRelativePath = this.remoteRelativePath.Substring(localRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }

            int lastSeparator = remoteRelativePath.LastIndexOf(CmisUtils.CMIS_FILE_SEPARATOR);
            string remoteRelativeFolder = lastSeparator >= 0 ?
                remoteRelativePath.Substring(0, lastSeparator)
                : String.Empty;
            string remoteRelativePathWithCorrectLeafname = CmisUtils.PathCombine(remoteRelativeFolder, localFilename);
            localRelativePath = database.RemoteToLocal(remoteRelativePathWithCorrectLeafname, isFolder);
        }
Ejemplo n.º 13
0
        public LocalPathSyncItem(string localPath, bool isFolder, RepoInfo repoInfo, Database.Database database)
        {
            this.isFolder = isFolder;
            this.database = database;
            this.localRoot = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.localRelativePath = localPath;
            if (localPath.StartsWith(this.localRoot))
            {
                this.localRelativePath = localPath.Substring(localRoot.Length).TrimStart(Path.DirectorySeparatorChar);
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Create sync item from the path of a remote folder.
 /// </summary>
 /// <param name="remoteFolderPath">Example: /sites/aproject/adir</param>
 public static SyncItem CreateFromRemoteFolder(string remoteFolderPath, RepoInfo repoInfo, Database.Database database)
 {
     return new RemotePathSyncItem(remoteFolderPath, true, repoInfo, database);
 }
Ejemplo n.º 15
0
 /// <summary></summary>
 /// <param name="localFolder"></param>
 /// <param name="remoteFileName"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromLocalFolderAndRemoteName(string localFolder, string remoteFileName, RepoInfo repoInfo)
 {
     return new LocalPathSyncItem(localFolder, remoteFileName, repoInfo);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Add a synchronized folder to the configuration.
        /// </summary>
        public void AddFolder(RepoInfo repoInfo)
        {
            if (null == repoInfo)
            {
                return;
            }
            SyncConfig.Folder folder = new SyncConfig.Folder() {
                DisplayName = repoInfo.Name,
                LocalPath = repoInfo.TargetDirectory,
                IgnoredFolders = new List<IgnoredFolder>(),
                RemoteUrl = repoInfo.Address,
                RepositoryId = repoInfo.RepoID,
                RemotePath = repoInfo.RemotePath,
                UserName = repoInfo.User,
                ObfuscatedPassword = repoInfo.Password.ObfuscatedPassword,
                PollInterval = repoInfo.PollInterval
            };
            foreach (string ignoredFolder in repoInfo.getIgnoredPaths())
            {
                folder.IgnoredFolders.Add(new IgnoredFolder(){Path = ignoredFolder});
            }
            this.configXml.Folders.Add(folder);

            Save();
        }
Ejemplo n.º 17
0
 /// <summary></summary>
 /// <param name="remoteFolder"></param>
 /// <param name="LocalFileName"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromRemoteFolderAndLocalName(string remoteFolder, string LocalFileName, RepoInfo repoInfo)
 {
     return new RemotePathSyncItem(remoteFolder, LocalFileName, repoInfo);
 }
Ejemplo n.º 18
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,
                    activityListener,
                    cmis))
                {
                    synchronizedFolder.Sync();
                    Console.WriteLine("Synced to clean state.");

                    // Clean.
                    Console.WriteLine("Clean all.");
                    Clean(localDirectory, synchronizedFolder);
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary></summary>
        /// <param name="localPath"></param>
        /// <param name="repoInfo"></param>
        public LocalPathSyncItem(string localPath, RepoInfo repoInfo)
        {
            this.localRoot = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.localPath = localPath;
            if (localPath.StartsWith(this.localRoot))
            {
                this.localPath = localPath.Substring(localRoot.Length).TrimStart(Path.DirectorySeparatorChar);
            }
            this.remotePath = PathRepresentationConverter.LocalToRemote(this.localPath);
        }
Ejemplo n.º 20
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);
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary></summary>
        /// <param name="remotePath"></param>
        /// <param name="repoInfo"></param>
        public RemotePathSyncItem(string remotePath, RepoInfo repoInfo)
        {
            this.localRoot = repoInfo.TargetDirectory;
            this.remoteRoot = PathRepresentationConverter.LocalToRemote(repoInfo.RemotePath);

            this.remotePath = remotePath;
            if (remotePath.StartsWith(this.remoteRoot))
            {
                this.remotePath = remotePath.Substring(this.remoteRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }
            this.localPath = PathRepresentationConverter.RemoteToLocal(this.remotePath);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Initialize (in the UI and syncing mechanism) an existing CmisSync synchronized folder.
        /// </summary>
        /// <param name="repositoryInfo">Synchronized folder path</param>
        private void AddRepository(RepoInfo repositoryInfo)
        {
            RepoBase repo = null;
            repo = new CmisSync.Lib.Sync.CmisRepo(repositoryInfo, activityListenerAggregator);

            repo.EventManager.AddEventHandler(
                new GenericSyncEventHandler<FileTransmissionEvent>( 50, delegate(ISyncEvent e){
                this.activitiesManager.AddTransmission(e as FileTransmissionEvent);
                return false;
            }));
            this.repositories.Add(repo);
            repo.Initialize();
        }
Ejemplo n.º 23
0
        /// <summary></summary>
        /// <param name="remoteFolder"></param>
        /// <param name="localRelativePath"></param>
        /// <param name="repoInfo"></param>
        public RemotePathSyncItem(string remoteFolder, string localRelativePath, RepoInfo repoInfo)
        {
            this.localRoot = repoInfo.TargetDirectory;
            this.remoteRoot = repoInfo.RemotePath;

            this.remotePath = Path.Combine(remoteFolder, PathRepresentationConverter.LocalToRemote(localRelativePath));
            if (this.remotePath.StartsWith(this.remoteRoot))
            {
                this.remotePath = this.remotePath.Substring(this.localRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }
            string remoteRootRelative = remoteFolder;
            if (remoteFolder.StartsWith(this.remoteRoot))
            {
                remoteRootRelative = remoteFolder.Substring(localRoot.Length).TrimStart(CmisUtils.CMIS_FILE_SEPARATOR);
            }
            this.localPath = Path.Combine(PathRepresentationConverter.RemoteToLocal(remoteRootRelative), localRelativePath);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Create a new CmisSync synchronized folder.
        /// </summary>
        public void CreateRepository(string name, Uri address, string user, string password, string repository, string remote_path, string local_path,
            List<string> ignoredPaths, bool syncAtStartup)
        {
            repoInfo = new RepoInfo(name, ConfigManager.CurrentConfig.ConfigPath);
            repoInfo.Address = address;
            repoInfo.User = user;
            repoInfo.Password = new Password(password);
            repoInfo.RepoID = repository;
            repoInfo.RemotePath = remote_path;
            repoInfo.TargetDirectory = local_path;
            repoInfo.PollInterval = Config.DEFAULT_POLL_INTERVAL;
            repoInfo.IsSuspended = false;
            repoInfo.LastSuccessedSync = new DateTime(1900, 01, 01);
            repoInfo.SyncAtStartup = syncAtStartup;
            repoInfo.MaxUploadRetries = 2;

            foreach (string ignore in ignoredPaths)
                repoInfo.addIgnorePath(ignore);

            // Check that the CmisSync root folder exists.
            if (!Directory.Exists(ConfigManager.CurrentConfig.FoldersPath))
            {
                Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Default Folder {0} does not exist", ConfigManager.CurrentConfig.FoldersPath));
                throw new DirectoryNotFoundException("Root folder don't exist !");
            }

            // Check that the folder is writable.
            if (!CmisSync.Lib.Utils.HasWritePermissionOnDir(ConfigManager.CurrentConfig.FoldersPath))
            {
                Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Default Folder {0} is not writable", ConfigManager.CurrentConfig.FoldersPath));
                throw new UnauthorizedAccessException("Root folder is not writable!");
            }

            // Check that the folder exists.
            if (Directory.Exists(repoInfo.TargetDirectory))
            {
                Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Repository Folder {0} already exist", repoInfo.TargetDirectory));
                throw new UnauthorizedAccessException("Repository folder already exists!");
            }

            // Create the local folder.
            Directory.CreateDirectory(repoInfo.TargetDirectory);

            // Add folder to XML config file.
            ConfigManager.CurrentConfig.AddFolder(repoInfo);

            // Initialize in the GUI.
            AddRepository(repoInfo);
            FolderListChanged();
        }
Ejemplo n.º 25
0
 /// <summary></summary>
 /// <param name="path"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromLocalPath(string path, RepoInfo repoInfo)
 {
     return new LocalPathSyncItem(path, repoInfo);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Add a synchronized folder to the configuration.
        /// </summary>
        public void AddFolder(RepoInfo repoInfo)
        {
            if (null == repoInfo)
            {
                return;
            }

            this.AddFolder(repoInfo.Name, repoInfo.TargetDirectory, repoInfo.Address, repoInfo.RepoID, repoInfo.RemotePath, repoInfo.User, repoInfo.Password, repoInfo.PollInterval, repoInfo.getIgnoredPaths());
        }
Ejemplo n.º 27
0
 /// <summary></summary>
 /// <param name="folder"></param>
 /// <param name="fileName"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromLocalPath(string folder, string fileName, RepoInfo repoInfo)
 {
     return new LocalPathSyncItem(Path.Combine(folder, fileName), repoInfo);
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Check whether the directory is worth syncing or not.
        /// Directories that are not worth syncing include ignored, system, and hidden folders.
        /// </summary>
        private static bool IsDirectoryWorthSyncing(string localDirectory, RepoInfo repoInfo)
        {
            if (!localDirectory.StartsWith(repoInfo.TargetDirectory))
            {
                Logger.WarnFormat("Local directory is outside repo target directory.  local={0}, repo={1}", localDirectory, repoInfo.TargetDirectory);
                return false;
            }

            //Check for ignored path...
            string path = localDirectory.Substring(repoInfo.TargetDirectory.Length).Replace("\\", "/");
            if (repoInfo.isPathIgnored(path))
            {
                Logger.DebugFormat("Skipping {0}: hidden folder", localDirectory);
                return false;
            }

            //Check system/hidden
            DirectoryInfo directoryInfo = new DirectoryInfo(localDirectory);
            if (directoryInfo.Exists)
            {
                if (directoryInfo.Attributes.HasFlag(FileAttributes.Hidden))
                {
                    Logger.DebugFormat("Skipping {0}: hidden folder", localDirectory);
                    return false;
                }
                if (directoryInfo.Attributes.HasFlag(FileAttributes.System))
                {
                    Logger.DebugFormat("Skipping {0}: system folder", localDirectory);
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 29
0
                /// <summary>
                /// Get all the configured info about a synchronized folder.
                /// </summary>
                public RepoInfo GetRepoInfo()
                {
                    // TODO: workaround
                    var localPath = LocalPath.TrimEnd(Path.DirectorySeparatorChar);

                    RepoInfo repoInfo = new RepoInfo(DisplayName, ConfigManager.CurrentConfig.ConfigPath);
                    repoInfo.User = UserName;
                    repoInfo.Password = new Password();
                    repoInfo.Password.ObfuscatedPassword = ObfuscatedPassword;
                    repoInfo.Address = RemoteUrl;
                    repoInfo.RepoID = RepositoryId;
                    repoInfo.RemotePath = RemotePath;
                    repoInfo.TargetDirectory = localPath;
                    repoInfo.MaxUploadRetries = uploadRetries;
                    repoInfo.MaxDownloadRetries = downloadRetries;
                    repoInfo.MaxDeletionRetries = deletionRetries;
                    if (PollInterval < 1) PollInterval = Config.DEFAULT_POLL_INTERVAL;
                    repoInfo.PollInterval = PollInterval;
                    repoInfo.IsSuspended = IsSuspended;
                    repoInfo.SyncAtStartup = SyncAtStartup;

                    foreach (IgnoredFolder ignoredFolder in IgnoredFolders)
                    {
                        repoInfo.addIgnorePath(ignoredFolder.Path);
                    }

                    if(SupportedFeatures != null && SupportedFeatures.ChunkedSupport != null && SupportedFeatures.ChunkedSupport == true)
                    {
                        repoInfo.ChunkSize = ChunkSize;
                        repoInfo.DownloadChunkSize = ChunkSize;
                    }
                    else
                    {
                        repoInfo.ChunkSize = 0;
                        repoInfo.DownloadChunkSize = 0;
                    }
                    if(SupportedFeatures != null && SupportedFeatures.ChunkedDownloadSupport!=null && SupportedFeatures.ChunkedDownloadSupport == true)
                        repoInfo.DownloadChunkSize = ChunkSize;

                    return repoInfo;
                }
Ejemplo n.º 30
0
 /// <summary>
 /// Check whether the file is worth syncing or not.
 /// Files that are not worth syncing include temp files, locks, etc.
 /// </summary>
 public static Boolean WorthSyncing(string localDirectory, string filename, RepoInfo repoInfo)
 {
     return IsFilenameWorthSyncing(localDirectory, filename) &&
         IsDirectoryWorthSyncing(localDirectory, repoInfo) &&
         IsFileWorthSyncing(Path.Combine(localDirectory, filename), repoInfo);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Check whether the file is worth syncing or not.
 /// Files that are not worth syncing include temp files, locks, etc.
 /// </summary>
 public static Boolean WorthSyncing(string localDirectory, string filename, RepoInfo repoInfo)
 {
     return(IsFilenameWorthSyncing(localDirectory, filename) &&
            IsDirectoryWorthSyncing(localDirectory, repoInfo) &&
            IsFileWorthSyncing(Path.Combine(localDirectory, filename), repoInfo));
 }