Beispiel #1
0
        public string TIFF([System.Web.Http.FromBody] UploadData uploadData)
        {
            MapExportItem exportItem = JsonConvert.DeserializeObject <MapExportItem>(uploadData.data);

            TIFFCreator tiffCreator = new TIFFCreator();
            Image       img         = tiffCreator.Create(exportItem);

            MemoryStream outStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outStream);

            zipStream.SetLevel(3);

            ZipEntry imageEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tiff"));

            imageEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(imageEntry);

            MemoryStream imageStream = new MemoryStream(imgToByteArray(img));

            byte[] buffer = new byte[4096];

            StreamUtils.Copy(imageStream, zipStream, buffer);

            imageStream.Close();
            zipStream.CloseEntry();

            ZipEntry worldFileEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tfw"));

            worldFileEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(worldFileEntry);
            MemoryStream worldFileStream = new MemoryStream(MapImageCreator.CreateWorldFile(exportItem));

            byte[] buffer2 = new byte[4096];
            StreamUtils.Copy(worldFileStream, zipStream, buffer2);

            worldFileStream.Close();
            zipStream.CloseEntry();

            zipStream.IsStreamOwner = false;    // False stops the Close also Closing the underlying stream.
            zipStream.Close();                  // Must finish the ZipOutputStream before using outputMemStream.

            outStream.Position = 0;
            outStream.ToArray();

            string[] fileInfo = byteArrayToFileInfo(outStream.ToArray(), "zip");
            if (exportItem.proxyUrl != "")
            {
                return(exportItem.proxyUrl + "/Temp/" + fileInfo[1]);
            }
            else
            {
                return(Request.Url.GetLeftPart(UriPartial.Authority) + "/Temp/" + fileInfo[1]);
            }
        }
        public ActionResult TIFF(string json)
        {
            MapExportItem exportItem = JsonConvert.DeserializeObject <MapExportItem>(json);

            TIFFCreator tiffCreator = new TIFFCreator();
            Image       img         = tiffCreator.Create(exportItem);

            MemoryStream outStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outStream);

            zipStream.SetLevel(3);

            ZipEntry imageEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tiff"));

            imageEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(imageEntry);

            MemoryStream imageStream = new MemoryStream(imgToByteArray(img));

            byte[] buffer = new byte[4096];

            StreamUtils.Copy(imageStream, zipStream, buffer);

            imageStream.Close();
            zipStream.CloseEntry();

            ZipEntry worldFileEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tfw"));

            worldFileEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(worldFileEntry);
            MemoryStream worldFileStream = new MemoryStream(MapImageCreator.CreateWorldFile(exportItem));

            byte[] buffer2 = new byte[4096];
            StreamUtils.Copy(worldFileStream, zipStream, buffer2);

            worldFileStream.Close();
            zipStream.CloseEntry();

            zipStream.IsStreamOwner = false;    // False stops the Close also Closing the underlying stream.
            zipStream.Close();                  // Must finish the ZipOutputStream before using outputMemStream.

            outStream.Position = 0;

            return(File(outStream.ToArray(), "application/octet-stream", "kartexport.zip"));
        }
Beispiel #3
0
        public string TIFF(string json)
        {
            _log.DebugFormat("Received json: {0}", json);

            // try to decode input string to see if it is base64 encoded
            try
            {
                byte[] decoded = Convert.FromBase64String(json);
                json = System.Text.Encoding.UTF8.GetString(decoded);
                _log.DebugFormat("json after decode: {0}", json);
            }
            catch (Exception e)
            {
                _log.DebugFormat("Could not decode base64. Will treat as non-base64 encoded: {0}", e.Message);
            }
            MapExportItem exportItem = JsonConvert.DeserializeObject <MapExportItem>(json);

            TIFFCreator tiffCreator = new TIFFCreator();
            Image       img         = tiffCreator.Create(exportItem);

            MemoryStream outStream = new MemoryStream();

            ZipOutputStream zipStream = new ZipOutputStream(outStream);

            zipStream.SetLevel(3);

            ZipEntry imageEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tiff"));

            imageEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(imageEntry);

            MemoryStream imageStream = new MemoryStream(imgToByteArray(img));

            byte[] buffer = new byte[4096];

            StreamUtils.Copy(imageStream, zipStream, buffer);

            imageStream.Close();
            zipStream.CloseEntry();

            ZipEntry worldFileEntry = new ZipEntry(ZipEntry.CleanName("kartexport.tfw"));

            worldFileEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(worldFileEntry);
            MemoryStream worldFileStream = new MemoryStream(MapImageCreator.CreateWorldFile(exportItem));

            byte[] buffer2 = new byte[4096];
            StreamUtils.Copy(worldFileStream, zipStream, buffer2);

            worldFileStream.Close();
            zipStream.CloseEntry();

            zipStream.IsStreamOwner = false;    // False stops the Close also Closing the underlying stream.
            zipStream.Close();                  // Must finish the ZipOutputStream before using outputMemStream.

            outStream.Position = 0;
            outStream.ToArray();

            string[] fileInfo = byteArrayToFileInfo(outStream.ToArray(), "zip");
            if (exportItem.proxyUrl != "")
            {
                return(exportItem.proxyUrl + "/Temp/" + fileInfo[1]);
            }
            else
            {
                return(Request.Url.GetLeftPart(UriPartial.Authority) + "/Temp/" + fileInfo[1]);
            }
        }