예제 #1
0
        /// <summary>
        /// Processes an element for the Compiler.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line number for the parent element.</param>
        /// <param name="parentElement">Parent element of element to process.</param>
        /// <param name="element">Element to process.</param>
        /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
        public override void ParseElement(SourceLineNumberCollection sourceLineNumbers, XmlElement parentElement,
                                          XmlElement element, params string[] contextValues)
        {
            switch (parentElement.LocalName)
            {
            case "File":

                string fileId      = contextValues[0];
                string componentId = contextValues[1];

                var fileName =
                    parentElement.HasAttribute("Name")
                        ? Core.GetAttributeLongFilename(sourceLineNumbers, parentElement.Attributes["Name"], false)
                        : parentElement.HasAttribute("Source")
                            ? Path.GetFileName(Core.GetAttributeValue(sourceLineNumbers, parentElement.Attributes["Source"], false))
                            : null;

                switch (element.LocalName)
                {
                case "PublishStencil":
                    ParseVisioElement(element, componentId, fileName, VisioContentType.Stencil);
                    break;

                case "PublishTemplate":
                    ParseVisioElement(element, componentId, fileName, VisioContentType.Template);
                    break;

                case "PublishHelpFile":
                    ParseVisioElement(element, componentId, fileName, VisioContentType.Help);
                    break;

                case "PublishAddon":
                    ParseVisioElement(element, componentId, fileName, VisioContentType.Addon);
                    break;

                case "Publish":
                    Core.OnMessage(VisioErrors.UsingPublish(sourceLineNumbers));
                    break;

                case "PublishAddin":
                    ParseAddinElement(element, fileId);
                    break;

                default:
                    Core.UnexpectedElement(parentElement, element);
                    break;
                }
                break;

            default:
                Core.UnexpectedElement(parentElement, element);
                break;
            }
        }
        public override void DatabaseFinalize(Output output)
        {
            try
            {
                HarvestAddinRegistrationsFromSourceFiles(output);
            }
            catch (Exception e)
            {
                Core.OnMessage(VisioErrors.InternalException(e.ToString()));
            }

            base.DatabaseFinalize(output);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceLineNumbers"></param>
        /// <param name="attrib"></param>
        /// <returns></returns>

        private uint ParseUint(SourceLineNumberCollection sourceLineNumbers, XmlAttribute attrib)
        {
            string attribValue = Core.GetAttributeBundleVariableValue(sourceLineNumbers, attrib);

            uint result;

            if (uint.TryParse(attribValue, out result))
            {
                return(result);
            }

            Core.OnMessage(VisioErrors.InvalidUint(sourceLineNumbers, attrib.LocalName, attribValue));

            return(0);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceLineNumbers"></param>
        /// <param name="attrib"></param>
        /// <returns></returns>

        private StaticEnableConditions ParseStaticEnableConditions(SourceLineNumberCollection sourceLineNumbers, XmlAttribute attrib)
        {
            string attribValue = Core.GetAttributeBundleVariableValue(sourceLineNumbers, attrib);

            switch (attribValue)
            {
            case "Document":
                return(StaticEnableConditions.Document);

            case "DocumentWindow":
                return(StaticEnableConditions.DocumentWindow);

            case "DrawingWindow":
                return(StaticEnableConditions.DrawingWindow);

            case "PageWindow":
                return(StaticEnableConditions.PageWindow);

            case "MasterWindow":
                return(StaticEnableConditions.MasterWindow);

            case "StencilWindow":
                return(StaticEnableConditions.StencilWindow);

            case "SheetWindow":
                return(StaticEnableConditions.SheetWindow);

            case "IconWindow":
                return(StaticEnableConditions.IconWindow);

            case "TargetContext":
                return(StaticEnableConditions.TargetContext);

            case "TargetContextPage":
                return(StaticEnableConditions.TargetContextPage);

            case "TargetContextMaster":
                return(StaticEnableConditions.TargetContextMaster);

            case "TargetContextSelection":
                return(StaticEnableConditions.TargetContextSelection);


            default:
                Core.OnMessage(VisioErrors.InvalidVisioEdition(sourceLineNumbers, attribValue));
                return(StaticEnableConditions.Document);
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceLineNumbers"></param>
        /// <param name="attrib"></param>
        /// <returns></returns>

        private AddinType ParseAddinType(SourceLineNumberCollection sourceLineNumbers, XmlAttribute attrib)
        {
            string attribValue = Core.GetAttributeBundleVariableValue(sourceLineNumbers, attrib);

            switch (attribValue)
            {
            case "COM":
                return(AddinType.COM);

            case "VSTO":
                return(AddinType.VSTO);

            default:
                Core.OnMessage(VisioErrors.InvalidAddinType(sourceLineNumbers, attribValue));
                return(AddinType.Unknown);
            }
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceLineNumbers"></param>
        /// <param name="attrib"></param>
        /// <returns></returns>

        private VisioEdition ParseVisioEditionAttributeValue(SourceLineNumberCollection sourceLineNumbers, XmlAttribute attrib)
        {
            string attribValue = Core.GetAttributeBundleVariableValue(sourceLineNumbers, attrib);

            switch (attribValue)
            {
            case "x86":
                return(VisioEdition.X86);

            case "x64":
                return(VisioEdition.X64);

            default:
                Core.OnMessage(VisioErrors.InvalidVisioEdition(sourceLineNumbers, attribValue));
                return(VisioEdition.Default);
            }
        }
예제 #7
0
        /// <summary>
        /// Parses Language attribute into LCID code.
        /// Language attribute can be either a LCID directly (in this case it is verified that it exists) or language name,
        /// in this case it is converted to LCID.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line number for the parent element.</param>
        /// <param name="attrib">Language attribute to parse</param>
        /// <returns>Language code (LCID)</returns>
        ///
        private int ParseVisioLanguageCode(SourceLineNumberCollection sourceLineNumbers, XmlAttribute attrib)
        {
            var attribValue = Core.GetAttributeBundleVariableValue(sourceLineNumbers, attrib);

            try
            {
                int lcid;
                var cultureInfo = int.TryParse(attribValue, out lcid)
                    ? CultureInfo.GetCultureInfo(lcid)
                    : CultureInfo.GetCultureInfoByIetfLanguageTag(attribValue);

                return(cultureInfo.LCID);
            }
            catch (Exception)
            {
                Core.OnMessage(VisioErrors.InvalidLanguage(sourceLineNumbers, attribValue));
                return(0);
            }
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceLineNumbers"></param>
        /// <param name="attrib"></param>
        /// <returns></returns>

        private EnablingPolicy ParseEnablingPolicy(SourceLineNumberCollection sourceLineNumbers, XmlAttribute attrib)
        {
            string attribValue = Core.GetAttributeBundleVariableValue(sourceLineNumbers, attrib);

            switch (attribValue)
            {
            case "AlwaysEnabled":
                return(EnablingPolicy.AlwaysEnabled);

            case "DynamicallyEnabled":
                return(EnablingPolicy.DynamicallyEnabled);

            case "StaticallyEnabled":
                return(EnablingPolicy.StaticallyEnabled);

            case "StaticallyThenDynamicallyEnabled":
                return(EnablingPolicy.StaticallyThenDynamicallyEnabled);

            default:
                Core.OnMessage(VisioErrors.InvalidVisioEdition(sourceLineNumbers, attribValue));
                return(EnablingPolicy.AlwaysEnabled);
            }
        }
        private void HarvestAddinRegistrationsFromSourceFiles(Output output)
        {
            var fileTable = output.Tables["WixFile"];

            if (fileTable == null)
            {
                return;
            }

            var addinRegistrationTable = output.Tables["AddinRegistration"];

            if (addinRegistrationTable == null)
            {
                return;
            }

            var paths = fileTable.Rows
                        .Cast <WixFileRow>()
                        .ToDictionary(item => item.File, item => item.Source);

            foreach (Row row in addinRegistrationTable.Rows)
            {
                var fileId    = (string)row[(int)TableFields.arqFile];
                var addinType = (AddinType)(int)row[(int)TableFields.arqAddinType];

                string filePath;
                if (!paths.TryGetValue(fileId, out filePath))
                {
                    Core.OnMessage(VisioErrors.FileIdentifierNotFound(fileId));
                    continue;
                }

                if (addinType == AddinType.Unknown)
                {
                    var detectedAddinType = GetAddinTypeFromFilePath(filePath);
                    if (detectedAddinType == AddinType.Unknown)
                    {
                        Core.OnMessage(VisioErrors.UnknownAddinType(fileId));
                        continue;
                    }

                    addinType = detectedAddinType;
                    row[(int)TableFields.arqAddinType] = (int)addinType;
                }

                if (addinType == AddinType.VSTO)
                {
                    var addinFilePath = Path.ChangeExtension(filePath, ".dll");

                    if (!File.Exists(addinFilePath))
                    {
                        continue;
                    }

                    var assembly = new Lazy <Assembly>(() => Assembly.Load(File.ReadAllBytes(addinFilePath)));

                    SetDefaultFriendlyNameFromAssemblyTitle(row, assembly);
                    SetDefaultDescriptionFromAssemblyDescription(row, assembly);
                }

                if (addinType == AddinType.COM)
                {
                    var assembly = new Lazy <Assembly>(() => Assembly.Load(File.ReadAllBytes(filePath)));

                    var addin = assembly.Value
                                .GetTypes()
                                .FirstOrDefault(t => t.IsClass && typeof(IDTExtensibility2).IsAssignableFrom(t));

                    if (addin == null)
                    {
                        Core.OnMessage(VisioErrors.AddinNotFound(filePath));
                        continue;
                    }

                    SetDefaultFriendlyNameFromAssemblyTitle(row, assembly);
                    SetDefaultDescriptionFromAssemblyDescription(row, assembly);

                    row[(int)TableFields.arqProgId]         = Marshal.GenerateProgIdForType(addin);
                    row[(int)TableFields.arqClassId]        = "{" + Marshal.GenerateGuidForType(addin).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
                    row[(int)TableFields.arqClass]          = addin.FullName;
                    row[(int)TableFields.arqAssembly]       = assembly.Value.FullName;
                    row[(int)TableFields.arqVersion]        = assembly.Value.GetName().Version.ToString();
                    row[(int)TableFields.arqRuntimeVersion] = assembly.Value.ImageRuntimeVersion;
                }
            }
        }