public static IEnumerable ImportKml(
        SqlString kml,
        SqlBoolean makeValid)
    {
        if (kml == null || string.IsNullOrEmpty(kml.Value))
        {
            return(new Collection <GeographyContext>());
        }

        Collection <GeographyContext> geographies = new Collection <GeographyContext>();

        Microsoft.SqlServer.SpatialToolbox.KMLProcessor.KMLProcessor parser =
            new Microsoft.SqlServer.SpatialToolbox.KMLProcessor.KMLProcessor(kml.Value.Trim());

        foreach (Geography p in parser.Geographies)
        {
            GeographyContext ge = new GeographyContext();
            ge.Id      = p.Id;
            ge.Context = p.Context;
            ge.Shape   = p.ToSqlGeography(makeValid.Value);

            geographies.Add(ge);
        }

        return(geographies);
    }
    /// <summary>
    /// This method is a helper method for the TVF function ImportKml. A Sql Server uses it to decode a row
    /// returned by the ImportKml function.
    /// </summary>
    /// <param name="rowData">A row returned by the ImportKml function</param>
    /// <param name="Id">Id extracted from a rowData</param>
    /// <param name="Context">Context extracted from a rowData</param>
    /// <param name="Shape">Shape extracted from a rowData</param>
    public static void DecodeGeographyContext(
        object rowData,
        out SqlString Id,
        out SqlString Context,
        out SqlGeography Shape)
    {
        GeographyContext data = rowData as GeographyContext;

        Id      = data.Id;
        Context = data.Context;
        Shape   = data.Shape;
    }
Esempio n. 3
0
 public CityController(ILogger <CityController> logger, GeographyContext context)
 {
     _geographyContext = context;
     _logger           = logger;
 }
Esempio n. 4
0
 public StatesController(GeographyContext context)
 {
     _context = context;
     _context.Database.EnsureCreated();
 }
 public TimezoneController(ILogger <TimezoneController> logger, GeographyContext context)
 {
     _geographyContext = context;
     _logger           = logger;
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a repository with acces to the database.
 /// </summary>
 /// <param name="context">Context to use.</param>
 public CountryRepository(GeographyContext context)
 {
     this.context = context;
 }
 /// <summary>
 /// Creates a repository with acces to the database.
 /// </summary>
 /// <param name="context">Context to use.</param>
 public ContinentRepository(GeographyContext context)
 {
     this.context = context;
 }
 public GeographyController(GeographyContext context)
 {
     _context = context;
 }
        public static void Initialize(this GeographyContext context)
        {
            context.Database.Migrate();

            if (!context.Countries.Any())
            {
                using (var reader = new StreamReader("InitialiseDB/Countries.csv"))
                    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                    {
                        var records = csv.GetRecords <Country>();

                        foreach (Country country in records)
                        {
                            context.Countries.Add(country);
                        }
                    }


                context.SaveChanges();
            }

            if (!context.Cities.Any())
            {
                using (var reader = new StreamReader("InitialiseDB/Cities.csv"))
                    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                    {
                        csv.Configuration.RegisterClassMap <CityMap>();
                        var records = csv.GetRecords <City>();

                        foreach (City city in records)
                        {
                            context.Cities.Add(city);
                        }
                    }

                context.SaveChanges();
            }

            if (!context.Timezones.Any())
            {
                using (var reader = new StreamReader("InitialiseDB/Timezones.csv"))
                    using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                    {
                        try
                        {
                            var records = csv.GetRecords <Timezone>();

                            foreach (Timezone timezone in records)
                            {
                                context.Timezones.Add(timezone);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }

                context.SaveChanges();
            }
        }