Example #1
0
        public void TestSystemsSphere()
        {
            string systemName = "Sol";
            List <Dictionary <string, object> > sphereSystems = StarMapService.GetStarMapSystemsSphere(systemName, 0, 10, false, false, false, false);

            Assert.AreEqual(12, sphereSystems.Count);
        }
Example #2
0
        private List <string> SystemsBeginningWith(string systemName)
        {
            IEdsmService edsmService = new StarMapService();

            return(edsmService.GetStarMapSystemsPartial(systemName, false, false)?.Select(s => s.systemname).ToList()
                   ?? new List <string>());
        }
Example #3
0
        public void TestSystemsCube()
        {
            string            systemName  = "Sol";
            List <StarSystem> starSystems = StarMapService.GetStarMapSystemsCube(systemName, 15, false, false, false, false);

            Assert.AreEqual(9, starSystems.Count);
        }
Example #4
0
        private static StarSystem GetSystemExtras(StarSystem starSystem, bool showInformation, bool showBodies, bool showStations, bool showFactions)
        {
            if (starSystem != null)
            {
                if (showBodies)
                {
                    List <Body> bodies = StarMapService.GetStarMapBodies(starSystem.name);
                    starSystem.bodies = bodies;
                }

                if (starSystem?.population > 0)
                {
                    List <Faction> factions = new List <Faction>();
                    if (showFactions || showStations)
                    {
                        factions            = StarMapService.GetStarMapFactions(starSystem.name);
                        starSystem.factions = factions;
                    }
                    if (showStations)
                    {
                        List <Station> stations = StarMapService.GetStarMapStations(starSystem.name);
                        starSystem.stations = SetStationFactionData(stations, factions);
                        starSystem.stations = stations;
                    }
                }

                starSystem = LegacyEddpService.SetLegacyData(starSystem, showInformation, showBodies, showStations);
            }

            return(starSystem);
        }
Example #5
0
        /// <summary>
        /// Send a comment to the starmap service and store locally
        /// </summary>
        public static void InvokeStarMapSystemComment(ref dynamic vaProxy)
        {
            try
            {
                string comment = vaProxy.GetText("EDDI system comment");
                if (comment == null)
                {
                    return;
                }

                if (EDDI.Instance.CurrentStarSystem != null)
                {
                    // Store locally
                    string     currentSystemName = EDDI.Instance.CurrentStarSystem.systemname;
                    StarSystem currentSystem     = StarSystemSqLiteRepository.Instance.GetOrFetchStarSystem(currentSystemName);
                    currentSystem.comment = comment == "" ? null : comment;
                    StarSystemSqLiteRepository.Instance.SaveStarSystem(currentSystem);

                    // Store in EDSM
                    IEdsmService edsmService = new StarMapService();
                    edsmService.sendStarMapComment(currentSystemName, comment);
                }
            }
            catch (Exception e)
            {
                setStatus(ref vaProxy, "Failed to store system comment", e);
            }
        }
Example #6
0
 public void start()
 {
     fakeEdsmRestClient  = new FakeEdsmRestClient();
     fakeEdsmService     = new StarMapService(fakeEdsmRestClient);
     dataProviderService = new DataProviderService(fakeEdsmService);
     MakeSafe();
 }
Example #7
0
        public void TestGetLogs()
        {
            StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8000/");
            Dictionary <string, StarMapLogInfo> logs = service.getStarMapLog();

            Assert.AreEqual(1, logs.Count);
        }
Example #8
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;
                foreach (string system in systems.Keys)
                {
                    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];
                    }
                    StarSystemSqLiteRepository.Instance.SaveStarSystem(CurrentStarSystem);
                }
                progress.Report("Obtained log");
            }
            catch (EDSMException edsme)
            {
                progress.Report("EDSM error received: " + edsme.Message);
            }
        }
