Skip to content

Instantly share code, notes, and snippets.

@HowardvanRooijen
Created February 26, 2015 11:24
Show Gist options
  • Save HowardvanRooijen/af02a80c2d1f70a50094 to your computer and use it in GitHub Desktop.
Save HowardvanRooijen/af02a80c2d1f70a50094 to your computer and use it in GitHub Desktop.
ValidNumberOfCoresLicenseRule
public class ValidNumberOfCoresLicenseRule : ILicenseValidationRule
{
public void Validate(LicenseCriteria licenseCriteria)
{
int licensedCores = 0;
if (licenseCriteria.MetaData.ContainsKey("LicensedCores"))
{
licensedCores = Convert.ToInt32(licenseCriteria.MetaData["LicensedCores"]);
}
if (Environment.ProcessorCount > licensedCores)
{
string message = string.Format("This license is only valid for {0} cores.", licensedCores);
throw new LicensedCoresExceededException(message, Environment.ProcessorCount)
{
LicenseCriteria = licenseCriteria
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment