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); } } }
/// <summary> /// Synchronize folder. /// </summary> private void Sync() { ConsoleController controller = new ConsoleController(); foreach (RepoInfo repoInfo in repos) { CmisRepo cmisRepo = new CmisRepo(repoInfo, controller); cmisRepo.SyncInNotBackground(); } }
// Sets up a fetcher that can get remote folders public Fetcher(RepoInfo repoInfo, ActivityListener activityListener) { OriginalRepoInfo = repoInfo; string remote_path = repoInfo.RemotePath.Trim("/".ToCharArray()); string address = repoInfo.Address.ToString(); if (address.EndsWith("/")) { address = address.Substring(0, address.Length - 1); } if (!remote_path.StartsWith("/")) { remote_path = "/" + remote_path; } if (!address.Contains("://")) { address = "ssh://" + address; } TargetFolder = repoInfo.TargetDirectory; RemoteUrl = new Uri(address + remote_path); IsActive = false; Logger.Info("Fetcher | Cmis Fetcher constructor"); TargetFolder = repoInfo.TargetDirectory; RemoteUrl = repoInfo.Address; if (!Directory.Exists(ConfigManager.CurrentConfig.FoldersPath)) { Logger.Fatal(String.Format("Fetcher | ERROR - Cmis Default Folder {0} do not exist", ConfigManager.CurrentConfig.FoldersPath)); throw new DirectoryNotFoundException("Root folder don't exist !"); } if (!Folder.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!"); } 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!"); } Directory.CreateDirectory(repoInfo.TargetDirectory); CmisRepo = new CmisRepo(repoInfo, activityListener); }
/// <summary> /// Synchronize folder. /// </summary> private bool Sync() { bool success = true; ConsoleController controller = new ConsoleController(); foreach (RepoInfo repoInfo in repos) { CmisRepo cmisRepo = new CmisRepo(repoInfo, controller, false); success &= cmisRepo.SyncInForeground(); } return(success); }
/// <summary> /// Load folder configuration. /// </summary> private void AddSynchronizedFolder(string folderName) { Config config = ConfigManager.CurrentConfig; CmisSync.Lib.Config.SyncConfig.Folder folder = config.GetFolder(folderName); if (folder == null) { System.Console.WriteLine("No folder found with this name: " + folderName); return; } RepoInfo repoInfo = folder.GetRepoInfo(); CmisRepo cmisRepo = new CmisRepo(repoInfo, controller, false, perpetual); repos.Add(cmisRepo); }
private void init() { Config config = ConfigManager.CurrentConfig; RepoInfo repoInfo = config.GetRepoInfo("documentLibrary"); ConsoleController controller = new ConsoleController(); cmisRepo = new CmisRepo(repoInfo, controller); cmisRepo.Initialize(); //main Loop cmisRepo.DoFirstSync(); TimerCallback timerDelegate = new TimerCallback(Sync); Timer timer = new Timer(timerDelegate, null, 0, 1000); }
/// <summary> /// Load folder configuration. /// </summary> private void Init(string folderName) { Config config = ConfigManager.CurrentConfig; CmisSync.Lib.Config.SyncConfig.Folder folder = config.getFolder(folderName); if (folder == null) { System.Console.WriteLine("No folder found with this name: " + folderName); return; } RepoInfo repoInfo = folder.GetRepoInfo(); ConsoleController controller = new ConsoleController(); cmisRepo = new CmisRepo(repoInfo, controller); }
/// <summary> /// Constructor. /// </summary> public Folder(CmisUtils.FolderTree tree, CmisRepo repo) { this.Path = tree.path; this.Repo = repo; this.Name = tree.Name; this.Type = FolderType.REMOTE; this.Status = LoadingStatus.DONE; this.Enabled = repo.Selected; foreach (CmisUtils.FolderTree t in tree.children) { this.SubFolder.Add(new Folder(t, Repo) { Parent = this }); } }
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); } } }
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); } } }
/// <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); }
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); } } }
/// <summary> /// Main method, pass folder name as argument. /// </summary> public static int Main(string[] args) { System.Console.WriteLine("Started CmisSyncOnce"); Utils.ConfigureLogging(); Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version); // Uncomment this line to disable SSL checking (for self-signed certificates) // ServicePointManager.CertificatePolicy = new YesCertPolicyHandler(); PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter()); bool perpetual = false; CmisSyncConsole instance = null; // -p means perpetual. if (args.Length > 0 && "-p".Equals(args[0])) { perpetual = true; } // Get optional config file from command line argument -c instance = new CmisSyncConsole(perpetual); // Load the specified synchronized folders, or all if none is specified. if (args.Length > 1 || (!perpetual && args.Length > 0)) { int i = 0; // Skip the -p argument if present. if ("-p".Equals(args[0])) { i++; } for (; i < args.Length; i++) { instance.AddSynchronizedFolder(args[i]); } } else { // No specific folders given, so load all folders. Config config = ConfigManager.CurrentConfig; foreach (CmisSync.Lib.Config.SyncConfig.Folder folder in config.Folders) { RepoInfo repoInfo = folder.GetRepoInfo(); CmisRepo cmisRepo = new CmisRepo(repoInfo, controller, false, perpetual); instance.repos.Add(cmisRepo); } } // Synchronize all bool success = instance.Run(); System.Console.WriteLine("Press enter to close..."); System.Console.ReadLine(); // Exit code 0 if synchronization was successful or not needed, // 1 if synchronization failed, or could not run. return(success ? 0 : 1); }
/// <summary> /// Main method, pass folder name as argument. /// </summary> public static int Main(string[] argumentsArray) { System.Console.WriteLine("Started CmisSyncOnce"); // Uncomment this line to disable SSL checking (for self-signed certificates) // ServicePointManager.CertificatePolicy = new YesCertPolicyHandler(); PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter()); var argumentsList = new List <string>(argumentsArray); bool perpetual = false; CmisSyncConsole instance = null; // -p means perpetual. if (argumentsList.Count >= 1 && "-p".Equals(argumentsList[0])) { perpetual = true; argumentsList.RemoveAt(0); } // Get optional config file from command line argument -c if (argumentsList.Count >= 2 && "-c".Equals(argumentsList[0])) { System.Console.WriteLine("argument -c"); // Set the config file to use. ConfigManager.CurrentConfigFile = argumentsList[1]; argumentsList.RemoveAt(0); // Remove -c argumentsList.RemoveAt(0); // Remove the path } System.Console.WriteLine("config: " + ConfigManager.CurrentConfigFile); // Now that we have the config, we can start logging (the log file location is in the config). Utils.ConfigureLogging(); Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version); instance = new CmisSyncConsole(perpetual); // Load the specified synchronized folders, or all if none is specified. bool enableWatcher = perpetual; // We consider that the watcher is only desirable for perpetual synchronization. if (argumentsList.Count >= 1) { foreach (var argument in argumentsList) { instance.AddSynchronizedFolder(argument, enableWatcher); } } else { // No specific folders given, so load all folders. foreach (CmisSync.Lib.Config.SyncConfig.Folder folder in ConfigManager.CurrentConfig.Folders) { RepoInfo repoInfo = folder.GetRepoInfo(); CmisRepo cmisRepo = new CmisRepo(repoInfo, controller, enableWatcher, perpetual); instance.repos.Add(cmisRepo); } } // Synchronize all bool success = instance.Run(); // Only for testing in an IDE, to see what happened in the console window before it gets closed by the IDE. //System.Console.WriteLine("Press enter to close..."); //System.Console.ReadLine(); // Exit code 0 if synchronization was successful or not needed, // 1 if synchronization failed, or could not run. return(success ? 0 : 1); }