Configuration of a CmisSync synchronized folder. It can be found in the XML configuration file.
 public SyncFolderWizardViewModel(Controller controller, Config.SyncConfig.SyncFolder model)
     : base(controller, model)
 {
     Pages = new List<Object>
     {
         new ViewModels.SyncFolderWizard.AccountPageViewModel(Controller, this),
         new ViewModels.SyncFolderWizard.RemotePageViewModel(Controller, this),
         new ViewModels.SyncFolderWizard.LocalPageViewModel(Controller, this)
     };
 }
Exemplo n.º 2
0
        public MissingFolderDialog(Config.SyncConfig.SyncFolder repo)
        {
            this.repo = repo;

            selectNewCommand = new RelayCommand(selectNew);
            removeFromSyncCommand = new RelayCommand(removeFromSync);
            resyncCommand = new RelayCommand(resync);

            InitializeComponent();
        }
Exemplo n.º 3
0
 public static void OpenRemoteFolder(Config.SyncConfig.SyncFolder repo)
 {
     if (repo != null)
     {
         Process.Start(CmisSync.Lib.Cmis.CmisUtils.GetBrowsableURL(repo));
     }
     else
     {
         Logger.Warn("Could not find requested config for \"" + repo + "\"");
     }
 }
Exemplo n.º 4
0
        /// <summary></summary>
        /// <param name="localPath"></param>
        /// <param name="repoInfo"></param>
        public LocalPathSyncItem(string localPath, Config.SyncConfig.SyncFolder repoInfo)
        {
            this.localRootPath = repoInfo.LocalPath;
            this.remoteRootPath = repoInfo.RemotePath;

            this.localRelativePath = localPath;
            if (localPath.StartsWith(this.localRootPath))
            {
                this.localRelativePath = localPath.Substring(this.localRootPath.Length).TrimStart(Path.DirectorySeparatorChar);
            }
            this.remoteRelativePath = PathRepresentationConverter.LocalToRemote(this.localRelativePath);
        }
