예제 #1
0
        public MapUpdateHistory UpdateMap(Map map)
        {
            Log.DebugFormat($"[MapApiFunctions.UpdateMap] start for '{map.ActivePilot}' and map '{map.Key}'");

            lock (_mylock)
            {
                try
                {
                    var result = Update(map, map.Key, map.ActivePilot, map.GetLastUpdate());

                    return(PrapairData(map, result));
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("[MapApiFunctions.UpdateMap] Critical error. Exception is {0}", ex);
                }

                MapUpdateHistory historyFailure;

                historyFailure.UpdatedSystems = 0;
                historyFailure.DeletedSustems = 0;
                historyFailure.Pilots         = 0;
                historyFailure.UpdateTime     = DateTime.UtcNow;

                return(historyFailure);
            }
        }
예제 #2
0
        public MapUpdateHistory DeleteConnectionBetweenSolarSystems(Map map, string pilotName, string key, string systemFrom, string systemTo)
        {
            Log.DebugFormat("[MapApiFunctions.DeleteConnectionBetweenSolarSystems] start");

            var address = _mapServerAddress + "/api/DeathNotice?mapKey=" + key + "&pilot=" + pilotName + "&solarSystemFrom=" + systemFrom + "&solarSystemTo=" + systemTo + "&ticks=" + map.GetLastUpdate() + "";;

            _apiCallsLog.Info(address);

            try
            {
                using (var client = new WebClient())
                {
                    string dataVerification;

                    if (map.IsPublic)
                    {
                        dataVerification = client.DownloadString(address);
                    }
                    else
                    {
                        dataVerification = MapRouter.DeathNotice(map.Key, map.ActivePilot, systemFrom, systemTo, map.GetLastUpdate());
                    }

                    var updatedData = JsonConvert.DeserializeObject(dataVerification).ToString();

                    Log.DebugFormat("[MapApiFunctions.DeleteConnectionBetweenSolarSystems] end");

                    return(PrapairData(map, updatedData));
                }
            }
            catch (Exception ex)
            {
                _errorsLog.ErrorFormat("[MapApiFunctions.DeleteConnectionBetweenSolarSystems] MapKey = {3} systemFrom = {2} systemTo = {1}  Critical error {0}", ex, systemTo, systemFrom, key);
            }

            MapUpdateHistory historyFailure;

            historyFailure.UpdatedSystems = 0;
            historyFailure.DeletedSustems = 0;
            historyFailure.Pilots         = 0;
            historyFailure.UpdateTime     = DateTime.UtcNow;

            return(historyFailure);
        }
예제 #3
0
        public MapUpdateHistory DeleteSignature(Map map, string pilotName, string key, string system, string code)
        {
            Log.DebugFormat("[MapApiFunctions.DeleteSignature] start");

            try
            {
                var address = _mapServerAddress + "/api/DeleteSignature?pilotName=" + pilotName + "&key=" + key + "&system=" + system + "&code=" + code + "&ticks=" + map.GetLastUpdate() + "";;

                _apiCallsLog.Info(address);

                using (var client = new WebClient())
                {
                    string dataVerification;

                    if (map.IsPublic)
                    {
                        dataVerification = client.DownloadString(address);
                    }
                    else
                    {
                        dataVerification = MapRouter.DeleteSignature(map.ActivePilot, map.Key, system, code, map.GetLastUpdate());
                    }

                    var updatedData = JsonConvert.DeserializeObject(dataVerification).ToString();

                    Log.DebugFormat("[MapApiFunctions.DeleteSignature] end");

                    return(PrapairData(map, updatedData));
                }
            }
            catch (Exception ex)
            {
                MapUpdateHistory historyFailure;

                historyFailure.UpdatedSystems = 0;
                historyFailure.DeletedSustems = 0;
                historyFailure.Pilots         = 0;
                historyFailure.UpdateTime     = DateTime.UtcNow;

                return(historyFailure);
            }
        }
