public static void SerializeLayer(XElement parent, Layer layer)
 {
     var layerElement = new XElement("Layer");
     layerElement.AddElement("Id", layer.Id);
     layerElement.AddElement("Size", layer.Size.ToString());
     if (layer.HasWeights)
     {
         var weights = layer.GetArray(ArrayName.Weights);
         var biasWeights = layer.GetArray(ArrayName.BiasWeights);
         weights.CopyToHost();
         biasWeights.CopyToHost();
         layerElement.AddElement("Weights", SerializeArrayValues(weights));
         layerElement.AddElement("BiasWeights", SerializeArrayValues(biasWeights));
     }
     parent.Add(layerElement);
 }
Exemple #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlns"></param>
        /// <returns></returns>
        public override XElement CreateElement(XNamespace xmlns)
        {
            var rdf = RssNamespace.RDF;

            var seq = new XElement(rdf + "Seq");
            foreach (var r in Resources)
            {
                seq.AddElement(new XElement(r.ElementName)
                    .AddAttribute("resource", r.Resource));
            }
            var element = new XElement(xmlns + "items")
                .AddElement(seq);

            return element;
        }
        /// <summary>
        /// Emits WiX XML.
        /// </summary>
        /// <returns></returns>
        public override XContainer[] ToXml()
        {
            XNamespace bal = "http://schemas.microsoft.com/wix/BalExtension";

            var root = new XElement("BootstrapperApplicationRef");

            var app = new XElement(bal + "WixStandardBootstrapperApplication");

            app.Add(this.MapToXmlAttributes());

            if (LicensePath.IsNotEmpty() && LicensePath.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
            {
                root.SetAttribute("Id", "WixStandardBootstrapperApplication.RtfLicense");
                app.SetAttribute("LicenseFile", LicensePath);
            }
            else
            {
                root.SetAttribute("Id", "WixStandardBootstrapperApplication.HyperlinkLicense");

                if (LicensePath.IsEmpty())
                {
                    //cannot use SetAttribute as we want to preserve empty attrs
                    app.Add(new XAttribute("LicenseUrl", ""));
                }
                else
                {
                    if (LicensePath.StartsWith("http")) //online HTML file
                    {
                        app.SetAttribute("LicenseUrl", LicensePath);
                    }
                    else
                    {
                        app.SetAttribute("LicenseUrl", System.IO.Path.GetFileName(LicensePath));
                        root.AddElement("Payload").AddAttributes("SourceFile=" + LicensePath);
                    }
                }
            }

            root.Add(app);

            return new[] { root };
        }
Exemple #4
0
        /// <summary>
        /// Converts the <see cref="T:WixSharp.CustomUI"/> instance into WiX <see cref="T:System.Xml.Linq.XElement"/>.
        /// </summary>
        /// <returns><see cref="T:System.Xml.Linq.XElement"/> instance.</returns>
        public virtual XElement ToXElement()
        {
            var ui = new XElement("UI")
                         .AddAttributes(this.Attributes);

            foreach (string key in TextStyles.Keys)
            {
                var font = TextStyles[key];
                var style = ui.AddElement(new XElement("TextStyle",
                                              new XAttribute("Id", key),
                                              new XAttribute("FaceName", font.FontFamily.Name),
                                              new XAttribute("Size", font.Size),
                                              new XAttribute("Bold", font.Bold.ToYesNo()),
                                              new XAttribute("Italic", font.Italic.ToYesNo()),
                                              new XAttribute("Strike", font.Strikeout.ToYesNo()),
                                              new XAttribute("Underline", font.Underline.ToYesNo())));
            }

            foreach (string key in Properties.Keys)
                ui.Add(new XElement("Property",
                           new XAttribute("Id", key),
                           new XAttribute("Value", Properties[key])));

            foreach (string dialogId in DialogRefs)
                ui.Add(new XElement("DialogRef",
                           new XAttribute("Id", dialogId)));

            foreach (PublishingInfo info in this.UISequence)
            {
                int index = 0;
                foreach (DialogAction action in info.Actions)
                {
                    index++;
                    var element = ui.AddElement(new XElement("Publish",
                                                    new XAttribute("Dialog", info.Dialog),
                                                    new XAttribute("Control", info.Control),
                                                    action.Condition));

                    Action<string, string> AddAttribute = (name, value) =>
                    {
                        if (!value.IsEmpty())
                            element.Add(new XAttribute(name, value));
                    };

                    AddAttribute("Event", action.Name);
                    AddAttribute("Value", action.Value);
                    AddAttribute("Property", action.Property);

                    if (action.Order.HasValue)
                    {
                        element.Add(new XAttribute("Order", action.Order.Value));
                    }
                    else if (info.Actions.Count > 1)
                    {
                        element.Add(new XAttribute("Order", index));
                    }
                }
            }

            foreach (Dialog dialog in this.CustomDialogs)
            {
                ui.Add(dialog.ToXElement());
            }

            return ui;
        }
Exemple #5
0
        private static IEnumerable<XElement> MappingComplexProperties(TypeBase type, MappingBase mapping, EDMObjects.SSDL.EntityType.EntityType table, string entityContainerNamespace)
        {
            foreach (ComplexProperty complexProperty in type.AllComplexProperties)
            {
                ComplexPropertyMapping complexPropertyMapping = mapping.GetEntityTypeSpecificComplexPropertyMapping(complexProperty);

                if (complexPropertyMapping != null)
                {
                    XElement complexPropertyElement = new XElement(mslNamespace + "ComplexProperty",
                        new XAttribute("Name", complexProperty.Name));

                    IEnumerable<PropertyMapping> scalarMappings = complexPropertyMapping.GetSpecificMappingForTable(table);

                    foreach (PropertyMapping scalarMapping in scalarMappings)
                    {
                        complexPropertyElement.AddElement(new XElement(mslNamespace + "ScalarProperty",
                            new XAttribute("Name", scalarMapping.Property.Name),
                            new XAttribute("ColumnName", scalarMapping.Column.Name)));
                    }

                    foreach (ComplexProperty subComplexProperty in complexProperty.ComplexType.ComplexProperties)
                    {
                        complexPropertyElement.Add(MappingComplexProperties(complexProperty.ComplexType, complexPropertyMapping, table, entityContainerNamespace));
                    }

                    yield return complexPropertyElement;
                }
            }
        }
Exemple #6
0
        static XElement AddDir(XElement parent, Dir wDir)
        {
            string name = wDir.Name;
            string id = "";

            if (wDir.IsIdSet())
            {
                id = wDir.Id;
            }
            else
            {
                //Special folder defined either directly or by Wix# environment constant
                //e.g. %ProgramFiles%, [ProgramFilesFolder] -> ProgramFilesFolder
                if (Compiler.EnvironmentConstantsMapping.ContainsKey(wDir.Name) ||                              // %ProgramFiles%
                    Compiler.EnvironmentConstantsMapping.ContainsValue(wDir.Name) ||                            // ProgramFilesFolder
                    Compiler.EnvironmentConstantsMapping.ContainsValue(wDir.Name.TrimStart('[').TrimEnd(']')))  // [ProgramFilesFolder]
                {
                    id = wDir.Name.Expand();
                    name = wDir.Name.Expand(); //name needs to be escaped
                }
                else
                {
                    id = parent.Attribute("Id").Value + "." + wDir.Name.Expand();
                }
            }

            XElement newSubDir = parent.AddElement(
                                             new XElement("Directory",
                                                 new XAttribute("Id", id),
                                                 new XAttribute("Name", name)));

            return newSubDir;
        }
Exemple #7
0
        static void ProcessProperties(Project wProject, XElement product)
        {
            foreach (var prop in wProject.Properties)
            {
                if (prop is PropertyRef)
                {
                    var propRef = (prop as PropertyRef);

                    if (propRef.Id.IsEmpty())
                        throw new Exception("'" + typeof(PropertyRef).Name + "'.Id must be set before compiling the project.");

                    product.Add(new XElement("PropertyRef",
                                    new XAttribute("Id", propRef.Id)));
                }
                else if (prop is RegValueProperty)
                {
                    var rvProp = (prop as RegValueProperty);

                    XElement RegistrySearchElement;
                    XElement xProp = product.AddElement(
                                new XElement("Property",
                                    new XAttribute("Id", rvProp.Name),
                                    RegistrySearchElement = new XElement("RegistrySearch",
                                        new XAttribute("Id", rvProp.Name + "_RegSearch"),
                                        new XAttribute("Root", rvProp.Root.ToWString()),
                                        new XAttribute("Key", rvProp.Key),
                                        new XAttribute("Type", "raw")
                                        ))
                                    .AddAttributes(rvProp.Attributes));

                    if (!rvProp.Value.IsEmpty())
                        xProp.Add(new XAttribute("Value", rvProp.Value));

                    if (rvProp.EntryName != "")
                        RegistrySearchElement.Add(new XAttribute("Name", rvProp.EntryName));
                }
                else
                {
                    product.Add(new XElement("Property",
                                    new XAttribute("Id", prop.Name),
                                    new XAttribute("Value", prop.Value))
                                    .AddAttributes(prop.Attributes));
                }
            }
        }
Exemple #8
0
        static void InsertWebSite(WebSite webSite, string dirID, XElement element)
        {
            XNamespace ns = "http://schemas.microsoft.com/wix/IIsExtension";

            var id = webSite.Name.Expand();
            XElement xWebSite = element.AddElement(new XElement(ns + "WebSite",
                                                   new XAttribute("Id", id),
                                                   new XAttribute("Description", webSite.Description),
                                                   new XAttribute("Directory", dirID)));

            xWebSite.AddAttributes(webSite.Attributes);

            foreach (WebSite.WebAddress address in webSite.Addresses)
            {
                XElement xAddress = xWebSite.AddElement(new XElement(ns + "WebAddress",
                                                            new XAttribute("Id", address.Address == "*" ? "AllUnassigned" : address.Address),
                                                            new XAttribute("Port", address.Port)));

                xAddress.AddAttributes(address.Attributes);
            }
        }
Exemple #9
0
        static void ProcessMergeModules(Dir wDir, XElement dirItem, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents)
        {
            foreach (Merge msm in wDir.MergeModules)
            {
                XElement media = dirItem.Parent("Product").Select("Media");
                XElement package = dirItem.Parent("Product").Select("Package");

                string language = package.Attribute("Languages").Value; //note Wix# expects package.Attribute("Languages") to have a single value (yest it is a temporary limitation)
                string diskId = media.Attribute("Id").Value;

                XElement merge = dirItem.AddElement(
                    new XElement("Merge",
                        new XAttribute("Id", msm.Id),
                        new XAttribute("FileCompression", msm.FileCompression.ToYesNo()),
                        new XAttribute("Language", language),
                        new XAttribute("SourceFile", msm.SourceFile),
                        new XAttribute("DiskId", diskId))
                        .AddAttributes(msm.Attributes));

                if (!featureComponents.ContainsKey(msm.Feature))
                    featureComponents[msm.Feature] = new List<string>();

                //currently WiX does not allow child Condition element but in the future release it most likely will
                //if (msm.Condition != null)
                //    merge.AddElement(
                //        new XElement("Condition", new XCData(msm.Condition.ToCData()))
                //            .AddAttributes(msm.Condition.Attributes));
            }
        }
Exemple #10
0
        static void ProcessDirectoryFiles(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem)
        {
            //insert files in the last leaf directory node
            foreach (File wFile in wDir.Files)
            {
                string fileId = wFile.Id;
                string compId = "Component." + wFile.Id;

                if (wFile.Feature != null)
                {
                    featureComponents.Map(wFile.Feature, compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                    new XElement("Component",
                        new XAttribute("Id", compId),
                        new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wFile.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", new XCData(wFile.Condition.ToCData()))
                            .AddAttributes(wFile.Condition.Attributes));

                XElement file = comp.AddElement(
                    new XElement("File",
                        new XAttribute("Id", fileId),
                        new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name)))
                        .AddAttributes(wFile.Attributes));

                if (wFile.ServiceInstaller != null)
                    comp.Add(wFile.ServiceInstaller.ToXml(wProject));

                if (wFile is Assembly && (wFile as Assembly).RegisterInGAC)
                {
                    file.Add(new XAttribute("KeyPath", "yes"),
                             new XAttribute("Assembly", ".net"),
                             new XAttribute("AssemblyManifest", fileId),
                             new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString()));
                }

                wFile.DriverInstaller.Compile(wProject, comp);

                //insert file associations
                foreach (FileAssociation wFileAssociation in wFile.Associations)
                {
                    XElement progId;
                    comp.Add(progId = new XElement("ProgId",
                                          new XAttribute("Id", wFileAssociation.Extension + ".file"),
                                          new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()),
                                          new XAttribute("Description", wFileAssociation.Description),
                                          new XElement("Extension",
                                              new XAttribute("Id", wFileAssociation.Extension),
                                              new XAttribute("ContentType", wFileAssociation.ContentType),
                                              new XElement("Verb",
                                                  wFileAssociation.Advertise ?
                                                     new XAttribute("Sequence", wFileAssociation.SequenceNo) :
                                                     new XAttribute("TargetFile", fileId),
                                                  new XAttribute("Id", wFileAssociation.Command),
                                                  new XAttribute("Command", wFileAssociation.Command),
                                                  new XAttribute("Argument", wFileAssociation.Arguments)))));

                    if (wFileAssociation.Icon != null)
                    {
                        progId.Add(
                            new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId),
                            new XAttribute("IconIndex", wFileAssociation.IconIndex));
                    }
                }

                //insert file owned shortcuts
                foreach (Shortcut wShortcut in wFile.Shortcuts)
                {
                    string locationDirId;

                    if (wShortcut.Location.IsEmpty())
                    {
                        locationDirId = wDir.Id;
                    }
                    else
                    {
                        Dir locationDir = wProject.FindDir(wShortcut.Location);

                        if (locationDir != null)
                        {
                            locationDirId = locationDir.Id;
                        }
                        else
                        {
                            if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location))
                                autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature);

                            locationDirId = wShortcut.Location.Expand();
                        }
                    }

                    var shortcutElement =
                        new XElement("Shortcut",
                            new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id),
                            new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId),
                            new XAttribute("Directory", locationDirId),
                            new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk"));

                    wShortcut.EmitAttributes(shortcutElement);

                    file.Add(shortcutElement);
                }

                //insert file related IIS virtual directories
                InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject);

                //insert file owned permissions
                ProcessFilePermissions(wProject, wFile, file);
            }
        }
