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 |
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); }
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); }
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)); }
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)); }