Esempio n. 1
0
        public static object SearchInSystems(SpanshSearchBodies _search)
        {
            return(null);

            /* _maxDistance = Math.Min(_maxDistance, 100);
             *
             * Dictionary<string, string> _sParams = new Dictionary<string, string>();
             *
             * spanshValue<double?>[] _spanshMats = new spanshValue<double?>[_materials.Length];
             * for (int i = 0; i < _materials.Length; i++)
             * {
             *   _spanshMats[i] = new spanshValue<double?>(_materials[i], ">", 0);
             * }
             * spanshSortValue[] _spanshMatsSort = new spanshSortValue[_materials.Length];
             * for (int i = 0; i < _materials.Length; i++)
             * {
             *   _spanshMatsSort[i] = new spanshSortValue(_materials[i].ToString(), false);
             * }
             *
             * spanshParam p = new spanshParam()
             * {
             *   size = 11,
             *   reference_system = _systemOrigin,
             *   filters = new spanshFilter()
             *   {
             *       distance_from_coords = new spanshValue<int?>() { max = _maxDistance },
             *       materials = _spanshMats,
             *       is_landable = new spanshValue<bool?>(_isLandable)
             *   },
             *   sort = new spanshSort[] { new spanshSort() {
             *       materials = _spanshMatsSort,
             *   },new spanshSort() {
             *       distance_from_coords = new spanshSortValue(true)
             *   } }
             * };
             * string _spanshJson = JsonConvert.SerializeObject(p, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); ;
             *
             * Console.WriteLine(_spanshJson);
             * string json = requestPOSTFromURL(Url_SpanshBodies, _spanshJson);
             * try
             * {
             *   SpanshBodiesResult result = JsonConvert.DeserializeObject<SpanshBodiesResult>(json);
             *   Console.WriteLine("Result: {0} RealCount: {1}", result.count, result.results.Length);
             *   Console.WriteLine("Search ID: " + result.search_reference);
             *
             *   return result;
             * }
             * catch (Exception ex)
             * {
             *   NexHudEngine.Log(ex.Message);
             *   NexHudEngine.Log(json);
             * }
             *
             * return null;*/
        }
Esempio n. 2
0
        public async void SearchInBodies(SpanshSearchBodies _search, Action <SpanshBodiesResult> _method, Action <SearchError> _onFailedMethod)
        {
            string _spanshJson = JsonConvert.SerializeObject(_search, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore
            });;

            NxLog.log(NxLog.Type.Debug, "SearchInBodies. json={0}", _spanshJson);

            SearchError   error = SearchError.None;
            Task <string> task  = new Task <string>(() => requestPOSTFromURL(URL_BODIES, _spanshJson, out error));

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

            if (error != SearchError.None)
            {
                _onFailedMethod?.Invoke(error);
            }
            else
            {
                // string json = requestPOSTFromURL(URL_BODIES, _spanshJson);
                try
                {
                    SpanshBodiesResult result = JsonConvert.DeserializeObject <SpanshBodiesResult>(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);
                }
            }
        }