Пример #1
0
        public void ParseCityRecord()
        {
            const string recordString = "00624,PENUELAS,PR,18.058333,66.721944,PENUELAS";

            var cr = new CityRecord(recordString);
            Assert.AreEqual("00624", cr.Zip);
            Assert.AreEqual("PENUELAS", cr.City);
            Assert.AreEqual("PR", cr.State);
            Assert.AreEqual(18.058333, cr.Latitude);
            Assert.AreEqual(-66.721944, cr.Longitude);
            Assert.AreEqual("PENUELAS", cr.County);
        }
Пример #2
0
        public void ParseCityRecord()
        {
            const string recordString = "00624,PENUELAS,PR,18.058333,66.721944,PENUELAS";

            var cr = new CityRecord(recordString);

            Assert.AreEqual("00624", cr.Zip);
            Assert.AreEqual("PENUELAS", cr.City);
            Assert.AreEqual("PR", cr.State);
            Assert.AreEqual(18.058333, cr.Latitude);
            Assert.AreEqual(-66.721944, cr.Longitude);
            Assert.AreEqual("PENUELAS", cr.County);
        }
Пример #3
0
        private void InsertCity(CityRecord city)
        {
            if (city == null)
                return; //not sure when this gets hit

            lock (_pending)
            {
                if (_executing >= ConcurrencyMax)
                {

                    _pending.Enqueue(city);
                    return;
                }
            }

            var insert = TableOperation.InsertOrReplace(city);
            _table.BeginExecute(insert, InsertComplete, _table);
            lock (_pending)
            {
                _executing++;
            }
        }
Пример #4
0
        private void InsertCity(CityRecord city)
        {
            if (city == null)
            {
                return; //not sure when this gets hit
            }
            lock (_pending)
            {
                if (_executing >= ConcurrencyMax)
                {
                    _pending.Enqueue(city);
                    return;
                }
            }

            var insert = TableOperation.InsertOrReplace(city);

            _table.BeginExecute(insert, InsertComplete, _table);
            lock (_pending)
            {
                _executing++;
            }
        }
Пример #5
0
        public ActionResult Upload()
        {
            foreach (string file in Request.Files)
            {
                var hpf = Request.Files[file];
                if (hpf == null)
                    continue;

                using (var sr = new StreamReader(hpf.InputStream))
                {
                    var batch = new List<CityRecord>();
                    var db = new GeocodeDb(WebConfigurationManager.AppSettings["GeocodeDbConnectionString"]);

                    while (!sr.EndOfStream)
                    {
                        var line = sr.ReadLine();
                        var city = new CityRecord(line);
                        batch.Add(city);

                        if (batch.Count == 100)
                        {
                            db.InsertCities(batch);
                            batch.Clear();
                        }
                    }

                    if (batch.Count > 0)
                    {
                        db.InsertCities(batch);
                    }
                }

            }

            return RedirectToAction("Index");
        }