Ejemplo n.º 1
0
        public GoogleLocationHistoryItems ReadJsonAndWriteToCache(String jsonPath, String userName, bool returnGoogleLocationHistoryItems)
        {
            GoogleLocationHistoryDatabaseCache googleLocationDatabaseCache = new GoogleLocationHistoryDatabaseCache(dbTools);

            googleLocationDatabaseCache.WriteLocationHistorySource(userName, jsonPath);

            GoogleLocationHistoryItems googleLocationHistory = null;

            if (returnGoogleLocationHistoryItems)
            {
                googleLocationHistory = new GoogleLocationHistoryItems(userName);
            }


            int locationsFoundCount = 0;
            var sqlTransactionBatch = googleLocationDatabaseCache.TransactionBegin();

            var dinamic = new DinamicStreamJsonParser()
            {
                PropertyToType = new Dictionary <string, Type>()
                {
                    { "locations", Type.GetType(Type.GetType("GoogleLocationHistory.GoogleJsonLocations").AssemblyQualifiedName) },
                    { "activity", Type.GetType(Type.GetType("GoogleLocationHistory.GoogleJsonActivity").AssemblyQualifiedName) },
                },
                ObjectFoundCallback = (object obj, long readPosition, long fileLength) =>
                {
                    if (obj.GetType() == typeof(GoogleJsonLocations))
                    {
                        locationsFoundCount++;
                        if (locationsFoundCount % 5000 == 0)
                        {
                            googleLocationDatabaseCache.TransactionCommit(sqlTransactionBatch);
                            sqlTransactionBatch = googleLocationDatabaseCache.TransactionBegin();
                        }
                        if (returnGoogleLocationHistoryItems)
                        {
                            googleLocationHistory.Add((GoogleJsonLocations)obj);
                        }

                        googleLocationDatabaseCache.WriteLocationHistory(userName, (GoogleJsonLocations)obj);

                        LocationFound?.Invoke(this, EventArgs.Empty);
                        LocationFoundParam?.Invoke(this, locationsFoundCount, readPosition, fileLength);
                    }
                },
                NewTypeFoundCallback = (object obj, string name) => {
                    Logger.Debug($"Found object {obj} with name {name}");
                },
                StreamReader = new StreamReader(jsonPath, System.Text.Encoding.UTF8, true, 1000),
            };

            dinamic.Parse();

            googleLocationDatabaseCache.TransactionCommit(sqlTransactionBatch);

            return(googleLocationHistory);
        }
Ejemplo n.º 2
0
        public void ReadJsonAndWriteToCache(String filePath, String userName)
        {
            username = userName;

            googleLocationDatabaseCache = new GoogleLocationHistoryDatabaseCache(dbTools);
            googleLocationDatabaseCache.WriteLocationHistorySource(userName, filePath); //Need check exist

            TextReader reader = File.OpenText(filePath);
            KmlFile    file   = KmlFile.Load(reader);

            if (file == null)
            {
                return;
            }

            // It's good practice for the root element of the file to be a Kml element
            if (file.Root is Kml kml)
            {
                ExtractPlacemarks(kml.Feature);
            }
        }