示例#1
0
        private void ForceUpdateCharactersPob(CancellationToken stoppingToken)
        {
            List <PoeCharacterModel> _chars =
                PoeContext.Characters
                .Select(c => new PoeCharacterModel {
                CharacterId = c.CharacterId, PobCode = c.PobCode
            })
                .ToList();

            foreach (var _c in _chars)
            {
                if (stoppingToken.IsCancellationRequested)
                {
                    return;
                }
                try
                {
                    string         newPobXml   = PobUtils.GetBuildXmlByXml(PobUtils.CodeToXml(_c.PobCode));
                    string         nextPobCode = PobUtils.XmlToCode(newPobXml);
                    PathOfBuilding nextPob     = PobUtils.XmlToPob(newPobXml);
                    _c.PobCode = nextPobCode;
                    _c.Pob     = nextPob;
                    _c.Pob     = PobUtils.XmlToPob(PobUtils.CodeToXml(_c.PobCode));
                    using (var db = new PoeDbContext())
                    {
                        db.Characters.Attach(_c);
                        db.Entry(_c).Property(x => x.PobCode).IsModified = true;
                        db.Entry(_c).Property(x => x.Pob).IsModified     = true;
                        db.SaveChanges();
                    }
                }
                catch (System.Exception e)
                {
                    _logger.LogError(e.ToString());
                }
            }
        }
示例#2
0
            public PoeCharacterModel ToCharacterModel(NLua.Lua luaState)
            {
                var    entry    = ladderEntry;
                string buildXml = PobUtils.GetBuildXmlByJsons(passivesJson, itemsJson, luaState);

                PathOfBuilding tryGetPob()
                {
                    PathOfBuilding pob;

                    try
                    {
                        pob = PobUtils.XmlToPob(buildXml);
                    }
                    catch (System.Exception e)
                    {
                        // TODO
                        // Log entry and e
                        if (e is System.InvalidOperationException || e is System.Xml.XmlException)
                        {
                            pob = null;
                            System.Console.WriteLine(e.ToString());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(pob);
                }

                PathOfBuilding pob = tryGetPob();

                if (pob != null)
                {
                    PoeItems    items    = JsonConvert.DeserializeObject <PoeItems>(itemsJson);
                    PoePassives passives = JsonConvert.DeserializeObject <PoePassives>(passivesJson);
                    string      code     = PobUtils.XmlToCode(buildXml);
                    var         poeChar  = new PoeCharacterModel()
                    {
                        CharacterId   = entry.Character.Id,
                        CharacterName = entry.Character.Name,
                        LeagueName    = leagueName,
                        Account       = entry.Account,
                        AccountName   = entry.Account != null ? entry.Account.Name : null,
                        Level         = entry.Character.Level,
                        Class         = entry.Character.Class,
                        Depth         = entry.Character.Depth ?? new PoeDepth {
                            Solo = 0, Default = 0
                        },
                        Dead           = entry.Dead,
                        Online         = entry.Online,
                        Rank           = entry.Rank,
                        Experience     = entry.Character.Experience,
                        LifeUnreserved = pob.GetStat("LifeUnreserved"),
                        EnergyShield   = pob.GetStat("EnergyShield"),
                        Pob            = pob,
                        PobCode        = code,
                        Items          = new List <PoeItem>()
                        {
                        }.Concat(items.items.Concat(passives.items.Select(i => i.ToPoeItem()))).ToList(),
                        UpdatedAt = System.DateTime.UtcNow,
                    };
                    return(poeChar);
                }
                else
                {
                    return(null);
                }
            }