Beispiel #1
0
        public void BulkStoreMunicipalityPopulation()
        {
            var befolkningKommune =
                new AreaLayer("Befolkning", AreaType.Kommune)
            {
                Description = "Befolkning per kommune",
                Code        = new Code {
                    Value = "KA", Registry = "NiN", Version = "2.0"
                },
                Owner = new Contact {
                    Company = "Artsdatabanken"
                },
                Established = DateTime.Now
            };

            using (StreamReader municipalityPopulationFile = new StreamReader(@"C:\Artsdatabanken\SSB\Befolkning\BefolkningKommuner.csv",
                                                                              Encoding.GetEncoding("iso-8859-1")))
            {
                string line;
                while ((line = municipalityPopulationFile.ReadLine()) != null)
                {
                    var    number     = int.Parse(line.Substring(0, 4));
                    string population = line.Substring(line.IndexOf(';') + 1);

                    befolkningKommune.Items.Add(new AreaLayerItem {
                        Number = number, Value = population
                    });
                }
            }
            befolkningKommune.MinValue = "500";
            befolkningKommune.MaxValue = "100000";

            SqlServer.BulkStoreAreaLayer(befolkningKommune);
        }
Beispiel #2
0
        public void BulkStoreCountyPopulation()
        {
            AreaLayer countyPopulation =
                new AreaLayer("Befolkning", AreaType.Fylke)
            {
                Description = "Befolkning per fylke",
                Code        = new Code {
                    Value = "KA", Registry = "NiN", Version = "2.0"
                },
                Owner = new Contact {
                    Company = "Artsdatabanken"
                },
                Established = DateTime.Now
            };

            using (
                StreamReader countyPopulationFile =
                    new StreamReader(@"C:\Artsdatabanken\SSB\Befolkning\BefolkningFylker.csv",
                                     Encoding.GetEncoding("iso-8859-1")))
            {
                string line;
                while ((line = countyPopulationFile.ReadLine()) != null)
                {
                    int    number     = int.Parse(line.Substring(0, 2));
                    string population = line.Substring(line.IndexOf(';') + 1);

                    countyPopulation.Items.Add(new AreaLayerItem {
                        Number = number, Value = population
                    });
                }
            }
            countyPopulation.MinValue = "70000";
            countyPopulation.MaxValue = "650000";

            SqlServer.BulkStoreAreaLayer(countyPopulation);
        }
        public async Task <string> UploadGrid()
        {
            Authorize("Dataleverandør");

            IFormFile    grid2 = Request.Form.Files.GetFile("grid");
            HttpFormFile grid  = new HttpFormFile(grid2);
            DataFiles    files = HttpFormFile.GetFormFiles(Request.Form.Files);

            var gridXml = grid.ReadXml();

            dataleveranseXmlGreier.ValidateGrid(gridXml);
            try
            {
                var gridFileDocId = Guid.NewGuid();
                var gridFile      = new File
                {
                    Id          = gridFileDocId.ToString(),
                    FileName    = grid.Filename,
                    ContentType = grid.ContentType,
                    Content     = grid.OpenReadStream()
                };
                await arkiv.LagreFil(gridFile);

                Collection <Nin.Types.MsSql.Document> documents;
                if (gridXml.Root.Name.LocalName.Equals("AdministrativtOmraadeKart"))
                {
                    AreaLayer areaLayer = AreaLayerImpl.FromXml(gridXml);
                    files.CheckDocuments(areaLayer.Documents);
                    areaLayer.DocGuid = gridFileDocId;
                    documents         = areaLayer.Documents;
                    SqlServer.BulkStoreAreaLayer(areaLayer);
                }
                else
                {
                    var gridLayer = GridLayerImpl.FromXml(gridXml);

                    files.CheckDocuments(gridLayer.Documents);
                    gridLayer.DocGuid = gridFileDocId;
                    documents         = gridLayer.Documents;
                    SqlServer.BulkStoreGridLayer(gridLayer);
                }

                foreach (var file in files.Values)
                {
                    var fileName = file.Filename;
                    var document = FindDocument(documents, fileName);

                    var docFile = new File
                    {
                        Id          = document.Guid.ToString(),
                        FileName    = fileName,
                        ContentType = file.ContentType,
                        Content     = file.OpenReadStream()
                    };
                    await arkiv.LagreFil(docFile);
                }
            }
            catch
            {
                arkiv.DiscardChanges();
                throw;
            }

            return("OK");
        }