Exemple #1
0
        public int GetLogs(DateTime starttimeutc, out List <HistoryEntry> log)
        {
            log = new List <HistoryEntry>();

            if (!IsApiKeySet)
            {
                return(0);
            }

            string query = "get-logs?showId=1&startdatetime=" + HttpUtility.UrlEncode(starttimeutc.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) + "&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            //string query = "get-logs?apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            var response = RequestGet("api-logs-v1/" + query);

            if ((int)response.StatusCode >= 400)
            {
                return(0);
            }

            var json = response.Body;

            if (json == null)
            {
                return(0);
            }

            JObject msg   = JObject.Parse(json);
            int     msgnr = msg["msgnum"].Value <int>();

            JArray logs = (JArray)msg["logs"];

            if (logs != null)
            {
                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    foreach (JObject jo in logs)
                    {
                        string   name  = jo["system"].Value <string>();
                        string   ts    = jo["date"].Value <string>();
                        long     id    = jo["systemId"].Value <long>();
                        DateTime etutc = DateTime.ParseExact(ts, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal); // UTC time

                        SystemClass sc = SystemClass.GetSystem(id, cn, SystemClass.SystemIDType.EdsmId);
                        if (sc == null)
                        {
                            sc = new SystemClass(name)
                            {
                                id_edsm = id
                            }
                        }
                        ;

                        HistoryEntry he = new HistoryEntry();
                        he.MakeVSEntry(sc, etutc, EDDConfig.Instance.DefaultMapColour, "", "");       // FSD jump entry
                        log.Add(he);
                    }
                }
            }

            return(msgnr);
        }
        public void No_filter_does_not_filter_anything()
        {
            var veryOldData = HistoryEntry.MakeVSEntry(sol, DateTime.UtcNow.Subtract(TimeSpan.FromDays(500000)), 0, "", "");
            var input       = new HistoryList(new List <HistoryEntry> {
                veryOldData
            });

            Check.That(TravelHistoryFilter.NoFilter.Filter(input)).ContainsExactly(veryOldData);
        }
        public void Data_age_filter_removes_data_older_than_the_limit_and_keeps_data_more_recent_than_the_limit()
        {
            var now         = HistoryEntry.MakeVSEntry(sol, DateTime.UtcNow, 0, "", "");
            var fourDaysAgo = HistoryEntry.MakeVSEntry(sol, DateTime.UtcNow.Subtract(TimeSpan.FromDays(4)), 0, "", "");
            var input       = new HistoryList(new List <HistoryEntry> {
                fourDaysAgo, now
            });

            Check.That(TravelHistoryFilter.FromDays(2).Filter(input)).ContainsExactly(now);
        }
        public void Last_2_items_filter_returns_the_2_most_recent_items_sorted_by_most_recent_and_removes_the_older_items()
        {
            var twentyDaysAgo = HistoryEntry.MakeVSEntry(sol, DateTime.UtcNow.Subtract(TimeSpan.FromDays(20)), 0, "", "");
            var tenDaysAgo    = HistoryEntry.MakeVSEntry(sol, DateTime.UtcNow.Subtract(TimeSpan.FromDays(10)), 0, "", "");
            var thirtyDaysAgo = HistoryEntry.MakeVSEntry(sol, DateTime.UtcNow.Subtract(TimeSpan.FromDays(30)), 0, "", "");
            var input         = new HistoryList(new List <HistoryEntry> {
                twentyDaysAgo, tenDaysAgo, thirtyDaysAgo
            });

            Check.That(TravelHistoryFilter.Last(2).Filter(input)).ContainsExactly(tenDaysAgo, twentyDaysAgo);
        }
