CmisSync.SetupController.CheckRepoPathAndName C# (CSharp) Method

CheckRepoPathAndName() public method

Check local repository path and repo name.
public CheckRepoPathAndName ( string localpath, string reponame ) : string
localpath string
reponame string
return string
        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.FolderAlreadyInUse, localpath, Program.Controller.Folders[index]));

                // Check whether folder name contains invalid characters.
                Regex regexRepoName = (Path.DirectorySeparatorChar.Equals('\\')) ? RepositoryRegex : RepositoryRegexLinux;
                if (!regexRepoName.IsMatch(reponame)||CmisSync.Lib.Utils.IsInvalidFolderName(reponame.Replace(Path.DirectorySeparatorChar, ' ')))
                    throw new ArgumentException(String.Format(Properties_Resources.InvalidRepoName, reponame));
                // Validate localpath
                if(localpath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    localpath = localpath.Substring(0,localpath.Length-1);
                if (CmisSync.Lib.Utils.IsInvalidFolderName(Path.GetFileName(localpath)))
                    throw new ArgumentException(String.Format(Properties_Resources.InvalidFolderName, Path.GetFileName(localpath)));
                // If no warning handler is registered, handle warning as error
                if (LocalPathExists == null)
                    CheckRepoPathExists(localpath);
                UpdateAddProjectButtonEvent(true);
                return String.Empty;
            }
            catch (Exception e)
            {
                UpdateAddProjectButtonEvent(false);
                return e.Message;
            }
        }

Usage Example

示例#1
0
        private void CheckCustomizeInput(TextBox localfolder_box, TextBox localrepopath_box, TextBlock localfolder_error_label)
        {
            string error = Controller.CheckRepoPathAndName(localrepopath_box.Text, localfolder_box.Text);

            if (!String.IsNullOrEmpty(error))
            {
                localfolder_error_label.Text       = error;
                localfolder_error_label.Visibility = Visibility.Visible;
                localfolder_error_label.Foreground = Brushes.Red;
            }
            else
            {
                try
                {
                    Controller.CheckRepoPathExists(localrepopath_box.Text);
                    localfolder_error_label.Visibility = Visibility.Hidden;
                }
                catch (ArgumentException e)
                {
                    localfolder_error_label.Visibility = Visibility.Visible;
                    localfolder_error_label.Foreground = Brushes.Orange;
                    localfolder_error_label.Text       = e.Message;
                }
            }
        }
All Usage Examples Of CmisSync.SetupController::CheckRepoPathAndName