示例#1
0
        static ServerRole()
        {
            object obj;

            if (CommonUtils.TryGetRegistryValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\ExchangeServer\\v15\\Diagnostics", "RoleName", string.Empty, out obj))
            {
                string text = obj.ToString().Trim();
                if (!string.IsNullOrEmpty(text))
                {
                    ServerRole.installedRoles.Add(text);
                }
            }
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            if (callingAssembly == null)
            {
                ServerRole.version = Environment.OSVersion.Version;
            }
            else
            {
                object[] customAttributes = callingAssembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
                if (customAttributes.Length != 1 || !ServerRole.TryParseVersion(((AssemblyFileVersionAttribute)customAttributes[0]).Version, out ServerRole.version))
                {
                    ServerRole.version = Environment.OSVersion.Version;
                }
            }
            foreach (ServerRole.Role role in ServerRole.roles)
            {
                ServerRole.CheckRole(role.Name, role.RegistryKey, role.RegistryValue);
            }
            if (ServerRole.installedRoles.Count == 0)
            {
                ServerRole.installedRoles.Add("Other");
            }
        }
示例#2
0
        private static void CheckRole(string role, string registryKey, string valueName)
        {
            object obj;

            if (CommonUtils.TryGetRegistryValue(registryKey, valueName, null, out obj))
            {
                ServerRole.installedRoles.Add(role);
                if (valueName != "ConfiguredVersion")
                {
                    return;
                }
                if (!ServerRole.TryParseVersion(obj.ToString(), out ServerRole.version))
                {
                    throw new FormatException("Unable to parse the version of this machine.");
                }
            }
        }