Exemple #5
0
        public int GetLogs(DateTime?starttimeutc, DateTime?endtimeutc, out List <HistoryEntry> log, out DateTime logstarttime, out DateTime logendtime)
        {
            log          = new List <HistoryEntry>();
            logstarttime = DateTime.MaxValue;
            logendtime   = DateTime.MinValue;

            if (!ValidCredentials)
            {
                return(0);
            }

            string query = "get-logs?showId=1&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);

            if (starttimeutc != null)
            {
                query += "&startDateTime=" + HttpUtility.UrlEncode(starttimeutc.Value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
            }

            if (endtimeutc != null)
            {
                query += "&endDateTime=" + HttpUtility.UrlEncode(endtimeutc.Value.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
            }

            var response = RequestGet("api-logs-v1/" + query, handleException: true);

            if (response.Error)
            {
                return(0);
            }

            var json = response.Body;

            if (json == null)
            {
                return(0);
            }

            JObject msg   = JObject.Parse(json);
            int     msgnr = msg["msgnum"].Int(0);

            JArray logs = (JArray)msg["logs"];

            if (logs != null)
            {
                string startdatestr = msg["startDateTime"].Value <string>();
                string enddatestr   = msg["endDateTime"].Value <string>();
                if (startdatestr == null || !DateTime.TryParseExact(startdatestr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out logstarttime))
                {
                    logstarttime = DateTime.MaxValue;
                }
                if (enddatestr == null || !DateTime.TryParseExact(enddatestr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out logendtime))
                {
                    logendtime = DateTime.MinValue;
                }

                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    foreach (JObject jo in logs)
                    {
                        string   name          = jo["system"].Value <string>();
                        string   ts            = jo["date"].Value <string>();
                        long     id            = jo["systemId"].Value <long>();
                        bool     firstdiscover = jo["firstDiscover"].Value <bool>();
                        DateTime etutc         = DateTime.ParseExact(ts, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal); // UTC time

                        ISystem sc = SystemClassDB.GetSystem(id, cn, SystemClassDB.SystemIDType.EdsmId, name: name);
                        if (sc == null)
                        {
                            if (DateTime.UtcNow.Subtract(etutc).TotalHours < 6) // Avoid running into the rate limit
                            {
                                sc = GetSystemsByName(name)?.FirstOrDefault(s => s.EDSMID == id);
                            }

                            if (sc == null)
                            {
                                sc = new SystemClass(name)
                                {
                                    EDSMID = id
                                };
                            }
                        }

                        HistoryEntry he = HistoryEntry.MakeVSEntry(sc, etutc, EliteConfigInstance.InstanceConfig.DefaultMapColour, "", "", firstdiscover: firstdiscover);       // FSD jump entry
                        log.Add(he);
                    }
                }
            }

            return(msgnr);
        }
Exemple #6
0
        public int GetLogs(DateTime starttimeutc, out List<HistoryEntry> log)
        {
            log = new List<HistoryEntry>();

            if (!IsApiKeySet)
                return 0;

            string query = "get-logs?showId=1&startdatetime=" + HttpUtility.UrlEncode(starttimeutc.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) + "&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            //string query = "get-logs?apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);

            var response = RequestGet("api-logs-v1/" + query, handleException: true);

            if (response.Error)
                return 0;

            var json = response.Body;

            if (json == null)
                return 0;

            JObject msg = JObject.Parse(json);
            int msgnr = msg["msgnum"].Value<int>();

            JArray logs = (JArray)msg["logs"];

            if (logs != null)
            {
                using (SQLiteConnectionSystem cn = new SQLiteConnectionSystem())
                {
                    foreach (JObject jo in logs)
                    {
                        string name = jo["system"].Value<string>();
                        string ts = jo["date"].Value<string>();
                        long id = jo["systemId"].Value<long>();
                        DateTime etutc = DateTime.ParseExact(ts, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal|DateTimeStyles.AssumeUniversal); // UTC time

                        SystemClass sc = SystemClass.GetSystem(id, cn, SystemClass.SystemIDType.EdsmId);
                        if (sc == null)
                            sc = new SystemClass(name)
                            {
                                id_edsm = id
                            };

                        HistoryEntry he = new HistoryEntry();
                        he.MakeVSEntry(sc, etutc, EDDConfig.Instance.DefaultMapColour, "", "");       // FSD jump entry
                        log.Add(he);
                    }
                }
            }

            return msgnr;
        }