aboutsummaryrefslogtreecommitdiff
path: root/src/tools/Dtf/Documents/Guide/Content/samplecas.htm
blob: 4dfed6f093c79b778681691b084abd190de65218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Sample C# Custom Action</title>
  <link rel="stylesheet" type="text/css" href="../styles/presentation.css" />
  <link rel="stylesheet" type="text/css" href="ms-help://Hx/HxRuntime/HxLink.css" />
</head>

<body>

  <div id="control">
    <span class="productTitle">Deployment Tools Foundation</span><br />
    <span class="topicTitle">Sample C# Custom Action</span><br />
    <div id="toolbar">
      <span id="chickenFeet">
        <a href="using.htm">Development Guide</a> &gt;
        <a href="managedcas.htm">Managed CAs</a> &gt;
        <a href="writingcas.htm">Writing CAs</a> &gt;
        <span class="nolink">C# Sample</span>
      </span>
    </div>
    </div>
    <div id="main">
      <div id="header">
      </div>
      <div class="summary">
      
            <p>MSI custom actions are MUCH easier to write in C# than 
            in C++!</p><pre><font face="Consolas, Courier New">    [CustomAction]
    <font color=blue>public</font> <font color=blue>static</font> ActionResult SampleCustomAction1(Session session)
    {
        session.Log(<font color="purple">"Hello from SampleCA1"</font>);
        
        <font color=blue>string</font> testProp = session[<font color="purple">"SampleCATest"</font>];
        <font color=blue>string</font> testProp2;
        testProp2 = (<font color="blue">string</font>) session.Database.ExecuteScalar(
            <font color="purple">"SELECT `Value` FROM `Property` WHERE `Property` = 'SampleCATest'"</font>);
        
        <font color=blue>if</font>(testProp == testProp2)
        {
            session.Log(<font color="purple">"Simple property test passed."</font>);
            <font color=blue>return</font> ActionResult.Success;
        }
        <font color=blue>else</font>
            <font color=blue>return</font> ActionResult.Failure;
    }
            </font></pre>
            <p>A sample CA project with two CAs is included in the
            Samples\ManagedCA directory.&nbsp; Running the CustomActionTest project will package the CA and insert
            it into a test MSI. The MSI will invoke the custom actions, but it will not install anything
            since the second sample CA returns ActionResult.UserExit.
            </p>
            
        <p><br/></p>
        <p><b>See also:</b></p>
        <ul>
            <li><a href="writingcas.htm">Writing Managed Custom Actions</a></li>
            <li><a href="caconfig.htm">Specifying the Runtime Version</a></li>
            <li><a href="databases.htm">Working with MSI Databases</a></li>
            <li><a href="buildingcas.htm">Building Managed Custom Actions</a></li>
            <li><a href="debuggingcas.htm">Debugging Managed Custom Actions</a></li>
        </ul>
        <p><br/></p>

      </div>
        
      <div id="footer">
        <p />
        Send comments on this topic to <a id="HT_MailLink" href="mailto:wix-users%40lists.sourceforge.net?Subject=Deployment Tools Foundation Documentation">
        wix-users@lists.sourceforge.net</a>

        <script type="text/javascript">
          var HT_mailLink = document.getElementById("HT_MailLink");
          var HT_mailLinkText = HT_mailLink.innerHTML;
          HT_mailLink.href += ": " + document.title;
          HT_mailLink.innerHTML = HT_mailLinkText;
        </script>

        <p />
        
      </div>
   </div>
    
</body>
</html>