private void readCurrentMapBoundingBoxDetails(MapDownloadResource currentMap, JsonReader reader) { reader.BeginObject(); while (reader.HasNext) { string key = reader.NextName(); if (key != null) { if (key.Equals(LAT_MAX_ID)) { currentMap.setBbLatMax(reader.NextDouble()); } else if (key.Equals(LAT_MIN_ID)) { currentMap.setBbLatMin(reader.NextDouble()); } else if (key.Equals(LONG_MAX_ID)) { currentMap.setBbLongMax(reader.NextDouble()); } else if (key.Equals(LONG_MIN_ID)) { currentMap.setBbLongMin(reader.NextDouble()); } } } reader.EndObject(); }
public Dictionary <string, MapDownloadResource> getAvailableMapsForACertainType(params string[] mapType) { StringBuilder query = new StringBuilder("SELECT ").Append(CODE).Append(", ").Append(PARENT_CODE).Append(", ").Append(REGION).Append(", ") .Append(NAMES).Append(", ").Append(SKM_FILE_PATH).Append(", " + "").Append(ZIP_FILE_PATH).Append(", ") .Append(TXG_FILE_PATH).Append(", ").Append(TXG_FILE_SIZE).Append(", ") .Append(SKM_AND_ZIP_FILES_SIZE).Append(", ").Append(SKM_FILE_SIZE).Append(", " + "").Append(UNZIPPED_FILE_SIZE) .Append(", ").Append(BOUNDING_BOX_LATITUDE_MAX).Append(", ").Append(BOUNDING_BOX_LATITUDE_MIN) .Append(", ").Append(BOUNDING_BOX_LONGITUDE_MAX).Append(", ").Append(BOUNDING_BOX_LONGITUDE_MIN) .Append(", ").Append(SUBTYPE).Append(", ").Append(STATE).Append(", " + "").Append(NO_DOWNLOADED_BYTES) .Append(", ").Append(FLAG_ID).Append(", ").Append(DOWNLOAD_PATH).Append(" FROM ").Append (MAPS_TABLE); if (mapType != null && mapType.Length > 0) { query.Append(" WHERE ").Append(SUBTYPE).Append("=?"); for (int i = 1; i < mapType.Length; i++) { query.Append(" or ").Append(SUBTYPE).Append("=?"); } } ICursor resultCursor = resourcesDAO.getDatabase().RawQuery(query.ToString(), mapType); if ((resultCursor != null) && (resultCursor.Count > 0)) { Dictionary <String, MapDownloadResource> maps = new Dictionary <String, MapDownloadResource>(); MapDownloadResource currentMap; try { resultCursor.MoveToFirst(); while (!resultCursor.IsAfterLast) { currentMap = new MapDownloadResource(); currentMap.Code = (resultCursor.GetString(0)); currentMap.ParentCode = (resultCursor.GetString(1)); currentMap.setNames(resultCursor.GetString(3)); currentMap.setSkmFilePath(resultCursor.GetString(4)); currentMap.setZipFilePath(resultCursor.GetString(5)); currentMap.setTXGFilePath(resultCursor.GetString(6)); currentMap.setTXGFileSize(resultCursor.GetInt(7)); currentMap.setSkmAndZipFilesSize(resultCursor.GetInt(8)); currentMap.setSkmFileSize(resultCursor.GetInt(9)); currentMap.setUnzippedFileSize(resultCursor.GetInt(10)); currentMap.setBbLatMax(resultCursor.GetDouble(11)); currentMap.setBbLatMin(resultCursor.GetDouble(12)); currentMap.setBbLongMax(resultCursor.GetDouble(13)); currentMap.setBbLongMin(resultCursor.GetDouble(14)); currentMap.setSubType(resultCursor.GetString(15)); currentMap.DownloadState = (sbyte)resultCursor.GetInt(16); currentMap.NoDownloadedBytes = (resultCursor.GetInt(17)); currentMap.FlagId = (resultCursor.GetInt(18)); currentMap.DownloadPath = (resultCursor.GetString(19)); maps.Add(currentMap.Code, currentMap); resultCursor.MoveToNext(); } } finally { resultCursor.Close(); } return(maps); } else { if (resultCursor != null) { resultCursor.Close(); } return(null); } }
/** * read maps packages list * @param maps a list of maps objects that will be read from JSON file * @param packagesArray packages array */ private void readMapsPackages(List <MapDownloadResource> maps, JSONArray packagesArray) { for (int i = 0; i < packagesArray.Length(); i++) { JSONObject currentPackageObject = null; try { currentPackageObject = packagesArray.GetJSONObject(i); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } if (currentPackageObject != null) { MapDownloadResource currentMap = new MapDownloadResource(); try { currentMap.Code = (currentPackageObject.GetString(PACKAGE_CODE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSubType(GetMapType(currentPackageObject.GetInt(TYPE_ID))); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONArray currentMapNames = currentPackageObject.GetJSONArray(LANGUAGES_ID); if (currentMapNames != null) { for (int j = 0; j < currentMapNames.Length(); j++) { JSONObject currentMapNameObject = currentMapNames.GetJSONObject(j); if (currentMapNameObject != null) { String currentMapName = currentMapNameObject.GetString(TL_NAME_ID); if (currentMapName != null) { currentMap.setName(currentMapName, currentMapNameObject.GetString(LNG_CODE_ID)); } } } } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONObject currentMapBoundingBox = currentPackageObject.GetJSONObject(BBOX_ID); if (currentMapBoundingBox != null) { currentMap.setBbLatMax(currentMapBoundingBox.GetDouble(LAT_MAX_ID)); currentMap.setBbLatMin(currentMapBoundingBox.GetDouble(LAT_MIN_ID)); currentMap.setBbLongMax(currentMapBoundingBox.GetDouble(LONG_MAX_ID)); currentMap.setBbLongMin(currentMapBoundingBox.GetDouble(LONG_MIN_ID)); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSkmFileSize(currentPackageObject.GetLong(SKM_SIZE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSkmFilePath(currentPackageObject.GetString(FILE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setZipFilePath(currentPackageObject.GetString(NB_ZIP_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setUnzippedFileSize(currentPackageObject.GetLong(UNZIP_SIZE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { JSONObject currentMapTXGDetails = currentPackageObject.GetJSONObject(TEXTURE_ID); if (currentMapTXGDetails != null) { currentMap.setTXGFilePath(currentMapTXGDetails.GetString(TEXTURES_BIG_FILE_ID)); currentMap.setTXGFileSize(currentMapTXGDetails.GetLong(SIZE_BIG_FILE_ID)); } } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } try { currentMap.setSkmAndZipFilesSize(currentPackageObject.GetLong(SIZE_ID)); } catch (JSONException ex) { SKLogging.WriteLog(TAG, ex.Message, SKLogging.LogDebug); } if ((currentMap.Code != null) && (currentMap.getSubType() != null)) { removeNullValuesIfExist(currentMap); maps.Add(currentMap); } } } }