Beispiel #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the list of characters that are not allowed for project names.
        /// Note that currently the kFilterProjName set is duplicated in AfDbApp::FilterForFileName.
        /// </summary>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static string GetInvalidProjectNameChars(FilenameFilterStrength strength)
        {
            // These are always invalid.
            string invalidChars = new string(Path.GetInvalidFileNameChars());

            // On Unix there are more characters valid in file names, but we
            // want the result to be identical on both platforms, so we have
            // to add those characters
            invalidChars = AddMissingChars(invalidChars, "?|<>\\*:\"");

            switch (strength)
            {
            case FilenameFilterStrength.kFilterProjName:
                // This is to avoid problems with restoring from backup.
                invalidChars = AddMissingChars(invalidChars, "()");
                goto case FilenameFilterStrength.kFilterMSDE;

            case FilenameFilterStrength.kFilterMSDE:
                // JohnT: I don't think this case is used any more.
                // In some MSDE SQL commands, we have used single quotes or square brackets to
                //   delimit a multi-word, Unicode database name.
                //   REVIEW: Perhaps a creative SQL guru can reduce these restrictions.
                invalidChars = AddMissingChars(invalidChars, "[];");
                goto case FilenameFilterStrength.kFilterBackup;

            case FilenameFilterStrength.kFilterBackup:
            default:
                break;
            }

            return(invalidChars);
        }
Beispiel #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the list of characters that are not allowed for project names.
        /// Note that currently the kFilterProjName set is duplicated in AfDbApp::FilterForFileName.
        /// </summary>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static string GetInvalidProjectNameChars(FilenameFilterStrength strength)
        {
            int    strengthInt  = (int)strength;
            string invalidChars = string.Empty;

            switch (strengthInt)
            {
            case (int)FilenameFilterStrength.kFilterProjName:
                // This is to avoid problems with restoring from backup.
                invalidChars += "()";
                goto case (int)(FilenameFilterStrength.kFilterMSDE);

            case (int)FilenameFilterStrength.kFilterMSDE:
                // In some MSDE SQL commands, we have used single quotes or square brackets to
                //   delimit a multi-word, Unicode database name.
                //   REVIEW: Perhaps a creative SQL guru can reduce these restrictions.
                invalidChars += "[];";
                goto case (int)(FilenameFilterStrength.kFilterBackup);

            case (int)FilenameFilterStrength.kFilterBackup:
            default:
                invalidChars += new string(Path.GetInvalidFileNameChars());
                break;
            }

            return(invalidChars);
        }
Beispiel #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Produce a version of the given name that can be used as a file name. This is done
        /// by replacing invalid characters with underscores '_'. In some cases MSDE and/or
        /// SQL have more stringent requirements for database names.
        /// </summary>
        /// <param name="sName">Name to be filtered</param>
        /// <param name="strength">How rigorous filtering is to be</param>
        /// <returns>the filtered name</returns>
        /// ------------------------------------------------------------------------------------
        public static string FilterForFileName(string sName, FilenameFilterStrength strength)
        {
            StringBuilder cleanName    = new StringBuilder(sName);
            string        invalidChars = GetInvalidProjectNameChars(strength);

            // replace all invalid characters with an '_'
            for (int i = 0; i < sName.Length; i++)
            {
                if (invalidChars.IndexOf(sName[i]) >= 0 || sName[i] < ' ')                 // eliminate all control characters too
                {
                    cleanName[i] = '_';
                }
            }
            return(cleanName.ToString());
        }
Beispiel #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the list of characters that are not allowed for project names.
        /// Note that currently the kFilterProjName set is duplicated in AfDbApp::FilterForFileName.
        /// </summary>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public static string GetInvalidProjectNameChars(FilenameFilterStrength strength)
        {
            // These are always invalid.
            string invalidChars = new string(Path.GetInvalidFileNameChars());
            // On Unix there are more characters valid in file names, but we
            // want the result to be identical on both platforms, so we have
            // to add those characters
            invalidChars = AddMissingChars(invalidChars, "?|<>\\*:\"");

            switch (strength)
            {
                case FilenameFilterStrength.kFilterProjName:
                    // This is to avoid problems with restoring from backup.
                    invalidChars = AddMissingChars(invalidChars, "()");
                    goto case FilenameFilterStrength.kFilterMSDE;
                case FilenameFilterStrength.kFilterMSDE:
                    // JohnT: I don't think this case is used any more.
                    // In some MSDE SQL commands, we have used single quotes or square brackets to
                    //   delimit a multi-word, Unicode database name.
                    //   REVIEW: Perhaps a creative SQL guru can reduce these restrictions.
                    invalidChars = AddMissingChars(invalidChars, "[];");
                    goto case FilenameFilterStrength.kFilterBackup;
                case FilenameFilterStrength.kFilterBackup:
                default:
                    break;
            }

            return invalidChars;
        }
Beispiel #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Produce a version of the given name that can be used as a file name. This is done
        /// by replacing invalid characters with underscores '_'. In some cases MSDE and/or
        /// SQL have more stringent requirements for database names.
        /// </summary>
        /// <param name="sName">Name to be filtered</param>
        /// <param name="strength">How rigorous filtering is to be</param>
        /// <returns>the filtered name</returns>
        /// ------------------------------------------------------------------------------------
        public static string FilterForFileName(string sName, FilenameFilterStrength strength)
        {
            StringBuilder cleanName = new StringBuilder(sName);
            string invalidChars = GetInvalidProjectNameChars(strength);

            // replace all invalid characters with an '_'
            for (int i = 0; i < sName.Length; i++)
            {
                if (invalidChars.IndexOf(sName[i]) >= 0 || sName[i] < ' ') // eliminate all control characters too
                    cleanName[i] = '_';
            }
            return cleanName.ToString();
        }
Beispiel #6
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Produce a version of the given name that can be used as a file name. This is done
 /// by replacing invalid characters with underscores '_'. In some cases MSDE and/or
 /// SQL have more stringent requirements for database names.
 /// </summary>
 /// <param name="sName">Name to be filtered</param>
 /// <param name="strength">How rigorous filtering is to be</param>
 /// <returns>the filtered name</returns>
 /// ------------------------------------------------------------------------------------
 public static string FilterForFileName(string sName, FilenameFilterStrength strength)
 {
     return(StringUtils.FilterForFileName(sName, GetInvalidProjectNameChars(strength)));
 }
Beispiel #7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the list of characters that are not allowed for project names.
		/// Note that currently the kFilterProjName set is duplicated in AfDbApp::FilterForFileName.
		/// </summary>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static string GetInvalidProjectNameChars(FilenameFilterStrength strength)
		{
			int strengthInt = (int)strength;
			string invalidChars = string.Empty;

			switch (strengthInt)
			{
				case (int)FilenameFilterStrength.kFilterProjName:
					// This is to avoid problems with restoring from backup.
					invalidChars += "()";
					goto case (int)(FilenameFilterStrength.kFilterMSDE);
				case (int)FilenameFilterStrength.kFilterMSDE:
					// In some MSDE SQL commands, we have used single quotes or square brackets to
					//   delimit a multi-word, Unicode database name.
					//   REVIEW: Perhaps a creative SQL guru can reduce these restrictions.
					invalidChars += "[];";
					goto case (int)(FilenameFilterStrength.kFilterBackup);
				case (int)FilenameFilterStrength.kFilterBackup:
				default:
					invalidChars += new string(Path.GetInvalidFileNameChars());
					break;
			}

			return invalidChars;
		}