Exemplo n.º 5
0
        /// <summary></summary>
        /// <param name="localFolder"></param>
        /// <param name="fileName"></param>
        /// <param name="repoInfo"></param>
        public LocalPathSyncItem(string localFolder, string fileName, Config.SyncConfig.SyncFolder repoInfo)
        {
            if (!isValidFileName(fileName)) {
                throw new ArgumentException();
            }

            this.localRootPath = repoInfo.LocalPath;
            this.remoteRootPath = repoInfo.RemotePath;

            this.localRelativePath = Path.Combine(localFolder, fileName);
            if (localRelativePath.StartsWith(this.localRootPath))
            {
                this.localRelativePath = localRelativePath.Substring(this.localRootPath.Length).TrimStart(Path.DirectorySeparatorChar);
            }
            this.remoteRelativePath = PathRepresentationConverter.LocalToRemote(this.localRelativePath);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a new CmisSync synchronized folder.
        /// </summary>
        public void AddAndStartNewSyncFolderSyncronization(Config.SyncConfig.SyncFolder syncFolderInfo)
        {
            //TODO: check repoInfo data

            checkDefaultRepositoryStncFolder();

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

            Directory.CreateDirectory(syncFolderInfo.LocalPath);

            // Add folder to XML config file.
            ConfigureAndStartSyncFolderSyncronization(syncFolderInfo);

            ConfigManager.CurrentConfig.AddSyncFolder(syncFolderInfo);
        }
Exemplo n.º 7
0
 public void TestConfig()
 {
     string configpath = Path.GetFullPath("testconfig.conf");
     try
     {
         //Create new config file with default values
         Config config = new Config(configpath);
         //Notifications should be switched on by default
         Assert.IsTrue(config.Notifications);
         Assert.AreEqual(config.Folders.Count, 0);
         config.Save();
         config = new Config(configpath);
     }
     catch (Exception)
     {
         if (File.Exists(configpath))
             File.Delete(configpath);
         throw;
     }
     File.Delete(configpath);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initialize (in the GUI and syncing mechanism) an existing CmisSync synchronized folder.
        /// </summary>
        /// <param name="repositoryInfo">Synchronized folder path</param>
        private void ConfigureAndStartSyncFolderSyncronization(Config.SyncConfig.SyncFolder repositoryInfo)
        {
            //create the local directory
            System.IO.Directory.CreateDirectory(repositoryInfo.LocalPath);

            CmisSync.Lib.Sync.SyncFolderSyncronizer syncronizer = new CmisSync.Lib.Sync.SyncFolderSyncronizer(repositoryInfo);
            syncronizer.Event += syncronizer_Event;
            this.SyncFolders.Add(syncronizer);
            syncronizer.Initialize();
        }
Exemplo n.º 9
0
        internal bool deleteAccount(Config.SyncConfig.Account account)
        {
            if (account == null)
            {
                return false;
            }

            if (account.SyncFolders.Count != 0)
            {
                MessageBox.Show("There are " + account.SyncFolders.Count + " synced folders commected to this account, remove them first.", "Unable to delete active Account");
                return false;
            }

            MessageBoxResult result = MessageBox.Show("Are you sure you want to remove the account '" + account.DisplayName + "' (pointing to '" + (account.RemoteUrl != null ? account.RemoteUrl.ToString() : "") + "')", "Delete Account", MessageBoxButton.YesNoCancel);
            if (result == MessageBoxResult.Yes)
            {
                ConfigManager.CurrentConfig.Accounts.Remove(account);
                ConfigManager.CurrentConfig.Save();
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 10
0
 public AccountViewModel(Controller controller, Config.SyncConfig.Account account)
     : this(controller)
 {
     this._account = account;
 }
Exemplo n.º 11
0
 public FolderViewModel(FolderViewModel parent, Config.SyncConfig.RemoteFolder folder)
     : base(parent, true)
 {
     this.folder = folder;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Check whether the directory is worth syncing or not.
        /// Directories that are not worth syncing include ignored, system, and hidden folders.
        /// </summary>
        public static bool IsDirectoryWorthSyncing(string localDirectory, Config.SyncConfig.SyncFolder repoInfo)
        {
            if (!localDirectory.StartsWith(repoInfo.LocalPath))
            {
                Logger.WarnFormat("Local directory is outside repo target directory.  local={0}, repo={1}", localDirectory, repoInfo.LocalPath);
                return false;
            }

            //Check for ignored path...
            string path = localDirectory.Substring(repoInfo.LocalPath.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;
        }
Exemplo n.º 13
0
 /// <summary></summary>
 /// <param name="folder"></param>
 /// <param name="fileName"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromRemotePath(string folder, string fileName, Config.SyncConfig.SyncFolder repoInfo)
 {
     return new RemotePathSyncItem(Path.Combine(folder, fileName), repoInfo);
 }
Exemplo n.º 14
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, Config.SyncConfig.SyncFolder repoInfo)
 {
     return new RemotePathSyncItem(remoteFolder, LocalFileName, repoInfo);
 }
Exemplo n.º 15
0
 /// <summary></summary>
 /// <param name="path"></param>
 /// <param name="repoInfo"></param>
 /// <returns></returns>
 public static SyncItem CreateFromRemotePath(string path, Config.SyncConfig.SyncFolder repoInfo)
 {
     return new RemotePathSyncItem(path, repoInfo);
 }
Exemplo n.º 16
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, Config.SyncConfig.SyncFolder repoInfo)
 {
     return new LocalPathSyncItem(localFolder, remoteFileName, repoInfo);
 }
Exemplo n.º 17
0
        /// <summary></summary>
        /// <param name="remotePath">either relative or absolute</param>
        /// <param name="syncFolderInfo"></param>
        public RemotePathSyncItem(string remotePath, Config.SyncConfig.SyncFolder syncFolderInfo)
        {
            this.localRootPath = syncFolderInfo.LocalPath;
            this.remoteRootPath = syncFolderInfo.RemotePath;

            this.remoteRelativePath = remotePath;
            if (remotePath.StartsWith(this.remoteRootPath))
            {
                this.remoteRelativePath = remotePath.Substring(this.remoteRootPath.Length).TrimStart(CmisPath.DirectorySeparatorChar);
            }
            this.localRelativePath = PathRepresentationConverter.RemoteToLocal(this.remoteRelativePath);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Remove a synchronized folder from the CmisSync configuration.
        /// This happens after the user removes the folder.
        /// </summary>
        /// <param name="folder_path">The synchronized folder to remove</param>
        private void RemoveRepository(Config.SyncConfig.Folder folder)
        {
            if (this.repositories.Count > 0)
            {
                for (int i = 0; i < this.repositories.Count; i++)
                {
                    RepoBase repo = this.repositories[i];

                    if (repo.LocalPath.Equals(folder.LocalPath))
                    {
                        repo.Dispose();
                        this.repositories.Remove(repo);
                        repo = null;
                        break;
                    }
                }
            }
            // Remove Cmis Database File
            string dbfilename = folder.DisplayName;
            dbfilename = dbfilename.Replace("\\", "_");
            dbfilename = dbfilename.Replace("/", "_");
            RemoveDatabase(dbfilename);
        }
Exemplo n.º 19
0
        private void handleMissingSyncFolder(Config.SyncConfig.SyncFolder syncFolderInfo)
        {
            bool handled = false;

            while (handled == false)
            {
                Views.MissingFolderDialog dialog = new Views.MissingFolderDialog(syncFolderInfo);
                dialog.ShowDialog();
                if (dialog.Result == Views.MissingFolderDialog.Action.MOVE)
                {
                    String startPath = Directory.GetParent(syncFolderInfo.LocalPath).FullName;
                    System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
                    fbd.SelectedPath = startPath;
                    fbd.Description = "Select the folder you have moved or renamed";
                    fbd.ShowNewFolderButton = false;
                    System.Windows.Forms.DialogResult result = fbd.ShowDialog();

                    if (result == System.Windows.Forms.DialogResult.OK && fbd.SelectedPath.Length > 0)
                    {
                        if (!Directory.Exists(fbd.SelectedPath))
                        {
                            throw new InvalidDataException();
                        }
                        Logger.Info("ControllerBase | Folder '" + syncFolderInfo.DisplayName + "' ('" + syncFolderInfo.LocalPath + "') moved to '" + fbd.SelectedPath + "'");
                        syncFolderInfo.LocalPath = fbd.SelectedPath;

                        ConfigureAndStartSyncFolderSyncronization(syncFolderInfo);
                        handled = true;
                    }
                }
                else if (dialog.Result == Views.MissingFolderDialog.Action.REMOVE)
                {
                    StopAndRemoveSyncFolderSyncronization(syncFolderInfo, true);
                    ConfigManager.CurrentConfig.SyncFolders.Remove(syncFolderInfo);

                    Logger.Info("ControllerBase | Removed folder '" + syncFolderInfo.DisplayName + "' from config");
                    handled = true;
                }
                else if (dialog.Result == Views.MissingFolderDialog.Action.RECREATE)
                {
                    StopAndRemoveSyncFolderSyncronization(syncFolderInfo, true);
                    AddAndStartNewSyncFolderSyncronization(syncFolderInfo);
                    //TODO: also remove and recreate the config to ensure a fresh start
                    Logger.Info("ControllerBase | Folder '" + syncFolderInfo.DisplayName + "' recreated");
                    handled = true;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Get the list of repositories of a CMIS server
        /// Each item contains id +
        /// </summary>
        /// <returns>The list of repositories. Each item contains the identifier and the human-readable name of the repository.</returns>
        private static List<Config.SyncConfig.RemoteRepository> doGetRepositories(Config.SyncConfig.Account account)
        {
            // If no URL was provided, return empty result.
            if (account.RemoteUrl == null)
            {
                throw new System.ArgumentException();
            }

            IList<IRepository> repositories;
            try
            {
                repositories = Auth.Auth.GetCmisRepositories(account.RemoteUrl, account.Credentials.UserName, account.Credentials.Password);
            }
            catch (CmisPermissionDeniedException e)
            {
                Logger.Error("CMIS server found, but permission denied. Please check username/password. ", e);
                throw;
            }
            catch (CmisRuntimeException e)
            {
                Logger.Error("No CMIS server at this address, or no connection. ", e);
                throw;
            }
            catch (CmisObjectNotFoundException e)
            {
                Logger.Error("No CMIS server at this address, or no connection. ", e);
                throw;
            }
            catch (CmisConnectionException e)
            {
                Logger.Error("No CMIS server at this address, or no connection. ", e);
                throw;
            }
            catch (CmisInvalidArgumentException e)
            {
                Logger.Error("Invalid URL, maybe Alfresco Cloud? ", e);
                throw;
            }

            List<Config.SyncConfig.RemoteRepository> result = new List<Config.SyncConfig.RemoteRepository>();
            // Populate the result list with identifier and name of each repository.
            foreach (IRepository repo in repositories)
            {
                // Repo name is sometimes empty (ex: Alfresco), in such case show the repo id instead.
                string name = repo.Name.Length == 0 ? repo.Id : repo.Name;

                result.Add(new Config.SyncConfig.RemoteRepository(account, repo.Id, name));
            }

            return result;
        }
Exemplo n.º 21
0
        private void StopAndRemoveSyncFolderSyncronization(Config.SyncConfig.SyncFolder syncFolderInfo, bool? keepLocalFiles = null)
        {
            bool found = false;
            //search and stop the syncher if already started
            foreach (CmisSync.Lib.Sync.SyncFolderSyncronizer syncher in this.SyncFolders)
            {
                //FIXME: can we identify a synced folder by it's localPath?
                if (syncFolderInfo.LocalPath.Equals(syncher.SyncFolderInfo.LocalPath))
                {
                    StopAndRemoveSyncFolderSyncronization(syncher, keepLocalFiles);
                    found = true;
                    break;
                }
            }

            if (found == false)
            {
                Logger.Warn("StopAndRemoveSyncFolderSyncronization(Config.SyncConfig.SyncFolder) cant find a SyncFolderSyncronizer for the provided SyncFolder (" + syncFolderInfo + "). The configuration will be removed from the CurrentConfig, but might be some leftover (local files, database, ecc...)");
                ConfigManager.CurrentConfig.RemoveSyncFolder(syncFolderInfo);
            }
        }
Exemplo n.º 22
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 IsWorthSyncing(string localDirectory, string filename, Config.SyncConfig.SyncFolder repoInfo)
 {
     return IsFilenameWorthSyncing(localDirectory, filename) &&
         IsDirectoryWorthSyncing(localDirectory, repoInfo) &&
         IsFileWorthSyncing(Path.Combine(localDirectory, filename), repoInfo);
 }
Exemplo n.º 23
0
        /// <summary>
        /// Try to find the CMIS server associated to any URL.
        /// Users can provide the URL of the web interface, and we have to return the CMIS URL
        /// Returns the list of repositories as well.
        /// </summary>
        public static ReadOnlyCollection<Config.SyncConfig.RemoteRepository> GetRepositories(Config.SyncConfig.Account account, bool discoverCorrectUriAndUpdate)
        {
            List<Config.SyncConfig.RemoteRepository> repositories = null;
            Exception firstException = null;

            // Try the given URL, maybe user directly entered the CMIS AtomPub endpoint URL.
            try
            {
                repositories = doGetRepositories(account);
            }
            catch (CmisRuntimeException e)
            {
                if (e.Message == "ConnectFailure")
                {
                    throw new NetworkException(e);
                }
                firstException = e;
            }
            catch (Exception e)
            {
                // Save first Exception and try other possibilities.
                firstException = e;
            }
            if (repositories != null)
            {
                // Found!
                return new ReadOnlyCollection<Config.SyncConfig.RemoteRepository>(repositories);
            }

            if (discoverCorrectUriAndUpdate == false)
            {
                throw firstException;
            }

            // Extract protocol and server name or IP address
            string prefix = account.RemoteUrl.GetLeftPart(UriPartial.Authority);

            // See https://github.com/aegif/CmisSync/wiki/What-address for the list of ECM products prefixes
            // Please send us requests to support more CMIS servers: https://github.com/aegif/CmisSync/issues
            string[] suffixes = {
                "/alfresco/api/-default-/public/cmis/versions/1.1/atom", // Alfresco 4.2 CMIS 1.1
                "/alfresco/api/-default-/public/cmis/versions/1.0/atom", // Alfresco 4.2 CMIS 1.0
                "/alfresco/cmisatom", // Alfresco 4.0 and 4.1
                "/alfresco/service/cmis", // Alfresco 3.x
                "/cmis/atom11", // OpenDataSpace
                "/rest/private/cmisatom/", // eXo Platform
                "/xcmis/rest/cmisatom", // xCMIS
                "/files/basic/cmis/my/servicedoc", // IBM Connections
                "/p8cmis/resources/Service", // IBM FileNet
                "/_vti_bin/cmis/rest?getRepositories", // Microsoft SharePoint
                "/nemakiware/atom/bedroom", // NemakiWare  TODO: different port, typically 8080 for Web UI and 3000 for CMIS
                "/nuxeo/atom/cmis", // Nuxeo
                "/cmis/atom",
                "/cmis/resources/", // EMC Documentum
                "/emc-cmis-ea/resources/", // EMC Documentum
                "/emc-cmis-weblogic/resources/", // EMC Documentum
                "/emc-cmis-wls/resources/", // EMC Documentum
                "/emc-cmis-was61/resources/", // EMC Documentum
                "/emc-cmis-wls1030/resources/", // EMC Documentum
                "/docushare/ds_mobile_connector/atom", // Xerox DocuShare
                "/documents/ds_mobile_connector/atom" // Xerox DocuShare  TODO: can be anything instead of "documents"
            };
            Uri originalUrl = account.RemoteUrl;
            string bestUrl = null;
            // Try all suffixes
            for (int i = 0; i < suffixes.Length; i++)
            {
                string fuzzyUrl = prefix + suffixes[i];
                Logger.Info("Sync | Trying with " + fuzzyUrl);
                try
                {
                    account.RemoteUrl = new Uri(fuzzyUrl);
                    repositories = doGetRepositories(account);
                }
                catch (CmisPermissionDeniedException e)
                {
                    firstException = e;
                    bestUrl = fuzzyUrl;
                }
                catch (Exception e)
                {
                    // Do nothing, try other possibilities.
                    Logger.Debug(e.Message);
                }
                if (repositories != null)
                {
                    // Found!
                    return new ReadOnlyCollection<Config.SyncConfig.RemoteRepository>(repositories);
                }
            }

            //restore the original url
            account.RemoteUrl = originalUrl;
            // Not found. Return also the first exception to inform the user correctly
            throw new ServerNotFoundException(firstException)
            {
                BestTryedUrl = new Uri(bestUrl)
            };
        }
Exemplo n.º 24
0
 public static void TestAccount(Config.SyncConfig.Account account)
 {
     //TODO: can we perform a simplier test?
     ReadOnlyCollection<Config.SyncConfig.RemoteRepository> repositories = CmisUtils.GetRepositories(account, true);
 }
Exemplo n.º 25
0
        private void handleMissingSyncFolder(Config.SyncConfig.Folder f)
        {
            bool handled = false;

            while (handled == false)
            {
                MissingFolderDialog dialog = new MissingFolderDialog(f);
                dialog.ShowDialog();
                if (dialog.action == MissingFolderDialog.Action.MOVE)
                {
                    String startPath = Directory.GetParent(f.LocalPath).FullName;
                    FolderBrowserDialog fbd = new FolderBrowserDialog();
                    fbd.SelectedPath = startPath;
                    fbd.Description = "Select the folder you have moved or renamed";
                    fbd.ShowNewFolderButton = false;
                    DialogResult result = fbd.ShowDialog();

                    if (result == DialogResult.OK && fbd.SelectedPath.Length > 0)
                    {
                        if (!Directory.Exists(fbd.SelectedPath))
                        {
                            throw new InvalidDataException();
                        }
                        Logger.Info("ControllerBase | Folder '" + f.DisplayName + "' ('" + f.LocalPath + "') moved to '" + fbd.SelectedPath + "'");
                        f.LocalPath = fbd.SelectedPath;

                        AddRepository(f.GetRepoInfo());
                        handled = true;
                    }
                }
                else if (dialog.action == MissingFolderDialog.Action.REMOVE)
                {
                    RemoveRepository(f);
                    ConfigManager.CurrentConfig.Folders.Remove(f);

                    Logger.Info("ControllerBase | Removed folder '" + f.DisplayName + "' from config");
                    handled = true;
                }
                else if (dialog.action == MissingFolderDialog.Action.RECREATE)
                {
                    RepoInfo info = f.GetRepoInfo();
                    RemoveRepository(f);
                    ConfigManager.CurrentConfig.Folders.Remove(f);
                    CreateRepository(info.Name,
                        info.Address,
                        info.User,
                        info.Password.ToString(),
                        info.RepoID,
                        info.RemotePath,
                        info.TargetDirectory,
                        info.getIgnoredPaths().OfType<String>().ToList(),
                        info.SyncAtStartup);
                    Logger.Info("ControllerBase | Folder '" + f.DisplayName + "' recreated");
                    handled = true;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            //handled == true
            //now resume the sincronization (if ever was suspended)
            //FIXME: the problem is that if the user suspended this repo it will get resumed anyway (ignoring the user setting)
            Program.Controller.ResumeRepositorySynchronization(f.DisplayName);
        }
Exemplo n.º 26
0
 public SyncFolderViewModel(Controller controller, Config.SyncConfig.SyncFolder model)
     : base(controller)
 {
     this.model = model;
 }
Exemplo n.º 27
0
        /// <summary>
        /// Check whether the file is worth syncing or not.
        /// This optionally excludes blank files or files too large.
        /// </summary>
        public static bool IsFileWorthSyncing(string filepath, Config.SyncConfig.SyncFolder 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;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Guess the web address where files can be seen using a browser.
        /// Not bulletproof. It depends on the server, and on some servers there is no web UI at all.
        /// </summary>
        public static string GetBrowsableURL(Config.SyncConfig.SyncFolder repo)
        {
            if (null == repo)
            {
                throw new ArgumentNullException("repo");
            }

            // Case of Alfresco.
            string suffix1 = "alfresco/cmisatom";
            string suffix2 = "alfresco/service/cmis";
            if (repo.Account.RemoteUrl.AbsoluteUri.EndsWith(suffix1) || repo.Account.RemoteUrl.AbsoluteUri.EndsWith(suffix2))
            {
                // Detect suffix length.
                int suffixLength = 0;
                if (repo.Account.RemoteUrl.AbsoluteUri.EndsWith(suffix1))
                    suffixLength = suffix1.Length;
                if (repo.Account.RemoteUrl.AbsoluteUri.EndsWith(suffix2))
                    suffixLength = suffix2.Length;

                string root = repo.Account.RemoteUrl.AbsoluteUri.Substring(0, repo.Account.RemoteUrl.AbsoluteUri.Length - suffixLength);
                if (repo.RemotePath.StartsWith("/Sites"))
                {
                    // Case of Alfresco Share.

                    // Example RemotePath: /Sites/thesite
                    // Result: http://server/share/page/site/thesite/documentlibrary
                    // Example RemotePath: /Sites/thesite/documentLibrary/somefolder/anotherfolder
                    // Result: http://server/share/page/site/thesite/documentlibrary#filter=path|%2Fsomefolder%2Fanotherfolder
                    // Example RemotePath: /Sites/s1/documentLibrary/éß和ệ
                    // Result: http://server/share/page/site/s1/documentlibrary#filter=path|%2F%25E9%25DF%25u548C%25u1EC7
                    // Example RemotePath: /Sites/s1/documentLibrary/a#bc/éß和ệ
                    // Result: http://server/share/page/site/thesite/documentlibrary#filter=path%7C%2Fa%2523bc%2F%25E9%25DF%25u548C%25u1EC7%7C

                    string path = repo.RemotePath.Substring("/Sites/".Length);
                    if (path.Contains("documentLibrary"))
                    {
                        int firstSlashPosition = path.IndexOf('/');
                        string siteName = path.Substring(0, firstSlashPosition);
                        string pathWithinSite = path.Substring(firstSlashPosition + "/documentLibrary".Length);
                        string escapedPathWithinSite = HttpUtility.UrlEncode(pathWithinSite);
                        string reescapedPathWithinSite = HttpUtility.UrlEncode(escapedPathWithinSite);
                        string sharePath = reescapedPathWithinSite.Replace("%252f", "%2F");
                        sharePath = sharePath.Replace("%2b", "%20");
                        return root + "share/page/site/" + siteName + "/documentlibrary#filter=path|" + sharePath;
                    }
                    else
                    {
                        // Site name only.
                        return root + "share/page/site/" + path + "/documentlibrary";
                    }
                }
                else
                {
                    // Case of Alfresco Web Client. Difficult to build a direct URL, so return root.
                    return root;
                }
            }
            else
            {
                // Another server was detected, try to open the thinclient url, otherwise try to open the repo path

                try
                {
                    // Connect to the CMIS repository.
                    ISession session = Auth.Auth.GetCmisSession(repo.Account.RemoteUrl, repo.Account.Credentials, repo.RepositoryId);

                    if (session.RepositoryInfo.ThinClientUri == null
                        || String.IsNullOrEmpty(session.RepositoryInfo.ThinClientUri.ToString()))
                    {
                        Logger.Error("CmisUtils GetBrowsableURL | Repository does not implement ThinClientUri: " + repo.Account.RemoteUrl.AbsoluteUri);
                        return repo.Account.RemoteUrl.AbsoluteUri + repo.RemotePath;
                    }
                    else
                    {
                        // Return CmisServer-provided thin URL.
                        return session.RepositoryInfo.ThinClientUri.ToString();
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("CmisUtils GetBrowsableURL | Exception " + e.Message, e);
                    // Server down or authentication problem, no way to know the right URL, so just open server.
                    return repo.Account.RemoteUrl.AbsoluteUri + repo.RemotePath;
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Remove a synchronized folder from the CmisSync configuration.
        /// This happens after the user removes the folder.
        /// </summary>
        /// <param name="folder">The synchronized folder to remove</param>
        private void RemoveRepository(Config.SyncConfig.Folder folder)
        {
            foreach (RepoBase repo in this.repositories)
            {
                if (repo.LocalPath.Equals(folder.LocalPath))
                {
                    repo.CancelSync();
                    repo.Dispose();
                    this.repositories.Remove(repo);
                    Logger.Info("Removed Repository: " + repo.Name);
                    break;
                }
            }

            // Remove Cmis Database File
            string dbfilename = folder.DisplayName;
            dbfilename = dbfilename.Replace("\\", "_");
            dbfilename = dbfilename.Replace("/", "_");
            RemoveDatabase(dbfilename);
        }
Exemplo n.º 30
0
 public RepositoryViewModel(Config.SyncConfig.RemoteRepository repo)
     : base(null, repo)
 {
 }