Exemple #11
0
        static void PostProcessMsm(Project project, XElement product)
        {
            var modules = from dir in project.AllDirs
                          from msm in dir.MergeModules
                          select new
                          {
                              Feature = msm.Feature,
                              MsmId = msm.Id
                          };

            var features = product.Descendants("Feature")
                                  .ToDictionary(x => x.Attribute("Id").Value);

            foreach (var item in modules)
            {
                XElement xFeature;

                if (item.Feature == null)
                {
                    if (features.ContainsKey("Complete"))
                        xFeature = features["Complete"];
                    else
                        throw new Exception("Merge Module " + item.MsmId + " does not belong to any feature and \"Complete\" feature is not found");
                }
                else
                {
                    if (features.ContainsKey(item.Feature.Id))
                    {
                        xFeature = features[item.Feature.Id];
                    }
                    else
                    {
                        xFeature = product.AddElement(item.Feature.ToXml());
                        features.Add(item.Feature.Id, xFeature);
                    }
                }

                xFeature.Add(new XElement("MergeRef",
                                 new XAttribute("Id", item.MsmId)));
            }
        }
        static XElement CrteateComponentFor(this XDocument doc, XElement xDir)
        {
            string compId = xDir.Attribute("Id").Value;
            XElement xComponent = xDir.AddElement(
                              new XElement("Component",
                                  new XAttribute("Id", compId),
                                  new XAttribute("Guid", WixGuid.NewGuid(compId))));

            foreach (XElement xFeature in doc.Root.Descendants("Feature"))
                xFeature.Add(new XElement("ComponentRef",
                    new XAttribute("Id", xComponent.Attribute("Id").Value)));

            return xComponent;
        }
