public string getStarMapComment(string systemName)
        {
            var client         = new RestClient(baseUrl);
            var commentRequest = new RestRequest("api-logs-v1/get-comment", Method.POST);

            commentRequest.AddParameter("apiKey", apiKey);
            commentRequest.AddParameter("commanderName", commanderName);
            commentRequest.AddParameter("systemName", systemName);
            var commentClientResponse          = client.Execute <StarMapLogResponse>(commentRequest);
            StarMapLogResponse commentResponse = commentClientResponse.Data;

            return((commentResponse != null) ? commentResponse.comment : null);
        }
        public void sendStarMapLog(DateTime timestamp, string systemName, decimal?x, decimal?y, decimal?z)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-logs-v1/set-log");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("systemName", systemName);
            request.AddParameter("dateVisited", timestamp.ToString("yyyy-MM-dd HH:mm:ss"));
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);
            if (x.HasValue)
            {
                request.AddParameter("x", ((decimal)x).ToString("0.000", EN_US_CULTURE));
            }
            if (y.HasValue)
            {
                request.AddParameter("y", ((decimal)y).ToString("0.000", EN_US_CULTURE));
            }
            if (z.HasValue)
            {
                request.AddParameter("z", ((decimal)z).ToString("0.000", EN_US_CULTURE));
            }

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending data to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    Logging.Debug("Data sent to EDSM");
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send data to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send starmap log";
            thread.Start();
        }
Exemple #3
0
        public void sendEvent(string eventData)
        {
            // The EDSM responder has a `inBeta` flag that it checks prior to sending data via this method.
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-journal-v1", Method.POST);

            request.AddParameter("commanderName", commanderName);
            request.AddParameter("apiKey", apiKey);
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);
            request.AddParameter("message", eventData);

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending event to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    if (response?.msgnum != 100)
                    {
                        if (response?.msg != null)
                        {
                            Logging.Warn("EDSM responded with " + response?.msg);
                        }
                        else
                        {
                            Logging.Warn(clientResponse?.ErrorMessage);
                        }
                    }
                    Thread.Sleep(200); // Add a buffer to prevent time outs.
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send event to EDSM", ex);
                }
            })
            {
                IsBackground = true,
                Name         = "StarMapService send event"
            };

            thread.Start();
        }
        public void sendRanks(int combat, int combatProgress,
                              int trade, int tradeProgress,
                              int exploration, int explorationProgress,
                              int cqc, int cqcProgress,
                              int federation, int federationProgress,
                              int empire, int empireProgress)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-commander-v1/set-ranks");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("Combat", combat + ";" + combatProgress);
            request.AddParameter("Trade", trade + ";" + tradeProgress);
            request.AddParameter("Explore", exploration + ";" + explorationProgress);
            request.AddParameter("CQC", cqc + ";" + cqcProgress);
            request.AddParameter("Federation", federation + ";" + federationProgress);
            request.AddParameter("Empire", empire + ";" + empireProgress);
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending data to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    Logging.Debug("Data sent to EDSM");
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send data to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send ranks";
            thread.Start();
        }
Exemple #5
0
        public Dictionary <string, StarMapLogInfo> getStarMapLog(DateTime?since = null)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-logs-v1/get-logs");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            if (since.HasValue)
            {
                request.AddParameter("startdatetime", since.Value.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            var starMapLogResponse      = client.Execute <StarMapLogResponse>(request);
            StarMapLogResponse response = starMapLogResponse.Data;

            Logging.Debug("Response for star map logs is " + JsonConvert.SerializeObject(response));

            Dictionary <string, StarMapLogInfo> vals = new Dictionary <string, StarMapLogInfo>();

            if (response != null && response.logs != null)
            {
                foreach (StarMapResponseLogEntry entry in response.logs)
                {
                    Logging.Debug("Log entry found for " + entry.system);
                    if (vals.ContainsKey(entry.system))
                    {
                        vals[entry.system].visits = vals[entry.system].visits + 1;
                        if (entry.date > vals[entry.system].lastVisit)
                        {
                            vals[entry.system].previousVisit = vals[entry.system].lastVisit;
                            vals[entry.system].lastVisit     = entry.date;
                        }
                        else if (vals[entry.system].previousVisit == null || entry.date > vals[entry.system].previousVisit)
                        {
                            vals[entry.system].previousVisit = entry.date;
                        }
                    }
                    else
                    {
                        vals[entry.system]           = new StarMapLogInfo();
                        vals[entry.system].system    = entry.system;
                        vals[entry.system].visits    = 1;
                        vals[entry.system].lastVisit = entry.date;
                    }
                }
            }
            return(vals);
        }
        public void sendShip(Ship ship)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-commander-v1/update-ship");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("shipId", ship.LocalId);
            request.AddParameter("shipName", ship.name);
            request.AddParameter("shipIdent", ship.ident);
            request.AddParameter("type", ship.EDName);
            request.AddParameter("paintJob", ship.paintjob);
            request.AddParameter("cargoQty", ship.cargocarried);
            request.AddParameter("cargoCapacity", ship.cargocapacity);
            request.AddParameter("linkToCoriolis", ship.CoriolisUri());

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending data to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    Logging.Debug("Data sent to EDSM");
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send data to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send ship";
            thread.Start();
        }
