private void PopulateDatabaseNameItemsWorker(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker == null)
            {
                return;
            }

            String[] databaseArray = null;

            try
            {
                if (!String.IsNullOrEmpty(this.serverName))
                {
                    using (ImpersonationHelper impersonationHelper = new ImpersonationHelper())
                    {
                        databaseArray = SetupDatabaseHelper.GetSqlDBNames(
                            !SetupDatabaseHelper.SqlServerIsOnLocalComputer(this.serverName),
                            this.serverName,
                            IsDefaultInstance(this.selectedInstance) ? String.Empty : this.selectedInstance,
                            this.port,
                            true);
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                e.Result = databaseArray;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Launch Setup in Silent Mode
        /// </summary>
        /// <returns>a SetupReturnValues reflecting success or possible failure causes</returns>
        private static SetupReturnValues SilentRun()
        {
            // Setup the data for the items to install
            PrepareInstallData.PrepareInstallDataItems();

            // Check to see that we have all the install files we need.
            // Make sure the file locations are set for the install files.
            SetupFileValidation.ResetInstallItemFileLocations(
                PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagConstants.LocationOfSetupFiles),
                PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagConstants.LocationOfSetupFiles));

            if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
            {
                if (!SetupFileValidation.HaveAllNeededInstallItemFiles())
                {
                    return(SetupReturnValues.InvalidInstallImage);
                }

                SetupHelpers.SetFeatureSwitches();
                // If we are not uninstalling, Do the prereq check
                if (2 == SetupHelpers.DoAllPrerequisiteChecks())
                {
                    // We failed prereq tests so we will fail the install
                    SetupLogger.LogError("We failed the prerequisite checks.");
                    return(SetupReturnValues.FailedPrerequisiteChecks);
                }

                // If this is a server installation,
                // - check if there is an existing database,
                // and if so, check if upgrade is supported from that version
                // - make sure client is also installed with server.
                if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Server))
                {
                    // Error conditions
                    // An unsupported database found
                    // A supported database is found, but user didnt explicitly specify upgrade

                    // CheckDatabase will throw an exception if DB version is
                    // incompatible
                    string sqlMachineName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlMachineNameTag);

                    String fullInstanceName = SetupDatabaseHelper.ConstructFullInstanceName(
                        !SetupDatabaseHelper.SqlServerIsOnLocalComputer(sqlMachineName),
                        sqlMachineName,
                        (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlInstanceNameTag),
                        (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));
                }
            }

            // Do the install using the passed information
            InstallActionProcessor installs = new InstallActionProcessor();

            SetupLogger.LogInfo("Silent ProcessInstalls Starting");

            SetupReturnValues rturn = installs.ProcessInstalls();

            SetupLogger.LogInfo("Silent ProcessInstalls Done");

            return(rturn);
        }
        private void comboBoxExistingDatabaseName_DropDownOpened(object sender, EventArgs e)
        {
            this.DisableInputMode();
            this.resetServerName();
            this.resetInstanceName();

            String[] databaseArray = null;
            try
            {
                if (!String.IsNullOrEmpty(this.serverName))
                {
                    using (ImpersonationHelper impersonationHelper = new ImpersonationHelper())
                    {
                        databaseArray = SetupDatabaseHelper.GetSqlDBNames(
                            !SetupDatabaseHelper.SqlServerIsOnLocalComputer(this.serverName),
                            this.serverName,
                            IsDefaultInstance(this.selectedInstance) ? String.Empty : this.selectedInstance,
                            this.port,
                            true);
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                this.EnableInputMode();
                this.comboBoxExistingDatabaseName.Text = String.Empty;
                this.comboBoxExistingDatabaseName.Items.Clear();

                if (databaseArray != null && databaseArray.Length > 0)
                {
                    foreach (String databaseName in databaseArray)
                    {
                        this.comboBoxExistingDatabaseName.Items.Add(databaseName);
                    }

                    // First satisfy the below scenario:
                    // - User clicked on existing db radio button and selected a db
                    // - then clicked new db radio button
                    // - and then clicked existing radio db again w/o changin server, instance, or port info
                    // Basically, check if the selected instance already exists in the list
                    // if yes, then choose it
                    // otherwise, this is a new population, select the first item
                    if (this.comboBoxExistingDatabaseName.Items.Contains(this.selectedDatabase))
                    {
                        this.comboBoxExistingDatabaseName.Text = selectedDatabase;
                    }
                    else
                    {
                        this.selectedDatabase = databaseArray[0];
                        this.comboBoxExistingDatabaseName.Text = this.selectedDatabase;
                    }
                }
            }
        }
        /// <summary>
        /// Reset the registry values
        /// </summary>
        private static void ResetRegistry()
        {
            // sql
            string sqlInstanceName    = GetSQLServerInstanceNameStr(false);
            string wapSqlInstanceName = GetSQLServerInstanceNameStr(true);

            WriteSqlRegistryValue(SetupConstants.InstanceNameRegistryValueName, sqlInstanceName);
            WriteWapSqlRegistryValue(SetupConstants.WapInstanceNameRegistryValueName, wapSqlInstanceName);
            string dbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);

            WriteSqlRegistryValue(SetupConstants.DBNameRegistryValueName, dbName);
            string wapDBName = (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDatabaseNameTag);

            WriteWapSqlRegistryValue(SetupConstants.WapDbNameRegistryValueName, wapDBName);
            string partialConnectionString    = SetupDatabaseHelper.ConstructConnectionString(sqlInstanceName);
            string wapPartialConnectionString = SetupDatabaseHelper.ConstructConnectionString(wapSqlInstanceName);
            string connectionString           = String.Format("{0}database={1}", partialConnectionString, dbName);
            string wapConnectionString        = String.Format("{0}database={1}", partialConnectionString, wapDBName);

            WriteSqlRegistryValue(SetupConstants.ConnectionStringRegistryValueName, connectionString);
            WriteWapSqlRegistryValue(SetupConstants.ConnectionStringRegistryValueName, wapConnectionString);

            string sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(false)));
            bool   onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, true) != 0;

            WriteSqlRegistryValue(SetupConstants.OnRemoteRegistryValueName, onRemoteMachine ? 1 : 0);
            WriteSqlRegistryValue(SetupConstants.MachineNameRegistryValueName, sqlMachineName);
            String sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);

            WriteSqlRegistryValue(SetupConstants.FqdnRegistryValueName, sqlMachineFqdn);

            sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(true)));
            onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, true) != 0;
            WriteWapSqlRegistryValue(SetupConstants.OnRemoteRegistryValueName, onRemoteMachine ? 1 : 0);
            WriteWapSqlRegistryValue(SetupConstants.MachineNameRegistryValueName, sqlMachineName);
            sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
            WriteWapSqlRegistryValue(SetupConstants.FqdnRegistryValueName, sqlMachineFqdn);

            // user name, company name under server
            String userName = SetupInputs.Instance.FindItem(SetupInputTags.UserNameTag);

            WriteServerRegistrationRegistryValue(SetupConstants.UserNameRegistryValueName, userName);

            // VmmServiceAccount
            String serviceAccount = UserAccountHelper.GetServiceAccount();

            if (SetupInputs.Instance.FindItem(SetupInputTags.CmpServiceLocalAccountTag))
            {
                serviceAccount = SetupConstants.LocalSystem;
            }

            WriteConfigSettingsRegistryValue(SetupConstants.ServerSetupInfoRegKey, SetupConstants.VmmServiceAccountValueName, serviceAccount);
        }
        public static bool CMPServerPostinstallProcessor()
        {
            bool returnValue = true;

            try
            {
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
                {
                    String currentSetupUser = String.Format(SetupConstants.UserAccountTemplate, Environment.UserDomainName, Environment.UserName);
                    SetupInputs.Instance.EditItem(SetupInputTags.SetupUserAccountTag, currentSetupUser);

                    SetupDatabaseHelper.CheckDatabase(
                        InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false),
                        SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag),
                        false);

                    SetupDatabaseHelper.CreateDB(false);

                    if (SetupInputs.Instance.FindItem(SetupInputTags.RemoteDatabaseImpersonationTag))
                    {
                        SetupDatabaseHelper.GrantSetupUserDBAccess(true, false);
                        SetupInputs.Instance.EditItem(SetupInputTags.RemoteDatabaseImpersonationTag, false);
                        PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.AfterGrantSetupUserDBAccess, true);
                    }

                    ServiceConfigurationHandler serviceConfigurationHandler = new ServiceConfigurationHandler();
                    CmpWorkerServiceHelper.ConfigureCMPWorkerService(serviceConfigurationHandler);

                    serviceConfigurationHandler.StartService(SetupConstants.EngineServiceName);
                }
            }
            catch (Exception exception)
            {
                SetupLogger.LogException(exception, "CMPServerPostinstallProcessor threw an exception");
                PropertyBagDictionary.Instance.SafeAdd(PropertyBagDictionary.VitalFailure,
                                                       (PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.VitalFailure)
                    ? (PropertyBagDictionary.Instance.GetProperty <InstallItemsInstallDataItem.InstallDataInputs>
                           (PropertyBagDictionary.VitalFailure) | InstallItemsInstallDataItem.InstallDataInputs.PostInstallItem)
                    : InstallItemsInstallDataItem.InstallDataInputs.PostInstallItem));
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.FailureReason))
                {
                    PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.FailureReason, exception);
                }
                returnValue = false;
            }

            return(returnValue);
        }
        private void comboBoxInstance_DropDownOpened(object sender, EventArgs e)
        {
            this.DisableInputMode();
            String[] instanceArray = null;
            try
            {
                this.resetServerName();
                if (!String.IsNullOrEmpty(this.serverName))
                {
                    using (ImpersonationHelper impersonationHelper = new ImpersonationHelper())
                    {
                        //PropertyBagDictionary.Instance.SafeAdd("SQLMachineName", this.serverName);
                        instanceArray = SetupDatabaseHelper.GetSqlInstanceNames(this.serverName);
                    }
                }
                this.comboBoxInstance.Text = String.Empty;
                this.comboBoxInstance.Items.Clear();
                if (instanceArray != null && instanceArray.Length > 0)
                {
                    foreach (String instanceName in instanceArray)
                    {
                        this.comboBoxInstance.Items.Add(instanceName);
                    }

                    if (this.comboBoxInstance.Items.Contains(this.selectedInstance))
                    {
                        this.comboBoxInstance.Text = this.selectedInstance;
                    }
                    else
                    {
                        this.selectedInstance      = instanceArray[0];
                        this.comboBoxInstance.Text = this.selectedInstance;
                    }
                }
            }
            catch (Exception backEndErrorException)
            {
                SetupLogger.LogException(backEndErrorException);
                SetupHelpers.ShowError(backEndErrorException.Message);
            }

            this.EnableInputMode();
        }
        private void PopulateInstanceItemsWorker(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker == null)
            {
                return;
            }

            String[] instanceArray = null;

            if (!String.IsNullOrEmpty(this.serverName))
            {
                using (ImpersonationHelper impersonationHelper = new ImpersonationHelper())
                {
                    instanceArray = SetupDatabaseHelper.GetSqlInstanceNames(this.serverName);
                }
            }

            e.Result = instanceArray;
        }
        public static bool WAPExtensionCommonPostIstallProcessor()
        {
            SetupLogger.LogInfo("WAPExtensionPostIstallProcessor: Entered.");
            bool returnValue = true;

            try
            {
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
                {
                    String currentSetupUser = String.Format(SetupConstants.UserAccountTemplate, Environment.UserDomainName, Environment.UserName);
                    SetupInputs.Instance.EditItem(SetupInputTags.SetupUserAccountTag, currentSetupUser);

                    SetupDatabaseHelper.CheckDatabase(
                        InstallItemCustomDelegates.GetSQLServerInstanceNameStr(true),
                        SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDatabaseNameTag),
                        true);

                    SetupDatabaseHelper.CreateDB(true);

                    if (SetupInputs.Instance.FindItem(SetupInputTags.WapRemoteDatabaseImpersonationTag))
                    {
                        SetupDatabaseHelper.GrantSetupUserDBAccess(true, true);
                        SetupInputs.Instance.EditItem(SetupInputTags.WapRemoteDatabaseImpersonationTag, false);
                        PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.WapAfterGrantSetupUserDBAccess, true);
                    }

                    SetupDatabaseHelper.DeployWAPDacpac();
                }
            }
            catch (ArgumentException exception)
            {
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.FailureReason))
                {
                    PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.FailureReason, exception);
                }
                returnValue = false;
            }

            return(returnValue);
        }
        /// <summary>
        /// Validates the inputs on this page
        /// </summary>
        /// <returns></returns>
        public override bool ValidatePage()
        {
            bool isPageValid = true;

            try
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                SetupInputs.Instance.EditItem(SetupInputTags.WapSqlMachineNameTag, this.textBoxServer.Text);
                SetupInputs.Instance.EditItem(SetupInputTags.WapSqlInstanceNameTag,
                                              IsDefaultInstance(this.comboBoxInstance.Text) ? String.Empty : this.comboBoxInstance.Text);

                this.port = String.IsNullOrEmpty(this.textBoxPort.Text) ?
                            InputDefaults.WapSqlServerPort : Convert.ToInt32(this.textBoxPort.Text);
                SetupInputs.Instance.EditItem(SetupInputTags.WapSqlServerPortTag, this.port);

                bool isNewDB = this.radioNewDatabase.IsChecked.GetValueOrDefault(false);

                SetupInputs.Instance.EditItem(SetupInputTags.WapCreateNewSqlDatabaseTag, isNewDB);

                if (isNewDB)
                {
                    SetupInputs.Instance.EditItem(SetupInputTags.WapSqlDatabaseNameTag, this.textBoxNewDatabaseName.Text);
                }
                else
                {
                    SetupInputs.Instance.EditItem(SetupInputTags.WapSqlDatabaseNameTag, this.comboBoxExistingDatabaseName.Text);
                }

                if (this.checkBoxNewUserId.IsChecked.GetValueOrDefault(false))
                {
                    String userName   = SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDBAdminNameTag);
                    String domainName = SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDBAdminDomainTag);
                    if (!UserAccountHelper.ValidateCredentials(userName, domainName, this.passwordBoxPassword.SecurePassword))
                    {
                        throw new Exception("Either the domain account or the password you entered are not valid.");
                    }
                }

                String fullInstanceName = SetupDatabaseHelper.ConstructFullInstanceName(
                    !SetupDatabaseHelper.SqlServerIsOnLocalComputer(this.serverName),
                    (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlMachineNameTag),
                    (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlInstanceNameTag),
                    (int)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlServerPortTag));

                SetupDatabaseHelper.CheckDatabase(
                    fullInstanceName,
                    (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDatabaseNameTag),
                    true);
            }
            catch (SqlException)
            {
                Exception exception = new Exception("Setup cannot connect to the specified SQL Server instance.");

                SetupLogger.LogException(exception);
                SetupHelpers.ShowError(exception.Message);

                isPageValid = false;
            }
            catch (Exception exception)
            {
                SetupLogger.LogException(exception);
                SetupHelpers.ShowError(exception.Message);

                isPageValid = false;
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }

            return(isPageValid);
        }
        public static string ConfigureServerCommandLineArguments()
        {
            StringBuilder arguments = new StringBuilder();

            // Check to see if this is an uninstall
            if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
            {
                arguments.Append("REMOVE=ALL ");
                arguments.AppendFormat(CultureInfo.InvariantCulture, "UNINSTALLSERVER = 1 ");
            }
            else
            {
                String serviceAccount = UserAccountHelper.GetServiceAccount();
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SERVERACCOUNTNAME=\"{0}\" ", serviceAccount);  // for agent installation
                if (SetupInputs.Instance.FindItem(SetupInputTags.CmpServiceLocalAccountTag))
                {
                    serviceAccount = SetupConstants.LocalSystem;
                }
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SERVICEACCOUNT=\"{0}\" ", serviceAccount); // for registry
                arguments.AppendFormat(CultureInfo.InvariantCulture, "USERNAME=\"{0}\" ", (String)SetupInputs.Instance.FindItem(SetupInputTags.UserNameTag));

                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLPORT=\"{0}\" ", (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));
                string sqlInstanceName = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "INSTANCENAME=\"{0}\" ", sqlInstanceName);

                String dbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "DATABASENAME=\"{0}\" ", dbName);
                string partialConnectionString = SetupDatabaseHelper.ConstructConnectionString(sqlInstanceName);
                string connectionString        = String.Format("{0}database={1}", partialConnectionString, dbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CONNECTIONSTR=\"{0}\" ", connectionString);

                string sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(false)));
                bool   onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, true) != 0;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "ONREMOTESERVER=\"{0}\" ", onRemoteMachine ? 1 : 0);

                String sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINENAME=\"{0}\" ", sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINEFQDN=\"{0}\" ", sqlMachineFqdn);

                arguments.AppendFormat(CultureInfo.InvariantCulture, "SETUPLANGUAGE=\"{0}\" ", CultureInfo.CurrentUICulture.Name);

                String certificateThumbprint = (String)SetupInputs.Instance.FindItem(SetupInputTags.CmpCertificateThumbprintTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CERTIFICATETHUMBPRINT=\"{0}\" ", "LocalMachine,My," + certificateThumbprint);

                // Encrypt the password of the worker service so that WAP extensions can use it
                InputParameter pwd            = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminPasswordTag);
                string         passwordAsText = null;
                if (pwd != null)
                {
                    IntPtr unmanagedString = IntPtr.Zero;
                    try
                    {
                        unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(pwd);
                        passwordAsText  = Marshal.PtrToStringUni(unmanagedString);
                    }
                    finally
                    {
                        Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
                    }
                }
                string encryptedPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(passwordAsText, certificateThumbprint), "[KText]");

                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONTEXTPASSWORDSTRING=\"{0}\" ", encryptedPassword);
            }

            return(arguments.ToString());
        }
        public static bool CMPServerPreinstallProcessor()
        {
            bool returnValue = true;

            try
            {
                InstallItemsInstallDataItem virtualMachineManagerInstallItem = null;

                // Find the installdata item in the array
                foreach (InstallItemsInstallDataItem itemToInstall in PropertyBagDictionary.Instance.GetProperty <ArrayList>(PropertyBagConstants.ItemsToInstall))
                {
                    if (string.Equals(itemToInstall.ControlTitle, PropertyBagConstants.CMPServer, StringComparison.OrdinalIgnoreCase))
                    {
                        virtualMachineManagerInstallItem = itemToInstall;
                        break;
                    }
                }

                if (virtualMachineManagerInstallItem == null)
                {
                    // Item not found - throw an exception
                    SetupLogger.LogError("PageCustomDelegates: VMMPreinstallProcessor: Install Data item not found.");
                    throw new ArgumentException(WpfResources.WPFResourceDictionary.InvalidArgument);
                }

                // Set the Install/Uninstall state
                virtualMachineManagerInstallItem.ItemWeAreInstallingEnumValue = virtualMachineManagerInstallItem.ItemWeAreInstallingEnumValue |
                                                                                (PropertyBagDictionary.Instance.PropertyExists("uninstall") ? InstallItemsInstallDataItem.InstallDataInputs.Uninstalling : InstallItemsInstallDataItem.InstallDataInputs.Installing);

                // If this is not an uninstall, remove the product code.
                if (0 == (virtualMachineManagerInstallItem.ItemWeAreInstallingEnumValue & InstallItemsInstallDataItem.InstallDataInputs.Uninstalling))
                {
                    virtualMachineManagerInstallItem.ProductCode = string.Empty;
                }

                // Set the location of the log file
                virtualMachineManagerInstallItem.LogFile = SetupHelpers.SetLogFilePath(virtualMachineManagerInstallItem.LogFile);

                SetupHelpers.CreateEventSources();

                // Adjust the command line arguments
                virtualMachineManagerInstallItem.Arguments += InstallItemCustomDelegates.ConfigureBasicCommandLineArguments() + InstallItemCustomDelegates.ConfigureServerCommandLineArguments();


                bool isRollback = PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.RollbacksToProcess);

                if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
                {
                    String currentSetupUser = String.Format(SetupConstants.UserAccountTemplate, Environment.UserDomainName, Environment.UserName);
                    SetupInputs.Instance.EditItem(SetupInputTags.SetupUserAccountTag, currentSetupUser);

                    if (SetupInputs.Instance.FindItem(SetupInputTags.RemoteDatabaseImpersonationTag))
                    {
                        SetupDatabaseHelper.GrantSetupUserDBAccess(false, false);
                        SetupInputs.Instance.EditItem(SetupInputTags.RemoteDatabaseImpersonationTag, false);
                        PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.AfterGrantSetupUserDBAccess, true);
                    }

                    ServiceConfigurationHandler.RemoveService(SetupConstants.EngineServiceName);

                    // Stopping the service sometimes does not end the processes and this keeps a lock on the process binaries
                    InstallItemCustomDelegates.EndCmpWorkerServiceProcess();

                    bool retainDB = SetupInputs.Instance.FindItem(SetupInputTags.RetainSqlDatabaseTag) ||
                                    !SetupInputs.Instance.FindItem(SetupInputTags.CreateNewSqlDatabaseTag);

                    if (!retainDB)
                    {
                        SetupDatabaseHelper.RemoveDB(false);
                    }
                }
            }
            catch (ArgumentException exception)
            {
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.FailureReason))
                {
                    PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.FailureReason, exception);
                }
                SetupLogger.LogException(exception);
                returnValue = false;
            }

            return(returnValue);
        }
        public static string ConfigureWAPExtensionCommonCommandLineArguments()
        {
            StringBuilder arguments = new StringBuilder();

            // Check to see if this is an uninstall
            if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
            {
                arguments.Append("REMOVE=ALL ");
            }
            else
            {
                arguments.Append("ADDLOCAL=ProductFeature,ServiceFeature ");

                // Save the user name to use on the cmp service database
                String userName = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminNameTag);

                // Add the SQL database information so that it can be written to the registry and accessed by the services
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLPORT=\"{0}\" ", (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));
                string sqlInstanceName = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "INSTANCENAME=\"{0}\" ", sqlInstanceName);

                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSQLPORT=\"{0}\" ", (int)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlServerPortTag));
                string wapSqlInstanceName = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(true);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPINSTANCENAME=\"{0}\" ", wapSqlInstanceName);

                String dbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "DATABASENAME=\"{0}\" ", dbName);
                string partialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, sqlInstanceName);
                string connectionString        = String.Format("{0}database={1}", partialConnectionString, dbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONNECTIONSTR=\"{0}\" ", connectionString);

                String wapDbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDatabaseNameTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPDATABASENAME=\"{0}\" ", wapDbName);
                string wapPartialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, wapSqlInstanceName);
                string wapConnectionString        = String.Format("{0}database={1}", wapPartialConnectionString, wapDbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPCONNECTIONSTR=\"{0}\" ", wapConnectionString);

                string sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(false)));
                bool   onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, StringComparison.OrdinalIgnoreCase) != 0;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "ONREMOTESERVER=\"{0}\" ", onRemoteMachine ? 1 : 0);

                string wapSqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(true)));
                bool   wapOnRemoteMachine = String.Compare(wapSqlMachineName, Environment.MachineName, StringComparison.OrdinalIgnoreCase) != 0;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPONREMOTESERVER=\"{0}\" ", wapOnRemoteMachine ? 1 : 0);

                String sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINENAME=\"{0}\" ", sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINEFQDN=\"{0}\" ", sqlMachineFqdn);

                String wapSqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSQLMACHINENAME=\"{0}\" ", wapSqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSQLMACHINEFQDN=\"{0}\" ", wapSqlMachineFqdn);

                String certificateThumbprint = (String)SetupInputs.Instance.FindItem(SetupInputTags.CmpCertificateThumbprintTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CERTIFICATETHUMBPRINT=\"{0}\" ", "LocalMachine,My," + certificateThumbprint);

                // Write the cmp database connection string
                sqlInstanceName            = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false);
                wapDbName                  = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);
                wapPartialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, sqlInstanceName);
                wapConnectionString        = String.Format("{0}database={1}", wapPartialConnectionString, wapDbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONNECTIONSTR=\"{0}\" ", wapConnectionString);

                String domain       = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminDomainTag);
                string fullUserName = String.IsNullOrEmpty(domain) ? userName : domain + @"\" + userName;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPDATABASEUSERNAME=\"{0}\" ", fullUserName);

                // Encrypt the password of the worker service so that WAP extensions can use it
                InputParameter pwd            = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminPasswordTag);
                string         passwordAsText = null;
                if (pwd != null)
                {
                    IntPtr unmanagedString = IntPtr.Zero;
                    try
                    {
                        unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(pwd);
                        passwordAsText  = Marshal.PtrToStringUni(unmanagedString);
                    }
                    finally
                    {
                        Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
                    }
                }
                string encryptedPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(passwordAsText, certificateThumbprint), "[KText]");

                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONTEXTPASSWORDSTRING=\"{0}\" ", encryptedPassword);

                //Write the MicrosoftMgmtSvcStoreContext connection string (part of WAP original installation)
                wapDbName = SetupConstants.DefaultWapStoreDBName;
                wapPartialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, sqlInstanceName);
                wapConnectionString        = String.Format("{0}database={1}", wapPartialConnectionString, wapDbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSTORECONNECTIONSTR=\"{0}\" ", wapConnectionString);

                X509Krypto krypto = new X509Krypto("My", "LocalMachine", certificateThumbprint);
                // Encrypt the password of the sql user that will be used by the website to access CMP DB
                //string encryptedCmpDbPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(SetupDatabaseHelper.SqlDbUserPassword, certificateThumbprint), "[KText]");

                string encryptedCmpDbPassword = krypto.EncyptKText(SetupDatabaseHelper.SqlDbUserPassword);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPDBPASSWORDSTRING=\"{0}\" ", encryptedCmpDbPassword);

                // Encrypt the password of the sql user that will be used by the website to access CMP WAP DB
                //string encryptedCmpWapDbPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(SetupDatabaseHelper.SqlDbUserPassword, certificateThumbprint), "[KText]");
                string encryptedCmpWapDbPassword = krypto.EncyptKText(SetupDatabaseHelper.SqlDbUserPassword);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPWAPDBPASSWORDSTRING=\"{0}\" ", encryptedCmpWapDbPassword);

                // Encrypt the password of the sql user that will be used by the website to access WAP's Microsoft.MgmtSvc.Store DB
                //string encryptedMgmtStoreDbPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(SetupDatabaseHelper.SqlDbUserPassword, certificateThumbprint), "[KText]");
                string encryptedMgmtStoreDbPassword = krypto.EncyptKText(SetupDatabaseHelper.SqlDbUserPassword);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "MGMTSTOREPASSWORDSTRING=\"{0}\" ", encryptedMgmtStoreDbPassword);
            }

            return(arguments.ToString());
        }
        public static bool WAPExtensionCommonPreinstallProcessor()
        {
            bool returnValue = true; // used to store the return value for this function

            try
            {
                InstallItemsInstallDataItem wapExtensionCommonInstallItem = null;

                // Find the installdata item in the array
                foreach (InstallItemsInstallDataItem itemToInstall in PropertyBagDictionary.Instance.GetProperty <ArrayList>(PropertyBagConstants.ItemsToInstall))
                {
                    if (string.Equals(itemToInstall.ControlTitle, PropertyBagConstants.WAPExtensionCommon, StringComparison.OrdinalIgnoreCase))
                    {
                        wapExtensionCommonInstallItem = itemToInstall;
                        break;
                    }
                }

                if (wapExtensionCommonInstallItem == null)
                {
                    // Item not found - throw an exception
                    SetupLogger.LogError("PageCustomDelegates: WAPExtensionCommonPreinstallProcessor: Install Data item not found.");
                    throw new ArgumentException(WpfResources.WPFResourceDictionary.InvalidArgument);
                }

                // Set the Install/Uninstall state
                wapExtensionCommonInstallItem.ItemWeAreInstallingEnumValue = wapExtensionCommonInstallItem.ItemWeAreInstallingEnumValue |
                                                                             (PropertyBagDictionary.Instance.PropertyExists("uninstall") ? InstallItemsInstallDataItem.InstallDataInputs.Uninstalling : InstallItemsInstallDataItem.InstallDataInputs.Installing);

                // If this is not an uninstall, remove the product code.
                if (0 == (wapExtensionCommonInstallItem.ItemWeAreInstallingEnumValue & InstallItemsInstallDataItem.InstallDataInputs.Uninstalling))
                {
                    wapExtensionCommonInstallItem.ProductCode = string.Empty;
                }

                // Set the location of the log file
                wapExtensionCommonInstallItem.LogFile = SetupHelpers.SetLogFilePath(wapExtensionCommonInstallItem.LogFile);

                // Adjust the command line arguments
                wapExtensionCommonInstallItem.Arguments += ConfigureBasicCommandLineArguments() + ConfigureWAPExtensionCommonCommandLineArguments();

                if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
                {
                    if (SetupInputs.Instance.FindItem(SetupInputTags.WapRemoteDatabaseImpersonationTag))
                    {
                        SetupDatabaseHelper.GrantSetupUserDBAccess(false, false);
                        SetupInputs.Instance.EditItem(SetupInputTags.WapRemoteDatabaseImpersonationTag, false);
                        PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.WapAfterGrantSetupUserDBAccess, true);
                    }

                    bool retainDB = SetupInputs.Instance.FindItem(SetupInputTags.WapRetainSqlDatabaseTag) ||
                                    (!SetupInputs.Instance.FindItem(SetupInputTags.WapCreateNewSqlDatabaseTag) &&
                                     PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.RollbacksToProcess));

                    if (!retainDB)
                    {
                        SetupDatabaseHelper.RemoveDB(true);
                    }
                }
            }
            catch (ArgumentException exception)
            {
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.FailureReason))
                {
                    PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.FailureReason, exception);
                }
                returnValue = false;
            }

            // Do any other tasks that are needed.
            return(returnValue);
        }
Beispiel #14
0
        public static int Main()
        {
            SetupReturnValues returnValue = SetupReturnValues.Failed;

            // This is needed to load the WPF stuff so
            // that we can get at the resources.
            Application apptry = Application.Current;

            Application.Equals(apptry, null);

            SetDefaultPropertyValues();

            SetupLogger.Initialize(PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagConstants.DefaultLogName));
            SetupLogger.LogInfo("Application Started");
            bool  createdNew;
            Mutex mSetupwizard = new Mutex(true, @"Global\Phoenix Setup", out createdNew);

            if (!createdNew)
            {
                SetupLogger.LogInfo("There is already another setup wizard running on this computer.");
                SetupLogger.LogInfo("Please wait until that program is finished.");
                returnValue = SetupReturnValues.AnotherSetupRunningOnThisMachine;
                MessageBox.Show(WPFResourceDictionary.AnotherSetupRunningOnThisMachineMessage, WPFResourceDictionary.SetupMessageBoxTitle, MessageBoxButton.OK);
                goto AllDone;
            }

            try
            {
                // Set CurrentDirectory
                Environment.CurrentDirectory = PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagDictionary.SetupExePath);

                try
                {
                    SetupLogger.Initialize(SetupHelpers.SetLogFilePath("SetupWizardAdditional.log"), LogLevel.Verbose, true);
                }
                catch (Exception exception)
                {
                    // Since the exception is thrown before the logger is initialized,
                    // just display the message in a message box
                    MessageBox.Show(exception.Message, WPFResourceDictionary.SetupMessageBoxTitle, MessageBoxButton.OK);
                    goto AllDone;
                }

                if (!ParseCommandLine())
                {
                    // Could not parse the command line
                    returnValue = SetupReturnValues.InvalidCommandLine;
                    goto AllDone;
                }

                // Get the state of the components on; this machine
                SystemStateDetection.CheckInstalledComponents();

                // If not silent, show splash screen here
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.Silent))
                {
                    Program.splashPage = new SplashPage();
                    Program.splashPage.Show();
                }
                else
                {
                    // Silent setup
                    // Check command line against the existing components
                    if (!CheckCommandLine())
                    {
                        returnValue = SetupReturnValues.InvalidCommandLine;
                        goto AllDone;
                    }
                }

                // If we don't have a location for the setup files, assume current location.
                if (!PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.LocationOfSetupFiles))
                {
                    PropertyBagDictionary.Instance.SafeAdd(
                        PropertyBagConstants.LocationOfSetupFiles,
                        PropertyBagDictionary.Instance.GetProperty <string>(PropertyBagDictionary.SetupExePath));
                }

                // Check to see if the path is valid for our install
                if (!SetupValidationHelpers.IsValidPathForInstall(SetupInputs.Instance.FindItem(SetupInputTags.BinaryInstallLocationTag)))
                {
                    SetupLogger.LogInfo("Invalid path passed to the setup. {0}", SetupInputs.Instance.FindItem(SetupInputTags.BinaryInstallLocationTag));
                    returnValue = SetupReturnValues.InvalidCommandLine;
                    if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.Silent))
                    {
                        goto AllDone;
                    }
                }

                // What we have selected is valid given the machine state, etc...
                if (!SetupHelpers.RationalizeComponents())
                {
                    SetupLogger.LogInfo("We could not rationalize the component choices.  We must fail.");
                    returnValue = SetupReturnValues.InvalidCommandLine;

                    goto AllDone;
                }

                // Need to load the install data items
                XmlSerializer dataItemSerializer = new XmlSerializer(typeof(InstallItems));
                using (MemoryStream stream = new MemoryStream())
                {
                    StreamWriter writer = new StreamWriter(stream);
                    writer.Write(Properties.Resources.InstallItems);
                    writer.Flush();
                    stream.Position = 0;
                    InstallItems inputInstallItems = (InstallItems)dataItemSerializer.Deserialize(stream);
                    SetupLogger.LogInfo("Start adding DataItems");
                    foreach (InstallItemsInstallDataItem installDataItem in inputInstallItems.InstallDataItem)
                    {
                        SetupLogger.LogInfo(installDataItem.DisplayTitle);

                        // localize the display title
                        installDataItem.DisplayTitle = InstallItemDisplayTitleEnumHelper.GetName((InstallItem)Enum.Parse(typeof(InstallItem), installDataItem.DisplayTitle));
                        // Add this Item to our data items
                        InstallDataItemRegistry.Instance.RegisterDataItem(installDataItem);
                    }
                    SetupLogger.LogInfo("Done adding DataItems");
                }

                if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagDictionary.Silent))
                {
                    returnValue = Program.SilentRun();
                }
                else
                {
                    Program.UiRun();
                    // Set the application return value: Always success in UI mode
                    returnValue = SetupReturnValues.Successful;
                }

                // Create the username/password in the DBs that the service will use to access the DB
                SetupDatabaseHelper.CreateSqlLoginUser(SetupDatabaseHelper.SqlUsernameDuringInstall, SetupDatabaseHelper.SqlDbUserPassword);
            }
            catch (Exception exception)
            {
                SetupLogger.LogInfo("Uncaught Exception", exception);
            }
            finally
            {
            }


            // All done with the install.
AllDone:
            // Reboot if we have to
            RebootIfNeeded();

            //release the setup wizard mutex
            mSetupwizard.ReleaseMutex();

            return((int)returnValue);
        }