简体   繁体   English

WiX自定义操作以按钮开头

[英]WiX Custom Action start with Button

I have a custom action to check the SQL Connection. 我有一个自定义操作来检查SQL连接。 Now, it should work with a Control Button, but that's not working. 现在,它应该可以与“控制按钮”一起使用,但这不起作用。

Custom action works nicely without the button: Here the wxs-File: 没有按钮,自定义操作也可以很好地工作:这是wxs-File:

<?xml version="1.0" encoding="UTF-8"?>

<Property Id="SERVERNAME" Value="MSSQL2008R2" />
<Property Id="DATABASENAME" Value="MyDatabase" />
<Property Id="USERNAME" Value="admin" />
<Property Id="PASSWORD" Value="mypassword" />

<Binary Id="CA_SQLTestDLL" SourceFile="$(var.CA_SQLConnectionTest.TargetDir)CA_SQLConnectionTest.CA.dll" />
<CustomAction Id="SQL_Test"
              BinaryKey="CA_SQLTestDLL"
              DllEntry="ConnectionTest"
              Execute="deferred"
              Return="check" />
<SetProperty Id="SQL_Test" Value="SERVERNAME=[SERVERNAME];DATABASENAME=[DATABASENAME];USERNAME=[USERNAME];PASSWORD=[PASSWORD]" Sequence="execute" Before="SQL_Test" />

<InstallExecuteSequence>
  <Custom Action="SQL_Test" After="InstallInitialize" />
</InstallExecuteSequence>


<UI>
  <Dialog Id="SQLServerConnectionTestDlg" Width="370" Height="270" Title="SQL Server connection test">
    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)" />
    <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
    <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
      <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
    </Control>
  </Dialog>
</UI>

Here is my CustomAction class: 这是我的CustomAction类:

Imports System.Data
Imports System.Data.SqlClient
Public Class CustomActions
<CustomAction()> _
Public Shared Function ConnectionTest(ByVal session As Session) As ActionResult
session.Log("############## Begin CUSTOMACTION ##############")
Dim userName As String
Dim password As String
Dim serverName As String
Dim dataBase As String

serverName = session.CustomActionData("SERVERNAME")
dataBase = session.CustomActionData("DATABASENAME")
userName = session.CustomActionData("USERNAME")
password = session.CustomActionData("PASSWORD")

Dim SqlConn As New SqlConnection
Dim SqlConnStr As String = "Data Source=" + serverName + ";Database=" + dataBase + ";Persist Security Info=True;User ID=" + userName + ";Password=" + password

If SqlConn.State = ConnectionState.Closed Then
  SqlConn.ConnectionString = SqlConnStr
  Try
    SqlConn.Open()
  Catch ex As Exception
    Return ActionResult.Failure
  End Try
End If
session.Log("### SUCCESSFULL ###")
Return ActionResult.Success
  End Function

End Class

install.log : install.log:

Calling custom action CA_SQLConnectionTest!CA_SQLConnectionTest.CustomActions.ConnectionTest
############## Begin CUSTOMACTION ##############
### SUCCESSFULL ###

Now, I'd like to start the custom action with a button. 现在,我想通过一个按钮开始自定义操作。 So i have to change Execute="deferred" to Execute="immediate" and add a button: 因此,我必须将Execute =“ deferred”更改为Execute =“ immediate”并添加一个按钮:

        <Control Id="TestConn" Type="PushButton" X="265" Y="205" Width="70" Height="18" Text="&amp;Test Connection">
      <Publish Event="DoAction" Value="SQL_Test">1</Publish>
      <Publish Property="ERRORMSG" Value="ConnectionTest">ACCEPTED = "1"</Publish>
      <Publish Event="SpawnDialog" Value="InvalidDBConnDlg">ACCEPTED = "0"</Publish>
    </Control>

      <Dialog Id="InvalidDBConnDlg" Width="260" Height="120" Title="MyTester">
    <Control Id="OK" Type="PushButton" X="102" Y="90" Width="56" Height="17" Default="yes" Cancel="yes" Text="OK">
      <Publish Event="EndDialog" Value="Exit" />
    </Control>
    <Control Id="Text" Type="Text" X="48" Y="22" Width="194" Height="60" Text="FAILED" />
    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="WixUI_Ico_Info" />
  </Dialog>

