Exemple #1
0
            /// <summary>
            /// Create a legal MSI identifier from a resource name and an index.
            /// </summary>
            /// <param name="name">The name of the resource for which an identifier should be created.</param>
            /// <param name="index">An index to append to the end of the identifier to make it unique.</param>
            /// <returns>A legal MSI identifier.</returns>
            public string CreateIdentifier(string name, int index)
            {
                if (null == name)
                {
                    throw new ArgumentNullException("name");
                }

                StringBuilder identifier = new StringBuilder();

                // Convert the name to a standard MSI identifier
                identifier.Append(Common.GetIdentifierFromName(name));

                // no legal identifier characters were found, use the base id instead
                if (0 == identifier.Length)
                {
                    identifier.Append(this.baseName);
                }

                // truncate the identifier if it's too long (reserve 3 characters for up to 99 collisions)
                int adjustedMaxLength = this.MaxIdentifierLength - (index != 0 ? 3 : 0);

                if (adjustedMaxLength < identifier.Length)
                {
                    identifier.Length = adjustedMaxLength;
                }

                // if the index is not zero, then append it to the identifier name
                if (0 != index)
                {
                    identifier.AppendFormat("_{0}", index);
                }

                return(identifier.ToString());
            }
Exemple #2
0
        private void ConvertFileElement(XElement element)
        {
            if (null == element.Attribute("Id"))
            {
                XAttribute attribute = element.Attribute("Name");

                if (null == attribute)
                {
                    attribute = element.Attribute("Source");
                }

                if (null != attribute)
                {
                    string name = Path.GetFileName(attribute.Value);

                    if (this.OnError(ConverterTestType.AssignAnonymousFileId, element, "The file id is being updated to '{0}' to ensure it remains the same as the default", name))
                    {
                        IEnumerable <XAttribute> attributes = element.Attributes().ToList();
                        element.RemoveAttributes();
                        element.Add(new XAttribute("Id", Common.GetIdentifierFromName(name)));
                        element.Add(attributes);
                    }
                }
            }
        }
Exemple #3
0
 /// <summary>
 /// Create an identifier based on passed file name
 /// </summary>
 /// <param name="name">File name to generate identifer from</param>
 /// <returns></returns>
 public string CreateIdentifierFromFilename(string filename)
 {
     return(Common.GetIdentifierFromName(filename));
 }
 /// <summary>
 /// Return an identifier based on passed file/directory name
 /// </summary>
 /// <param name="name">File/directory name to generate identifer from</param>
 /// <returns>A version of the name that is a legal identifier.</returns>
 public static string GetIdentifierFromName(string name)
 {
     return(Common.GetIdentifierFromName(name));
 }