Exemplo n.º 1
0
        public async void SearchInSystems(SpanshSearchSystems _search, Action <SpanshSystemsResult> _method, Action <SearchError> _onFailedMethod)
        {
            string      _spanshJson = string.Empty;
            SearchError error       = SearchError.None;

            try
            {
                _spanshJson = JsonConvert.SerializeObject(_search, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });;
                NxLog.log(NxLog.Type.Debug, "SearchInSystems. json={0}", _spanshJson);
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(NxLog.Type.Error, ex.Message);
                _onFailedMethod?.Invoke(error = SearchError.SerializationFailed);
                return;
            }

            Task <string> task = new Task <string>(() => requestPOSTFromURL(URL_SYSTEMS, _spanshJson, out error));

            task.Start();
            string json = await task;

            if (error != SearchError.None)
            {
                _onFailedMethod?.Invoke(error);
            }
            else
            {
                // string json = requestPOSTFromURL(URL_BODIES, _spanshJson);
                try
                {
                    SpanshSystemsResult result = JsonConvert.DeserializeObject <SpanshSystemsResult>(json, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });
                    NxLog.log(NxLog.Type.Debug, "Search Successful! Search ID = " + result.search_reference);

                    _method?.Invoke(result);
                }
                catch (Exception ex)
                {
                    NexHudEngine.Log(NxLog.Type.Error, ex.Message);
                    NexHudEngine.Log(NxLog.Type.Error, ex.StackTrace);
                    _onFailedMethod?.Invoke(error = SearchError.DeserializationFailed);
                }
            }
        }
Exemplo n.º 2
0
        private static void LoadLists()
        {
            NxLog.log(NxLog.Type.Info, "load SearchSystemList.json");
            string path = Environment.CurrentDirectory + "\\Config\\SearchSystemList.json";

            if (File.Exists(path))
            {
                string             _json = File.ReadAllText(path);
                SearchSystemList[] _list = JsonConvert.DeserializeObject <SearchSystemList[]>(_json);
                foreach (SearchSystemList s in _list)
                {
                    CustomSearch custom = new CustomSearch()
                    {
                        SearchName   = s.searchName,
                        SystemsNotes = new Dictionary <string, string>(),
                        SearchSystem = new SpanshSearchSystems()
                        {
                            filters = new SpanshFilterSystems()
                        }
                    };
                    List <string> names = new List <string>();
                    for (int i = 0; i < s.systemNames.Length; i += 2)
                    {
                        names.Add(s.systemNames[i]);
                        custom.SystemsNotes.Add(s.systemNames[i], s.systemNames[i + 1]);
                    }
                    custom.SearchSystem.filters.name = new SpanshValue <string[]>(names.ToArray());
                    custom.Serializable = false;

                    custom.SearchSystem.sort = new SpanshSort[] { new SpanshSort()
                                                                  {
                                                                      distance_from_coords = new SpanshSortValue(true)
                                                                  } };
                    Searchs.Add(custom);
                }
                ;
            }
        }