Now, when i push the button will the setup cancled and i have a fatal error in the log-File: 现在,当我按下按钮时,安装程​​序将取消,并且在日志文件中出现致命错误:

Action 16:43:20: SQL_Test. 
Action start 16:43:20: SQL_Test.
MSI (c) (5C:5C) [16:43:20:236]: Invoking remote custom action. DLL: C:\Users\LOC~1.CRE\AppData\Local\Temp\MSIC08C.tmp, Entrypoint: ConnectionTest
Action ended 16:43:20: SQL_Test. Return value 3.
MSI (c) (5C:20) [16:43:20:404]: Note: 1: 2205 2:  3: Error 
MSI (c) (5C:20) [16:43:20:404]: Note: 1: 2228 2:  3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 2896 
DEBUG: Error 2896:  Executing action SQL_Test failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: SQL_Test, , 
Action ended 16:43:20: WelcomeDlg. Return value 3.
MSI (c) (5C:54) [16:43:20:405]: Doing action: FatalError
MSI (c) (5C:54) [16:43:20:405]: Note: 1: 2205 2:  3: ActionText 
Action 16:43:20: FatalError. 
Action start 16:43:20: FatalError.
Action 16:43:20: FatalError. Dialog created
Action ended 16:43:23: FatalError. Return value 2.
Action ended 16:43:23: INSTALL. Return value 3.
MSI (c) (5C:54) [16:43:23:488]: Destroying RemoteAPI object.
MSI (c) (5C:50) [16:43:23:488]: Custom Action Manager thread ending

Config useLegacyV2RuntimeActivationPolicy is "true" Config useLegacyV2RuntimeActivationPolicy为“ true”

I use WIX3.10 in Visual Studio 2013 我在Visual Studio 2013中使用WIX3.10

I am not sure what I am doing wrong. 我不确定自己在做什么错。 But i think it's a problem with the InstallExecuteSequence. 但是我认为这是InstallExecuteSequence的问题。

I hope someone can help me, thanks 我希望有人可以帮助我,谢谢

Well immediate is the correct thing to do, because you can't have deferred custom actions in the UI sequence (so it can't be a problem with the execute sequence as you suspect). 立即执行是正确的做法,因为您不能在UI序列中延迟自定义操作(因此,您怀疑执行序列不会有问题)。

Beyond that, if the code starts and it fails then it's a coding/environmental issue. 除此之外,如果代码开始并且失败,那么这就是编码/环境问题。 You should just put message box calls in your code while you're in this debugging stage, check that you have the values, and certainly do more that just trhow away any exception with that try/catch! 在此调试阶段,您应该只在代码中放入消息框调用,检查是否具有值,并且当然可以做更多的事情,以免尝试/捕获该异常! You're asking what the error might be at the same time that you discard it and return a failure result. 您要问的是在丢弃错误并返回失败结果的同时错误可能是什么。

Thanks, you have right, it's not a problem with the execute sequence. 谢谢,您说对了,执行顺序不是问题。

I've narrowed down the problem. 我已经解决了问题。 When I don't use CustomActionData then works the custom action 当我不使用CustomActionData时,将执行自定义操作

userName = session.CustomActionData("USERNAME")
password = session.CustomActionData("PASSWORD")
...

Why I can't not transfer values? 为什么我不能转让价值?

Update: 更新:

The command doesnt' work here: 该命令在这里不起作用:

session.CustomActionData("USERNAME")

With the follow command works fine: 使用以下命令可以正常工作:

session("USERNAME")

CustomActionData cannot be accessed with immediate custom action. 无法使用立即的自定义操作访问CustomActionData。

But you can directly access properties using sessions. 但是您可以使用会话直接访问属性。

try this 尝试这个

  userName = session["USERNAME"];
  password = session["PASSWORD"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM