当前位置: 首页>>代码示例>>C#>>正文


C# Session.Property方法代码示例

本文整理汇总了C#中Session.Property方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Property方法的具体用法?C# Session.Property怎么用?C# Session.Property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Session的用法示例。


在下文中一共展示了Session.Property方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnInstall

    public static ActionResult OnInstall(Session session)
    {
        //Note if your custom action requires non-GAC assembly then you need deploy it too.
        //You can do it by setting ManagedAction.RefAssemblies.
        //See "Wix# Samples\DTF (ManagedCA)\Different Scenarios\ExternalAssembly" sample for details.

        //System.Diagnostics.Debugger.Launch();

        session.Log("------------- " + session.Property("INSTALLDIR"));
        session.Log("------------- " + session.Property("CONFIG_FILE"));
        session.Log("------------- " + session.Property("APP_FILE"));

        return session.HandleErrors(() =>
        {
            string configFile = session.Property("INSTALLDIR") + "MyApp.exe.config";

            //alternative ways of extracting 'deferred' properties
            //configFile = session.Property("APP_FILE") + ".config";
            //configFile = session.Property("CONFIG_FILE");

            UpdateAsAppConfig(configFile);

            //alternative implementations for the config manipulations
            UpdateAsXml(configFile);
            UpdateAsText(configFile);
            UpdateWithWixSharp(configFile);

            MessageBox.Show(GetContext());
        });
    }
开发者ID:Eun,项目名称:WixSharp,代码行数:30,代码来源:setup.cs

示例2: ChangeUserAccountOfServiceForWindowsAuthentication

    /// <summary>
    /// Changes installed SonarQube service's log on user to current logged on user
    /// if windows authentication is chosen.
    /// </summary>
    public static bool ChangeUserAccountOfServiceForWindowsAuthentication(Session session)
    {
        string authType = session.Property("SQLAUTHTYPE");
        string setupType = session.Property("SETUPTYPE");
        string currentLoggedInUser = session.Property("CURRENTLOGGEDINUSER");

        bool success = true;

        // If authentication type is Windows, we need to change the service log on to current user.
        // For SQL auth, it works with System log on which is the default one.
        if (AuthenticationType.Windows.Equals(authType, StringComparison.InvariantCultureIgnoreCase) &&
            SetupType.Express.Equals(setupType, StringComparison.InvariantCultureIgnoreCase))
        {
            try
            {
                string queryString = "SELECT * FROM WIN32_SERVICE WHERE DISPLAYNAME='SonarQube'";

                ObjectQuery oQuery = new ObjectQuery(queryString);
                ManagementObjectSearcher objectSearcher = new ManagementObjectSearcher(oQuery);
                ManagementObjectCollection objectCollection = objectSearcher.Get();

                foreach (ManagementObject mObject in objectCollection)
                {
                    string serviceName = mObject.GetPropertyValue("Name") as string;
                    string fullServiceName = "Win32_Service.Name='" + serviceName + "'";
                    ManagementObject mo = new ManagementObject(fullServiceName);

                    string username = currentLoggedInUser;
                    string password = string.Empty;

                    // Ask current logged on user's password
                    if (!WindowsAuthenticationHelper.PromptForPassword(session, username, out password))
                    {
                        // [TODO] Localization
                        SendMessageBoxMessageToBA(session, "Authentication failed. Service may not run as expected.");
                        success = false;
                    }
                    else
                    {
                        mo.InvokeMethod("Change", new object[] { null, null, null, null, null, null, username, password, null, null, null });
                    }
                }
            }
            catch (Exception e)
            {
                session.Log("[ChangeUserAccountForService] {0}", e.Message);
            }
        }
        return success;
    }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:54,代码来源:Program.cs

示例3: InstallSonarQubeNTService

    /// <summary>
    /// Installs SonarQube NT service.
    /// </summary>
    public static bool InstallSonarQubeNTService(Session session)
    {
        bool result = true;
        Process installServiceProcess = new Process();
        JavaVersionInformation information = JavaVersionHelper.GetJavaVersionInformation();

        installServiceProcess.StartInfo.FileName = session.Property("INSTALLDIR") +
                                                   string.Format(@"\{0}\bin\windows-x86-{1}\InstallNTService.bat",
                                                                 BootstrapperConstants.SonarQubeProductName,
                                                                 (int)information.Architecture);

        installServiceProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        installServiceProcess.StartInfo.CreateNoWindow = true;
        installServiceProcess.StartInfo.UseShellExecute = false;
        installServiceProcess.Start();

        // We have to set the wait time for this process as in case of failures, batch file
        // prompts user about the failure and waits for the user response (key hit) to exit.
        installServiceProcess.WaitForExit(ProcessExitWaitTime);

        // This needs to be done as this batch file can wait for standard input in case of failure.
        // We nicely kill this process ourselves in this case to not stop the setup from progressing.
        if (!installServiceProcess.HasExited)
        {
            installServiceProcess.Kill();
        }

        if (installServiceProcess.ExitCode != 0)
        {
            session.Log("[InstallSonarQubeNTService] Process exited with {0}", installServiceProcess.ExitCode);
            result = false;
        }

        return result;
    }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:38,代码来源:Program.cs