Example #9
0
        public void TestSystems()
        {
            string[]          systemNames = new string[] { "Sol", "Achenar", "Alioth" };
            List <StarSystem> starSystems = StarMapService.GetStarMapSystems(systemNames, true, false);

            Assert.AreEqual(3, starSystems.Count);
        }
        public void TestSolLog()
        {
            StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8080/");
            service.sendStarMapLog(DateTime.Now, "Sol", null, null, null);

            StarMapInfo info = service.getStarMapInfo("Sol");
            Assert.IsTrue(info.Visits >= 1);  // can be any number thanks to repeated testing
        }
Example #11
0
 public static Traffic GetSystemHostility(string systemName, long?edsmId = null)
 {
     if (string.IsNullOrEmpty(systemName))
     {
         return(null);
     }
     return(StarMapService.GetStarMapHostility(systemName, edsmId));
 }
Example #12
0
        public CrimeMonitor()
        {
            IEdsmService edsmService = new StarMapService();

            dataProviderService = new DataProviderService(edsmService);
            criminalrecord      = new ObservableCollection <FactionRecord>();
            homeSystems         = new Dictionary <string, string>();
            BindingOperations.CollectionRegistering += Record_CollectionRegistering;
            initializeCrimeMonitor();
        }
Example #13
0
        public void TestSolLog()
        {
            StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8080/");

            service.sendStarMapLog("Sol", null, null, null);

            StarMapInfo info = service.getStarMapInfo("Sol");

            Assert.IsTrue(info.Visits >= 1);  // can be any number thanks to repeated testing
        }
        public void TestProximaCentauriComment()
        {
            StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8080/");
            service.sendStarMapLog(DateTime.Now, "Proxima Centauri", null, null, null);

            service.sendStarMapComment("Proxima Centauri", "Not so far away");

            StarMapInfo info = service.getStarMapInfo("Proxima Centauri");
            Assert.AreEqual("Not so far away", info.Comment);
        }
Example #15
0
        public void TestProximaCentauriComment()
        {
            StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8080/");

            service.sendStarMapLog("Proxima Centauri", null, null, null);

            service.sendStarMapComment("Proxima Centauri", "Not so far away");

            StarMapInfo info = service.getStarMapInfo("Proxima Centauri");

            Assert.AreEqual("Not so far away", info.Comment);
        }
        /// <summary>
        /// Obtain the EDSM log and sync it with the local datastore
        /// </summary>
        private void edsmObtainLogClicked(object sender, RoutedEventArgs e)
        {
            IEDDIStarSystemRepository starSystemRepository = new EDDIStarSystemSqLiteRepository();
            StarMapConfiguration      starMapConfiguration = StarMapConfiguration.FromFile();

            string commanderName;

            if (String.IsNullOrEmpty(starMapConfiguration.commanderName))
            {
                // Fetch the commander name from the companion app
                CompanionAppService companionAppService = new CompanionAppService(debug);
                Commander           cmdr = companionAppService.Profile();
                if (cmdr != null && cmdr.Name != null)
                {
                    commanderName = cmdr.Name;
                }
                else
                {
                    edsmFetchLogsButton.IsEnabled = false;
                    edsmFetchLogsButton.Content   = "Companion app not configured and no name supplied; cannot obtain logs";
                    return;
                }
            }
            else
            {
                commanderName = starMapConfiguration.commanderName;
            }

            edsmFetchLogsButton.IsEnabled = false;
            edsmFetchLogsButton.Content   = "Obtaining log...";

            StarMapService starMapService = new StarMapService(starMapConfiguration.apiKey, commanderName);

            Dictionary <string, StarMapLogInfo> systems = starMapService.getStarMapLog();

            foreach (string system in systems.Keys)
            {
                EDDIStarSystem CurrentStarSystemData = starSystemRepository.GetEDDIStarSystem(system);
                if (CurrentStarSystemData == null)
                {
                    // We have no record of this system; set it up
                    CurrentStarSystemData      = new EDDIStarSystem();
                    CurrentStarSystemData.Name = system;
                    // Due to the potential large number of systems being imported we don't pull individual system data at this time
                }
                CurrentStarSystemData.TotalVisits   = systems[system].visits;
                CurrentStarSystemData.LastVisit     = systems[system].lastVisit;
                CurrentStarSystemData.PreviousVisit = systems[system].previousVisit;
                starSystemRepository.SaveEDDIStarSystem(CurrentStarSystemData);
            }

            edsmFetchLogsButton.Content = "Log obtained";
        }