Exemple #7
0
        public void sendStarMapComment(string systemName, string comment)
        {
            if (!EdsmCredentialsSet())
            {
                return;
            }

            var request = new RestRequest("api-logs-v1/set-comment", Method.POST);

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("systemName", systemName);
            request.AddParameter("comment", comment);

            Thread thread = new Thread(() =>
            {
                try
                {
                    var clientResponse          = restClient.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    if (response?.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response?.msg ?? clientResponse.ErrorMessage);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send comment to EDSM", ex);
                }
            })
            {
                IsBackground = true,
                Name         = "StarMapService send starmap comment"
            };

            thread.Start();
        }
Exemple #8
0
        public void sendStarMapComment(string systemName, string comment)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-logs-v1/set-comment");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("systemName", systemName);
            request.AddParameter("comment", comment);

            Thread thread = new Thread(() =>
            {
                var clientResponse          = client.Execute <StarMapLogResponse>(request);
                StarMapLogResponse response = clientResponse.Data;
                // TODO check response
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send starmap comment";
            thread.Start();
        }
        public void sendCredits(decimal credits, decimal loan)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-commander-v1/set-credits");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("balance", credits);
            request.AddParameter("loan", loan);
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending data to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    Logging.Debug("Data sent to EDSM");
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send data to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send credits";
            thread.Start();
        }
        public void sendData(Dictionary <string, int> data)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-commander-v1/set-materials");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("type", "data");
            request.AddParameter("values", JsonConvert.SerializeObject(data));
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending data to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    Logging.Debug("Data sent to EDSM");
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send data to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send data";
            thread.Start();
        }
Exemple #11
0
        public StarMapInfo getStarMapInfo(string systemName)
        {
            var client = new RestClient(baseUrl);

            // First fetch the data itself
            var logRequest = new RestRequest("api-logs-v1/get-logs", Method.POST);

            logRequest.AddParameter("apiKey", apiKey);
            logRequest.AddParameter("commanderName", commanderName);
            logRequest.AddParameter("systemName", systemName);
            var logClientResponse          = client.Execute <StarMapLogResponse>(logRequest);
            StarMapLogResponse logResponse = logClientResponse.Data;

            if (logResponse?.msgnum != 100)
            {
                Logging.Warn("EDSM responded with " + logResponse.msg ?? logClientResponse.ErrorMessage);
            }

            // Also grab any comment that might be present
            var commentRequest = new RestRequest("api-logs-v1/get-comment", Method.POST);

            commentRequest.AddParameter("apiKey", apiKey);
            commentRequest.AddParameter("commanderName", commanderName);
            commentRequest.AddParameter("systemName", systemName);
            var commentClientResponse          = client.Execute <StarMapLogResponse>(commentRequest);
            StarMapLogResponse commentResponse = commentClientResponse.Data;

            if (commentResponse?.msgnum != 100)
            {
                Logging.Warn("EDSM responded with " + commentResponse.msg ?? commentClientResponse.ErrorMessage);
            }

            int      visits     = (logResponse != null && logResponse.logs != null) ? logResponse.logs.Count : 1;
            DateTime lastUpdate = (logResponse != null && logResponse.lastUpdate != null) ? (DateTime)logResponse.lastUpdate : new DateTime();
            string   comment    = commentResponse?.comment;

            return(new StarMapInfo(visits, lastUpdate, comment));
        }
Exemple #12
0
        public void sendStarMapLog(DateTime timestamp, string systemName, decimal?x, decimal?y, decimal?z)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-logs-v1/set-log");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("systemName", systemName);
            request.AddParameter("dateVisited", timestamp.ToString("yyyy-MM-dd HH:mm:ss"));
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);
            if (x.HasValue)
            {
                request.AddParameter("x", ((decimal)x).ToString("0.000", EN_US_CULTURE));
            }
            if (y.HasValue)
            {
                request.AddParameter("y", ((decimal)y).ToString("0.000", EN_US_CULTURE));
            }
            if (z.HasValue)
            {
                request.AddParameter("z", ((decimal)z).ToString("0.000", EN_US_CULTURE));
            }

            Thread thread = new Thread(() =>
            {
                Logging.Debug("Sending data to EDSM: " + request);
                var clientResponse          = client.Execute <StarMapLogResponse>(request);
                StarMapLogResponse response = clientResponse.Data;
                Logging.Debug("Data sent to EDSM");
                // TODO check response
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send starmap log";
            thread.Start();
        }
Exemple #13
0
        public void sendEvent(string eventData)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-journal-v1", Method.POST);

            request.AddParameter("commanderName", commanderName);
            request.AddParameter("apiKey", apiKey);
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);
            request.AddParameter("message", eventData);

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending event to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send event to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService send event";
            thread.Start();
        }
        public void sendShipSold(int shipId)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-commander-v1/sell-ship");

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            request.AddParameter("shipId", shipId);

            Thread thread = new Thread(() =>
            {
                try
                {
                    Logging.Debug("Sending data to EDSM: " + client.BuildUri(request).AbsoluteUri);
                    var clientResponse          = client.Execute <StarMapLogResponse>(request);
                    StarMapLogResponse response = clientResponse.Data;
                    Logging.Debug("Data sent to EDSM");
                    if (response.msgnum != 100)
                    {
                        Logging.Warn("EDSM responded with " + response.msg);
                    }
                }
                catch (ThreadAbortException)
                {
                    Logging.Debug("Thread aborted");
                }
                catch (Exception ex)
                {
                    Logging.Warn("Failed to send data to EDSM", ex);
                }
            });

            thread.IsBackground = true;
            thread.Name         = "StarMapService sell ship";
            thread.Start();
        }
