Esempio n. 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();
        }
Esempio n. 2
0
        public async Task <File> HentFil(string id)
        {
            var metadata = new Reference <RavenJObject>();

            var file = new File
            {
                Content     = await ravenFilesStore.Session.DownloadAsync("/files/" + id, metadata),
                FileName    = metadata.Value.Value <string>("filename"),
                ContentType = metadata.Value.Value <string>("contentType")
            };


            return(file);
        }
Esempio n. 3
0
        public async Task <string> LagreFil(File file)
        {
            var metadata = new RavenJObject
            {
                { "filename", file.FileName },
                { "contentType", file.ContentType }
            };

            ravenFilesStore.Session.RegisterUpload("/files/" + file.Id, file.Content, metadata);

            await ravenFilesStore.Session.SaveChangesAsync();

            return(file.Id);
        }
        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");
        }
        public async Task <string> UploadGridDelivery()
        {
            Authorize("Dataleverandør");

            var mapType = RequestForm("kartType");
            var files   = HttpFormFile.GetFormFiles(Request.Form.Files);

            var delivery = new GridDelivery
            {
                Name        = RequestForm("navn"),
                Description = RequestForm("beskrivelse"),
                Code        = new Code
                {
                    Value    = RequestForm("kode"),
                    Registry = RequestForm("koderegister"),
                    Version  = RequestForm("kodeversjon")
                },
                Owner = new Contact
                {
                    Company       = RequestForm("firmanavn"),
                    ContactPerson = RequestForm("kontaktperson"),
                    Email         = RequestForm("ownerEmail"),
                    Homesite      = RequestForm("hjemmeside"),
                    Phone         = RequestForm("telefon")
                },
                Established = DateTime.Parse(RequestForm("etablertDato"))
            };

            delivery.MapGridTypeNumber(RequestForm("ssbType"));
            delivery.MapAreaTypeNumber(RequestForm("aoType"));
            delivery.DocumentDescription = RequestForm("dokumentBeskrivelse");
            delivery.Username            = RequestForm("username");

            try
            {
                foreach (var file in files.Values)
                {
                    var document = new Nin.Types.RavenDb.Document {
                        FileName = file.Filename
                    };
                    delivery.Documents.Add(document);

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

                arkiv.LagreRutenettleveranse(delivery);
                arkiv.SaveChanges();
            }
            catch
            {
                arkiv.DiscardChanges();
                throw;
            }

            return("OK");
        }