Beispiel #1
0
        public void ParseAdminAreaMapTest_ParseOk()
        {
            XDocument areaLayerXml = TestXml.ReadXDocument(@"Data\AreaLayer\AdministrativtOmraadeKartTest.xml");

            var areaLayer = AreaLayerImpl.FromXml(areaLayerXml);

            Assert.NotNull(areaLayer);
        }
        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");
        }