Esempio n. 1
0
        static void Main(string[] args)
        {
            var culture = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentCulture = culture;

            //var parser = new KmlParserV2();
            var parser = new KmlParser();
            var layer = parser.ReadKmlFile();
            List<string> errors = parser.ListErrors(layer);

            if (!errors.Any())
            {
                Console.WriteLine(" Ingrese el regionId (numeros)");
                int regionId = Convert.ToInt32(Console.ReadLine());
                layer.RegionId = regionId;

                Console.Write("\n Archivo leido correctamente, no contiene erorres" + "\n");
                Console.WriteLine(" Importando archivos a la base de datos...");
                LayerRepository la = new LayerRepository(ConfigurationManager.ConnectionStrings["Earthwatchers_DSN"].ConnectionString);
                la.SaveLayerFull(layer);

                Console.WriteLine(" Archivos importados correctamente");
                Console.WriteLine(" Desea intersectar las lands con los poligonos? (( Y / N ))");

                var intersects = Console.ReadLine();
                if (intersects == "Y" || intersects == "y")
                {
                    LandRepository landrepo = new LandRepository(ConfigurationManager.ConnectionStrings["Earthwatchers_DSN"].ConnectionString);

                    var layerId = layer.Id;

                    Console.WriteLine(" Intersectando Lands con zona, Hora de inicio: " + DateTime.Now);

                    bool succeed = landrepo.IntersectLandsWithZone(regionId, layerId);
                    if (succeed)
                    {
                        Console.WriteLine(" Lands Actualizadas Correctamente");
                        Console.WriteLine(" Hora de fin: " + DateTime.Now);

                    }
                    else
                    {
                        Console.WriteLine(" Error al actualizar las lands");
                        Console.WriteLine(" Hora de fin: " + DateTime.Now);
                    }
                }

            }
            else
            {
                Console.WriteLine("\n Archivo leido correctamente, contiene erorres en los siguientes campos: " + "\n");

                foreach (string er in errors)
                {
                    Console.WriteLine(" " + er.ToString());
                }
                Console.WriteLine("\n Solucione los problemas pendientes y vuelva a cargar el archivo");
                Console.ReadLine();
            }
        }
        public LandMini AssignLandToEarthwatcher(int earthwatcherId, string basecamp, string geohexKey)
        {
            var land = GetFreeLand(basecamp, "'" + geohexKey + "'");

            if (land != null)
            {
                var landRepository = new LandRepository(connection.ConnectionString);
                landRepository.AssignLandToEarthwatcher(land.GeohexKey, earthwatcherId);
            }
            return(land);
        }
        public LandMini AssignLandToEarthwatcher(int earthwatcherId, string geohexKey)
        {
            var earthwatcher = GetEarthwatcher(earthwatcherId);

            var land = GetFreeLandByEarthwatcherIdAndPlayingRegion(earthwatcherId, earthwatcher.PlayingRegion);
            if (land != null)
            {
                var landRepository = new LandRepository(connection.ConnectionString);
                landRepository.AssignLandToEarthwatcher(land.GeohexKey, earthwatcherId, earthwatcher.PlayingRegion);
            }
            return land;
        }
 public HttpResponseMessage Delete(int id, HttpRequestMessage<int> request)
 {
     if (id != 0)
     {
         basecampRepository.Delete(id);
         LayerRepository layerRepository = new LayerRepository(ConfigurationManager.ConnectionStrings["EarthwatchersConnection"].ConnectionString);
         layerRepository.DeleteZone(id);
         LandRepository landRepository = new LandRepository(ConfigurationManager.ConnectionStrings["EarthwatchersConnection"].ConnectionString);
         landRepository.LoadLandBasecamp();
         return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
     }
     return new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound };
 }
Esempio n. 5
0
        public LandMini AssignLandToEarthwatcher(int earthwatcherId, string geohexKey)
        {
            var earthwatcher = GetEarthwatcher(earthwatcherId);

            var land = GetFreeLandByEarthwatcherIdAndPlayingRegion(earthwatcherId, earthwatcher.PlayingRegion);

            if (land != null)
            {
                var landRepository = new LandRepository(connection.ConnectionString);
                landRepository.AssignLandToEarthwatcher(land.GeohexKey, earthwatcherId, earthwatcher.PlayingRegion);
            }
            return(land);
        }
