private static void PopluateReplacementDictionary(Project project, Dictionary <string, string> replacementsDictionary, string modelName) { // create a "fixed" version that removes non-valid characters and leading underscores var fixedModelName = XmlConvert.EncodeName(modelName).TrimStart('_'); // make sure that the model name is a valid xml attribute value if (!EscherAttributeContentValidator.IsValidXmlAttributeValue(fixedModelName)) { VsUtils.ShowErrorDialog( string.Format( CultureInfo.CurrentCulture, Resources.ModelObjectItemWizard_NonValidXmlAttributeValue, modelName)); Marshal.ThrowExceptionForHR(VSConstants.E_ABORT); } // set the value to be used for namespace in blank models replacementsDictionary.Add("$namespace$", fixedModelName); // set the value to be used for EntityContainerName in blank models var entityContainerName = PackageManager.Package.ConnectionManager.ConstructUniqueEntityContainerName( fixedModelName + EntityContainerNameSuffix, project); replacementsDictionary.Add("$conceptualEntityContainerName$", entityContainerName); // set default value of the EnablePluralization flag dependent on current culture var pluralizationDefault = (CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "en").ToString(); replacementsDictionary.Add("$enablePluralization$", pluralizationDefault); }
// <summary> // Returns a string which is valid as a model namespace given the // proposedModelNamespace as a starting point. // </summary> // <param name="proposedModelNamespace">The proposed model namespace</param> // <param name="defaultModelNamespace">The model namespace to use if removal of invalid chars results in an empty string</param> internal static string ConstructValidModelNamespace(string proposedModelNamespace, string defaultModelNamespace) { Debug.Assert(!string.IsNullOrWhiteSpace(defaultModelNamespace), "defaultModelNamespace must not be null or empty"); if (IsValidModelNamespace(proposedModelNamespace)) { return(proposedModelNamespace); } if (String.IsNullOrEmpty(proposedModelNamespace)) { return(defaultModelNamespace); } var trialModelNamespace = proposedModelNamespace.Replace("<", "").Replace(">", "").Replace("&", ""); if (!EscherAttributeContentValidator.IsValidXmlAttributeValue(trialModelNamespace) || string.IsNullOrEmpty(trialModelNamespace)) { return(defaultModelNamespace); } if (IsValidModelNamespace(trialModelNamespace)) { // if trialModelNamespace is now valid just return it return(trialModelNamespace); } // if trialModelNamespace is invalid must be an invalid identifier // try stripping any leading numbers while (trialModelNamespace.Length > 0 && !Char.IsLetter(trialModelNamespace[0])) { trialModelNamespace = trialModelNamespace.Substring(1); } if (String.IsNullOrEmpty(trialModelNamespace)) { return(defaultModelNamespace); } if (IsValidModelNamespace(trialModelNamespace)) { return(trialModelNamespace); } // try adding a one to the end trialModelNamespace += "1"; if (IsValidModelNamespace(trialModelNamespace)) { return(trialModelNamespace); } // give up and return default return(defaultModelNamespace); }