Exemple #13
0
        public static XElement Write(CSDLContainer csdlContainer)
        {
            // Instantiate Schema
            XElement schema = new XElement(csdlNamespace + "Schema",
                new XAttribute("Namespace", csdlContainer.Namespace),
                new XAttribute("Alias", csdlContainer.Alias),
                new XAttribute(XNamespace.Xmlns + "annotation", csdlAnnotationNamespace.NamespaceName),
                new XAttribute("xmlns", csdlNamespace.NamespaceName));

            // EntityContainer
            string entityContainerNamespace = string.Concat(csdlContainer.Namespace, ".");
            XElement entityContainer = new XElement(csdlNamespace + "EntityContainer", new XAttribute("Name", csdlContainer.Name));
            schema.Add(entityContainer);

            // EntityContainer : EntitySets
            foreach (EntityType entityType in csdlContainer.EntitySets)
            {
                XElement entitySetElement = new XElement(csdlNamespace + "EntitySet",
                    new XAttribute("Name", entityType.EntitySetName), 
                    new XAttribute("EntityType", string.Concat(entityContainerNamespace, entityType.Name)));
                    //.AddAttribute(csdlCodeGenerationNamespace, "GetterAccess", entityType.EntitySetVisibility); // Not available in EF 4.0

                entityContainer.Add(entitySetElement);
            }

            // EntityContainer : AssociationSets
            foreach (Association association in csdlContainer.Associations)
            {
                XElement associationSetElement = new XElement(csdlNamespace + "AssociationSet",
                    new XAttribute("Name", association.AssociationSetName),
                    new XAttribute("Association", string.Concat(entityContainerNamespace, association.Name)));

                associationSetElement.Add(
                    new XElement(csdlNamespace + "End", new XAttribute("Role", association.PropertyEnd1Role), new XAttribute("EntitySet", association.PropertyEnd1.EntityType.EntitySetName)),
                    new XElement(csdlNamespace + "End", new XAttribute("Role", association.PropertyEnd2Role), new XAttribute("EntitySet", association.PropertyEnd2.EntityType.EntitySetName)));

                entityContainer.AddElement(associationSetElement);
            }

            // EntityContainer : FunctionImports
            foreach (Function function in csdlContainer.Functions)
            {
                XElement functionElement = new XElement(csdlNamespace + "FunctionImport",
                    new XAttribute("Name", function.Name))
                    .AddAttribute("EntitySet", function.EntityType == null ? null : function.EntityType.EntitySetName)
                    .AddAttribute("ReturnType", function.ReturnType);

                foreach (FunctionParameter functionParameter in function.Parameters)
                {
                    functionElement.AddElement(new XElement(csdlNamespace + "Paramter",
                        new XAttribute("Name", functionParameter.Name),
                        new XAttribute("Type", functionParameter.Type))
                        .AddAttribute("MaxLength", functionParameter.MaxLength)
                        .AddAttribute("Mode", functionParameter.Mode)
                        .AddAttribute("Precision", functionParameter.Precision)
                        .AddAttribute("Scale", functionParameter.Scale));
                }

                entityContainer.AddElement(functionElement);
            }

            // ComplexTypes
            foreach (ComplexType complexType in csdlContainer.ComplexTypes)
            {
                XElement complexTypeElement = new XElement(csdlNamespace + "ComplexType",
                    new XAttribute("Name", complexType.Name));
                    //.AddAttribute(new XAttribute(csdlCodeGenerationNamespace + "TypeAccess", complexType.Visibility)); // Not available in EF 4.0

                complexTypeElement.Add(WriteScalarProperties(complexType));
                complexTypeElement.Add(WriteComplexProperties(complexType, string.Concat(csdlContainer.Alias, ".")));

                schema.AddElement(complexTypeElement);
            }

            // EntityTypes
            foreach (EntityType entityType in csdlContainer.EntityTypes)
            {
                XElement entityTypeElement = new XElement(csdlNamespace + "EntityType")
                    .AddAttribute("Name", entityType.Name)
                    //.AddAttribute(csdlCodeGenerationNamespace, "TypeAccess", entityType.Visibility) // Not available in EF 4.0
                    .AddAttribute("BaseType", entityType.BaseType == null ? null : string.Concat(entityContainerNamespace, entityType.BaseType.Name))
                    .AddAttribute("Abstract", entityType.Abstract);

                if (entityType.SpecificKeys.Any())
                {
                    XElement keyElement = new XElement(csdlNamespace + "Key");
                    
                    entityType.ScalarProperties.Where(sp => sp.IsKey).ForEach(scalarProperty =>
                    {
                        keyElement.AddElement(new XElement(csdlNamespace + "PropertyRef")
                            .AddAttribute("Name", scalarProperty.Name));                        
                    });

                    entityTypeElement.AddElement(keyElement);
                }

                entityTypeElement.Add(WriteScalarProperties(entityType));
                entityTypeElement.Add(WriteComplexProperties(entityType, string.Concat(csdlContainer.Alias, ".")));

                // EntityType : NavigationProperties
                entityType.NavigationProperties.Where(np => np.Generate).ForEach(navigationProperty =>
                {
                    entityTypeElement.AddElement(new XElement(csdlNamespace + "NavigationProperty")
                        .AddAttribute("Name", navigationProperty.Name)
                        .AddAttribute("Relationship", string.Concat(entityContainerNamespace, navigationProperty.Association.Name))
                        .AddAttribute("FromRole", navigationProperty.Association.GetRoleName(navigationProperty))
                        .AddAttribute("ToRole", navigationProperty.Association.GetRoleName(navigationProperty.Association.PropertiesEnd.First(role => role != navigationProperty))));
                        //.AddAttribute(csdlCodeGenerationNamespace, "GetterAccess", navigationProperty.GetVisibility) // Not available in EF 4.0
                        //.AddAttribute(csdlCodeGenerationNamespace, "SetterAccess", navigationProperty.SetVisibility));
                });

                schema.AddElement(entityTypeElement);
            }

            // Associations
            foreach (Association association in csdlContainer.Associations)
            { 
                XElement associationElement = new XElement(csdlNamespace + "Association")
                    .AddAttribute("Name", association.Name);
                    
                associationElement.AddElement(new XElement(csdlNamespace + "End")
                    .AddAttribute("Role", association.PropertyEnd1Role)
                    .AddAttribute("Type", string.Concat(entityContainerNamespace, association.PropertyEnd1.EntityType.Name))
                    .AddAttribute("Multiplicity", CardinalityStringConverter.CardinalityToString(association.PropertyEnd1.Cardinality)));

                associationElement.AddElement(new XElement(csdlNamespace + "End")
                    .AddAttribute("Role", association.PropertyEnd2Role)
                    .AddAttribute("Type", string.Concat(entityContainerNamespace, association.PropertyEnd2.EntityType.Name))
                    .AddAttribute("Multiplicity", CardinalityStringConverter.CardinalityToString(association.PropertyEnd2.Cardinality)));

                if (association.PrincipalRole != null)
                { 
                    XElement referentialConstraintElement = new XElement(csdlNamespace + "ReferentialConstraint");

                    XElement principalElement = (new XElement(csdlNamespace + "Principal")
                        .AddAttribute("Role", association.PrincipalRole));

                    foreach (ScalarProperty propertyRef in association.PrincipalProperties)
                        principalElement.AddElement(new XElement(csdlNamespace + "PropertyRef").AddAttribute("Name", propertyRef.Name));

                    XElement dependentElement = (new XElement(csdlNamespace + "Dependent")
                        .AddAttribute("Role", association.DependentRole));

                    foreach (ScalarProperty propertyRef in association.DependentProperties)
                        dependentElement.AddElement(new XElement(csdlNamespace + "PropertyRef").AddAttribute("Name", propertyRef.Name));

                    referentialConstraintElement.AddElement(principalElement);
                    referentialConstraintElement.AddElement(dependentElement);
                    associationElement.AddElement(referentialConstraintElement);
                }

                schema.AddElement(associationElement);
            }

            return schema;
        }