Example #17
0
        public void TestSystemsCubeUnknown()
        {
            string systemName = "No such system";

            try
            {
                List <StarSystem> starSystems = StarMapService.GetStarMapSystemsCube(systemName, 15, false, false, false, false);
                Assert.IsNull(starSystems);
            }
            catch (System.Exception)
            {
                Assert.Fail();
            }
        }
Example #18
0
        // Uses the EDSM data service and legacy EDDP data
        public static StarSystem GetSystemData(string system, bool showCoordinates = true, bool showSystemInformation = true, bool showBodies = true, bool showStations = true, bool showFactions = true)
        {
            if (system == null || string.IsNullOrEmpty(system))
            {
                return(null);
            }

            StarSystem starSystem = StarMapService.GetStarMapSystem(system, showCoordinates, showSystemInformation);

            starSystem = GetSystemExtras(starSystem, showSystemInformation, showBodies, showStations, showFactions) ?? new StarSystem()
            {
                name = system
            };
            return(starSystem);
        }
Example #19
0
        public static List <StarSystem> GetSystemsData(string[] systemNames, bool showCoordinates = true, bool showSystemInformation = true, bool showBodies = true, bool showStations = true, bool showFactions = true)
        {
            if (systemNames == null || systemNames.Length == 0)
            {
                return(null);
            }

            List <StarSystem> starSystems     = StarMapService.GetStarMapSystems(systemNames, showCoordinates, showSystemInformation);
            List <StarSystem> fullStarSystems = new List <StarSystem>();

            foreach (string systemName in systemNames)
            {
                fullStarSystems.Add(GetSystemExtras(starSystems.Find(s => s.name == systemName), showSystemInformation, showBodies, showStations, showFactions) ?? new StarSystem()
                {
                    name = systemName
                });
            }
            return(starSystems);
        }
Example #20
0
        /// <summary>
        /// Obtain the EDSM log and sync it with the local datastore
        /// </summary>
        private async void edsmObtainLogClicked(object sender, RoutedEventArgs e)
        {
            StarMapConfiguration starMapConfiguration = StarMapConfiguration.FromFile();

            if (string.IsNullOrEmpty(starMapConfiguration.apiKey))
            {
                edsmFetchLogsButton.IsEnabled = false;
                edsmFetchLogsButton.Content   = Properties.EDSMResources.log_button_empty_api_key;
                return;
            }

            string commanderName;

            if (string.IsNullOrEmpty(starMapConfiguration.commanderName))
            {
                // Fetch the commander name from the companion app
                Commander cmdr = EDDI.Instance.Cmdr;
                if (cmdr != null && cmdr.name != null)
                {
                    commanderName = cmdr.name;
                }
                else
                {
                    edsmFetchLogsButton.IsEnabled = false;
                    edsmFetchLogsButton.Content   = Properties.EDSMResources.log_button_companion_unconfigured;
                    return;
                }
            }
            else
            {
                commanderName = starMapConfiguration.commanderName;
            }

            edsmFetchLogsButton.IsEnabled = false;
            edsmFetchLogsButton.Content   = Properties.EDSMResources.log_button_fetching;

            var          progress    = new Progress <string>(s => edsmFetchLogsButton.Content = s);
            IEdsmService edsmService = new StarMapService();
            await Task.Factory.StartNew(() => obtainEdsmLogs(edsmService, progress), TaskCreationOptions.LongRunning);

            starMapConfiguration.lastFlightLogSync = DateTime.UtcNow;
            starMapConfiguration.ToFile();
        }
