public void InitializeEventHandlers() { btnAdd.Click += (object o, EventArgs e) => { if (VerifyValues()) { //Creates base API from KeyID and vCode APIKey newAPI = new APIKey() { KeyID = Convert.ToInt32(txtKeyID.Text), VCode = txtVCode.Text }; //Looks up the keys type (Corp or Char) try { newAPI.Type = _repository.GetAPIType(newAPI); //This will either come back with 1 "Corp" value, or up to 3 for a "Char" key foreach (KeyValuePair<string, string> charOrCorp in _repository.GetCharsOrCorpOnAPI(newAPI)) { //This is the same API, but for a different toon. So use the same key, just change name and id. newAPI.CharacterName = charOrCorp.Key; newAPI.CharacterID = Convert.ToInt32(charOrCorp.Value); try { _repository.AddAPIKey(newAPI); _logger.Info("New API Added. KeyID: " + newAPI.KeyID + "vCode: " + newAPI.VCode); } catch (Exception exn) { _logger.Error(string.Format("Failed to add a new API Key. KeyID: {0}, vCode: {1}. Error: {2}", newAPI.KeyID, newAPI.VCode, exn.Message)); } this.Close(); } } catch (Exception exn) { _logger.Error(string.Format("Unable to retrieve API type KeyID: {0}, vCode: {1}. Exception: {2}", newAPI.KeyID, newAPI.VCode, exn.Message)); apiError.SetError(btnAdd, "Incorrect API Combination, or API server is offline."); } } }; }
public void AddAPIKey(APIKey ApiKey) { if (!File.Exists(ApplicationAPIKeyXMLPath)) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Natalie Cruella\" + System.AppDomain.CurrentDomain.FriendlyName); CreateBaseAPIXML(); } XmlDocument doc = new XmlDocument(); doc.Load(ApplicationAPIKeyXMLPath); System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(APIKey)); StringWriter wr = new StringWriter(); ser.Serialize(wr, ApiKey); XmlDocument newNode = new XmlDocument(); newNode.LoadXml(wr.ToString()); XmlNode newAPI = newNode.DocumentElement; XmlNode nod = doc.DocumentElement; XmlNode importNode = nod.OwnerDocument.ImportNode(newAPI, true); nod.AppendChild(importNode); doc.Save(ApplicationAPIKeyXMLPath); }
public bool IsAPIValid(APIKey key) { System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("user-agent", "LogisticiansTools: - Contact Natalie Cruella"); string URL = string.Format("{0}/account/APIKeyInfo.xml.aspx?keyID={1}&vCode={2}", _baseEveApi, key.KeyID, key.VCode); System.IO.Stream dataStream = webClient.OpenRead(URL); string XMLData = new System.IO.StreamReader(dataStream).ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLData); XmlNode nod = doc.GetElementsByTagName("key")[0]; int accessMask = Convert.ToInt32(nod.Attributes["accessMask"].Value); string apiType = GetAPIType(key); if (apiType.ToUpper() == "CHAR") return (accessMask & 67108864) == 67108864; else if (apiType.ToUpper() == "CORP") return (accessMask & 8388608) == 8388608; else return false; }
public Dictionary<string, string> GetCharsOrCorpOnAPI(APIKey key) { Dictionary<string, string> chars = new Dictionary<string, string>(); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("user-agent", "LogisticiansTools: - Contact Natalie Cruella"); string URL = string.Format("{0}/account/APIKeyInfo.xml.aspx?keyID={1}&vCode={2}", _baseEveApi, key.KeyID, key.VCode); System.IO.Stream dataStream = webClient.OpenRead(URL); string XMLData = new System.IO.StreamReader(dataStream).ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLData); XmlNodeList nodes = doc.GetElementsByTagName("row"); if (key.Type.ToLower() == "corp") { //chars.Add(nodes[0].Attributes["corporationName"].Value.ToString() + " (Corp)"); chars.Add(nodes[0].Attributes["corporationName"].Value.ToString() + " (Corp)", nodes[0].Attributes["corporationID"].Value.ToString()); } else if (key.Type.ToLower() == "char") { foreach (XmlNode nod in nodes) { //chars.Add(nod.Attributes["characterName"].Value.ToString() + " (Pilot)"); chars.Add(nod.Attributes["characterName"].Value.ToString() + " (Pilot)", nod.Attributes["characterID"].Value.ToString()); } } return chars; }
public IEnumerable<Contract> GetAvailableContractsByStatus(APIKey key, string status) { IEnumerable<Contract> contracts = GetAvailableContracts(key); return contracts.ToList().Where(x => x.Status == status); }
public IEnumerable<Contract> GetAvailableContracts(APIKey key) { List<Contract> contracts = new List<Contract>(); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("user-agent", "LogisticiansTools: - Contact Natalie Cruella"); string URL = string.Format("{0}/{1}/Contracts.xml.aspx?keyID={2}&vCode={3}", _baseEveApi, key.Type, key.KeyID, key.VCode); if (key.Type.ToUpper() == "CHAR") { URL += "&characterID=" + key.CharacterID; } System.IO.Stream dataStream = webClient.OpenRead(URL); string XMLData = new System.IO.StreamReader(dataStream).ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLData); XmlNodeList nodes = doc.GetElementsByTagName("row"); foreach (XmlNode node in nodes) { if (node.Attributes["type"].Value.ToString().ToLower() == "courier" && (node.Attributes["status"].Value.ToString().ToLower() == "outstanding" || node.Attributes["status"].Value.ToString().ToLower() == "inprogress")) { Contract newContract = new Contract() { AssigneeID = Convert.ToInt32(node.Attributes["assigneeID"].Value), ContractID = Convert.ToInt32(node.Attributes["contractID"].Value), ContractType = node.Attributes["type"].Value.ToString(), EndStationID = Convert.ToInt32(node.Attributes["endStationID"].Value), Reward = Convert.ToDecimal(node.Attributes["reward"].Value), Collateral = Convert.ToDecimal(node.Attributes["collateral"].Value), Expiration = Convert.ToDateTime(node.Attributes["dateExpired"].Value), IssuerCorpID = Convert.ToInt32(node.Attributes["issuerCorpID"].Value), IssuerID = Convert.ToInt32(node.Attributes["issuerID"].Value), StartStationID = Convert.ToInt32(node.Attributes["startStationID"].Value), Status = node.Attributes["status"].Value.ToString(), Volume = Convert.ToSingle(node.Attributes["volume"].Value) }; newContract.StartStation = GetStationByID(newContract.StartStationID); newContract.StartSystem = newContract.StartStation.SolarSystem; newContract.EndStation = GetStationByID(newContract.EndStationID); newContract.EndSystem = newContract.EndStation.SolarSystem; contracts.Add(newContract); } } return contracts; }
public string GetAPIType(APIKey key) { System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("user-agent", "LogisticiansTools: - Contact Natalie Cruella"); string URL = string.Format("{0}/account/APIKeyInfo.xml.aspx?keyID={1}&vCode={2}", _baseEveApi, key.KeyID, key.VCode); System.IO.Stream dataStream = webClient.OpenRead(URL); string XMLData = new System.IO.StreamReader(dataStream).ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLData); string apiType = doc.GetElementsByTagName("key")[0].Attributes["type"].Value.ToString(); apiType = (apiType == "Character" || apiType == "Account") ? "Char" : "Corp"; return apiType; }
public void DeleteAPIKey(APIKey key) { System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(APIKey)); XmlDocument doc = new XmlDocument(); doc.Load(ApplicationAPIKeyXMLPath); XmlNode docNode = doc.DocumentElement; XmlNodeList nodes = doc.GetElementsByTagName("APIKey"); foreach (XmlNode nod in nodes) { APIKey apiKey = (APIKey)ser.Deserialize(new StringReader(nod.OuterXml)); if (apiKey.VCode == key.VCode && apiKey.KeyID == key.KeyID && apiKey.CharacterName == key.CharacterName) { docNode.RemoveChild(nod); break; } } doc.Save(ApplicationAPIKeyXMLPath); }
private void PopulateContracts(APIKey key) { pnlContractCont.Controls.Clear(); try { IEnumerable<Contract> contracts = new List<Contract>(); if (key != null) { //Get all available contracts on the key. So if they are outstanding or in-progress if (cmbStatus.Text.Trim() == "All") contracts = _dataRepository.GetAvailableContracts(key); else contracts = _dataRepository.GetAvailableContractsByStatus(key, cmbStatus.Text.Trim()); } if (contracts.Count() == 0) { Label noContracts = new Label(); noContracts.Text = "No Contracts"; //Center the label on the panel noContracts.Location = new Point((pnlContractCont.Width / 2 ) - (noContracts.Width / 2), 20); pnlContractCont.Controls.Add(noContracts); } else { foreach (Contract contract in contracts.OrderBy(x => x.Expiration).ToList()) { //Create a new contract view control for each contract. _PropertyChanged event is raised when the control is clicked / chosen ContractView newContract = new ContractView(contract); newContract.Width = pnlContractCont.Width; newContract._propertyChanged += (sender, e) => RespondToContract(sender, e); pnlContractCont.Controls.Add(newContract); //Put the controls location directly under the last one. pnlContractCont.Controls[pnlContractCont.Controls.Count - 1].Location = new Point(0, ((pnlContractCont.Controls.Count - 1) * newContract.Size.Height) + 10); } } } catch (Exception) { MessageBox.Show("Unable to retrieve contracts for this API. Please try again"); } }