Exemple #14
0
        public static XElement WriteXElement(SSDLContainer ssdlContainer)
        {
            // Instantiate Schema
            XElement schema = new XElement(ssdlNamespace + "Schema",
                new XAttribute("Namespace", ssdlContainer.Namespace), 
                new XAttribute("Alias", "Self"),
                new XAttribute(XNamespace.Xmlns + "store", storeNamespace.NamespaceName),
                new XAttribute("xmlns", ssdlNamespace.NamespaceName))
                .AddAttribute("Provider", ssdlContainer.Provider)
                .AddAttribute("ProviderManifestToken", ssdlContainer.ProviderManifestToken);
            
            // EntityContainer
            string entityContainerNamespace = string.Concat(ssdlContainer.Namespace, ".");
            XElement entityContainer = new XElement(ssdlNamespace + "EntityContainer", new XAttribute("Name", ssdlContainer.Name));
            schema.Add(entityContainer);

            // EntityContainer : EntitySets
            foreach (EntityType entityType in ssdlContainer.EntityTypes)
            {
                XElement entitySet = new XElement(ssdlNamespace + "EntitySet",
                    new XAttribute("Name", entityType.EntitySetName), new XAttribute("EntityType", string.Concat(entityContainerNamespace, entityType.Name)))
                        .AddAttribute(entityType.StoreType == StoreType.Views ? null : new XAttribute("Schema", entityType.Schema))
                        .AddAttribute("Table", entityType.Table)
                        .AddAttribute(storeNamespace, "Name", entityType.StoreName)
                        .AddAttribute(storeNamespace, "Schema", entityType.StoreSchema)
                        .AddAttribute(storeNamespace, "Type", entityType.StoreType)
                        .AddElement(string.IsNullOrEmpty(entityType.DefiningQuery) ? null : new XElement(ssdlNamespace + "DefiningQuery", entityType.DefiningQuery));

                entityContainer.Add(entitySet);
            }

            // EntityContainer : Associations
            foreach (Association association in ssdlContainer.AssociationSets)
            {
                XElement associationSet = new XElement(ssdlNamespace + "AssociationSet", 
                    new XAttribute("Name", association.AssociationSetName), new XAttribute("Association", string.Concat(entityContainerNamespace, association.Name)));

                string role2Name = association.Role2.Name;

                // If the association end properties are the same properties
                if (association.Role1.Name == association.Role2.Name && association.Role1.Type.Name == association.Role2.Type.Name)
                    role2Name += "1";

                associationSet.Add(
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", association.Role1.Name), new XAttribute("EntitySet", association.Role1.Type.Name)),
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", role2Name), new XAttribute("EntitySet", association.Role2.Type.Name)));
            
                entityContainer.Add(associationSet);
            }

            // EntityTypes
            foreach (EntityType entityType in ssdlContainer.EntityTypes)
            {
                XElement entityTypeElement = new XElement(ssdlNamespace + "EntityType", new XAttribute("Name", entityType.Name));

                XElement keys = new XElement(ssdlNamespace + "Key");

                foreach (Property property in entityType.Properties)
                {
                    // If we have a table then we set a key element if the current property is a primary key or part of a composite key.
                    // AND: If we have a view then we make a composite key of all non-nullable properties of the entity (VS2010 is also doing this).
                    if ((entityType.StoreType == StoreType.Tables && property.IsKey) || (entityType.StoreType == StoreType.Views && property.Nullable == false))
                        keys.Add(new XElement(ssdlNamespace + "PropertyRef", new XAttribute("Name", property.Name)));
                }

                if (!keys.IsEmpty)
                    entityTypeElement.Add(keys);

                foreach (Property property in entityType.Properties)
                {
                    entityTypeElement.Add(new XElement(ssdlNamespace + "Property", new XAttribute("Name", property.Name), new XAttribute("Type", property.Type))
                        .AddAttribute("Collation", property.Collation)
                        .AddAttribute("DefaultValue", property.DefaultValue)
                        .AddAttribute("FixedLength", property.FixedLength)
                        .AddAttribute("MaxLength", property.MaxLength)
                        .AddAttribute("Nullable", property.Nullable)
                        .AddAttribute("Precision", property.Precision)
                        .AddAttribute("Scale", property.Scale)
                        .AddAttribute("StoreGeneratedPattern", property.StoreGeneratedPattern)
                        .AddAttribute(storeNamespace, "Name", property.StoreName)
                        .AddAttribute(storeNamespace, "Schema", property.StoreSchema)
                        .AddAttribute(storeNamespace, "Type", property.StoreType)
                        .AddAttribute("Unicode", property.Unicode));
                }

                schema.AddElement(entityTypeElement);
            }

            foreach (Association association in ssdlContainer.AssociationSets)
            {
                string role2Name = association.Role2.Name;

                // If the association end properties are the same properties
                if (association.Role1.Name == association.Role2.Name && association.Role1.Type.Name == association.Role2.Type.Name)
                    role2Name += "1";
                
                XElement associationElement = new XElement(ssdlNamespace + "Association", new XAttribute("Name", association.Name),
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", association.Role1.Name), new XAttribute("Type", string.Concat(entityContainerNamespace, association.Role1.Type.Name)), new XAttribute("Multiplicity", CardinalityStringConverter.CardinalityToString(association.Role1.Cardinality))),
                        new XElement(ssdlNamespace + "End", new XAttribute("Role", role2Name), new XAttribute("Type", string.Concat(entityContainerNamespace, association.Role2.Type.Name)), new XAttribute("Multiplicity", CardinalityStringConverter.CardinalityToString(association.Role2.Cardinality))));

                string dependentRoleName = association.DependantRole.Name;

                // If the association end properties are the same properties
                if (association.PrincipalRole.Name == association.DependantRole.Name && association.PrincipalRole.Type.Name == association.DependantRole.Type.Name)
                    dependentRoleName += "1";

                XElement principalRoleElement = new XElement(ssdlNamespace + "Principal", new XAttribute("Role", association.PrincipalRole.Name));
                foreach (Property property in association.PrincipalRole.Properties)
                    principalRoleElement.Add(new XElement(ssdlNamespace + "PropertyRef", new XAttribute("Name", property.Name)));

                XElement dependentRoleElement = new XElement(ssdlNamespace + "Dependent", new XAttribute("Role", dependentRoleName));
                foreach (Property property in association.DependantRole.Properties)
                    dependentRoleElement.Add(new XElement(ssdlNamespace + "PropertyRef", new XAttribute("Name", property.Name)));

                XElement referentialConstraintElement = new XElement(ssdlNamespace + "ReferentialConstraint", principalRoleElement, dependentRoleElement);
                associationElement.Add(referentialConstraintElement);

                schema.Add(associationElement);
            }

            foreach (Function function in ssdlContainer.Functions)
            {
                XElement functionElement = new XElement(ssdlNamespace + "Function", new XAttribute("Name", function.Name))
                    .AddAttribute("Aggregate", function.Aggregate)
                    .AddAttribute("BuiltIn", function.BuiltIn)
                    .AddAttribute("CommandText", function.CommandText)
                    .AddAttribute("IsComposable", function.IsComposable)
                    .AddAttribute("NiladicFunction", function.NiladicFunction)
                    .AddAttribute("ReturnType", function.ReturnType)
                    .AddAttribute("StoreFunctionName", function.StoreFunctionName)
                    .AddAttribute("ParameterTypeSemantics", function.ParameterTypeSemantics)
                    .AddAttribute("Schema", function.Schema)
                    .AddAttribute(storeNamespace, "Name", function.StoreName)
                    .AddAttribute(storeNamespace, "Schema", function.StoreSchema)
                    .AddAttribute(storeNamespace, "Type", function.StoreType);

                foreach (FunctionParameter functionParameter in function.Parameters)
                {
                    functionElement.Add(new XElement(ssdlNamespace + "Parameter", 
                        new XAttribute("Name", functionParameter.Name), new XAttribute("Type", functionParameter.Type), new XAttribute("Mode", functionParameter.Mode))
                            .AddAttribute("MaxLength", functionParameter.MaxLength)
                            .AddAttribute("Precision", functionParameter.Precision)
                            .AddAttribute("Scale", functionParameter.Scale)
                            .AddAttribute(storeNamespace, "Name", functionParameter.StoreName)
                            .AddAttribute(storeNamespace, "Schema", functionParameter.StoreSchema)
                            .AddAttribute(storeNamespace, "Type", functionParameter.StoreType));
                }

                schema.Add(functionElement);
            }

            return schema;
        }
Exemple #15
0
        /// <summary>
        /// Converts the <see cref="T:WixSharp.Control"/> instance into WiX <see cref="T:System.Xml.Linq.XElement"/>.
        /// </summary>
        /// <returns><see cref="T:System.Xml.Linq.XElement"/> instance.</returns>
        public virtual XElement ToXElement()
        {
            var control =
                new XElement("Control",
                    new XAttribute("Id", this.Id),
                    new XAttribute("Width", this.Width),
                    new XAttribute("Height", this.Height),
                    new XAttribute("X", this.X),
                    new XAttribute("Y", this.Y),
                    new XAttribute("Type", this.Type))
                    .AddAttributes(this.Attributes);

            if (!Property.IsEmpty()) control.Add(new XAttribute("Property", this.Property));

            if (Hidden) control.Add(new XAttribute("Hidden", this.Hidden.ToYesNo()));

            if (Disabled) control.Add(new XAttribute("Disabled", this.Disabled.ToYesNo()));

            if (!Tooltip.IsEmpty()) control.Add(new XAttribute("ToolTip", this.Tooltip));
            if (!Text.IsEmpty()) control.Add(new XElement("Text", this.Text));

            if (!EmbeddedXML.IsEmpty())
            {
                foreach (var element in XDocument.Parse("<root>" + EmbeddedXML + "</root>").Root.Elements())
                    control.Add(element);
            }

            int index = 0;
            foreach (ControlActionData data in Actions)
            {
                index++;
                var publishElement = control.AddElement(new XElement("Publish",
                                                            new XAttribute("Value", data.Value),
                                                            new XAttribute("Order", index),
                                                            data.Condition));
                if (!data.Event.IsEmpty())
                    publishElement.Add(new XAttribute("Event", data.Event));

                if (!data.Property.IsEmpty())
                    publishElement.Add(new XAttribute("Property", data.Property));
            }

            foreach (WixControlCondition condition in Conditions)
            {
                control.AddElement(new XElement("Condition",
                                       new XAttribute("Action", condition.Action.ToString()),
                                       condition.Value));
            }

            return control;
        }
Exemple #16
0
        static void ProcessFeatures(Project project, XElement product, Dictionary<Feature, List<string>> featureComponents, List<string> autoGeneratedComponents, List<string> defaultFeatureComponents)
        {
            if (!featureComponents.ContainsKey(project.DefaultFeature))
            {
                featureComponents[project.DefaultFeature] = new List<string>(defaultFeatureComponents); //assign defaultFeatureComponents to the project's default Feature
            }
            else
            {
                foreach (string comp in defaultFeatureComponents)
                    featureComponents[project.DefaultFeature].Add(comp);
            }

            var feature2XML = new Dictionary<Feature, XElement>();

            //generate disconnected XML nodes
            foreach (Feature wFeature in featureComponents.Keys)
            {
                var comps = featureComponents[wFeature];

                XElement xFeature = new XElement("Feature",
                                                  new XAttribute("Id", wFeature.Id),
                                                  new XAttribute("Title", wFeature.Name),
                                                  new XAttribute("Absent", wFeature.AllowChange ? "allow" : "disallow"),
                                                  new XAttribute("Level", wFeature.IsEnabled ? "1" : "2"))
                                                  .AddAttributes(wFeature.Attributes);

                if (!wFeature.Description.IsEmpty())
                    xFeature.SetAttributeValue("Description", wFeature.Description);

                if (!wFeature.ConfigurableDir.IsEmpty())
                    xFeature.SetAttributeValue("ConfigurableDirectory", wFeature.ConfigurableDir);

                if (wFeature.Condition != null)
                    //intentionally leaving out AddAttributes(...) as Level is the only valid attribute on */Feature/Condition
                    xFeature.Add(
                        new XElement("Condition",
                            new XAttribute("Level", wFeature.Condition.Level),
                            new XCData(wFeature.Condition.ToCData())));

                foreach (string componentId in featureComponents[wFeature])
                    xFeature.Add(new XElement("ComponentRef",
                                    new XAttribute("Id", componentId)));

                foreach (string componentId in autoGeneratedComponents)
                    xFeature.Add(new XElement("ComponentRef",
                                    new XAttribute("Id", componentId)));

                feature2XML.Add(wFeature, xFeature);
            }

            //establish relationships
            foreach (Feature wFeature in featureComponents.Keys)
            {
                if (wFeature.Children.Count != 0)
                {
                    foreach (Feature wChild in wFeature.Children)
                    {
                        wChild.Parent = wFeature;
                        XElement xFeature = feature2XML[wFeature];

                        if (feature2XML.ContainsKey(wChild))
                        {
                            XElement xChild = feature2XML[wChild];
                            xFeature.Add(xChild);
                        }
                    }
                }
            }

            //remove childless features as they have non practical value
            feature2XML.Keys
                       .Where(x => !feature2XML[x].HasElements)
                       .ToArray()
                       .ForEach(key => feature2XML.Remove(key));

            var topLevelFeatures = feature2XML.Keys
                                              .Where(x=>x.Parent == null)
                                              .Select(x=>feature2XML[x]);

            foreach (XElement xFeature in topLevelFeatures)
            {
                product.AddElement(xFeature);
            }
        }
Exemple #17
0
        static void ProcessUpgradeStrategy(Project project, XElement product)
        {
            if (project.MajorUpgradeStrategy != null)
            {
                Func<string, string> ExpandVersion = (version) => version == "%this%" ? project.Version.ToString() : version;

                var upgradeElement = product.AddElement(
                    new XElement("Upgrade",
                       new XAttribute("Id", project.UpgradeCode)));

                if (project.MajorUpgradeStrategy.UpgradeVersions != null)
                {
                    VersionRange versions = project.MajorUpgradeStrategy.UpgradeVersions;

                    var upgradeVersion = upgradeElement.AddElement(
                        new XElement("UpgradeVersion",
                           new XAttribute("Minimum", ExpandVersion(versions.Minimum)),
                           new XAttribute("IncludeMinimum", versions.IncludeMinimum.ToYesNo()),
                           new XAttribute("Maximum", ExpandVersion(versions.Maximum)),
                           new XAttribute("IncludeMaximum", versions.IncludeMaximum.ToYesNo()),
                           new XAttribute("Property", "UPGRADEFOUND")));

                    if (versions.MigrateFeatures.HasValue)
                        upgradeVersion.SetAttributeValue("MigrateFeatures", versions.MigrateFeatures.Value.ToYesNo());
                }

                if (project.MajorUpgradeStrategy.PreventDowngradingVersions != null)
                {
                    VersionRange versions = project.MajorUpgradeStrategy.PreventDowngradingVersions;

                    var upgradeVersion = upgradeElement.AddElement(
                        new XElement("UpgradeVersion",
                               new XAttribute("Minimum", ExpandVersion(versions.Minimum)),
                               new XAttribute("IncludeMinimum", versions.IncludeMinimum.ToYesNo()),
                               new XAttribute("OnlyDetect", "yes"),
                               new XAttribute("Property", "NEWPRODUCTFOUND")));

                    if (versions.MigrateFeatures.HasValue)
                        upgradeVersion.SetAttributeValue("MigrateFeatures", versions.MigrateFeatures.Value.ToYesNo());

                    var installExec = product.SelectOrCreate("InstallExecuteSequence");
                    var installUI = product.SelectOrCreate("InstallUISequence");

                    bool preventDowngrading = (project.MajorUpgradeStrategy.NewerProductInstalledErrorMessage != null);

                    if (preventDowngrading)
                    {
                        product.Add(new XElement("CustomAction",
                                        new XAttribute("Id", "PreventDowngrading"),
                                        new XAttribute("Error", project.MajorUpgradeStrategy.NewerProductInstalledErrorMessage)));

                        installExec.Add(new XElement("Custom", "NEWPRODUCTFOUND",
                                            new XAttribute("Action", "PreventDowngrading"),
                                            new XAttribute("After", "FindRelatedProducts")));

                        installUI.Add(new XElement("Custom", "NEWPRODUCTFOUND",
                                          new XAttribute("Action", "PreventDowngrading"),
                                          new XAttribute("After", "FindRelatedProducts")));
                    }

                    installExec.Add(new XElement("RemoveExistingProducts",
                                        new XAttribute("After", project.MajorUpgradeStrategy.RemoveExistingProductAfter.ToString())));
                }
            }
        }
Exemple #18
0
        static void ProcessDirectoryShortcuts(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem)
        {
            //insert directory owned shortcuts
            foreach (Shortcut wShortcut in wDir.Shortcuts)
            {
                string compId = wShortcut.Id;
                if (wShortcut.Feature != null)
                {
                    if (!featureComponents.ContainsKey(wShortcut.Feature))
                        featureComponents[wShortcut.Feature] = new List<string>();

                    featureComponents[wShortcut.Feature].Add(compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                   new XElement("Component",
                       new XAttribute("Id", compId),
                       new XAttribute("Guid", WixGuid.NewGuid(compId))));

                if (wShortcut.Condition != null)
                    comp.AddElement(
                        new XElement("Condition", wShortcut.Condition.ToCData())
                            .AddAttributes(wShortcut.Condition.Attributes));

                XElement sc;
                sc = comp.AddElement(
                   new XElement("Shortcut",
                       new XAttribute("Id", wDir.Id + "." + wShortcut.Id),
                       //new XAttribute("Directory", wDir.Id), //not needed for Wix# as this attributed is required only if the shortcut is not nested under a Component element.
                       new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : GetShortcutWorkingDirectopry(wShortcut.Target)),
                       new XAttribute("Target", wShortcut.Target),
                       new XAttribute("Arguments", wShortcut.Arguments),
                       new XAttribute("Name", wShortcut.Name + ".lnk")));

                wShortcut.EmitAttributes(sc);
            }
        }
Exemple #19
0
        static void PostProcessMsm(Project project, XElement product)
        {
            var modules = from dir in project.AllDirs
                          from msm in dir.MergeModules
                          select new
                          {
                              Feature = msm.Feature,
                              MsmId = msm.Id
                          };

            var features = (from f in product.Elements("Feature")
                            select f)
                           .ToDictionary(x => x.Attribute("Id").Value);

            foreach (var item in modules)
            {
                XElement xFeature;

                if (item.Feature == null)
                {
                    if (features.ContainsKey("Complete"))
                        xFeature = features["Complete"];
                    else
                        throw new Exception("Merge Module " + item.MsmId + " does not belong to any feature and \"Complete\" feature is not found");
                }
                else
                {
                    if (features.ContainsKey(item.Feature.Id))
                        xFeature = features[item.Feature.Id];
                    else
                        xFeature = product.AddElement(
                                             new XElement("Feature",
                                                 new XAttribute("Id", item.Feature.Id),
                                                 new XAttribute("Title", item.Feature.Name),
                                                 new XAttribute("Absent", item.Feature.AllowChange ? "allow" : "disallow"),
                                                 new XAttribute("Level", item.Feature.IsEnabled ? "1" : "2"))
                                                 .AddAttributes(item.Feature.Attributes));
                }

                xFeature.Add(new XElement("MergeRef",
                                 new XAttribute("Id", item.MsmId)));
            }
        }
Exemple #20
0
        static void ProcessFeatures(Project project, XElement product, Dictionary<Feature, List<string>> featureComponents, List<string> autoGeneratedComponents, List<string> defaultFeatureComponents)
        {
            if (!featureComponents.ContainsKey(project.DefaultFeature))
            {
                featureComponents[project.DefaultFeature] = new List<string>(defaultFeatureComponents); //assign defaultFeatureComponents to the project's default Feature
            }
            else
            {
                foreach (string comp in defaultFeatureComponents)
                    featureComponents[project.DefaultFeature].Add(comp);
            }

            var feature2XML = new Dictionary<Feature, XElement>();

            //generate disconnected XML nodes
            foreach (Feature wFeature in featureComponents.Keys)
            {
                var comps = featureComponents[wFeature];

                XElement xFeature = wFeature.ToXml();

                foreach (string componentId in featureComponents[wFeature])
                    xFeature.Add(new XElement("ComponentRef",
                                    new XAttribute("Id", componentId)));

                foreach (string componentId in autoGeneratedComponents)
                    xFeature.Add(new XElement("ComponentRef",
                                    new XAttribute("Id", componentId)));

                feature2XML.Add(wFeature, xFeature);
            }

            //establish relationships
            foreach (Feature wFeature in featureComponents.Keys)
            {
                if (wFeature.Children.Count != 0)
                {
                    foreach (Feature wChild in wFeature.Children)
                    {
                        wChild.Parent = wFeature;
                        XElement xFeature = feature2XML[wFeature];

                        if (feature2XML.ContainsKey(wChild))
                        {
                            XElement xChild = feature2XML[wChild];
                            xFeature.Add(xChild);
                        }
                    }
                }
            }

            //remove childless features as they have non practical value
            feature2XML.Keys
                       .Where(x => !feature2XML[x].HasElements)
                       .ToArray()
                       .ForEach(key => feature2XML.Remove(key));

            var topLevelFeatures = feature2XML.Keys
                                              .Where(x => x.Parent == null)
                                              .Select(x => feature2XML[x])
                                              .ToArray();

            foreach (XElement xFeature in topLevelFeatures)
            {
                product.AddElement(xFeature);
            }
        }
Exemple #21
0
        static void InsertIISElements(XElement dirItem, XElement component, IISVirtualDir[] wVDirs, Project project)
        {
            //http://ranjithk.com/2009/12/17/automating-web-deployment-using-windows-installer-xml-wix/

            XNamespace ns = "http://schemas.microsoft.com/wix/IIsExtension";

            string dirID = dirItem.Attribute("Id").Value;
            var xProduct = component.Parent("Product");

            var uniqueWebSites = new List<WebSite>();

            bool wasInserted = true;
            foreach (IISVirtualDir wVDir in wVDirs)
            {
                wasInserted = true;

                XElement xWebApp;
                var xVDir = component.AddElement(new XElement(ns + "WebVirtualDir",
                                                     new XAttribute("Id", wVDir.Name.Expand()),
                                                     new XAttribute("Alias", wVDir.Alias.IsEmpty() ? wVDir.Name : wVDir.Alias),
                                                     new XAttribute("Directory", dirID),
                                                     new XAttribute("WebSite", wVDir.WebSite.Name.Expand()),
                                                     xWebApp = new XElement(ns + "WebApplication",
                                                         new XAttribute("Id", wVDir.AppName.Expand() + "WebApplication"),
                                                         new XAttribute("Name", wVDir.AppName))));
                if (wVDir.AllowSessions.HasValue)
                    xWebApp.Add(new XAttribute("AllowSessions", wVDir.AllowSessions.Value.ToYesNo()));
                if (wVDir.Buffer.HasValue)
                    xWebApp.Add(new XAttribute("Buffer", wVDir.Buffer.Value.ToYesNo()));
                if (wVDir.ClientDebugging.HasValue)
                    xWebApp.Add(new XAttribute("ClientDebugging", wVDir.ClientDebugging.Value.ToYesNo()));
                if (wVDir.DefaultScript.HasValue)
                    xWebApp.Add(new XAttribute("DefaultScript", wVDir.DefaultScript.Value.ToString()));
                if (wVDir.Isolation.HasValue)
                    xWebApp.Add(new XAttribute("Isolation", wVDir.Isolation.Value.ToString()));
                if (wVDir.ParentPaths.HasValue)
                    xWebApp.Add(new XAttribute("ParentPaths", wVDir.ParentPaths.Value.ToYesNo()));
                if (wVDir.ScriptTimeout.HasValue)
                    xWebApp.Add(new XAttribute("ScriptTimeout", wVDir.ScriptTimeout.Value));
                if (wVDir.ServerDebugging.HasValue)
                    xWebApp.Add(new XAttribute("ServerDebugging", wVDir.ServerDebugging.Value.ToYesNo()));
                if (wVDir.SessionTimeout.HasValue)
                    xWebApp.Add(new XAttribute("SessionTimeout", wVDir.SessionTimeout.Value));

                //do not create WebSite on IIS but install WebApp into existing
                if (!wVDir.WebSite.InstallWebSite)
                {
                    if (!uniqueWebSites.Contains(wVDir.WebSite))
                        uniqueWebSites.Add(wVDir.WebSite);
                }
                else
                {
                    InsertWebSite(wVDir.WebSite, dirID, component);
                }

                if (wVDir.WebAppPool != null)
                {
                    var id = wVDir.Name.Expand() + "_AppPool";

                    xWebApp.Add(new XAttribute("WebAppPool", id));

                    var xAppPool = component.AddElement(new XElement(ns + "WebAppPool",
                                                            new XAttribute("Id", id),
                                                            new XAttribute("Name", wVDir.WebAppPool.Name)));

                    xAppPool.AddAttributes(wVDir.WebAppPool.Attributes);
                }

                if (wVDir.WebDirProperties != null)
                {
                    var propId = wVDir.Name.Expand() + "_WebDirProperties";

                    var xDirProp = xProduct.AddElement(new XElement(ns + "WebDirProperties",
                                                           new XAttribute("Id", propId)));

                    xDirProp.AddAttributes(wVDir.WebDirProperties.Attributes);

                    xVDir.Add(new XAttribute("DirProperties", propId));
                }
            }

            foreach (WebSite webSite in uniqueWebSites)
            {
                InsertWebSite(webSite, dirID, xProduct);
            }

            if (wasInserted)
            {
                if (!project.WixExtensions.Contains("WixIIsExtension.dll"))
                    project.WixExtensions.Add("WixIIsExtension.dll");

                if (!project.WixNamespaces.Contains("xmlns:iis=\"http://schemas.microsoft.com/wix/IIsExtension\""))
                    project.WixNamespaces.Add("xmlns:iis=\"http://schemas.microsoft.com/wix/IIsExtension\"");
            }
        }
Exemple #22
0
        static void ProcessMergeModules(Dir wDir, XElement dirItem, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents)
        {
            foreach (Merge msm in wDir.MergeModules)
            {
                XElement media = dirItem.Parent("Product").Select("Media");
                XElement package = dirItem.Parent("Product").Select("Package");

                string language = package.Attribute("Languages").Value; //note Wix# expects package.Attribute("Languages") to have a single value (yest it is a temporary limitation)
                string diskId = media.Attribute("Id").Value;

                XElement merge = dirItem.AddElement(
                    new XElement("Merge",
                        new XAttribute("Id", msm.Id),
                        new XAttribute("FileCompression", msm.FileCompression.ToYesNo()),
                        new XAttribute("Language", language),
                        new XAttribute("SourceFile", msm.SourceFile),
                        new XAttribute("DiskId", diskId))
                        .AddAttributes(msm.Attributes));

                //MSM features are very different as they are not associated with the component but with the merge module thus
                //it's not possible to add the feature 'child' MergeRef neither to featureComponents nor defaultFeatureComponents.
                //Instead we'll let PostProcessMsm to handle it because ProcessFeatures cannot do this. It will ignore this feature
                //as it has no nested elements.
                //Not elegant at all but works.
                //In the future it can be improved by allowing MergeRef to be added in the global collection featureMergeModules/DefaultfeatureComponents.
                //Then PostProcessMsm will not be needed.
                if (msm.Feature != null && !featureComponents.ContainsKey(msm.Feature))
                    featureComponents[msm.Feature] = new List<string>();
            }
        }
Exemple #23
0
        /// <summary>
        /// Processes the custom actions.
        /// </summary>
        /// <param name="wProject">The w project.</param>
        /// <param name="product">The product.</param>
        /// <exception cref="System.Exception">Step.PreviousAction is specified for the very first 'Custom Action'.\nThere cannot be any previous action as it is the very first one in the sequence.</exception>
        static void ProcessCustomActions(Project wProject, XElement product)
        {
            string lastActionName = null;

            foreach (Action wAction in wProject.Actions)
            {
                string step = wAction.Step.ToString();

                if (wAction.When == When.After && wAction.Step == Step.PreviousAction)
                {
                    if (lastActionName == null)
                        throw new Exception("Step.PreviousAction is specified for the very first 'Custom Action'.\nThere cannot be any previous action as it is the very first one in the sequence.");
                    step = lastActionName;
                }
                else if (wAction.When == When.After && wAction.Step == Step.PreviousActionOrInstallFinalize)
                    step = lastActionName ?? Step.InstallFinalize.ToString();
                else if (wAction.When == When.After && wAction.Step == Step.PreviousActionOrInstallInitialize)
                    step = lastActionName ?? Step.InstallInitialize.ToString();

                lastActionName = wAction.Name.Expand();

                List<XElement> sequences = new List<XElement>();

                if (wAction.Sequence != Sequence.NotInSequence)
                {
                    foreach (var item in wAction.Sequence.GetValues())
                        sequences.Add(product.SelectOrCreate(item));
                }

                XAttribute sequenceNumberAttr = wAction.SequenceNumber.HasValue ?
                                                    new XAttribute("Sequence", wAction.SequenceNumber.Value) :
                                                    new XAttribute(wAction.When.ToString(), step);

                if (wAction is SetPropertyAction)
                {
                    var wSetPropAction = (SetPropertyAction)wAction;

                    var actionId = wSetPropAction.Id;
                    lastActionName = actionId; //overwrite previously set standard CA name

                    product.AddElement(
                        new XElement("CustomAction",
                            new XAttribute("Id", actionId),
                            new XAttribute("Property", wSetPropAction.PropName),
                            new XAttribute("Value", wSetPropAction.Value))
                            .AddAttributes(wSetPropAction.Attributes));

                    sequences.ForEach(sequence =>
                        sequence.Add(new XElement("Custom", wAction.Condition.ToString(),
                                         new XAttribute("Action", actionId),
                                         sequenceNumberAttr)));
                }
                else if (wAction is ScriptFileAction)
                {
                    var wScriptAction = (ScriptFileAction)wAction;

                    sequences.ForEach(sequence =>
                         sequence.Add(new XElement("Custom", wAction.Condition.ToString(),
                                          new XAttribute("Action", wAction.Id),
                                          sequenceNumberAttr)));

                    product.Add(new XElement("Binary",
                                    new XAttribute("Id", wAction.Name.Expand() + "_File"),
                                    new XAttribute("SourceFile", Utils.PathCombine(wProject.SourceBaseDir, wScriptAction.ScriptFile))));

                    product.Add(new XElement("CustomAction",
                                    new XAttribute("Id", wAction.Name.Expand()),
                                    new XAttribute("BinaryKey", wAction.Name.Expand() + "_File"),
                                    new XAttribute("VBScriptCall", wScriptAction.Procedure),
                                    new XAttribute("Return", wAction.Return))
                                    .AddAttributes(wAction.Attributes));
                }
                else if (wAction is ScriptAction)
                {
                    var wScriptAction = (ScriptAction)wAction;

                    sequences.ForEach(sequence =>
                        sequence.Add(new XElement("Custom", wAction.Condition.ToString(),
                                       new XAttribute("Action", wAction.Id),
                                       sequenceNumberAttr)));

                    product.Add(new XElement("CustomAction",
                                    new XCData(wScriptAction.Code),
                                    new XAttribute("Id", wAction.Name.Expand()),
                                    new XAttribute("Script", "vbscript"),
                                    new XAttribute("Return", wAction.Return))
                                    .AddAttributes(wAction.Attributes));
                }
                else if (wAction is ManagedAction)
                {
                    var wManagedAction = (ManagedAction)wAction;
                    var asmFile = Utils.PathCombine(wProject.SourceBaseDir, wManagedAction.ActionAssembly);
                    var packageFile = asmFile.PathChangeDirectory(wProject.OutDir.PathGetFullPath())
                                             .PathChangeExtension(".CA.dll");

                    var existingBinary = product.Descendants("Binary")
                                                .Where(e => e.Attribute("SourceFile").Value == packageFile)
                                                .FirstOrDefault();

                    string bynaryKey;

                    if (existingBinary == null)
                    {
                        PackageManagedAsm(
                            asmFile,
                            packageFile,
                            wManagedAction.RefAssemblies.Concat(wProject.DefaultRefAssemblies).Distinct().ToArray(),
                            wProject.OutDir,
                            wProject.CustomActionConfig,
                            wProject.Platform);

                        bynaryKey = wAction.Name.Expand() + "_File";
                        product.Add(new XElement("Binary",
                                        new XAttribute("Id", bynaryKey),
                                        new XAttribute("SourceFile", packageFile)));
                    }
                    else
                    {
                        bynaryKey = existingBinary.Attribute("Id").Value;
                    }

                    if (wManagedAction.Execute == Execute.deferred && wManagedAction.UsesProperties != null) //map managed action properties
                    {
                        string mapping = wManagedAction.ExpandAllUsedProperties();

                        if (!mapping.IsEmpty())
                        {
                            var setPropValuesId = "Set_" + wAction.Id + "_Props";

                            product.Add(new XElement("CustomAction",
                                            new XAttribute("Id", setPropValuesId),
                                            new XAttribute("Property", wAction.Id),
                                            new XAttribute("Value", mapping)));

                            sequences.ForEach(sequence =>
                                sequence.Add(
                                    new XElement("Custom",
                                        new XAttribute("Action", setPropValuesId),
                                        wAction.SequenceNumber.HasValue ?
                                            new XAttribute("Sequence", wAction.SequenceNumber.Value) :
                                            new XAttribute("After", "InstallInitialize"))));
                        }
                    }

                    sequences.ForEach(sequence =>
                        sequence.Add(new XElement("Custom", wAction.Condition.ToString(),
                                         new XAttribute("Action", wAction.Id),
                                         sequenceNumberAttr)));

                    product.Add(new XElement("CustomAction",
                                    new XAttribute("Id", wAction.Id),
                                    new XAttribute("BinaryKey", bynaryKey),
                                    new XAttribute("DllEntry", wManagedAction.MethodName),
                                    new XAttribute("Impersonate", wAction.Impersonate.ToYesNo()),
                                    new XAttribute("Execute", wAction.Execute),
                                    new XAttribute("Return", wAction.Return))
                                    .AddAttributes(wAction.Attributes));
                }
                else if (wAction is QtCmdLineAction)
                {
                    var cmdLineAction = (QtCmdLineAction)wAction;
                    var cmdLineActionId = wAction.Name.Expand();
                    var setCmdLineActionId = "Set_" + cmdLineActionId + "_CmdLine";

                    product.AddElement(
                        new XElement("CustomAction",
                            new XAttribute("Id", setCmdLineActionId),
                            new XAttribute("Property", "QtExecCmdLine"),
                            new XAttribute("Value", "\"" + cmdLineAction.AppPath.ExpandCommandPath() + "\" " + cmdLineAction.Args.ExpandCommandPath()))
                            .AddAttributes(cmdLineAction.Attributes));

                    product.AddElement(
                        new XElement("CustomAction",
                            new XAttribute("Id", cmdLineActionId),
                            new XAttribute("BinaryKey", "WixCA"),
                            new XAttribute("DllEntry", "CAQuietExec"),
                            new XAttribute("Impersonate", wAction.Impersonate.ToYesNo()),
                            new XAttribute("Execute", wAction.Execute),
                            new XAttribute("Return", wAction.Return)));

                    lastActionName = cmdLineActionId;

                    sequences.ForEach(sequence =>
                        sequence.Add(
                            new XElement("Custom", wAction.Condition.ToString(),
                                new XAttribute("Action", setCmdLineActionId),
                                sequenceNumberAttr)));

                    sequences.ForEach(sequence =>
                        sequence.Add(
                            new XElement("Custom", wAction.Condition.ToString(),
                                new XAttribute("Action", cmdLineActionId),
                                new XAttribute("After", setCmdLineActionId))));

                    var extensionAssembly = Utils.PathCombine(WixLocation, @"WixUtilExtension.dll");
                    if (wProject.WixExtensions.Find(x => x == extensionAssembly) == null)
                        wProject.WixExtensions.Add(extensionAssembly);
                }
                else if (wAction is InstalledFileAction)
                {
                    var fileAction = (InstalledFileAction)wAction;

                    sequences.ForEach(sequence =>
                        sequence.Add(
                            new XElement("Custom", wAction.Condition.ToString(),
                                new XAttribute("Action", wAction.Id),
                                sequenceNumberAttr)));

                    var actionElement = product.AddElement(
                        new XElement("CustomAction",
                            new XAttribute("Id", wAction.Name.Expand()),
                            new XAttribute("ExeCommand", fileAction.Args.ExpandCommandPath()),
                            new XAttribute("Return", wAction.Return))
                            .AddAttributes(wAction.Attributes));

                    actionElement.Add(new XAttribute("FileKey", fileAction.Key));
                }
                else if (wAction is BinaryFileAction)
                {
                    var binaryAction = (BinaryFileAction)wAction;

                    sequences.ForEach(sequence =>
                        sequence.Add(
                            new XElement("Custom", wAction.Condition.ToString(),
                                new XAttribute("Action", wAction.Id),
                                sequenceNumberAttr)));

                    var actionElement = product.AddElement(
                        new XElement("CustomAction",
                            new XAttribute("Id", wAction.Name.Expand()),
                            new XAttribute("ExeCommand", binaryAction.Args.ExpandCommandPath()),
                            new XAttribute("Impersonate", wAction.Impersonate.ToYesNo()),
                            new XAttribute("Execute", wAction.Execute),
                            new XAttribute("Return", wAction.Return))
                            .AddAttributes(wAction.Attributes));

                    actionElement.Add(new XAttribute("BinaryKey", binaryAction.Key));
                }
                else if (wAction is PathFileAction)
                {
                    var fileAction = (PathFileAction)wAction;

                    sequences.ForEach(sequence =>
                        sequence.Add(
                            new XElement("Custom", fileAction.Condition.ToString(),
                                new XAttribute("Action", fileAction.Id),
                                sequenceNumberAttr)));

                    var actionElement = product.AddElement(
                        new XElement("CustomAction",
                            new XAttribute("Id", fileAction.Name.Expand()),
                            new XAttribute("ExeCommand", "\"" + fileAction.AppPath.ExpandCommandPath() + "\" " + fileAction.Args.ExpandCommandPath()),
                            new XAttribute("Return", wAction.Return))
                            .AddAttributes(fileAction.Attributes));

                    Dir installedDir = Array.Find(wProject.Dirs, (x) => x.Name == fileAction.WorkingDir);
                    if (installedDir != null)
                        actionElement.Add(new XAttribute("Directory", installedDir.Id));
                    else
                        actionElement.Add(new XAttribute("Directory", fileAction.WorkingDir.Expand()));
                }
            }
        }
Exemple #24
0
        static void ProcessOdbcSources(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem)
        {
            foreach (ODBCDataSource wODBCDataSource in wDir.ODBCDataSources)
            {
                string dsnId = wODBCDataSource.Id;
                string compId = "Component." + wODBCDataSource.Id;

                if (wODBCDataSource.Feature != null)
                {
                    if (!featureComponents.ContainsKey(wODBCDataSource.Feature))
                        featureComponents[wODBCDataSource.Feature] = new List<string>();

                    featureComponents[wODBCDataSource.Feature].Add(compId);
                }
                else
                {
                    defaultFeatureComponents.Add(compId);
                }

                XElement comp = dirItem.AddElement(
                   new XElement("Component",
                       new XAttribute("Id", compId),
                       new XAttribute("Guid", WixGuid.NewGuid(compId))));

                XElement dsn = comp.AddElement(
                    new XElement("ODBCDataSource",
                        new XAttribute("Id", wODBCDataSource.Id),
                        new XAttribute("Name", wODBCDataSource.Name),
                        new XAttribute("DriverName", wODBCDataSource.DriverName),
                        new XAttribute("KeyPath", wODBCDataSource.KeyPath.ToYesNo()),
                        new XAttribute("Registration", (wODBCDataSource.PerMachineRegistration ? "machine" : "user"))));

                foreach (Property prop in wODBCDataSource.Properties)
                {
                    dsn.AddElement(
                        new XElement("Property",
                                    new XAttribute("Id", prop.Name),
                                    new XAttribute("Value", prop.Value)));
                }
            }
        }
Exemple #25
0
        public static XElement Write(EDM edm)
        {
            CSDLContainer csdlContainer = edm.CSDLContainer;
            string entityContainerNamespace = string.Concat(csdlContainer.Namespace, ".");

            // Instantiate Mapping
            XElement mapping = new XElement(mslNamespace + "Mapping",
                new XAttribute("Space", "C-S"));

            // EntityContainerMapping
            XElement entityContainerMapping = new XElement(mslNamespace + "EntityContainerMapping", 
                new XAttribute("StorageEntityContainer", edm.SSDLContainer.Name),
                new XAttribute("CdmEntityContainer", csdlContainer.Name));

            foreach (EntityType entitySet in csdlContainer.EntitySets)
            {
                IEnumerable<EntityType> entityTypes = csdlContainer.EntityTypes.Where(entityType => entityType.EntitySetName == entitySet.EntitySetName);

                // EntityContainerMapping : EntitySetMapping
                XElement entitySetMappingElement = new XElement(mslNamespace + "EntitySetMapping", 
                    new XAttribute("Name", entitySet.Name));

                // EntityContainerMapping : EntitySetMapping : EntityTypeMapping
                foreach (EntityType entityType in entityTypes)
                {
                    XElement entityTypeMappingElement = new XElement(mslNamespace + "EntityTypeMapping", 
                        new XAttribute("TypeName", string.Format("IsTypeOf({0}{1})", entityContainerNamespace, entityType.Name)));

                    // EntityContainerMapping : EntitySetMapping : EntityTypeMapping : MappingFragment
                    foreach (EDMObjects.SSDL.EntityType.EntityType table in entityType.Mapping.MappedSSDLTables)
                    { 
                        XElement mappingFragmentElement = new XElement(mslNamespace + "MappingFragment", 
                            new XAttribute("StoreEntitySet", table.EntitySetName));

                        IEnumerable<PropertyMapping> scalarMappings = entityType.Mapping.GetSpecificMappingForTable(table);

                        foreach (PropertyMapping scalarMapping in scalarMappings)
                        {
                            mappingFragmentElement.AddElement(new XElement(mslNamespace + "ScalarProperty",
                                new XAttribute("Name", scalarMapping.Property.Name),
                                new XAttribute("ColumnName", scalarMapping.Column.Name)));
                        }

                        mappingFragmentElement.Add(MappingComplexProperties(entityType, entityType.Mapping, table, entityContainerNamespace));

                        IEnumerable<ConditionMapping> conditionMappings = entityType.Mapping.ConditionsMapping.Where(condition => condition.Table == table);

                        foreach (ConditionMapping conditionMapping in conditionMappings)
                        {
                            XElement conditionElement = new XElement(mslNamespace + "Condition");

                            if (conditionMapping is ColumnConditionMapping)
                                conditionElement.AddAttribute("ColumnName", (conditionMapping as ColumnConditionMapping).Column.Name);
                            else if (conditionMapping is PropertyConditionMapping)
                                conditionElement.AddAttribute("Name", (conditionMapping as PropertyConditionMapping).CSDLProperty.Name);

                            mappingFragmentElement.Add(conditionElement.AddMappingConditionAttribute(conditionMapping));
                        }

                        entityTypeMappingElement.Add(mappingFragmentElement);
                    }

                    entitySetMappingElement.Add(entityTypeMappingElement);
                }

                // EntityContainerMapping : EntitySetMapping : CUDFunctionMapping
                foreach (EntityType entityType in entityTypes)
                {
                    entitySetMappingElement.Add(CUDFunctionMapping(entityType, entityContainerNamespace, string.Concat(edm.SSDLContainer.Namespace, ".")));
                }

                entityContainerMapping.Add(entitySetMappingElement);
            }

            // EntityContainerMapping : AssociationSetMappings
            IEnumerable<Association> associations = csdlContainer.Associations.Where(association => association.Mapping.SSDLTableMapped != null);

            foreach (Association association in associations)
            {
                XElement associationSetMappingElement = new XElement(mslNamespace + "AssociationSetMapping",
                    new XAttribute("Name", association.AssociationSetName),
                    new XAttribute("TypeName", string.Concat(entityContainerNamespace, association.Name)),
                    new XAttribute("StoreEntitySet", association.Mapping.SSDLTableMapped.Name));

                XElement endPropertyElement1 = new XElement(mslNamespace + "EndProperty",
                    new XAttribute("Name", association.PropertyEnd1Role));

                foreach (PropertyMapping navigationPropertyMapping in association.PropertyEnd1.Mapping)
                {
                    endPropertyElement1.AddElement(new XElement(mslNamespace + "ScalarProperty",
                        new XAttribute("Name", navigationPropertyMapping.Property.Name),
                        new XAttribute("ColumnName", navigationPropertyMapping.Column.Name)));
                }

                XElement endPropertyElement2 = new XElement(mslNamespace + "EndProperty",
                    new XAttribute("Name", association.PropertyEnd2Role));

                foreach (PropertyMapping navigationPropertyMapping in association.PropertyEnd2.Mapping)
                {
                    endPropertyElement2.AddElement(new XElement(mslNamespace + "ScalarProperty",
                        new XAttribute("Name", navigationPropertyMapping.Property.Name),
                        new XAttribute("ColumnName", navigationPropertyMapping.Column.Name)));
                }

                associationSetMappingElement.Add(endPropertyElement1);
                associationSetMappingElement.Add(endPropertyElement2);

                entityContainerMapping.Add(associationSetMappingElement);
            }

            // EntityContainerMapping : Conditions
            foreach (Function function in csdlContainer.Functions)
            {
                entityContainerMapping.Add(new XElement(mslNamespace + "FunctionImportMapping",
                    new XAttribute("FunctionImportName", function.Name),
                    new XAttribute("FunctionName", string.Format("{0}.{1}", edm.SSDLContainer.Namespace, function.SSDLFunction.Name))));
            }

            return mapping.AddElement(entityContainerMapping);
        }
Exemple #26
0
        public static XElement Write(EDMView edmView)
        {
            XElement connectionElement = null;
            XElement optionsElement = null;

            if (edmView.EDM.DesignerProperties == null || edmView.EDM.DesignerProperties.FirstOrDefault(dp => dp.Name == "MetadataArtifactProcessing") == null)
            {
                List<DesignerProperty> standardDesignerProperties = null;

                if (edmView.EDM.DesignerProperties == null)
                    standardDesignerProperties = new List<DesignerProperty>();
                else
                    standardDesignerProperties = edmView.EDM.DesignerProperties.ToList();

                standardDesignerProperties.Add(new DesignerProperty() { Name = "MetadataArtifactProcessing", Value = "EmbedInOutputAssembly" });

                edmView.EDM.DesignerProperties = standardDesignerProperties;
            }

            connectionElement = new XElement(edmxNamespace + "Connection");
            XElement designerInfoPropertyElement1 = new XElement(edmxNamespace + "DesignerInfoPropertySet");
            connectionElement.Add(designerInfoPropertyElement1);

            foreach (DesignerProperty designerProperty in edmView.EDM.DesignerProperties)
            {
                designerInfoPropertyElement1.Add(new XElement(edmxNamespace + "DesignerProperty",
                    new XAttribute("Name", designerProperty.Name),
                    new XAttribute("Value", designerProperty.Value)));
            }

            optionsElement = new XElement(edmxNamespace + "Options");
            XElement designerInfoPropertyElement2 = new XElement(edmxNamespace + "DesignerInfoPropertySet");
            optionsElement.Add(designerInfoPropertyElement2);

            foreach (DesignerProperty designerProperty in edmView.EDM.DesignerProperties)
            {
                designerInfoPropertyElement2.Add(new XElement(edmxNamespace + "DesignerProperty",
                    new XAttribute("Name", designerProperty.Name),
                    new XAttribute("Value", designerProperty.Value)));
            }

            XElement designerElement = new XElement(edmxNamespace + "Designer")
                .AddElement(connectionElement)
                .AddElement(optionsElement);

            //if (edmView.EDM.EDMXDesignerDiagrams != null)
            //    designerElement.AddElement(new XElement(edmxNamespace + "Diagrams", edmView.EDM.EDMXDesignerDiagrams));
            //else
                designerElement.AddElement(new XElement(edmxNamespace + "Diagrams", Write(edmView.DesignerViews)));

            return designerElement;
        }
Exemple #27
0
        private static XElement CUDFunctionMapping(EntityType entityType, string entityContainerNamespace, string storeContainerNamespace)
        {
            EntityTypeMapping mapping = entityType.Mapping;

            if (mapping.InsertFunctionMapping == null || mapping.UpdateFunctionMapping == null || mapping.DeleteFunctionMapping == null)
                return null;

            XElement modificationFunctionMapping = new XElement(mslNamespace + "ModificationFunctionMapping");

            var insertFunction = mapping.InsertFunctionMapping;

            if (insertFunction != null)
            {
                XElement insertFunctionElement = new XElement(mslNamespace + "InsertFunction",
                    new XAttribute("FunctionName", string.Concat(storeContainerNamespace, insertFunction.SSDLFunction.Name)));

                insertFunctionElement.Add(CUDFunctionMappingAssociation(insertFunction));
                insertFunctionElement.Add(CUDFunctionMappingParameters(insertFunction));
                insertFunctionElement.Add(CUDFunctionMappingResults(insertFunction));

                modificationFunctionMapping.AddElement(insertFunctionElement);
            }

            var updateFunction = mapping.UpdateFunctionMapping;

            if (updateFunction != null)
            {
                XElement updateFunctionElement = new XElement(mslNamespace + "UpdateFunction",
                    new XAttribute("FunctionName", string.Concat(storeContainerNamespace, updateFunction.SSDLFunction.Name)));

                updateFunctionElement.Add(CUDFunctionMappingAssociation(updateFunction));
                updateFunctionElement.Add(CUDFunctionMappingParameters(updateFunction));
                updateFunctionElement.Add(CUDFunctionMappingResults(updateFunction));

                modificationFunctionMapping.AddElement(updateFunctionElement);
            }

            var deleteFunction = mapping.DeleteFunctionMapping;

            if (deleteFunction != null)
            {
                XElement deleteFunctionElement = new XElement(mslNamespace + "DeleteFunction",
                    new XAttribute("FunctionName", string.Concat(storeContainerNamespace, deleteFunction.SSDLFunction.Name)));

                deleteFunctionElement.Add(CUDFunctionMappingAssociation(deleteFunction));
                deleteFunctionElement.Add(CUDFunctionMappingParameters(deleteFunction));
                deleteFunctionElement.Add(CUDFunctionMappingResults(deleteFunction));

                modificationFunctionMapping.AddElement(deleteFunctionElement);
            }

            return new XElement(mslNamespace + "EntityTypeMapping",
                new XAttribute("TypeName", string.Concat(entityContainerNamespace, entityType.Name)),
                modificationFunctionMapping);
        }
Exemple #28
0
        /// <summary>
        /// Emits WiX XML.
        /// </summary>
        /// <returns></returns>
        public XContainer[] ToXml()
        {
            var result = new List<XContainer>();

            var root = new XElement("Bundle",
                           new XAttribute("Name", Name));

            root.AddAttributes(this.Attributes);
            root.Add(this.MapToXmlAttributes());

            if (Application is ManagedBootstrapperApplication)
            {
                var app = Application as ManagedBootstrapperApplication;
                if (app.PrimaryPackageId == null)
                {
                    var lastPackage = Chain.OfType<WixSharp.Bootstrapper.Package>().LastOrDefault();
                    if (lastPackage != null)
                    {
                        lastPackage.EnsureId();
                        app.PrimaryPackageId = lastPackage.Id;
                    }
                }
            }

            //important to call AutoGenerateSources after PrimaryPackageId is set
            Application.AutoGenerateSources(this.OutDir);

            root.Add(Application.ToXml());

            string variabes = this.StringVariablesDefinition +";"+ Application.StringVariablesDefinition;

            foreach (var entry in variabes.ToDictionary())
            {
                root.AddElement("Variable", "Name=" + entry.Key + ";Value=" + entry.Value + ";Persisted=yes;Type=string");
            }

            var xChain = root.AddElement("Chain");
            foreach (var item in this.Chain)
                xChain.Add(item.ToXml());

            xChain.SetAttribute("DisableRollback", DisableRollback);
            xChain.SetAttribute("DisableSystemRestore", DisableSystemRestore);
            xChain.SetAttribute("ParallelCache", ParallelCache);

            result.Add(root);
            return result.ToArray();
        }