예제 #1
0
        public async Task LastOppDataleveranse(DataleveranseXmlGreier dataDeliveryCore, IDataFile metadata, DataFiles files,
                                               string username)
        {
            if (metadata == null)
            {
                throw new Exception("Kan ikke lagre en tom leveranse.");
            }

            var dataDeliveryXml = metadata.ReadXml();

            dataDeliveryCore.ValidateDataDelivery(dataDeliveryXml);
            var dataleveranse = DataleveranseXmlGreier.ParseDataDelivery(dataDeliveryXml);

            files.CheckDocuments(dataleveranse);
            DataleveranseXmlGreier.ValidateDataDeliveryContent(dataleveranse);

            OvertaForForrigeVersjon(dataleveranse);
            ImporterDataleveranse(dataleveranse, username);

            var metadataFile = new File
            {
                Id          = dataleveranse.Id.Replace("DataDeliveries/", ""),
                FileName    = metadata.Filename,
                ContentType = metadata.ContentType,
                Content     = metadata.OpenReadStream()
            };

            await LagreFil(metadataFile);

            foreach (var file in files.Values)
            {
                var fileName = file.Filename;
                var document = dataleveranse.Metadata.FindDocument(fileName);
                if (document == null)
                {
                    throw new DataDeliveryParseException("Finner ingen referanse i datafilen til vedlegg '" + fileName +
                                                         "'.");
                }

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

            SaveChanges();
        }
        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");
        }