Esempio n. 6
0
        /// <summary>
        /// Devuelve todos los datos de un earthwatcher, inclusive con su listado de lands, dependiendo del parametro getLands
        /// </summary>
        /// <param name="name"></param>
        /// <param name="getLands"></param>
        /// <returns></returns>
        public Earthwatcher GetEarthwatcher(string name, bool getLands)
        {
            try
            {
                connection.Open();
                //var earthwatchers = connection.Query<Earthwatcher>(string.Format("EXEC Earthwatcher_GetEarthwatcherByName {0}", name));
                var earthwatchers = connection.Query <Earthwatcher>("select Id, EarthwatcherGuid as Guid, Name, Role, PasswordPrefix, hashedpassword, country, avatar, FullName, email, Telephone, IsPowerUser, Language, Region, NotifyMe, NickName, CreatedDate, ApiEwId, AllowAutoShare, PlayingRegion, PlayingCountry from Earthwatcher where Name = @Name", new { Name = name });
                connection.Close();

                var earthwatcher = earthwatchers.FirstOrDefault();
                if (earthwatcher != null && getLands)
                {
                    //Traigo las lands del usuario
                    earthwatcher.Lands = GetEarthwatcherLands(earthwatcher.Name, earthwatcher.PlayingRegion);

                    //Si no tiene ninguna, para que no pinche le asigno una
                    if (earthwatcher.Lands.Count == 0)
                    {
                        var newLand = AssignLandToEarthwatcher(earthwatcher.Id, string.Empty);
                        if (newLand != null)
                        {
                            var  landRepository = new LandRepository(connection.ConnectionString);
                            Land newLandObj     = landRepository.GetLandByGeoHexKey(newLand.GeohexKey);
                            if (newLandObj != null)
                            {
                                earthwatcher.Lands.Add(newLandObj);
                            }
                        }
                    }
                }
                return(earthwatcher);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public LandMini AssignLandToEarthwatcher(int earthwatcherId, string basecamp, string geohexKey) 
 {
     var land = GetFreeLand(basecamp, "'" + geohexKey + "'");
     if (land != null)
     {
         var landRepository = new LandRepository(connection.ConnectionString);
         landRepository.AssignLandToEarthwatcher(land.GeohexKey, earthwatcherId);
     }
     return land;
 }
 private List<Land> GetEarthwatcherLands(string name)
 {
     var landRepository = new LandRepository(connection.ConnectionString);
     return landRepository.GetLandByEarthwatcherName(name);
 }
        /// <summary>
        /// Devuelve todos los datos de un earthwatcher, inclusive con su listado de lands, dependiendo del parametro getLands
        /// </summary>
        /// <param name="name"></param>
        /// <param name="getLands"></param>
        /// <returns></returns>
        public Earthwatcher GetEarthwatcher(string name, bool getLands)
        {
            try
            {
                connection.Open();
                //var earthwatchers = connection.Query<Earthwatcher>(string.Format("EXEC Earthwatcher_GetEarthwatcherByName {0}", name));
                var earthwatchers = connection.Query<Earthwatcher>("select Id, EarthwatcherGuid as Guid, Name, Role, PasswordPrefix, hashedpassword, country, avatar, FullName, email, Telephone, IsPowerUser, Language, Region, NotifyMe, NickName, CreatedDate, ApiEwId, AllowAutoShare, PlayingRegion, PlayingCountry from Earthwatcher where Name = @Name", new { Name = name });
                connection.Close();

                var earthwatcher = earthwatchers.FirstOrDefault();
                if (earthwatcher != null && getLands)
                {
                    //Traigo las lands del usuario
                    earthwatcher.Lands = GetEarthwatcherLands(earthwatcher.Name, earthwatcher.PlayingRegion);

                    //Si no tiene ninguna, para que no pinche le asigno una
                    if (earthwatcher.Lands.Count == 0)
                    {
                        var newLand = AssignLandToEarthwatcher(earthwatcher.Id, string.Empty);
                        if(newLand != null)
                        {
                            var landRepository = new LandRepository(connection.ConnectionString);
                            Land newLandObj = landRepository.GetLandByGeoHexKey(newLand.GeohexKey);
                            if (newLandObj != null)
                            {
                                earthwatcher.Lands.Add(newLandObj);
                            }
                        }
                    }
                }
                return earthwatcher;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List<string> ReadKmlFile(int id)
        {
            var errors = new List<string>();
            var path = ConfigurationManager.AppSettings.Get("kml.fincas.path");
            if (Directory.GetFiles(path).Count() > 1)
            {
                errors.Add("Se encontró mas de un archivo kml a procesar en la carpeta, estos archivos ya fueron eliminados. Intente nuevamente la operación");

                for (var i = 0; i <= Directory.GetFiles(path).Count(); i++ )
                {
                    var filename = Directory.GetFiles(path).FirstOrDefault();
                    var archivePath = ConfigurationManager.AppSettings.Get("kml.fincas.archive.path");
                    var archiveName = new FileInfo(filename).Name.Replace(".kml", string.Format("{0}.{1}.{2}.kml", "archive", DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss")));
                    if (!Directory.Exists(archivePath))
                        Directory.CreateDirectory(archivePath);
                    File.Move(filename, Path.Combine(archivePath, archiveName));
                }
            }
            else
            {
                BasecampRepository basecampRepo = new BasecampRepository(ConfigurationManager.ConnectionStrings["EarthwatchersConnection"].ConnectionString);
                var fincaRegionId = (basecampRepo.GetById(id)).RegionId;
                var FincasLayerName = "FincasLayer" + fincaRegionId;
                var filename = Directory.GetFiles(path).FirstOrDefault();
                XDocument xDoc = XDocument.Load(filename);
                XNamespace ns = "http://www.opengis.net/kml/2.2";

                var doc = xDoc.Descendants(ns + "Document").ToList();
                Layer layer = new Layer();
                layer.Name = FincasLayerName;
                layer.Zones = doc.Elements(ns + "Folder").Select(ze =>
                       new Zone(ze.Element(ns + "name").Value,
                                  ze.Descendants(ns + "Placemark").Select(pm =>
                                        new Polygon()
                                        {
                                            Name = pm.Element(ns + "name").Value,
                                            Locations = pm.Descendants(ns + "coordinates").First().Value.Trim()
                                                                            .Replace("\n", "")
                                                                            .Replace("\t", "")
                                                                            .Split(' ')
                                                                            .Select(x => new Location(ParseLatitude(x), ParseLongitude(x)))
                                                                            .ToList(),
                                            PolygonGeom = ParsePolygon(pm.Descendants(ns + "coordinates").First().Value.Trim()
                                                                           .Replace("\n", " ")
                                                                           .Replace("\t", " ")
                                                                           .Replace(",0 ", "|")
                                                                           .Replace(",", " ")
                                                                           .Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries))
                                        }).ToList(),
                                    ze.Element(ns + "description").Value,
                                 id.ToString() //Agrega el basecampId a la zona
                                    )).ToList();

                errors = KmlParserBasecamp.ListErrors(layer);

                if (errors.Count == 0)
                {
                    //Save finca
                    LayerRepository la = new LayerRepository(ConfigurationManager.ConnectionStrings["EarthwatchersConnection"].ConnectionString);
                    la.SaveFincaFull(layer);
                    LandRepository landRepo = new LandRepository(ConfigurationManager.ConnectionStrings["EarthwatchersConnection"].ConnectionString);
                    landRepo.LoadLandBasecamp(fincaRegionId);
                }

                //Una vez finalizado mover a la carpeta Achieved
                var archivePath = ConfigurationManager.AppSettings.Get("kml.fincas.archive.path");
                var archiveName = new FileInfo(filename).Name.Replace(".kml", string.Format("{0}.{1}.{2}.kml", "archive", DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss")));
                if (!Directory.Exists(archivePath))
                    Directory.CreateDirectory(archivePath);
                File.Move(filename, Path.Combine(archivePath, archiveName));
            }

            return errors;
        }
        private List <Land> GetEarthwatcherLands(string name)
        {
            var landRepository = new LandRepository(connection.ConnectionString);

            return(landRepository.GetLandByEarthwatcherName(name));
        }