internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo) { IValidationResult validationResult = new ValidationResult(); // Define the bitwise masks for both character and corporation api keys. const int charContractMask = 67108864; const int corpContractMask = 8388608; int checkResult = 0; // Perform a bitwise AND to determine if contract access is available on the api key. if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account) { checkResult = apiKeyInfo.AccessMask & charContractMask; if (checkResult == 0) { validationResult.AddError("ApiKey.AccessMask", "A character api key must have 'Contracts' access enabled."); } } else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation) { checkResult = apiKeyInfo.AccessMask & corpContractMask; if (checkResult == 0) { validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have 'Contracts' access enabled."); } } return validationResult; }
internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo) { IValidationResult validationResult = new ValidationResult(); // Define the bitwise masks for both character and corporation api keys. const int charContractMask = 67108864; const int corpContractMask = 8388608; int checkResult = 0; // Perform a bitwise AND to determine if contract access is available on the api key. if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account) { checkResult = apiKeyInfo.AccessMask & charContractMask; if (checkResult == 0) { validationResult.AddError("ApiKey.AccessMask", "A character api key must have 'Contracts' access enabled."); } } else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation) { checkResult = apiKeyInfo.AccessMask & corpContractMask; if (checkResult == 0) { validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have 'Contracts' access enabled."); } } return(validationResult); }
internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo) { IValidationResult validationResult = new ValidationResult(); // Check the access mask of the key is correct. if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account) { if (apiKeyInfo.AccessMask != 67108864) { validationResult.AddError("ApiKey.AccessMask", "A character api key must have an access mask of 67108864 ('Contracts' Only)."); } } else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation) { if (apiKeyInfo.AccessMask != 8388608) { validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have an access mask of 8388608 ('Contracts' Only)."); } } return validationResult; }
/// <summary> /// This method returns information about an Api Key and the characters exposed by it. /// </summary> /// <param name="apiId">A valid eve api id (keyID).</param> /// <param name="apiKey">A valid eve api key (vCode).</param> /// <param name="apiUrl">An optional apiUrl parameter that overrides the method's internal value. Primarily used in unit tests to force errors.</param> /// <returns>Returns a populated IEveDataApiKey object relating to the passed Api Key, or a null object if a problem occured.</returns> internal IEveDataApiKey ApiKeyInfo(int apiId, string apiKey, string apiUrl = "") { XDocument xmlDoc; IEveDataApiKey apiKeyInfo = null; // Assign the Api Url to a string if it has not already been passed as a parameter. if (apiUrl == string.Empty) { apiUrl = "https://api.eveonline.com/account/APIKeyInfo.xml.aspx?keyID=" + apiId + "&vCode=" + apiKey; } try { xmlDoc = XDocument.Load(apiUrl); // Populate key values. apiKeyInfo = xmlDoc.Descendants("key") .Select(x => new EveDataApiKey() { AccessMask = Conversion.StringToInt32(x.Attribute("accessMask").Value), Expires = Conversion.StringToDateTime(x.Attribute("expires").Value), Type = Conversion.StringToEnum <EveDataApiKeyType>(x.Attribute("type").Value, EveDataApiKeyType.Character) }) .FirstOrDefault(); // Populate key characters. apiKeyInfo.Characters = xmlDoc.Descendants("row") .Select(x => new EveDataApiKeyCharacter() { CharacterId = Conversion.StringToInt32(x.Attribute("characterID").Value), CharacterName = x.Attribute("characterName").Value, CorporationId = Conversion.StringToInt32(x.Attribute("corporationID").Value), CorporationName = x.Attribute("corporationName").Value }) .ToList(); } catch (System.FormatException e) { logger.LogMessage("An error occured while parsing the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the data source present and correct?", 0, "Message", MethodBase.GetCurrentMethod().Name); logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name); } catch (System.Net.WebException e) { logger.LogMessage("An error occured while parsing the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the data source present and correct?", 0, "Message", MethodBase.GetCurrentMethod().Name); logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name); } catch (System.Xml.XmlException e) { logger.LogMessage("An error occured while loading the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the API available?", 0, "Message", MethodBase.GetCurrentMethod().Name); logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name); } catch (System.NullReferenceException e) { logger.LogMessage("An error occured while loading the CCP ApiKeyInfo Xml for ApiID: " + apiId + ". Is the API key correct?", 0, "Message", MethodBase.GetCurrentMethod().Name); logger.LogMessage(e.ToString(), 0, "Exception", MethodBase.GetCurrentMethod().Name); } catch (Exception) { throw; } return(apiKeyInfo); }
public IValidationResult ApiKey(IEveDataApiKey apiKeyInfo) { return(SalesAgentCheck.ApiKey(apiKeyInfo)); }
/// <summary> /// <para>Adds a sales agent from an api key and account id.</para> /// </summary> /// <param name="apiId">A valid eve api id (keyID).</param> /// <param name="apiKey">A valid eve api key (vCode).</param> /// <param name="accountId">The id of the account for which a sales agent should be added.</param> /// <returns>Returns a validation result object.</returns> internal IValidationResult AddSalesAgent(int apiId, string apiKey, int accountId) { IValidationResult validationResult = new ValidationResult(); // Check the remaining sales agent licences for the account. if (this.GetRemainingSalesAgentLicences(accountId) <= 0) { validationResult.AddError("SalesAgent.Licences", "You have exceeded the number of sales agent licences available with your account subscription plan."); } else { // Fetch details about the Api Key from Eve Data. IEveDataApiKey apiKeyInfo = this.eveDataSource.GetApiKeyInfo(apiId, apiKey); if (apiKeyInfo != null) { // Validate the api key. validationResult = this.doctrineShipsValidation.ApiKey(apiKeyInfo); if (validationResult.IsValid == true) { // Use the api key info to populate a new sales agent object. SalesAgent newSalesAgent = new SalesAgent(); // If this is a character or account key use the character details, if a corp key use the corp details. if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account) { // If this is an account key, the first character in the list will be used. newSalesAgent.SalesAgentId = apiKeyInfo.Characters.FirstOrDefault().CharacterId; newSalesAgent.Name = apiKeyInfo.Characters.FirstOrDefault().CharacterName; newSalesAgent.ImageUrl = eveDataSource.GetCharacterPortraitUrl(newSalesAgent.SalesAgentId); newSalesAgent.IsCorp = false; } else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation) { newSalesAgent.SalesAgentId = apiKeyInfo.Characters.FirstOrDefault().CorporationId; newSalesAgent.Name = apiKeyInfo.Characters.FirstOrDefault().CorporationName; newSalesAgent.ImageUrl = eveDataSource.GetCorporationLogoUrl(newSalesAgent.SalesAgentId); newSalesAgent.IsCorp = true; } // Populate the remaining properties. newSalesAgent.AccountId = accountId; newSalesAgent.ApiId = apiId; newSalesAgent.ApiKey = apiKey; newSalesAgent.IsActive = true; newSalesAgent.LastForce = DateTime.UtcNow; newSalesAgent.LastContractRefresh = DateTime.UtcNow; // Validate the new sales agent. validationResult = this.doctrineShipsValidation.SalesAgent(newSalesAgent); if (validationResult.IsValid == true) { // Add the new sales agent and log the event. this.doctrineShipsRepository.CreateSalesAgent(newSalesAgent); this.doctrineShipsRepository.Save(); logger.LogMessage("Sales Agent '" + newSalesAgent.Name + "' Successfully Added For Account Id: " + newSalesAgent.AccountId, 2, "Message", MethodBase.GetCurrentMethod().Name); } } } else { validationResult.AddError("ApiKey.Valid", "An invalid api key was entered or the eve api is currently unavailable."); } } return(validationResult); }
public IValidationResult ApiKey(IEveDataApiKey apiKeyInfo) { return SalesAgentCheck.ApiKey(apiKeyInfo); }