//Download and save file locally public Stream LoadFile(Stream input) { string body = new StreamReader(input).ReadToEnd(); NameValueCollection _nvc = HttpUtility.ParseQueryString(body); string _fileName = _nvc["FileName"]; string _client_id = _nvc["ClientId"]; string _show_id = _nvc["ShowId"]; string _accessKey = @_nvc["AccessKey"]; string _secretKey = @_nvc["SecretKey"]; string _bucketName = @_nvc["BucketName"]; string s3DirectoryName = _client_id + @"/" + _show_id; string _localPath = "h://dxf_uploads//" + _client_id + " // " + _show_id + "//" + _fileName; string fileNameInS3 = _client_id + @"/" + _show_id + @"/dxf/" + _fileName; AmazonS3Transfer amazonS3Transfer = new AmazonS3Transfer(); bool loadStatus = amazonS3Transfer.getMyFileFromS3(_bucketName, fileNameInS3, _localPath, _accessKey, _secretKey); Dictionary <string, string> status = new Dictionary <string, string>(); if (loadStatus == true) { status.Add("status_code", "1"); } else { status.Add("status_code", "0"); } string result = JsonConvert.SerializeObject(status); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return(new MemoryStream(Encoding.UTF8.GetBytes(result))); }
//Get Jpeg from selected Layers public Stream GetPictures(Stream input) { string body = new StreamReader(input).ReadToEnd(); NameValueCollection _nvc = HttpUtility.ParseQueryString(body); string _boothOutlineLayer = _nvc["BoothOutline"]; string _boothNumberLayer = _nvc["BoothNumber"]; string _fileName = _nvc["FileName"]; string _client_id = _nvc["ClientId"]; string _show_id = _nvc["ShowId"]; string _accessKey = @_nvc["AccessKey"]; string _secretKey = @_nvc["SecretKey"]; string _bucketName = @_nvc["BucketName"]; DxfModel _model = ReadDxf("h://dxf_uploads//" + _client_id + " // " + _show_id + "//" + _fileName); foreach (DxfLayer _layer in _model.Layers) { if (_layer.Name != _boothOutlineLayer && _layer.Name != _boothNumberLayer) { _layer.Enabled = false; } } string outfile = Path.GetFileNameWithoutExtension(Path.GetFullPath(_fileName)); Stream stream; GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.BlackBackgroundCorrectForBackColor); Size maxSize = new Size(750, 750); Bitmap bitmap = ImageExporter.CreateAutoSizedBitmap( _model, graphics, Matrix4D.Identity, System.Drawing.Color.Black, maxSize ); string fileNameS3 = outfile + ".jpg"; string filePath = "h://dxf_uploads//" + _client_id + " // " + _show_id + "//" + fileNameS3; stream = File.Create(filePath); ImageExporter.EncodeImageToJpeg(bitmap, stream); string _subDirectory = _client_id + @"/" + _show_id + @"/dxf"; AmazonS3Transfer amazonS3Transfer = new AmazonS3Transfer(); bool uploadStatus = amazonS3Transfer.sendMyFileToS3(stream, _bucketName, _subDirectory, fileNameS3, _accessKey, _secretKey); Dictionary <string, string> status = new Dictionary <string, string>(); if (uploadStatus == true) { status.Add("status_code", "1"); } else { status.Add("status_code", "0"); } string result = JsonConvert.SerializeObject(status); WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"; return(new MemoryStream(Encoding.UTF8.GetBytes(result))); }