Immediate custom action is what I am trying to do.  I have no need for it to be 
deferred.


-----Original Message-----
From: John Cooper [mailto:jocoo...@jackhenry.com] 
Sent: Thursday, February 26, 2015 2:26 PM
To: General discussion about the WiX toolset.
Subject: Re: [WiX-users] using a custom action to read properties from a XML 
file

Are you trying to set properties from a deferred custom action?  It looks like 
it.  Only immediate custom actions can set properties.  I have an immediate 
custom action that reads an XML file and sets a bunch of properties.  But a 
deferred custom action isn't going to have access.

--
John Merryweather Cooper
Senior Software Engineer | Integration Development Group | Continuing 
Development Jack Henry & Associates, Inc.® | Lenexa, KS  66214 | Ext:  431050 
|jocoo...@jackhenry.com

-----Original Message-----
From: Davis, Jeff [mailto:jda...@nanometrics.com]
Sent: Thursday, February 26, 2015 3:33 PM
To: wix-users@lists.sourceforge.net
Subject: [WiX-users] using a custom action to read properties from a XML file

I am having a heck of time trying get my mind wrapped around the way to create 
and use a custom action in my C# Wix Project in Visual Studio 2013.

I want to be able to open a specified XML file and return an attribute from a 
specified key and then use that to initialized a property in the installer and 
display it in the dialog.  Then when installer is run it will write the value 
to a target XML file to the same key and attribute.   In My case I have a 
MAC_ID  Property that is in a UI text box that I want to initialize from a XML 
file attribute and then write to a new XML file during the install.   The write 
is pretty straightforward since it is built into WIx.  But I can't get the read 
working.

I created this Custom Action

    public class CustomActions
    {
        [CustomAction]
        public static ActionResult ReadXmlValue(Session session)
        {
            string fileName = session.CustomActionData["FileName"];
            string xmlnode = session.CustomActionData["Node"];
            string key = session.CustomActionData["Key"];

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(fileName);
            if (xmlDoc.DocumentElement != null)
            {
                XmlNodeList nodeList = 
xmlDoc.DocumentElement.SelectNodes(xmlnode);

                if (nodeList != null)
                    foreach (XmlNode node in nodeList)
                    {
                        var selectSingleNode = node.SelectSingleNode(key);
                        if (selectSingleNode != null) session["Value"] = 
selectSingleNode.InnerText;
                    }
            }

            return ActionResult.Success;
        }
    }


My WXS script looks like this


   <Property Id="MAC_ID" Secure="yes" Value="0"/>
    <Property Id="MACIDTemplate">
      <![CDATA[&&-&&-&&-&&-&&-&&]]>
    </Property>

    <CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="ReadXMLValue" 
Execute="deferred" Return="check" />
    <CustomAction Id="SetCustomActionDataValue" Return="check" 
Property="myActionId" Value="FileName='.\FilesToInstall\Program 
Files\Zygo\MetroProX\cfg\NewView.IC.xml';Node='\Settings\Section\Section\Section\add';Key='Mac'"
 />
    <CustomAction Id="ReadXMLValue" Property="Value" Value="[MAC_ID]" />

    <InstallExecuteSequence>
      <Custom Action="SetCustomActionDataValue" Before="myActionId">NOT 
Installed</Custom>
      <Custom Action="myActionId" Before="InstallFinalize">NOT 
Installed</Custom>
    </InstallExecuteSequence>


But I don't think I have this setup right?


Jeff Davis
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored 
by Intel and developed in partnership with Slashdot Media, is your hub for all 
things parallel software development, from weekly thought leadership blogs to 
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users
NOTICE: This electronic mail message and any files transmitted with it are 
intended exclusively for the individual or entity to which it is addressed. The 
message, together with any attachment, may contain confidential and/or 
privileged information.
Any unauthorized review, use, printing, saving, copying, disclosure or 
distribution is strictly prohibited. If you have received this message in 
error, please immediately advise the sender by reply email and delete all 
copies.


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored 
by Intel and developed in partnership with Slashdot Media, is your hub for all 
things parallel software development, from weekly thought leadership blogs to 
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to