Exemple #15
0
        private void SendEventBatch(List <IDictionary <string, object> > eventData, StarMapConfiguration starMapConfiguration)
        {
            if (!EdsmCredentialsSet())
            {
                return;
            }

            // Filter any stale data
            eventData = eventData
                        .Where(e => JsonParsing.getDateTime("timestamp", e) > starMapConfiguration.lastJournalSync)
                        .ToList();
            if (eventData.Count == 0)
            {
                return;
            }

            // The EDSM responder has a `gameIsBeta` flag that it checks prior to sending data via this method.
            var request = new RestRequest("api-journal-v1", Method.POST);

            request.AddParameter("commanderName", commanderName);
            request.AddParameter("apiKey", apiKey);
            request.AddParameter("fromSoftware", Constants.EDDI_NAME);
            request.AddParameter("fromSoftwareVersion", Constants.EDDI_VERSION);
            request.AddParameter("message", JsonConvert.SerializeObject(eventData).Normalize());
            request.Timeout = JournalTimeoutMilliseconds;

            try
            {
                Logging.Debug("Sending message to EDSM: " + restClient.BuildUri(request).AbsoluteUri);
                var clientResponse          = restClient.Execute <StarMapLogResponse>(request);
                StarMapLogResponse response = clientResponse.Data;

                if (response is null)
                {
                    Logging.Warn(clientResponse.ErrorMessage);
                    ReEnqueueEvents(eventData);
                }
                else if (response.msgnum >= 100 && response.msgnum <= 103)
                {
                    // 100 -  Everything went fine!
                    // 101 -  The journal message was already processed in our database.
                    // 102 -  The journal message was already in a newer version in our database.
                    // 103 -  Duplicate event request (already reported from another software client).
                    starMapConfiguration.lastJournalSync = eventData
                                                           .Select(e => JsonParsing.getDateTime("timestamp", e))
                                                           .Max();
                    starMapConfiguration.ToFile();
                }
                if (response?.msgnum != 100)
                {
                    if (!string.IsNullOrEmpty(response?.msg))
                    {
                        Logging.Warn("EDSM responded with: " + response.msg);
                    }
                    else
                    {
                        Logging.Warn("EDSM responded with: " + JsonConvert.SerializeObject(response));
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Warn("Failed to send event to EDSM", ex);
            }
        }
Exemple #16
0
        public Dictionary <string, StarMapLogInfo> getStarMapLog(DateTime?since = null)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("api-logs-v1/get-logs", Method.POST);

            request.AddParameter("apiKey", apiKey);
            request.AddParameter("commanderName", commanderName);
            if (since.HasValue)
            {
                request.AddParameter("startdatetime", since.Value.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            else
            {
                /// Though not documented in the api, Anthor from EDSM has confirmed that this
                /// unpublished parameter is valid and overrides "startdatetime" and "enddatetime".
                request.AddParameter("fullSync", 1);
            }
            var starMapLogResponse      = client.Execute <StarMapLogResponse>(request);
            StarMapLogResponse response = starMapLogResponse.Data;

            if (response != null)
            {
                Logging.Debug("Response for star map logs is " + JsonConvert.SerializeObject(response));
                if (response.msgnum != 100)
                {
                    // An error occurred
                    throw new EDSMException(response.msg);
                }
            }
            else
            {
                Logging.Debug("No response received.");
                throw new EDSMException();
            }

            Dictionary <string, StarMapLogInfo> vals = new Dictionary <string, StarMapLogInfo>();

            if (response != null && response.logs != null)
            {
                foreach (StarMapResponseLogEntry entry in response.logs)
                {
                    if (vals.ContainsKey(entry.system))
                    {
                        vals[entry.system].visits = vals[entry.system].visits + 1;
                        if (entry.date > vals[entry.system].lastVisit)
                        {
                            vals[entry.system].previousVisit = vals[entry.system].lastVisit;
                            vals[entry.system].lastVisit     = entry.date;
                        }
                        else if (vals[entry.system].previousVisit == null || entry.date > vals[entry.system].previousVisit)
                        {
                            vals[entry.system].previousVisit = entry.date;
                        }
                    }
                    else
                    {
                        vals[entry.system]           = new StarMapLogInfo();
                        vals[entry.system].system    = entry.system;
                        vals[entry.system].visits    = 1;
                        vals[entry.system].lastVisit = entry.date;
                    }
                }
            }
            return(vals);
        }