Exemplo n.º 1
0
        private Expression BuildBinaryExpression(BinaryType binary, Expression left, Expression right)
        {
            if (binary == BinaryType.And)
            {
                return(Expression.And(left, right));
            }

            if (binary == BinaryType.Or)
            {
                return(Expression.Or(left, right));
            }

            if (binary == BinaryType.Equal)
            {
                return(Expression.Equal(left, right));
            }

            if (binary == BinaryType.GreaterThan)
            {
                return(Expression.GreaterThan(left, right));
            }

            if (binary == BinaryType.GreaterThanOrEqual)
            {
                return(Expression.GreaterThanOrEqual(left, right));
            }

            if (binary == BinaryType.LessThan)
            {
                return(Expression.LessThan(left, right));
            }

            if (binary == BinaryType.LessThanOrEqual)
            {
                return(Expression.LessThanOrEqual(left, right));
            }

            if (binary == BinaryType.Contains)
            {
                var containsMethod = typeof(string).GetMethod("Contains");
                return(Expression.Call(left, containsMethod, (ConstantExpression)right));
            }

            if (binary == BinaryType.StartsWith)
            {
                var startsWithMethod = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
                return(Expression.Call(left, startsWithMethod, (ConstantExpression)right));
            }

            if (binary == BinaryType.EndsWith)
            {
                var endsWithMethod = typeof(string).GetMethod("EndsWith", new[] { typeof(string) });
                return(Expression.Call(left, endsWithMethod, (ConstantExpression)right));
            }

            if (binary == BinaryType.In)
            {
                var method = right.Type.GetMethod("Contains");
                return(Expression.Call(right, method, left));
            }

            throw new Exception(binary.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes the Binary and Icon tables.
        /// </summary>
        /// <param name="writer">XmlWriter where the Intermediate should persist itself as XML.</param>
        /// <param name="binaryType">type of binary to process.</param>
        /// <param name="binaryName">Name of binary to process.</param>
        private void ProcessBinaryTable(XmlWriter writer, BinaryType binaryType, string binaryName)
        {
            if (!this.inputDatabase.TableExists(binaryType.ToString()))
            {
                return;
            }
            string query = String.Concat("SELECT * FROM `", binaryType.ToString(), "`");
            if (0 < binaryName.Length)
            {
                if (this.binariesProcessed.ContainsKey(binaryName))
                {
                    return;  // not an error because multiple controls can reference a binary/icon
                }
                query = String.Concat(query, " WHERE `Name`='", binaryName, "'");
            }

            using (View view = this.inputDatabase.OpenExecuteView(query))
            {
                if (this.exportBinaries)
                {
                    if ((BinaryType.Binary == binaryType && !this.binariesExported) ||
                        (BinaryType.Icon == binaryType && !this.iconsExported))
                    {
                        string binaryFileName = String.Concat(binaryType.ToString(), ".idt");
                        this.inputDatabase.Export(binaryType.ToString(), this.exportBasePath, binaryFileName);
                        File.Delete(Path.Combine(this.exportBasePath, binaryFileName));
                        if (BinaryType.Binary == binaryType)
                        {
                            this.binariesExported = true;
                        }
                        else if (BinaryType.Icon == binaryType)
                        {
                            this.iconsExported = true;
                        }
                    }
                }
                Record record;
                while (view.Fetch(out record))
                {
                    string name = record[(int)MsiInterop.Binary.Name];
                    if (this.binariesProcessed.ContainsKey(name))
                    {
                        continue;  // not an error because multiple controls can reference a property
                    }
                    else
                    {
                        this.binariesProcessed[name] = true;
                    }
                    string id = this.StripModuleId(name);
                    if (this.skipVSI && ("dirca_checkfx" == id.ToLower() || "vsdca_vsdlaunchconditions" == id.ToLower()))
                    {
                        this.core.OnMessage(WixWarnings.FilteringVSIStuff(null, WarningLevel.Major, "Binary", id.ToLower()));
                        continue;
                    }

                    if (null == writer)
                    {
                        writer = this.InitializeXmlTextWriter(Path.GetFullPath(Path.Combine(Path.Combine(this.outputFolder, "BaseLibrary"), String.Concat(binaryType.ToString(), ".wxs"))));
                        if (this.generateFragments)
                        {
                            // initalize the fragment
                            writer.WriteStartElement("Fragment");
                        }
                    }
                    writer.WriteStartElement(binaryType.ToString());
                    this.core.WriteAttributeString(writer, "Id", id);
                    this.core.WriteAttributeString(writer, "SourceFile", Path.Combine(binaryType.ToString(), String.Concat(id, ".ibd")));
                    writer.WriteEndElement();
                }

                if (this.generateFragments && null != writer)
                {
                    writer.WriteEndElement();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses a binary or icon element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        /// <param name="binaryType">"Binary" or "Icon" table type enum.</param>
        /// <returns>Identifier for the new row.</returns>
        private string ParseBinaryOrIconElement(XmlNode node, BinaryType binaryType)
        {
            SourceLineNumberCollection sourceLineNumbers = this.core.GetSourceLineNumbers(node);
            string id = null;
            string sourceFile = null;

            foreach (XmlAttribute attrib in node.Attributes)
            {
                switch (attrib.LocalName)
                {
                    case "Id":
                        id = this.core.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
                        break;
                    case "SourceFile":
                    case "src":
                        if (null != sourceFile)
                        {
                            this.core.OnMessage(WixErrors.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name, "SourceFile", "src"));
                        }
                        sourceFile = this.core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;
                    default:
                        this.core.UnexpectedAttribute(sourceLineNumbers, attrib);
                        break;
                }
            }
            if (null == id)
            {
                this.core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name, "Id"));
                id = CompilerCore.IllegalIdentifier;
            }
            else if (CompilerCore.IllegalIdentifier != id) // only check legal values
            {
                if (55 < id.Length)
                {
                    this.core.OnMessage(WixErrors.BinaryOrIconIdentifierTooLong(sourceLineNumbers, node.Name, "Id", id));
                }
                else if (!this.compilingProduct && 18 < id.Length) // if we're not doing a product then we can't be sure that a binary identifier over 18 characters will fit
                {
                    this.core.OnMessage(WixWarnings.BinaryOrIconIdentifierCannotBeModularized(sourceLineNumbers, node.Name, "Id", id));
                }
            }

            if (null == sourceFile)
            {
                this.core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name, "SourceFile"));
            }

            // find unexpected child elements
            foreach (XmlNode child in node.ChildNodes)
            {
                if (XmlNodeType.Element == child.NodeType)
                {
                    this.core.UnexpectedElement(node, child);
                }
            }

            Debug.Assert("Binary" == binaryType.ToString() || "Icon" == binaryType.ToString());
            Row row = this.core.CreateRow(sourceLineNumbers, binaryType.ToString());
            row[0] = id;
            row[1] = sourceFile;

            return id;
        }