示例#1
0
        /// <summary>
        /// Fetches the value of the specified environment variable.
        /// </summary>
        /// <param name="environmentVariable">The name of the environment variable.</param>
        /// <returns>The value of the environment variable.</returns>
        public string FetchEnvironmentVariableValue(String environmentVariable)
        {
            var query = $"SELECT * FROM Win32_Environment WHERE Name='{environmentVariable}'";
            var value = WMI.WMIQuery_GetPropertyValue(_mgmtScope, query, "variableValue");

            return(value);
        }
示例#2
0
        public TestServer(String address = null, bool factoryReset = false)
        {
            if (address != null)
            {
                _address = address;
                Common.LockServer(_address);
            }
            else
            {
                if (Settings.RemoteServers.Length > 1 && Settings.Environment == Enumerations.EnvironmentSetting.Remote)
                {
                    _address = Common.FindAndLockATestServer();
                }
                else if (Settings.RemoteServers.Length == 1 && Settings.Environment == Enumerations.EnvironmentSetting.Remote)
                {
                    _address = Settings.RemoteServers[0];
                    Common.LockServer(_address);
                }
                else
                {
                    _address = System.Environment.MachineName;
                }
            }

            if (Settings.Environment == Enumerations.EnvironmentSetting.Remote)
            {
                _connection = new ConnectionOptions {
                    Authentication = AuthenticationLevel.PacketPrivacy, Username = "******", Password = "******"
                };
                _driveRoot = $@"\\{_address}\C$\";
            }
            else
            {
                _connection = new ConnectionOptions {
                    Authentication = AuthenticationLevel.PacketPrivacy
                };
                _driveRoot = @"C:\";
            }

            _dataPath    = $@"{_driveRoot}ProgramData\New Relic\.NET Agent\";
            _installPath = $@"{_driveRoot}Program Files\New Relic\.NET Agent\";

            _mgmtScope = new ManagementScope {
                Options = _connection, Path = new ManagementPath($@"\\{_address}\root\cimv2")
            };

            _configPath            = $@"{_dataPath}\newrelic.config";
            _processorArchitecture = WMI.WMIQuery_GetPropertyValue(_mgmtScope, "SELECT * FROM Win32_OperatingSystem", "OSArchitecture") == "64-bit"
                ? "x64"
                : "x86";
            _processorBit = _processorArchitecture == "x64"
                ? "64"
                : "32";

            if (factoryReset)
            {
                FactoryReset();
            }
        }