Example #21
0
        public static void obtainEdsmLogs(StarMapConfiguration starMapConfiguration, string commanderName, IProgress <string> progress)
        {
            StarMapService starMapService = new StarMapService(starMapConfiguration.apiKey, commanderName);
            Dictionary <string, StarMapLogInfo> systems  = starMapService.getStarMapLog();
            Dictionary <string, string>         comments = starMapService.getStarMapComments();

            foreach (string system in systems.Keys)
            {
                progress.Report(system);
                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];
                }
                StarSystemSqLiteRepository.Instance.SaveStarSystem(CurrentStarSystem);
            }
        }
        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($"{Properties.EDSMResources.log_button_fetching_progress} {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(Properties.EDSMResources.log_button_fetched);
            }
            catch (EDSMException edsme)
            {
                progress.Report(Properties.EDSMResources.log_button_error_received + edsme.Message);
            }
        }
Example #23
0
        public void Reload()
        {
            // Set up the star map service
            starMapService = new StarMapService();
            if (ignoredEvents == null)
            {
                ignoredEvents = starMapService?.getIgnoredEvents();
            }

            if (starMapService != null && updateThread == null)
            {
                // Spin off a thread to download & sync flight logs & system comments from EDSM in the background
                updateThread = new Thread(() => DataProviderService.syncFromStarMapService())
                {
                    IsBackground = true,
                    Name         = "EDSM updater"
                };
                updateThread.Start();
            }
        }
 public void Reload()
 {
     // Set up the star map service
     StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();
     if (starMapCredentials != null && starMapCredentials.apiKey != null)
     {
         // Commander name might come from star map credentials or the companion app's profile
         string commanderName = null;
         if (starMapCredentials.commanderName != null)
         {
             commanderName = starMapCredentials.commanderName;
         }
         else if (EDDI.Instance.Cmdr != null)
         {
             commanderName = EDDI.Instance.Cmdr.name;
         }
         if (commanderName != null)
         {
             starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
         }
     }
 }
        public void Reload()
        {
            // Set up the star map service
            StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();

            if (starMapCredentials != null && starMapCredentials.apiKey != null)
            {
                // Commander name might come from star map credentials or the companion app's profile
                string commanderName = null;
                if (starMapCredentials.commanderName != null)
                {
                    commanderName = starMapCredentials.commanderName;
                }
                else if (EDDI.Instance.Cmdr != null)
                {
                    commanderName = EDDI.Instance.Cmdr.name;
                }
                if (commanderName != null)
                {
                    starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
                }
            }
        }
Example #26
0
        private static StarSystem GetSystemExtras(StarSystem starSystem, bool showInformation, bool showBodies, bool showStations, bool showFactions)
        {
            if (starSystem != null)
            {
                if (showBodies)
                {
                    List <Body> bodies = StarMapService.GetStarMapBodies(starSystem.name) ?? new List <Body>();
                    foreach (Body body in bodies)
                    {
                        body.systemname    = starSystem.name;
                        body.systemAddress = starSystem.systemAddress;
                        body.systemEDDBID  = starSystem.EDDBID;
                        starSystem.bodies.Add(body);
                    }
                }

                if (starSystem?.population > 0)
                {
                    List <Faction> factions = new List <Faction>();
                    if (showFactions || showStations)
                    {
                        factions            = StarMapService.GetStarMapFactions(starSystem.name);
                        starSystem.factions = factions;
                    }
                    if (showStations)
                    {
                        List <Station> stations = StarMapService.GetStarMapStations(starSystem.name);
                        starSystem.stations = SetStationFactionData(stations, factions);
                        starSystem.stations = stations;
                    }
                }

                starSystem = LegacyEddpService.SetLegacyData(starSystem, showInformation, showBodies, showStations);
            }

            return(starSystem);
        }
