Ejemplo n.º 1
0
        public void updateMapResource(MapDownloadResource mapResource)
        {
            ContentValues values = new ContentValues();

            values.Put(STATE, mapResource.DownloadState);
            values.Put(NO_DOWNLOADED_BYTES, mapResource.NoDownloadedBytes);
            values.Put(SKM_FILE_PATH, mapResource.getSKMFilePath());
            values.Put(SKM_FILE_SIZE, mapResource.getSkmFileSize());
            values.Put(TXG_FILE_PATH, mapResource.getTXGFilePath());
            values.Put(TXG_FILE_SIZE, mapResource.getTXGFileSize());
            values.Put(ZIP_FILE_PATH, mapResource.getZipFilePath());
            values.Put(SKM_AND_ZIP_FILES_SIZE, mapResource.getSkmAndZipFilesSize());
            values.Put(UNZIPPED_FILE_SIZE, mapResource.getUnzippedFileSize());
            values.Put(DOWNLOAD_PATH, mapResource.DownloadPath);
            try
            {
                resourcesDAO.getDatabase().BeginTransaction();
                resourcesDAO.getDatabase().Update(MAPS_TABLE, values, CODE + "=?", new String[] { mapResource.Code });
                resourcesDAO.getDatabase().SetTransactionSuccessful();
            }
            catch (SQLException e)
            {
                SKLogging.WriteLog(TAG, "SQL EXCEPTION SAVE MAP DATA " + e.Message, SKLogging.LogError);
            }
            finally
            {
                resourcesDAO.getDatabase().EndTransaction();
            }
        }
 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();
 }
 private void readCurrentMapTXGDetails(MapDownloadResource currentMap, JsonReader reader)
 {
     reader.BeginObject();
     while (reader.HasNext)
     {
         string key = reader.NextName();
         if (key != null)
         {
             if (key.Equals(TEXTURES_BIG_FILE_ID))
             {
                 currentMap.setTXGFilePath(reader.NextString());
             }
             else if (key.Equals(SIZE_BIG_FILE_ID))
             {
                 currentMap.setTXGFileSize(reader.NextLong());
             }
             else
             {
                 // for now, we skip the tags referring ZIP files details related to TXG files
                 reader.SkipValue();
             }
         }
     }
     reader.EndObject();
 }
        private void readCurrentMapNames(MapDownloadResource currentMap, JsonReader reader)
        {
            string currentMapName = null;

            reader.BeginObject();
            while (reader.HasNext)
            {
                string key = reader.NextName();
                if (key != null)
                {
                    if (key.Equals(TL_NAME_ID))
                    {
                        currentMapName = reader.NextString();
                    }
                    else if (key.Equals(LNG_CODE_ID))
                    {
                        if (currentMapName != null)
                        {
                            currentMap.setName(currentMapName, reader.NextString());
                        }
                    }
                }
            }
            reader.EndObject();
        }
Ejemplo n.º 5
0
 private void removeNullValuesIfExist(MapDownloadResource currentMap)
 {
     if (currentMap.ParentCode == null)
     {
         currentMap.ParentCode = ("");
     }
     if (currentMap.DownloadPath == null)
     {
         currentMap.DownloadPath = ("");
     }
     if (currentMap.getSKMFilePath() == null)
     {
         currentMap.setSkmFilePath("");
     }
     if (currentMap.getZipFilePath() == null)
     {
         currentMap.setZipFilePath("");
     }
     if (currentMap.getTXGFilePath() == null)
     {
         currentMap.setTXGFilePath("");
     }
 }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 /**
  * 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);
             }
         }
     }
 }
        private void readCurrentMapDetails(List <MapDownloadResource> maps, JsonReader reader)
        {
            MapDownloadResource currentMap = new MapDownloadResource();

            reader.BeginObject();
            while (reader.HasNext)
            {
                string key = reader.NextName();
                if (key != null)
                {
                    if (key.Equals(PACKAGE_CODE_ID))
                    {
                        currentMap.Code = reader.NextString();
                    }
                    else if (key.Equals(TYPE_ID))
                    {
                        currentMap.setSubType(getMapType(reader.NextInt()));
                    }
                    else if (key.Equals(LANGUAGES_ID))
                    {
                        reader.BeginArray();
                        while (reader.HasNext)
                        {
                            readCurrentMapNames(currentMap, reader);
                        }
                        reader.EndArray();
                    }
                    else if (key.Equals(BBOX_ID))
                    {
                        readCurrentMapBoundingBoxDetails(currentMap, reader);
                    }
                    else if (key.Equals(SKM_SIZE_ID))
                    {
                        currentMap.setSkmFileSize(reader.NextLong());
                    }
                    else if (key.Equals(FILE_ID))
                    {
                        currentMap.setSkmFilePath(reader.NextString());
                    }
                    else if (key.Equals(NB_ZIP_ID))
                    {
                        currentMap.setZipFilePath(reader.NextString());
                    }
                    else if (key.Equals(UNZIP_SIZE_ID))
                    {
                        currentMap.setUnzippedFileSize(reader.NextLong());
                    }
                    else if (key.Equals(TEXTURE_ID))
                    {
                        readCurrentMapTXGDetails(currentMap, reader);
                    }
                    else if (key.Equals(SIZE_ID))
                    {
                        currentMap.setSkmAndZipFilesSize(reader.NextLong());
                    }
                    else
                    {
                        // for now, we skip the elevation tag
                        reader.SkipValue();
                    }
                }
            }
            reader.EndObject();

            if ((currentMap.Code != null) && (currentMap.getSubType() != null))
            {
                removeNullValuesIfExist(currentMap);
                maps.Add(currentMap);
            }
        }