public static void AddListBoxEntry(Session session, string propertyName, int order, string value, string text)  
               
        {
             

                        Record newEntry    = new Record(4);  
                               newEntry[0] = propertyName;  
                               newEntry[1] = order;  
                               newEntry[2] = value;  
                               newEntry[3] = text;  

                        try 
                        {
                Microsoft.Deployment.WindowsInstaller.View listBoxView = session.Database.OpenView("SELECT * FROM ComboBox");  //`Property`, `Order`, `Value`, `Text`
                            listBoxView.Execute();

                                listBoxView.Modify(ViewModifyMode.InsertTemporary, newEntry);

                listBoxView.Close();  
                           
            }  
                        catch (InstallerException ix)  
                            {
                     
                                    //RecurseLogInstallerException(session, ix, 0); 
                    session.Log(ix.Message);

                               
                } 

                       

                   
        }
示例#2
0
        public static ActionResult FillDBServerNameAction(Session xiSession)
        {
            Microsoft.Deployment.WindowsInstaller.View lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
            lView.Execute();
            int    lIndex   = 1;
            string HostName = Dns.GetHostName();

            ServiceController[] services = ServiceController.GetServices();
            //从机器服务列表中找到本机的SqlServer引擎
            foreach (ServiceController s in services)
            {
                if (s.Status != ServiceControllerStatus.Running)
                {
                    continue;
                }
                if (s.ServiceName.ToLower().IndexOf("mssql$") != -1)
                {
                    Record lRecord = xiSession.Database.CreateRecord(4);
                    lRecord.SetString(1, "DBSERVER");
                    lRecord.SetInteger(2, lIndex);
                    lRecord.SetString(3, HostName + "\\" + s.ServiceName.Substring(s.ServiceName.IndexOf("$") + 1)); // Use lWebsiteName only if you want to look up the site by name.
                    lRecord.SetString(3, HostName + "\\" + s.ServiceName.Substring(s.ServiceName.IndexOf("$") + 1));
                    lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
                    if (lIndex == 1)
                    {
                        xiSession["DBSERVER"] = HostName + "\\" + s.ServiceName.Substring(s.ServiceName.IndexOf("$") + 1);
                    }
                    lIndex++;
                }
                else if (s.ServiceName.ToLower() == "mssqlserver")
                {
                    Record lRecord = xiSession.Database.CreateRecord(4);
                    lRecord.SetString(1, "DBSERVER");
                    lRecord.SetInteger(2, lIndex);
                    lRecord.SetString(3, HostName); // Use lWebsiteName only if you want to look up the site by name.
                    lRecord.SetString(3, HostName);
                    lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
                    if (lIndex == 1)
                    {
                        xiSession["DBSERVER"] = HostName;
                    }
                    lIndex++;
                }
            }
            lView.Close();
            return(ActionResult.Success);
        }
示例#3
0
        private static ActionResult EnumSqlServersIntoComboBox(Session session, IEnumerable <DataRow> rows)
        {
            try
            {
                //Debugger.Break();

                session.Log("EnumSQLServers: Begin");

                View view = session.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='DATABASE_SERVER'");
                view.Execute();

                view = session.Database.OpenView("SELECT * FROM ComboBox");
                view.Execute();

                Int32 index = 1;
                session.Log("EnumSQLServers: Enumerating SQL servers");
                foreach (DataRow row in rows)
                {
                    String serverName = row["Name"].ToString();

                    // Create a record for this web site. All I care about is
                    // the name so use it for fields three and four.
                    session.Log("EnumSQLServers: Processing SQL server: {0}", serverName);

                    Record record = session.Database.CreateRecord(4);
                    record.SetString(1, "DATABASE_SERVER");
                    record.SetInteger(2, index);
                    record.SetString(3, serverName);
                    record.SetString(4, serverName);

                    session.Log("EnumSQLServers: Adding record");
                    view.Modify(ViewModifyMode.InsertTemporary, record);
                    index++;
                }

                view.Close();

                session.Log("EnumSQLServers: End");
            }
            catch (Exception ex)
            {
                session.Log("EnumSQLServers: exception: {0}", ex.Message);
                throw;
            }

            return(ActionResult.Success);
        }