Example #27
0
        public void Reload()
        {
            // Set up the star map service
            starMapService = null;
            StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();

            if (starMapCredentials != null && starMapCredentials.apiKey != null)
            {
                // Commander name might come from star map credentials or the companion app's profile
                string commanderName = null;
                if (starMapCredentials.commanderName != null)
                {
                    commanderName = starMapCredentials.commanderName;
                }
                else if (EDDI.Instance.Cmdr != null)
                {
                    commanderName = EDDI.Instance.Cmdr.name;
                }
                if (commanderName != null)
                {
                    starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
                }
                if (ignoredEvents == null)
                {
                    ignoredEvents = starMapService?.getIgnoredEvents();
                }
            }

            if (starMapService != null && updateThread == null)
            {
                // Spin off a thread to download & sync EDSM flight logs & system comments in the background
                updateThread = new Thread(() => starMapService.Sync(starMapCredentials.lastSync));
                updateThread.IsBackground = true;
                updateThread.Name         = "EDSM updater";
                updateThread.Start();
            }
        }
 public static void obtainEdsmLogs(StarMapConfiguration starMapConfiguration, string commanderName, IProgress<string> progress)
 {
     StarMapService starMapService = new StarMapService(starMapConfiguration.apiKey, commanderName);
     Dictionary<string, StarMapLogInfo> systems = starMapService.getStarMapLog();
     Dictionary<string, string> comments = starMapService.getStarMapComments();
     foreach (string system in systems.Keys)
     {
         progress.Report(system);
         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];
         }
         StarSystemSqLiteRepository.Instance.SaveStarSystem(CurrentStarSystem);
     }
 }
Example #29
0
        public void TestProximaDistance()
        {
            StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8080/");

            service.sendStarMapDistance("Sol", "HIP 11658", 350.35M);
        }
 public void TestProximaDistance()
 {
     StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8080/");
     service.sendStarMapDistance("Sol", "HIP 11658", 350.35M);
 }
Example #31
0
        public StarSystem GetServiceSystem(string serviceType, int maxStationDistance, bool prioritizeOrbitalStations)
        {
            StarSystem currentSystem = EDDI.Instance?.CurrentStarSystem;

            if (currentSystem != null)
            {
                // Get the filter parameters
                string shipSize = EDDI.Instance?.CurrentShip?.size ?? "Large";
                ServiceFilter.TryGetValue(serviceType, out dynamic filter);
                int cubeLy = filter.cubeLy;

                //
                List <string> checkedSystems = new List <string>();
                string        ServiceSystem  = null;
                int           maxTries       = 5;

                while (ServiceSystem == null && maxTries > 0)
                {
                    List <StarSystem> cubeSystems = StarMapService.GetStarMapSystemsCube(currentSystem.systemname, cubeLy);
                    if (cubeSystems?.Any() ?? false)
                    {
                        // Filter systems using search parameters
                        cubeSystems = cubeSystems.Where(s => s.population >= filter.population).ToList();
                        cubeSystems = cubeSystems.Where(s => filter.security.Contains(s.security)).ToList();
                        if (serviceType != "facilitator")
                        {
                            cubeSystems = cubeSystems
                                          .Where(s => filter.econ.Contains(s.Economies.FirstOrDefault(e => e.invariantName != "None")?.invariantName))
                                          .ToList();
                        }

                        // Retreive systems in current radius which have not been previously checked
                        List <string> systemNames = cubeSystems.Select(s => s.systemname).Except(checkedSystems).ToList();
                        if (systemNames.Count > 0)
                        {
                            List <StarSystem> StarSystems = StarSystemSqLiteRepository.Instance.GetOrFetchStarSystems(systemNames.ToArray(), true, false);
                            checkedSystems.AddRange(systemNames);

                            SortedList <decimal, string> nearestList = new SortedList <decimal, string>();
                            foreach (StarSystem starsystem in StarSystems)
                            {
                                // Filter stations within the system which meet the station type prioritization,
                                // max distance from the main star, game version, and landing pad size requirements
                                List <Station> stations = !prioritizeOrbitalStations && EDDI.Instance.inHorizons ? starsystem.stations : starsystem.orbitalstations
                                                          .Where(s => s.stationservices.Count > 0).ToList();
                                stations = stations.Where(s => s.distancefromstar <= maxStationDistance).ToList();
                                if (serviceType == "facilitator")
                                {
                                    stations = stations.Where(s => s.LandingPadCheck(shipSize)).ToList();
                                }
                                int stationCount = stations.Where(s => s.stationservices.Contains(filter.service)).Count();

                                // Build list to find the 'service' system nearest to the current system, meeting station requirements
                                if (stationCount > 0)
                                {
                                    decimal distance = CalculateDistance(currentSystem, starsystem);
                                    if (!nearestList.ContainsKey(distance))
                                    {
                                        nearestList.Add(distance, starsystem.systemname);
                                    }
                                }
                            }

                            // Nearest 'service' system
                            ServiceSystem = nearestList.Values.FirstOrDefault();
                            if (ServiceSystem != null)
                            {
                                return(StarSystems.FirstOrDefault(s => s.systemname == ServiceSystem));
                            }
                        }
                    }

                    // Increase search radius in 10 Ly increments (up to 50 Ly)
                    // until the required 'service' is found
                    cubeLy += 10;
                    maxTries--;
                }
            }
            return(null);
        }
 public void Stop()
 {
     starMapService = null;
 }
