ParseSuffix() public static method

Parses name from format 'name(x)'
public static ParseSuffix ( string name, string &nameBase, bool &inValidNumber ) : int
name string name to parse
nameBase string parsed namebase
inValidNumber bool true if correct format is detected but (x) is not a valid number
return int
Ejemplo n.º 1
0
        public static string IncrementNameSuffixToLastName(string currentName, int parentNodeId)
        {
            currentName = RepositoryPath.GetFileName(currentName);
            var    ext = Path.GetExtension(currentName);
            string nameBase;
            bool   inValidNumber;
            var    fileName = Path.GetFileNameWithoutExtension(currentName);

            ContentNamingHelper.ParseSuffix(fileName, out nameBase, out inValidNumber);
            var lastName = DataProvider.Current.GetNameOfLastNodeWithNameBase(parentNodeId, nameBase, ext);

            // if there is no suffixed name in db, return with first variant
            if (lastName == null)
            {
                return(String.Format("{0}(1){1}", nameBase, ext));
            }

            // there was a suffixed name in db in the form namebase(x), increment it
            // car(5)-> car(6), car(test)(5) -> car(test)(6), car(test) -> car(guid)
            string newNameBase;
            var    newName = ContentNamingHelper.IncrementNameSuffix(lastName, out newNameBase);

            // incremented name base differs from original name base (for example 'car(hello)(2)' and 'car(5)')
            // edge case, use guid with original namebase
            if (newNameBase != nameBase)
            {
                return(String.Format("{0}({1}){2}", nameBase, Guid.NewGuid().ToString(), ext));
            }

            // incremented name base and original name base are equal, so incremented name is correct (eg 'car(2)')
            return(newName);
        }
Ejemplo n.º 2
0
        public static string IncrementNameSuffix(string name, out string nameBase)
        {
            name = RepositoryPath.GetFileName(name);
            var  ext      = Path.GetExtension(name);
            var  fileName = Path.GetFileNameWithoutExtension(name);
            bool inValidNumber;
            var  index   = ContentNamingHelper.ParseSuffix(fileName, out nameBase, out inValidNumber);
            var  newName = (inValidNumber) ?
                           String.Format("{0}({1}){2}", nameBase, Guid.NewGuid().ToString(), ext) :
                           String.Format("{0}({1}){2}", nameBase, ++index, ext);

            return(newName);
        }
Ejemplo n.º 3
0
        public static string IncrementNameSuffix(string name)
        {
            name = RepositoryPath.GetFileName(name);
            var ext      = Path.GetExtension(name);
            var fileName = Path.GetFileNameWithoutExtension(name);

            string nameBase;
            var    index = ContentNamingHelper.ParseSuffix(fileName, out nameBase);

            if (index < 0)
            {
                index = 0;
            }
            return(String.Format("{0}({1}){2}", nameBase, ++index, ext));
        }
Ejemplo n.º 4
0
        public static string IncrementNameSuffixToLastName(string currentName, int parentNodeId)
        {
            currentName = RepositoryPath.GetFileName(currentName);
            var    ext = Path.GetExtension(currentName);
            string nameBase;
            var    fileName = Path.GetFileNameWithoutExtension(currentName);
            var    count    = ContentNamingHelper.ParseSuffix(fileName, out nameBase);

            var lastName = DataProvider.Current.GetNameOfLastNodeWithNameBase(parentNodeId, nameBase, ext);

            // if there is no suffixed name in db, return with first variant
            if (lastName == null)
            {
                return(String.Format("{0}(1){1}", nameBase, ext));
            }

            // there was a suffixed name in db in the form namebase(x), increment it
            // car(5)-> car(6), car(test)(5) -> car(test)(6), car(test) -> car(guid)
            return(ContentNamingHelper.IncrementNameSuffix(lastName));
        }