using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Net;
using System.Web;
using System.Text;
using System.IO;
using System.Xml.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace tracker
{
public partial class image_teste : System.Web.UI.Page
{
List<PatenteVsImage> patentes = new List<PatenteVsImage>();
string soldier;
protected void Page_Load(object sender, EventArgs e)
{
FillPatentesList();
soldier = Request.QueryString["soldier"];
LoadImage(GetPatente(soldier));
}
protected string GetHTML(string url)
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
// Display the contents of the page to the console.
Stream streamResponse = response.GetResponseStream();
// Get stream object
StreamReader streamRead = new StreamReader(streamResponse);
return streamRead.ReadToEnd();
}
protected void LoadImage(string patente)
{
string url = "http://www.infrfo.com/ranks/";
string imageName = patentes.Where(w => w.Patente.Equals(patente)).Select(s => s.Image).SingleOrDefault();
url += imageName;
if (imageName != "space")
{
url += GetOnLinePlayerStatus() + ".png";
}
Response.ClearContent();
Response.ContentType = "image/png"; //Seta o tipo de conteudo que a pagina ira retornar
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
MemoryStream memostream = new MemoryStream();
// Display the contents of the page to the console.
Stream streamResponse = response.GetResponseStream();
System.Drawing.Image image = System.Drawing.Image.FromStream(streamResponse);
image.Save(memostream, ImageFormat.Png);
memostream.WriteTo(Response.OutputStream);
image.Clone();
memostream.Close();
}
protected string GetPatente(string soldier)
{
string html = GetHTML(@"http://login.aa3.americasarmy.com/personnel_jacket?soldier=" + soldier + "&type=Performance");
string patente = ReturnHTMLEspecificValue(html, "<div class=\"current_rank_label\" alt=\"");
return patente;
}
protected string ReturnHTMLEspecificValue(string text4Search, string whatSearch)
{
string text = text4Search.Substring(text4Search.IndexOf(whatSearch, 0) + whatSearch.Length);
StringBuilder retorno = new StringBuilder();
for (int i = 0; i < text.Length - 1; i++)
{
if (text[i] == '<' || text[i] == '"')
{
break;
}
if (text[i] != '"' && text[i] != '>')
{
retorno.Append(text[i]);
}
}
return retorno.ToString();
}
protected string GetOnLinePlayerStatus()
{
string status = "off";
XDocument xml = XDocument.Load(@"http://battletracker.com/clanfeed/aa3/26087/claninfo.xml");
var st = from i in xml.Elements("DATA").Elements("PLAYERLIST").Elements("PLAYER")
where i.Element("PLAYERNAME").Value == soldier
select i.Element("PLAYERSTATUS").Value;
if (st.Count() > 0)
{
status = (st.SingleOrDefault() == "0") ? "off" : "on";
}
return status;
}
protected void FillPatentesList()
{
patentes.Add(new PatenteVsImage("Recruit", "space.png"));
patentes.Add(new PatenteVsImage("Private", "Soldado_"));
patentes.Add(new PatenteVsImage("Private First Class", "cabo_"));
patentes.Add(new PatenteVsImage("Specialist", "3 Sargento_"));
patentes.Add(new PatenteVsImage("Corporal", "2 Sargento_"));
patentes.Add(new PatenteVsImage("Sergeant", "Sargento_"));
patentes.Add(new PatenteVsImage("Staff Sergeant", "Sub-Tenente_"));
patentes.Add(new PatenteVsImage("Sergeant First Class", "2 Tenente_"));
patentes.Add(new PatenteVsImage("Master Sergeant", "Tenente_"));
patentes.Add(new PatenteVsImage("First Sergeant", "Capitao_"));
patentes.Add(new PatenteVsImage("Sergeant Major", "Major_"));
patentes.Add(new PatenteVsImage("CommandSergeantMajor", "Tenente-Coronel_"));
patentes.Add(new PatenteVsImage("Sergeant Major of AA", "Coronel_"));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace tracker
{
public class PatenteVsImage
{
string _patente;
public string Patente
{
get { return _patente; }
}
string _image;
public string Image
{
get { return _image; }
}
public PatenteVsImage(string patente, string image)
{
_patente = patente;
_image = image;
}
}
}