예제 #1
0
        private void CollectData(string colectorName)
        {
            try
            {
                EarthquakeCollector collector = null;
                Collectors.TryGetValue(colectorName, out collector);
                var earthquakeFromColector = FilterDuplicate(collector.Collect());

                foreach (Earthquake earthquake in earthquakeFromColector)
                {
                    if (!EarthquakeExist(earthquake))
                    {
                        if (earthquake.MagnitudeType != null && earthquake.MagnitudeType.Id != Guid.Empty)
                        {
                            earthquake.MagnitudeType = Repository.DbContext.MagtitudesTypes.Where(p => p.Id == earthquake.MagnitudeType.Id).FirstOrDefault();
                        }

                        if (earthquake.Source != null && earthquake.Source.Id != Guid.Empty)
                        {
                            earthquake.Source = Repository.DbContext.Sources.Where(p => p.Id == earthquake.Source.Id).FirstOrDefault();
                        }

                        if (earthquake.Place != null && earthquake.Place.Id != Guid.Empty)
                        {
                            earthquake.Place = Repository.DbContext.Places.Where(p => p.Id == earthquake.Place.Id).FirstOrDefault();
                        }

                        Repository.DbContext.Earthquakes.Add(earthquake);
                    }
                }

                Repository.Save();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbevex)
            {
                ExceptionUtility.Error(dbevex, this.GetType());
            }

            catch (Exception ex)
            {
                ExceptionUtility.Error(ex, this.GetType());
            }
        }