Example #33
0
 public void Stop()
 {
     updateThread?.Abort();
     updateThread   = null;
     starMapService = null;
 }
 public void Stop()
 {
     starMapService = null;
 }
        private EDDI()
        {
            try
            {
                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " starting");

                // Start by ensuring that our primary data structures have something in them.  This allows them to be updated
                // from any source
                Cmdr = new Commander();
                Ship = new Ship();
                Shipyard = new List<Ship>();

                // Set up the EDDI configuration
                EDDIConfiguration configuration = EDDIConfiguration.FromFile();
                Logging.Verbose = configuration.Debug;
                if (configuration.HomeSystem != null && configuration.HomeSystem.Trim().Length > 0)
                {
                    HomeStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(configuration.HomeSystem.Trim());
                    if (HomeStarSystem != null)
                    {
                        Logging.Debug("Home star system is " + HomeStarSystem.name);
                        if (configuration.HomeStation != null && configuration.HomeStation.Trim().Length > 0)
                        {
                            string homeStationName = configuration.HomeStation.Trim();
                            foreach (Station station in HomeStarSystem.stations)
                            {
                                if (station.name == homeStationName)
                                {
                                    HomeStation = station;
                                    Logging.Debug("Home station is " + HomeStation.name);
                                    break;

                                }
                            }
                        }
                    }
                }

                // Set up the app service
                if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.READY)
                {
                    // Carry out initial population of profile
                    try
                    {
                        refreshProfile();
                    }
                    catch (Exception ex)
                    {
                        Logging.Debug("Failed to obtain profile: " + ex);
                    }
                }

                Cmdr.insurance = configuration.Insurance;
                if (Cmdr.name != null)
                {
                    Logging.Info("EDDI access to the companion app is enabled");
                }
                else
                {
                    // If InvokeUpdatePlugin failed then it will have have left an error message, but this once we ignore it
                    Logging.Info("EDDI access to the companion app is disabled");
                }

                // Set up the star map service
                StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();
                if (starMapCredentials != null && starMapCredentials.apiKey != null)
                {
                    // Commander name might come from star map credentials or the companion app's profile
                    string commanderName = null;
                    if (starMapCredentials.commanderName != null)
                    {
                        commanderName = starMapCredentials.commanderName;
                    }
                    else if (Cmdr != null && Cmdr.name != null)
                    {
                        commanderName = Cmdr.name;
                    }
                    if (commanderName != null)
                    {
                        starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
                        Logging.Info("EDDI access to EDSM is enabled");
                    }
                }
                if (starMapService == null)
                {
                    Logging.Info("EDDI access to EDSM is disabled");
                }

                // We always start in normal space
                Environment = Constants.ENVIRONMENT_NORMAL_SPACE;

                // Set up monitors and responders
                monitors = findMonitors();
                responders = findResponders();

                // Check for an update
                string response;
                try
                {
                    if (Constants.EDDI_VERSION.Contains("b"))
                    {
                        response = Net.DownloadString("http://api.eddp.co/betaversion");
                    }
                    else
                    {
                        response = Net.DownloadString("http://api.eddp.co/version");
                    }
                    if (Versioning.Compare(response, Constants.EDDI_VERSION) == 1)
                    {
                        SpeechService.Instance.Say(null, "EDDI version " + response.Replace(".", " point ") + " is now available.", false);
                    }
                }
                catch
                {
                    SpeechService.Instance.Say(null, "There was a problem connecting to external data services; some features may not work fully", false);
                }

                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " initialised");
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to initialise", ex);
            }
        }
 public void TestGetLogs()
 {
     StarMapService service = new StarMapService("secret", "McDonald", "http://beta.edsm.net:8000/");
     Dictionary<string, StarMapLogInfo> logs = service.getStarMapLog();
     Assert.AreEqual(1, logs.Count);
 }