예제 #4
0
        public MapUpdateHistory PublishSignatures(Map map, string pilotName, string key, string system, List <CosmicSignature> signatures)
        {
            Log.DebugFormat("[MapApiFunctions.PublishSignatures] start");

            try
            {
                var signaturesJson = JsonConvert.SerializeObject(signatures, Formatting.Indented);

                var address = _mapServerAddress + "/api/PublishSignatures?pilotName=" + pilotName + "&key=" + key + "&system=" + system + "&signatures=" + signaturesJson + "&ticks=" + map.GetLastUpdate() + "";;

                _apiCallsLog.Info(address);

                using (var client = new WebClient())
                {
                    string dataVerification;

                    if (map.IsPublic)
                    {
                        dataVerification = client.DownloadString(address);
                    }
                    else
                    {
                        dataVerification = MapRouter.PublishSignatures(map.ActivePilot, map.Key, system, signaturesJson, map.GetLastUpdate());
                    }

                    var updatedData = JsonConvert.DeserializeObject(dataVerification).ToString();

                    Log.DebugFormat("[MapApiFunctions.PublishSignatures] end");

                    return(PrapairData(map, updatedData));
                }
            }
            catch (Exception ex)
            {
                _errorsLog.ErrorFormat("[MapApiFunctions.PublishSignatures] MapKey = {3} SolarSystemName = {2} Signatures = {1}  Critical error {0}", ex, signatures, system, key);
            }

            MapUpdateHistory historyFailure;

            historyFailure.UpdatedSystems = 0;
            historyFailure.DeletedSustems = 0;
            historyFailure.Pilots         = 0;
            historyFailure.UpdateTime     = DateTime.UtcNow;

            return(historyFailure);
        }
예제 #5
0
        public MapUpdateHistory PublishDeadLetter(Map map, string mapKey, string pilot, string systemFrom, string systemTo)
        {
            Log.DebugFormat("[MapApiFunctions.PublishDeadLetter] start");

            try
            {
                var address = _mapServerAddress + "/api/Signatures?mapKey=" + mapKey + "&pilot=" + pilot + "&systemFrom=" + systemFrom + "&systemTo=" + systemTo + "&ticks=" + map.GetLastUpdate() + "";

                _apiCallsLog.Info(address);

                using (var client = new WebClient())
                {
                    string dataVerification;

                    if (map.IsPublic)
                    {
                        dataVerification = client.DownloadString(address);
                    }
                    else
                    {
                        dataVerification = MapRouter.DeathNotice(map.Key, map.ActivePilot, systemFrom, systemTo, map.GetLastUpdate());
                    }

                    _commandsLog.InfoFormat("[MapApiFunctions.PublishDeadLetter] PublishDeadLetter in system {2}, previous syste, {3} with map key ='{0}' for pilot ='{1}'", mapKey, pilot, systemTo, systemFrom);

                    var updatedData = JsonConvert.DeserializeObject(dataVerification).ToString();

                    Log.DebugFormat("[MapApiFunctions.PublishDeadLetter] end");

                    return(PrapairData(map, updatedData));
                }
            }
            catch (Exception ex)
            {
                _errorsLog.ErrorFormat("[MapApiFunctions.PublishDeadLetter] PublishDeadLetter in system {2}, previous syste, {3} with map key ='{0}' for pilot ='{1}' exception is {4}", mapKey, pilot, systemTo, systemFrom, ex);

                MapUpdateHistory historyFailure;

                historyFailure.UpdatedSystems = 0;
                historyFailure.DeletedSustems = 0;
                historyFailure.Pilots         = 0;
                historyFailure.UpdateTime     = DateTime.UtcNow;

                return(historyFailure);
            }
        }
예제 #6
0
        public MapUpdateHistory DeleteSolarSystem(Map map, string system)
        {
            Log.DebugFormat($"[MapApiFunctions.DeleteSolarSystem] start for system {system}");

            try
            {
                var address = _mapServerAddress + "/api/DeleteSolarSystem?mapKey=" + map.Key + "&system=" + system + "&pilotName=" + map.ActivePilot + "&ticks=" + map.GetLastUpdate() + "";

                _apiCallsLog.Info(address);

                using (var client = new WebClient())
                {
                    string dataVerification;

                    if (map.IsPublic)
                    {
                        dataVerification = client.DownloadString(address);
                    }
                    else
                    {
                        dataVerification = MapRouter.DeleteSolarSystem(map.Key, system, map.ActivePilot, map.GetLastUpdate());
                    }

                    _commandsLog.InfoFormat("[Map.DeleteSolarSystem] Delete Solar System {2} with map key ='{0}' for pilot ='{1}'", map.Key, map.ActivePilot, system);

                    var updatedData = JsonConvert.DeserializeObject(dataVerification).ToString();

                    Log.DebugFormat($"[MapApiFunctions.DeleteSolarSystem] end  for system {system}");

                    return(PrapairData(map, updatedData));
                }
            }
            catch (Exception ex)
            {
                _commandsLog.ErrorFormat("[Map.DeleteSolarSystem] Critical error - Delete Solar System {2} with map key ='{0}' for pilot ='{1}' Exception {3}", map.Key, map.ActivePilot, system, ex);

                MapUpdateHistory historyFailure;

                historyFailure.UpdatedSystems = 0;
                historyFailure.DeletedSustems = 0;
                historyFailure.Pilots         = 0;
                historyFailure.UpdateTime     = DateTime.UtcNow;

                return(historyFailure);
            }
        }