Ejemplo n.º 1
0
        private void zkb_DoWork(object sender, DoWorkEventArgs e)
        {
            string redistURL  = @"https://redisq.zkillboard.com/listen.php";
            string strContent = string.Empty;

            try
            {
                HttpClient hc       = new HttpClient();
                var        response = hc.GetAsync(redistURL).Result;
                if (response.IsSuccessStatusCode)
                {
                    strContent = response.Content.ReadAsStringAsync().Result;
                }
            }
            catch
            {
                e.Result = -1;
                return;
            }

            ZKBData.ZkbData z = ZKBData.ZkbData.FromJson(strContent);
            if (z != null && z.Package != null)
            {
                ZKBDataSimple zs = new ZKBDataSimple();
                zs.KillID            = long.Parse(z.Package.KillId.ToString());
                zs.VictimAllianceID  = long.Parse(z.Package.Killmail.Victim.AllianceId.ToString());
                zs.VictimCharacterID = long.Parse(z.Package.Killmail.Victim.CharacterId.ToString());
                zs.VictimCorpID      = long.Parse(z.Package.Killmail.Victim.CharacterId.ToString());
                zs.SystemName        = EveManager.Instance.GetEveSystemNameFromID(z.Package.Killmail.SolarSystemId);
                if (zs.SystemName == string.Empty)
                {
                    zs.SystemName = z.Package.Killmail.SolarSystemId.ToString();
                }

                zs.KillTime = z.Package.Killmail.KillmailTime.ToLocalTime();
                string shipID = z.Package.Killmail.Victim.ShipTypeId.ToString();
                if (EveManager.Instance.ShipTypes.Keys.Contains(shipID))
                {
                    zs.ShipType = EveManager.Instance.ShipTypes[shipID];
                }
                else
                {
                    zs.ShipType = "Unknown (" + shipID + ")";
                }

                zs.VictimAllianceName = EveManager.Instance.GetAllianceName(zs.VictimAllianceID);

                Application.Current.Dispatcher.Invoke((Action)(() =>
                {
                    KillStream.Insert(0, zs);
                }));
            }

            e.Result = 0;
        }
Ejemplo n.º 2
0
        private async void zkb_DoWork(object sender, DoWorkEventArgs e)
        {
            string redistURL = @"https://redisq.zkillboard.com/listen.php";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(redistURL);

            request.Method    = WebRequestMethods.Http.Get;
            request.Timeout   = 60000;
            request.UserAgent = "SMT/0.82";
            request.KeepAlive = true;
            request.Proxy     = null;
            HttpWebResponse response;

            try
            {
                response = request.GetResponse() as HttpWebResponse;
            }
            catch (Exception)
            {
                e.Result = -1;
                return;
            }

            Stream responseStream = response.GetResponseStream();

            using (StreamReader sr = new StreamReader(responseStream))
            {
                try
                {
                    // Need to return this response
                    string strContent = sr.ReadToEnd();

                    ZKBData.ZkbData z = ZKBData.ZkbData.FromJson(strContent);
                    if (z.Package != null)
                    {
                        ZKBDataSimple zs = new ZKBDataSimple();
                        zs.KillID            = long.Parse(z.Package.KillId.ToString());
                        zs.VictimAllianceID  = long.Parse(z.Package.Killmail.Victim.AllianceId.ToString());
                        zs.VictimCharacterID = long.Parse(z.Package.Killmail.Victim.CharacterId.ToString());
                        zs.VictimCorpID      = long.Parse(z.Package.Killmail.Victim.CharacterId.ToString());
                        zs.SystemName        = EveManager.Instance.GetEveSystemNameFromID(z.Package.Killmail.SolarSystemId);
                        if (zs.SystemName == string.Empty)
                        {
                            zs.SystemName = z.Package.Killmail.SolarSystemId.ToString();
                        }

                        zs.KillTime = z.Package.Killmail.KillmailTime;
                        string shipID = z.Package.Killmail.Victim.ShipTypeId.ToString();
                        if (EveManager.Instance.ShipTypes.Keys.Contains(shipID))
                        {
                            zs.ShipType = EveManager.Instance.ShipTypes[shipID];
                        }
                        else
                        {
                            zs.ShipType = "Unknown (" + shipID + ")";
                        }

                        zs.VictimAllianceName = EveManager.Instance.GetAllianceName(zs.VictimAllianceID);

                        Application.Current.Dispatcher.Invoke((Action)(() =>
                        {
                            KillStream.Insert(0, zs);
                        }));
                    }
                }
                catch
                {
                    e.Result = -1;
                    return;
                }
            }

            e.Result = 0;
        }