WIX, Dot Net managed custom Action, dynamically fill combo box with SQL Server instances, MSI

后端 未结 3 1985
感情败类
感情败类 2021-02-04 14:19

In WIX am in-need of a dot net managed custom code to dynamically populate a combo box with the values of sql server instances in that network.

I tried to google but go

3条回答
  •  爱一瞬间的悲伤
    2021-02-04 14:46

        [CustomAction]   
        public static ActionResult FillServerInstances(Session xiSession)
        {         
            xiSession.Log("Begin CustomAction");
    
            xiSession.Log("Opening view");
            View lView = xiSession.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='DBSRVR'");
            lView.Execute();
    
            lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
            lView.Execute();
    
            int Index = 1;
            bool flag = false;
            try
            {
                foreach (DataRow dr in Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers(false).Rows)
                {
                    String InstanceName = dr["Name"].ToString();
    
                    if (InstanceName.Equals(xiSession["ComputerName"] + @"\" + xiSession["SQLINSTANCENAME"], StringComparison.InvariantCultureIgnoreCase))
                    { flag = true; }
    
                    Record lRecord = xiSession.Database.CreateRecord(4);
                    xiSession.Log("Setting record details");
                    lRecord.SetString(1, "DBSRVR");
                    lRecord.SetInteger(2, Index);
                    lRecord.SetString(3, InstanceName);
                    lRecord.SetString(4, InstanceName);
    
                    xiSession.Log("Adding record");
                    lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
    
                    ++Index;
                }
            }
            catch (Exception ex)
            {
                logException(xiSession, ex);              
            }
            if (flag)
            {
                xiSession["DBSRVR"] = xiSession["ComputerName"].ToString() + @"\" + xiSession["SQLINSTANCENAME"].ToString();
            }
    
            lView.Close();
    
            xiSession.Log("Closing view");
            lView.Close();
            return ActionResult.Success;       
        }
    

提交回复
热议问题