Created
February 26, 2015 11:24
-
-
Save HowardvanRooijen/af02a80c2d1f70a50094 to your computer and use it in GitHub Desktop.
ValidNumberOfCoresLicenseRule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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