Wrapper for DirectoryInfo
Inheritance: FileSystemInfoWrapper, IDirectoryInfo
        /// <summary>
        /// Gets the directories of the original instance wrapped by new DirectoryInfoWrapper instances.
        /// </summary>
        /// <returns>The directories.</returns>
        public IDirectoryInfo[] GetDirectories() {
            DirectoryInfo[] originalDirs = this.original.GetDirectories();
            IDirectoryInfo[] wrappedDirs = new IDirectoryInfo[originalDirs.Length];
            for (int i = 0; i < originalDirs.Length; i++) {
                wrappedDirs[i] = new DirectoryInfoWrapper(originalDirs[i]);
            }

            return wrappedDirs;
        }
        /// <summary>
        /// Gets the directories of the original instance wrapped by new DirectoryInfoWrapper instances.
        /// </summary>
        /// <returns>The directories.</returns>
        public IDirectoryInfo[] GetDirectories()
        {
            DirectoryInfo[]  originalDirs = this.original.GetDirectories();
            IDirectoryInfo[] wrappedDirs  = new IDirectoryInfo[originalDirs.Length];
            for (int i = 0; i < originalDirs.Length; i++)
            {
                wrappedDirs[i] = new DirectoryInfoWrapper(originalDirs[i]);
            }

            return(wrappedDirs);
        }
Beispiel #3
0
        /// <summary>
        /// Check local repository path and repo name.
        /// </summary>
        /// <param name="localpath"></param>
        /// <param name="reponame"></param>
        /// <returns>validity error, or empty string if valid</returns>
        public string CheckRepoPathAndName(string localpath, string reponame)
        {
            try
            {
                // Check whether foldername is already in use
                int index = Program.Controller.Folders.FindIndex(x => x.Equals(reponame, StringComparison.OrdinalIgnoreCase));
                if (index != -1)
                {
                    throw new ArgumentException(string.Format(Properties_Resources.FolderAlreadyExist, reponame));
                }

                // Check whether folder name contains invalid characters.
                Regex regexRepoName = Path.DirectorySeparatorChar.Equals('\\') ? this.RepositoryRegex : this.RepositoryRegexLinux;
                if (!regexRepoName.IsMatch(reponame) || CmisSync.Lib.Utils.IsInvalidFolderName(reponame.Replace(Path.DirectorySeparatorChar, ' '), new List <string>()))
                {
                    throw new ArgumentException(string.Format(Properties_Resources.InvalidRepoName, reponame));
                }

                // Validate localpath
                localpath = localpath.TrimEnd(Path.DirectorySeparatorChar);
                if (CmisSync.Lib.Utils.IsInvalidFolderName(Path.GetFileName(localpath), new List <string>()))
                {
                    throw new ArgumentException(string.Format(Properties_Resources.InvalidFolderName, Path.GetFileName(localpath)));
                }

                IDirectoryInfo dir = new CmisSync.Lib.Storage.FileSystem.DirectoryInfoWrapper(new DirectoryInfo(localpath));
                while (!dir.Exists)
                {
                    dir = dir.Parent;
                }

                if (!dir.IsExtendedAttributeAvailable())
                {
                    throw new ArgumentException(string.Format("The filesystem where {0} points to is not able to save extended attributes, please choose another drive or turn on extended attributes", localpath));
                }

                // If no warning handler is registered, handle warning as error
                if (this.LocalPathExists == null)
                {
                    this.CheckRepoPathExists(localpath);
                }

                this.UpdateAddProjectButtonEvent(true);
                return(string.Empty);
            }
            catch (Exception e)
            {
                this.UpdateAddProjectButtonEvent(false);
                return(e.Message);
            }
        }
        public void FindRootFolder([Values(true, false)]bool withValidation) {
            string id = "id";
            string path = Path.GetTempPath();
            var fsInfo = new DirectoryInfoWrapper(new DirectoryInfo(path));
            var matcher = new PathMatcher(path, "/");
            var storage = new MetaDataStorage(this.engine, matcher, withValidation);
            var rootFolder = new MappedObject("/", id, MappedObjectType.Folder, null, "token");
            storage.SaveMappedObject(rootFolder);

            Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null, "Not findable by ID");
            Assert.That(storage.GetObjectByLocalPath(fsInfo), Is.Not.Null, "Not findable by path");
        }
        /// <summary>
        /// Check local repository path and repo name.
        /// </summary>
        /// <param name="localpath"></param>
        /// <param name="reponame"></param>
        /// <returns>validity error, or empty string if valid</returns>
        public string CheckRepoPathAndName(string localpath, string reponame) {
            try {
                // Check whether foldername is already in use
                int index = Program.Controller.Folders.FindIndex(x => x.Equals(reponame, StringComparison.OrdinalIgnoreCase));
                if (index != -1) {
                    throw new ArgumentException(string.Format(Properties_Resources.FolderAlreadyExist, reponame));
                }

                // Check whether folder name contains invalid characters.
                Regex regexRepoName = Path.DirectorySeparatorChar.Equals('\\') ? this.RepositoryRegex : this.RepositoryRegexLinux;
                if (!regexRepoName.IsMatch(reponame) || CmisSync.Lib.Utils.IsInvalidFolderName(reponame.Replace(Path.DirectorySeparatorChar, ' '), new List<string>())) {
                    throw new ArgumentException(string.Format(Properties_Resources.InvalidRepoName, reponame));
                }

                // Validate localpath
                localpath = localpath.TrimEnd(Path.DirectorySeparatorChar);
                if (CmisSync.Lib.Utils.IsInvalidFolderName(Path.GetFileName(localpath), new List<string>())) {
                    throw new ArgumentException(string.Format(Properties_Resources.InvalidFolderName, Path.GetFileName(localpath)));
                }

                IDirectoryInfo dir = new CmisSync.Lib.Storage.FileSystem.DirectoryInfoWrapper(new DirectoryInfo(localpath));
                while (!dir.Exists) {
                    dir = dir.Parent;
                }

                if (!dir.IsExtendedAttributeAvailable()) {
                    throw new ArgumentException(string.Format("The filesystem where {0} points to is not able to save extended attributes, please choose another drive or turn on extended attributes", localpath));
                }

                // If no warning handler is registered, handle warning as error
                if (this.LocalPathExists == null) {
                    this.CheckRepoPathExists(localpath);
                }

                this.UpdateAddProjectButtonEvent(true);
                return string.Empty;
            } catch (Exception e) {
                this.UpdateAddProjectButtonEvent(false);
                return e.Message;
            }
        }