public string Check(string key, CheckMode checkMode, KeyDatabase keyDatabase) { key = key.ToUpper(); string result = ""; for (int j = 0; j < key.Length; j++) { char chr = key[j]; if (!(chr == '-' || (chr >= '0' && chr <= '9') || (chr >= 'A' && chr <= 'Z'))) { return(result); } } KeyDetail detail = keyDatabase.GetKeyDetail(key); bool isKeyExistOnDB = true; if (detail == null) //Key is not exist on DB { detail = PIDChecker.Check(key); isKeyExistOnDB = false; } if (detail == null || detail.prd.Contains("Unsupported")) //Key is invalid { // result += "Key: " + key + "\n"; // result += "Error: Key is invalid or not supported\n\n"; return(result); } bool isActivationCountUpdated = false; bool isErrorCodeUpdated = false; bool isGetErrorCodeFail = false; if (!(isKeyExistOnDB && detail.activationCount < 0)) { detail.activationCount = GetRemainingActivations(detail.eid); isActivationCountUpdated = true; } if (detail.activationCount <= 0) { bool isNeedGetErrorCode = true; bool isVLKey = false; if (detail.activationCount == 0) { isVLKey = true; } if (detail.errorCode == "0xC004C003" || detail.errorCode == "0xC004C060" || detail.errorCode == "0xC004C004" || detail.errorCode == "Key Blocked") //key blocked or no remaining { isNeedGetErrorCode = false; } else { if (isKeyExistOnDB && detail.time != "") { var now = DateTime.Now; var lastTime = Utils.ConvertStringToTime(detail.time); var dt = now - lastTime; int timeToRecheck = 4; if (detail.prd.Contains("Windows 7") || detail.prd.Contains("Office14")) { timeToRecheck = 10; } if (dt.TotalMinutes <= timeToRecheck) { isNeedGetErrorCode = false; } } } if (isNeedGetErrorCode && checkMode == CheckMode.ALL_DATA) { string errorCode = this.GetErrorCodeOnServer(detail.prd, detail.key, isVLKey); if (errorCode == "") { isGetErrorCodeFail = true; } else { detail.errorCode = errorCode; isErrorCodeUpdated = true; } } } if (!isKeyExistOnDB) { detail.time = Utils.GetCurrentTime(); keyDatabase.AddKeyToDB(detail); } else if ((isErrorCodeUpdated || isActivationCountUpdated) && !isGetErrorCodeFail) { detail.time = Utils.GetCurrentTime(); keyDatabase.UpdateKeyInDB(detail); } else if (detail.time == "") { detail.time = Utils.GetCurrentTime(); } result += "Key: " + key + "\r\n"; result += "Description: " + detail.prd + "\r\n"; result += "Sub Type: " + detail.sub + "\r\n"; if (detail.activationCount >= 0) { result += "Activation Count: " + detail.activationCount.ToString() + "\r\n"; } if (detail.activationCount <= 0 && checkMode == CheckMode.ALL_DATA) { if (isGetErrorCodeFail) { result += "Error Code: Server busy, please try again later\r\n"; } else { result += "Error Code: " + detail.errorCode + "\r\n"; } } result += "Time: " + detail.time + "\r\n\r\n"; return(result); }
public List <string> FindKeysInLine(string content, CheckMode checkMode, KeyDatabase keyDatabase) { List <string> result = new List <string>(); return(result); }