Example #37
0
        private EDDI()
        {
            try
            {
                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " starting");

                // Start by ensuring that our primary data structures have something in them.  This allows them to be updated
                // from any source
                Cmdr     = new Commander();
                Ship     = new Ship();
                Shipyard = new List <Ship>();

                // Set up the EDDI configuration
                EDDIConfiguration configuration = EDDIConfiguration.FromFile();
                Logging.Verbose = configuration.Debug;
                if (configuration.HomeSystem != null && configuration.HomeSystem.Trim().Length > 0)
                {
                    HomeStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(configuration.HomeSystem.Trim());
                    if (HomeStarSystem != null)
                    {
                        Logging.Debug("Home star system is " + HomeStarSystem.name);
                        if (configuration.HomeStation != null && configuration.HomeStation.Trim().Length > 0)
                        {
                            string homeStationName = configuration.HomeStation.Trim();
                            foreach (Station station in HomeStarSystem.stations)
                            {
                                if (station.name == homeStationName)
                                {
                                    HomeStation = station;
                                    Logging.Debug("Home station is " + HomeStation.name);
                                    break;
                                }
                            }
                        }
                    }
                }

                // Set up the app service
                if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.READY)
                {
                    // Carry out initial population of profile
                    try
                    {
                        refreshProfile();
                    }
                    catch (Exception ex)
                    {
                        Logging.Debug("Failed to obtain profile: " + ex);
                    }
                }

                Cmdr.insurance = configuration.Insurance;
                if (Cmdr.name != null)
                {
                    Logging.Info("EDDI access to the companion app is enabled");
                }
                else
                {
                    // If InvokeUpdatePlugin failed then it will have have left an error message, but this once we ignore it
                    Logging.Info("EDDI access to the companion app is disabled");
                }

                // Set up the star map service
                StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();
                if (starMapCredentials != null && starMapCredentials.apiKey != null)
                {
                    // Commander name might come from star map credentials or the companion app's profile
                    string commanderName = null;
                    if (starMapCredentials.commanderName != null)
                    {
                        commanderName = starMapCredentials.commanderName;
                    }
                    else if (Cmdr != null && Cmdr.name != null)
                    {
                        commanderName = Cmdr.name;
                    }
                    if (commanderName != null)
                    {
                        starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
                        Logging.Info("EDDI access to EDSM is enabled");
                    }
                }
                if (starMapService == null)
                {
                    Logging.Info("EDDI access to EDSM is disabled");
                }

                // We always start in normal space
                Environment = Constants.ENVIRONMENT_NORMAL_SPACE;

                // Set up monitors and responders
                monitors   = findMonitors();
                responders = findResponders();

                // Check for an update
                string response;
                try
                {
                    if (Constants.EDDI_VERSION.Contains("b"))
                    {
                        response = Net.DownloadString("http://api.eddp.co/betaversion");
                    }
                    else
                    {
                        response = Net.DownloadString("http://api.eddp.co/version");
                    }
                    if (Versioning.Compare(response, Constants.EDDI_VERSION) == 1)
                    {
                        SpeechService.Instance.Say(null, "EDDI version " + response.Replace(".", " point ") + " is now available.", false);
                    }
                }
                catch
                {
                    SpeechService.Instance.Say(null, "There was a problem connecting to external data services; some features may not work fully", false);
                }

                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " initialised");
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to initialise: " + ex.ToString());
            }
        }
Example #38
0
 private List <string> SystemsBeginningWith(string systemName)
 {
     return(StarMapService.GetStarMapSystemsPartial(systemName, false, false).Select(s => s.name).ToList());
 }