示例4: UnzipSonarQube

        public static ActionResult UnzipSonarQube(Session session)
        {
            try
            {
                SendProgressMessageToBA(session, "Unzipping SonarQube 5.2", 3);

                string archivePath = Path.Combine(session.Property("INSTALLDIR"), BootstrapperConstants.SonarQubeProductName + ".zip");
                string extractPath = session.Property("INSTALLDIR");

                ZipFile.ExtractToDirectory(archivePath, extractPath);
                System.IO.File.Delete(archivePath);
                return ActionResult.Success;
            }
            catch (Exception e)
            {
                session.Log("[UnzipSonarQube] {0}", e.Message);
                return ActionResult.Failure;
            }
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:19,代码来源:Program.cs

示例5: StartSonarBatch

        public static ActionResult StartSonarBatch(Session session)
        {
            try
            {
                SendProgressMessageToBA(session, "Starting SonarQube process", 6);

                Process sonarServerBatchProcess = new Process();
                JavaVersionInformation information = JavaVersionHelper.GetJavaVersionInformation();

                sonarServerBatchProcess.StartInfo.FileName = session.Property("INSTALLDIR") +
                                                                string.Format(@"\{0}\bin\windows-x86-{1}\StartSonar.bat",
                                                                            BootstrapperConstants.SonarQubeProductName,
                                                                            (int)information.Architecture);

                sonarServerBatchProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                sonarServerBatchProcess.StartInfo.UseShellExecute = false;
                sonarServerBatchProcess.Start();
                return ActionResult.Success;
            }
            catch (Exception e)
            {
                session.Log("[StartSonarBatch] {0}", e.Message);
                return ActionResult.Failure;
            }
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:25,代码来源:Program.cs

示例6: SetupSonarQubeConfiguration

        public static ActionResult SetupSonarQubeConfiguration(Session session)
        {
            return session.HandleErrors(() =>
            {
                SendProgressMessageToBA(session, "Configuring SonarQube", 5);

                // The default temp directory can be only accessed by SYSTEM account. Hence we change
                // the temp directory to the one present in SonarQube installation folder.
                try
                {
                    System.IO.File.AppendAllText(Path.Combine(session.Property("INSTALLDIR"), BootstrapperConstants.SonarQubeProductName, @"conf\wrapper.conf"),

                                                 Environment.NewLine
                                                 + "wrapper.java.additional.2=-Djava.io.tmpdir=../../temp/"
                                                 + Environment.NewLine);
                }
                catch (Exception e)
                {
                    session.Log("[SetupSonarQubeConfiguration] {0}", e.Message);
                }

                try
                {
                    string setupType = session.Property("SETUPTYPE");

                    if (setupType.Equals(SetupType.Express, StringComparison.InvariantCultureIgnoreCase)
                        || setupType.Equals(SetupType.Custom, StringComparison.InvariantCultureIgnoreCase))
                    {
                        // Update SonarQube configuration file
                        session.Log("[SetupSonarQubeConfiguration] Updating sonar.properties for {0} setup.", setupType);
                        SonarConfigurationFileEditor.UpdateSonarPropertiesFileForSql(session);
                    }
                }
                catch (Exception e)
                {
                    session.Log("[SetupSonarQubeConfiguration] {0}", e.Message);
                }
            });
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:39,代码来源:Program.cs

示例7: SetSqlAuthInEnvironmentPath

        public static ActionResult SetSqlAuthInEnvironmentPath(Session session)
        {
            return session.HandleErrors(() =>
            {
                SendProgressMessageToBA(session, "Configuring SQL authentication dll", 4);

                string setupType = session.Property("SETUPTYPE");

                if (SetupType.Express.Equals(setupType, StringComparison.InvariantCultureIgnoreCase))
                {
                    SetPathToSqlAuthDllForTarget(session, EnvironmentVariableTarget.Machine);
                    SetPathToSqlAuthDllForTarget(session, EnvironmentVariableTarget.User);
                }
            });
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:15,代码来源:Program.cs

示例8: CleanSonarQubeInstallation

        public static ActionResult CleanSonarQubeInstallation(Session session)
        {
            return session.HandleErrors(() =>
            {
                SendProgressMessageToBA(session, "Cleaning SonarQube", 2);

                string extractPath = session.Property("INSTALLDIR");

                try
                {
                    Directory.Delete(extractPath, true);
                }
                catch (Exception e)
                {
                    session.Log("[CleanSonarQubeInstallation] {0}", e.Message);
                }
            });
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:18,代码来源:Program.cs

示例9: ChangeUserPrivilegesToLogOnAsService

        public static ActionResult ChangeUserPrivilegesToLogOnAsService(Session session)
        {
            return session.HandleErrors(() =>
            {
                string ntrightsPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), @"ntrights.exe");
                string setupType = session.Property("SETUPTYPE");
                string currentLoggedInUser = session.Property("CURRENTLOGGEDINUSER");

                if (SetupType.Express.Equals(setupType, StringComparison.InvariantCultureIgnoreCase))
                {
                    SendProgressMessageToBA(session, "Granting user log on as service permission", 1);

                    session.SaveBinary("NtRights", ntrightsPath);

                    try
                    {
                        Process ntRightsProcess = new Process();

                        ntRightsProcess.StartInfo.FileName = ntrightsPath;
                        ntRightsProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        ntRightsProcess.StartInfo.CreateNoWindow = true;
                        ntRightsProcess.StartInfo.UseShellExecute = false;
                        ntRightsProcess.StartInfo.Arguments = "+r SeServiceLogonRight -u \"" + currentLoggedInUser + "\"";

                        ntRightsProcess.Start();

                        ntRightsProcess.WaitForExit(ProcessExitWaitTime);

                        // This needs to be done as this process can wait for standard input in case of failure.
                        // We nicely kill this process ourselves in this case to not stop the setup from progressing.
                        if (!ntRightsProcess.HasExited)
                        {
                            ntRightsProcess.Kill();
                        }

                        if (ntRightsProcess.ExitCode == 0)
                        {
                            // [TODO] Add strings for localization
                            SendMessageBoxMessageToBA(session, string.Format("The account {0} has been granted the Log On As A Service right.",
                                                                    currentLoggedInUser));
                        }
                        else
                        {
                            SendMessageBoxMessageToBA(session, string.Format("The account {0} couldn't be grated the Log On As A Service right.",
                                                                    currentLoggedInUser));
                        }
                    }
                    catch (Exception e)
                    {
                        session.Log("[ChangeUserPrivilegesToLogOnAsService] {0}", e.Message);
                    }
                    finally
                    {
                        // We can safely try to delete this file here as Delete() doesn't throw exception for
                        // file not found.
                        System.IO.File.Delete(ntrightsPath);
                    }
                }
            });
        }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:60,代码来源:Program.cs

示例10: SetPathToSqlAuthDllForTarget

    public static bool SetPathToSqlAuthDllForTarget(Session session, EnvironmentVariableTarget target)
    {
        // Set the path for sql auth dll so that SonarQube service can find it for sql connection

        string pathVal = Environment.GetEnvironmentVariable("Path", target);
        string pathToSqlAuthDll = string.Empty;

        // If Path variable's value is null, we need to check if we're remotely connected to the machine
        // If yes, we return without doing anything otherwise log an error.
        if (pathVal == null)
        {
            string sessionName = Environment.GetEnvironmentVariable("SessionName", EnvironmentVariableTarget.Machine);

            if (sessionName != null &&
                sessionName.StartsWith("RDP"))
            {
                session.Log("[SetPathToSqlAuthDllForTarget] Remotely connected to machine {0}", sessionName);

                return true;
            }
            else
            {
                session.Log("[SetPathToSqlAuthDllForTarget] Couldn't get path environment variable's value");

                return false;
            }
        }

        pathToSqlAuthDll = session.Property("INSTALLDIR");

        if (!pathVal.Contains(pathToSqlAuthDll))
        {
            Environment.SetEnvironmentVariable("Path",
                                               Environment.GetEnvironmentVariable("Path", target)
                                               + ";" + pathToSqlAuthDll,
                                               target);
        }

        return true;
    }
开发者ID:SonarQubeCommunity,项目名称:sonarqube-windows-installer,代码行数:40,代码来源:Program.cs


注:本文中的Session.Property方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。