コード例 #1
0
        public void OnDependenciesResolved()
        {
            sessionManager = new SessionMannager(config.MaxConcurrentWebSessions, config.MaxWebRequestsPerMinutePerSession);
            dependency.Register(sessionManager);

            dataParser = dependency.Create <WebDataParser>();
        }
コード例 #2
0
            public async Task Run(ILogEnd log, SessionMannager sessionManager, int tawUnitId)
            {
                var newVersion = new Random().Next();                 // all person to unit relations without this unit version will be deleted

                log = log.ProfileStart($"unit {tawUnitId}");

                var url = Unit.GetUnitRoasterPage(tawUnitId);

                var response = await sessionManager.GetUrlAsync(url, log.Profile("getting html"));

                var html = response.HtmlDocument;

                var roasterDiv = html.GetElementbyId("ctl00_bcr_UpdatePanel1").SelectSingleNode("./div/ul");

                using (log.ScopeStart("parsing html"))
                    await ParseUnitContents(log, roasterDiv, null);

                using (var log2 = log.ScopeStart("processing people"))
                {
                    var tasks = new List <Task>(personNameToPersonLines.Count);

                    foreach (var kvp in personNameToPersonLines)
                    {
                        var personName  = kvp.Key;
                        var personLines = kvp.Value;
                        var task        = Task.Run(async() =>
                        {
                            using (var log3 = log2.ProfileStart(personName))
                            {
                                using (var data = Db.NewContext)
                                {
                                    foreach (var personLine in personLines)
                                    {
                                        await personLine.FinishParsing(log3, data);
                                    }
                                    var personUnitIds = personLines.Select(p => p.PersonToUnitId).ToArray();
                                    var utcNow        = DateTime.UtcNow;
                                    // if some person to unit is still valid, and not one of those we just updated, mark it as not valid anymore
                                    data
                                    .People
                                    .First(p => p.Name == personName)
                                    .Units
                                    .Where(u => u.Removed > utcNow)                                             // still valid, not removed
                                    .Where(u => !personUnitIds.Contains(u.PersonUnitId))                        // except those we found & updated
                                    .ForEach(u => u.Removed = utcNow);                                          // remove it

                                    try
                                    {
                                        await data.SaveChangesAsync();
                                    }
                                    catch (Exception e)
                                    {
                                        log3.Fatal(e);
                                    }
                                }
                            }
                        });
                        tasks.Add(task);
                    }
                    ;
                    await Task.WhenAll(tasks.ToArray());
                }
            }
コード例 #3
0
 public async Task UpdateUnitContents(ILogEnd log, SessionMannager sessionManager, int tawUnitId)
 {
     await new UpdateUnitContentsHandler(this).Run(log, sessionManager, tawUnitId);
 }