private void UpdateSingleUser(string a_KeyID, string a_Verification) { Settings.V1._ApiKey tempKey = new Settings.V1._ApiKey(); UInt32.TryParse(a_KeyID, out tempKey.KeyID); tempKey.Verification = a_Verification; string errorHeader = "Failed to update user " + a_KeyID; XmlDocument xmlReply = EveApi.MakeRequest("account/Characters.xml.aspx", tempKey, 0, errorHeader); if (null == xmlReply) { return; } XmlNodeList characterNodes = xmlReply.GetElementsByTagName("row"); if (0 == characterNodes.Count) { ErrorMessageBox.Show(errorHeader + "No characters found"); return; } DeleteCharactersFromUser(a_KeyID); foreach (XmlNode characterNode in characterNodes) { ListViewItem newItem = LstCharacters.Items.Add(a_KeyID); newItem.SubItems.Add(characterNode.Attributes["characterID"].Value); newItem.SubItems.Add(characterNode.Attributes["name"].Value); newItem.SubItems.Add(characterNode.Attributes["corporationName"].Value); } }
private static String MakeUrl(String a_ApiUrl, Settings.V1._ApiKey a_ApiKey, UInt32 a_ApiUser) { List <String> parameters = new List <String>(); if (null != a_ApiKey) { parameters.Add("KeyID=" + a_ApiKey.KeyID); parameters.Add("vCode=" + a_ApiKey.Verification); } if (0 != a_ApiUser) { parameters.Add("characterID=" + a_ApiUser); } String parameterList = String.Join("&", parameters.ToArray()); string requestUrl = "http://api.eve-online.com/" + a_ApiUrl; if ("" != parameterList) { requestUrl += "?"; requestUrl += parameterList; } return(requestUrl); }
private bool LoadSkills(Settings.V1._ApiKey a_ApiKey, UInt32 a_UserID, Dictionary <UInt32, UInt32> a_Result) { String errorHeader = "Failed to load skills"; XmlDocument xmlReply = EveApi.MakeRequest("char/CharacterSheet.xml.aspx", a_ApiKey, a_UserID, errorHeader); if (null == xmlReply) { return(false); } try { XmlNodeList skillNodes = xmlReply.SelectNodes("/eveapi/result/rowset[@name='skills']/row"); foreach (XmlNode currNode in skillNodes) { UInt32 typeID = UInt32.Parse(currNode.Attributes["typeID"].Value); UInt32 level = UInt32.Parse(currNode.Attributes["level"].Value); a_Result[typeID] = level; } } catch (System.Exception a_Exception) { ErrorMessageBox.Show(errorHeader + ":\n" + "Failed to parse EVE API reply:\n" + a_Exception.Message); return(false); } // Safety check for possible XML format change if (0 == a_Result.Count) { return(false); } return(true); }
public static Settings.V1._ApiKey GetCharacterKey(Settings a_Settings, UInt32 a_CharacterID) { Settings.V1._ApiChar character = a_Settings.ApiAccess.Chars.FirstOrDefault(a => a.CharacterID == a_CharacterID); if (null == character) { return(null); } Settings.V1._ApiKey key = a_Settings.ApiAccess.Keys.FirstOrDefault(a => a.KeyID == character.KeyID); return(key); }
public static XmlDocument MakeRequest(String a_ApiUrl, Settings.V1._ApiKey a_ApiKey, UInt32 a_ApiUser, String a_FailMessage) { try { XmlDocument xmlReply = Engine.LoadXmlWithUserAgent(MakeUrl(a_ApiUrl, a_ApiKey, a_ApiUser)); XmlNodeList errorNodes = xmlReply.GetElementsByTagName("error"); if (0 != errorNodes.Count) { Engine.ShowXmlRequestErrors(a_FailMessage + ":\n", errorNodes); return(null); } return(xmlReply); } catch (System.Net.WebException a_Exception) { String errorHint = ""; if (a_Exception.Response is HttpWebResponse) { HttpWebResponse httpResponse = (HttpWebResponse)a_Exception.Response; switch (httpResponse.StatusCode) { case HttpStatusCode.Forbidden: errorHint = "(Did you provide API key with insufficient access?)"; break; } } String errorMessage = a_FailMessage + ":\n" + a_Exception.Message; if ("" != errorHint) { errorMessage += "\n"; errorMessage += errorHint; } SpecialFNs.ErrorMessageBox.Show(errorMessage); return(null); } catch (System.Exception a_Exception) { SpecialFNs.ErrorMessageBox.Show(a_FailMessage + ":\n" + a_Exception.Message); return(null); } }
public Boolean LoadAssets(UInt32 a_CharID) { string assetsCachePath = GetAssetsCacheFilePath(a_CharID); try { if (LoadAssetsXml(assetsCachePath, true)) { return(true); } } catch (System.Exception a_Exception) { System.Diagnostics.Debug.WriteLine(a_Exception.Message); } Settings.V1._ApiKey apiKey = m_Engine.GetCharacterKey(a_CharID); if (null == apiKey) { return(false); } string errorHeader = "Failed to update assets"; XmlDocument assetsXml = EveApi.MakeRequest("char/AssetList.xml.aspx", apiKey, a_CharID, errorHeader); if (null == assetsXml) { return(false); } ParseAssetsXML(assetsXml); // Ignore saving errors try { assetsXml.Save(assetsCachePath); } catch (System.Exception a_Exception) { System.Diagnostics.Debug.WriteLine(a_Exception.Message); } return(true); }
private bool SavePage_ApiKeys() { if (HasOrphanedUsers()) { if (DialogResult.Yes != MessageBox.Show("You entered some users, but did not [Load characters]. If you continue now, the corresponding characters will not be available.\nContinue anyway?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)) { return(false); } } m_Settings.ApiAccess.Keys.Clear(); for (int i = 0; i < LstUsers.Items.Count; i++) { ListViewItem currItem = LstUsers.Items[i]; string userID = currItem.Text; string apiKey = currItem.SubItems[1].Text; Settings.V1._ApiKey newRow = new Settings.V1._ApiKey(); newRow.KeyID = Convert.ToUInt32(userID); newRow.Verification = apiKey; m_Settings.ApiAccess.Keys.Add(newRow); } m_Settings.ApiAccess.Chars.Clear(); for (int i = 0; i < LstCharacters.Items.Count; i++) { ListViewItem currItem = LstCharacters.Items[i]; string keyID = currItem.Text; string charID = currItem.SubItems[1].Text; string charName = currItem.SubItems[2].Text; string charCorp = currItem.SubItems[3].Text; Settings.V1._ApiChar newRow = new Settings.V1._ApiChar(); newRow.KeyID = Convert.ToUInt32(keyID); newRow.CharacterID = Convert.ToUInt32(charID); newRow.CharacterName = charName; newRow.CorporationName = charCorp; m_Settings.ApiAccess.Chars.Add(newRow); } return(true); }
private void BtnLoadSkills_Click(object sender, EventArgs e) { if (null == CmbLoadSkills.SelectedItem) { return; } UInt32 userID = TextItemWithUInt32.GetData(CmbLoadSkills.SelectedItem); Settings.V1._ApiKey apiKey = Engine.GetCharacterKey(m_Settings, userID); if (null == apiKey) { ErrorMessageBox.Show("Can't find API key for selected character"); return; } Dictionary <UInt32, UInt32> skills = new Dictionary <UInt32, UInt32>(); if (!LoadSkills(apiKey, userID, skills)) { return; } EveSkills[] skillIDs = (EveSkills[])Enum.GetValues(typeof(EveSkills)); foreach (EveSkills currSkill in skillIDs) { UInt32 skillLevel = 0; if (skills.ContainsKey((UInt32)currSkill)) { skillLevel = skills[(UInt32)currSkill]; } m_Settings.Refining.Skills[(UInt32)currSkill] = skillLevel; } PrpRefining.Refresh(); }