Example #1
0
        public static void obtainEdsmLogs(StarMapConfiguration starMapConfiguration, string commanderName, IProgress <string> progress)
        {
            StarMapService starMapService = new StarMapService(starMapConfiguration.apiKey, commanderName);

            try
            {
                Dictionary <string, StarMapLogInfo> systems  = starMapService.getStarMapLog();
                Dictionary <string, string>         comments = starMapService.getStarMapComments();
                int total = systems.Count;
                int i     = 0;
                List <StarSystem> syncSystems = new List <StarSystem>();

                foreach (string system in systems.Keys)
                {
                    ++i;
                    progress.Report($"Obtaining log {i}/{total}");
                    StarSystem CurrentStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(system, false);
                    CurrentStarSystem.visits    = systems[system].visits;
                    CurrentStarSystem.lastvisit = systems[system].lastVisit;
                    if (comments.ContainsKey(system))
                    {
                        CurrentStarSystem.comment = comments[system];
                    }
                    syncSystems.Add(CurrentStarSystem);

                    if (syncSystems.Count == StarMapService.syncBatchSize)
                    {
                        StarMapService.saveStarSystems(syncSystems);
                        syncSystems.Clear();
                    }
                }
                if (syncSystems.Count > 0)
                {
                    StarMapService.saveStarSystems(syncSystems);
                }

                progress.Report("Obtained log");
            }
            catch (EDSMException edsme)
            {
                progress.Report("EDSM error received: " + edsme.Message);
            }
        }