Example #1
0
    public void instantiateTeam(int teamID)
    {
        CharacterXML chars = new CharacterXML();

        chars.getData();

        TeamXML teams = new TeamXML();

        teams.getData();

        List <string> teamC = teams.getTeam(teamID);

        one   = chars.getCharacter(Convert.ToInt32(teamC[1]));
        two   = chars.getCharacter(Convert.ToInt32(teamC[2]));
        three = chars.getCharacter(Convert.ToInt32(teamC[3]));
        four  = chars.getCharacter(Convert.ToInt32(teamC[4]));
        five  = chars.getCharacter(Convert.ToInt32(teamC[5]));
    }
Example #2
0
        private ActionResult HandleBattleNetCharacterRequest(string characterRegionServer)
        {
            string characterName = characterRegionServer.EverythingBefore("@").Trim().ToLowerInvariant();
            string region        = characterRegionServer.EverythingBetween("@", "-").Trim().ToLowerInvariant();
            string realm         = characterRegionServer.EverythingBetween("-", "!").Trim().ToLowerInvariant();
            bool   forceRefresh  = characterRegionServer.Contains("!");

            if (string.IsNullOrEmpty(characterName) || string.IsNullOrEmpty(region) || string.IsNullOrEmpty(realm))
            {
                return(View());
            }

            DateTime lastRefreshed;
            string   charXml = GetCachedCharacterXml(characterName, region, realm, out lastRefreshed);

            if (forceRefresh)
            {
                charXml       = null;
                lastRefreshed = DateTime.MinValue;
            }
            if (charXml == null || lastRefreshed < DateTime.Now.AddMinutes(-CACHE_DURATION_MIN))
            {
                try
                {
                    string json = GetBattleNetJson(characterName, region, realm, lastRefreshed);
                    if (json != null)
                    {
                        try
                        {
                            Character character = ConvertBattleNetJsonToCharacter(json, region);
                            charXml = ConvertCharacterToXml(character);

                            using (RawrDBDataContext context = new RawrDBDataContext())
                            {
                                var characterXML = context.CharacterXMLs
                                                   .Where(cxml =>
                                                          cxml.CharacterName == characterName &&
                                                          cxml.Region == region &&
                                                          cxml.Realm == realm)
                                                   .FirstOrDefault();
                                if (characterXML == null)
                                {
                                    characterXML = new CharacterXML()
                                    {
                                        CharacterName = characterName,
                                        Region        = region,
                                        Realm         = realm
                                    };
                                    context.CharacterXMLs.InsertOnSubmit(characterXML);
                                }
                                characterXML.LastRefreshed = DateTime.Now;
                                characterXML.XML           = charXml;
                                characterXML.CurrentModel  = character.CurrentModel;
                                context.SubmitChanges();
                            }

                            _loadedChars += string.Format("{3}: Loaded {0}@{1}-{2} ({4})\r\n", characterName, region, realm, DateTime.Now, character.CurrentModel);
                        }
                        catch (Exception ex)
                        {
                            _loadedChars += string.Format("{3}: ERROR PARSING - {0}@{1}-{2}\r\n", characterName, region, realm, DateTime.Now);
                            Response.Write(string.Format("<Error>{0}</Error>", ex));
                            return(View());
                        }
                    }
                }
                catch (Exception ex)
                {
                    _loadedChars += string.Format("{3}: ERROR PARSING - {0}@{1}-{2}\r\n", characterName, region, realm, DateTime.Now);

                    WebException wex = ex as WebException;
                    if (wex != null)
                    {
                        Response.Write(string.Format("<Error>{0}</Error>", new StreamReader(wex.Response.GetResponseStream()).ReadToEnd()));
                        return(View());
                    }
                    else
                    {
                        Response.Write(string.Format("<Error>{0}</Error>", ex));
                        return(View());
                    }
                }
            }

            Response.Write(charXml ?? string.Format("<Error>There was an error resulting in null charXml. {0} could not be loaded</Error>", characterRegionServer.TrimEnd('!')));
            return(View());
        }
        private ActionResult HandleBattleNetCharacterRequest(string characterRegionServer)
        {
            string characterName = characterRegionServer.EverythingBefore("@").Trim().ToLowerInvariant();
            string region = characterRegionServer.EverythingBetween("@", "-").Trim().ToLowerInvariant();
            string realm = characterRegionServer.EverythingBetween("-", "!").Trim().ToLowerInvariant();
            bool forceRefresh = characterRegionServer.Contains("!");

            if (string.IsNullOrEmpty(characterName) || string.IsNullOrEmpty(region) || string.IsNullOrEmpty(realm))
                return View();

            DateTime lastRefreshed;
            string charXml = GetCachedCharacterXml(characterName, region, realm, out lastRefreshed);
            if (forceRefresh)
            {
                charXml = null;
                lastRefreshed = DateTime.MinValue;
            }
            if (charXml == null || lastRefreshed < DateTime.Now.AddMinutes(-CACHE_DURATION_MIN))
            {
                try
                {
                    string json = GetBattleNetJson(characterName, region, realm, lastRefreshed);
                    if (json != null)
                    {
                        try
                        {
                            Character character = ConvertBattleNetJsonToCharacter(json, region);
                            charXml = ConvertCharacterToXml(character);

                            using (RawrDBDataContext context = new RawrDBDataContext())
                            {
                                var characterXML = context.CharacterXMLs
                                                    .Where(cxml =>
                                                        cxml.CharacterName == characterName &&
                                                        cxml.Region == region &&
                                                        cxml.Realm == realm)
                                                    .FirstOrDefault();
                                if (characterXML == null)
                                {
                                    characterXML = new CharacterXML()
                                    {
                                        CharacterName = characterName,
                                        Region = region,
                                        Realm = realm
                                    };
                                    context.CharacterXMLs.InsertOnSubmit(characterXML);
                                }
                                characterXML.LastRefreshed = DateTime.Now;
                                characterXML.XML = charXml;
                                characterXML.CurrentModel = character.CurrentModel;
                                context.SubmitChanges();
                            }

                            _loadedChars += string.Format("{3}: Loaded {0}@{1}-{2} ({4})\r\n", characterName, region, realm, DateTime.Now, character.CurrentModel);
                        }
                        catch (Exception ex)
                        {
                            _loadedChars += string.Format("{3}: ERROR PARSING - {0}@{1}-{2}\r\n", characterName, region, realm, DateTime.Now);
                            Response.Write(string.Format("<Error>{0}</Error>", ex));
                            return View();
                        }
                    }
                }
                catch (Exception ex)
                {
                    _loadedChars += string.Format("{3}: ERROR PARSING - {0}@{1}-{2}\r\n", characterName, region, realm, DateTime.Now);

                    WebException wex = ex as WebException;
                    if (wex != null)
                    {
                        Response.Write(string.Format("<Error>{0}</Error>", new StreamReader(wex.Response.GetResponseStream()).ReadToEnd()));
                        return View();
                    }
                    else
                    {
                        Response.Write(string.Format("<Error>{0}</Error>", ex));
                        return View();
                    }
                }
            }

            Response.Write(charXml ?? string.Format("<Error>There was an error resulting in null charXml. {0} could not be loaded</Error>", characterRegionServer.TrimEnd('!')));
            return View();
        }