Ejemplo n.º 1
0
        public HttpResponseMessage Get(string directory, string btsId, string name)
        {
            var response    = new HttpResponseMessage(HttpStatusCode.OK);
            var dwgService  = new BtsDwgService(directory, btsId);
            var data        = dwgService.GetFile(name);
            var ext         = Path.GetExtension(name);
            var contentType = ext?.ToLower().QueryContentType();

            response.Content = new ByteArrayContent(data);
            response.Content.Headers.Add("Content-Disposition", "attachment; filename*=UTF-8''" + name.UrlEncode());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);

            return(response);
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> Upload()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            Func <HttpRequestMessage, string, string> getQuerystring = (request, key) =>
            {
                var queryStrings = request.GetQueryNameValuePairs();
                if (queryStrings == null)
                {
                    return(null);
                }

                var match = queryStrings.FirstOrDefault(kv => string.Compare(kv.Key, key, StringComparison.OrdinalIgnoreCase) == 0);
                return(string.IsNullOrEmpty(match.Value) ? null : match.Value);
            };

            var btsId     = getQuerystring(Request, "btsId");
            var directory = getQuerystring(Request, "directory");

            if (string.IsNullOrEmpty(btsId) || string.IsNullOrEmpty(directory))
            {
                throw new DirectoryNotFoundException("基站ID或者图纸目录为空");
            }

            var provider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);

            var dwgService = new BtsDwgService(directory, btsId);

            foreach (var file in provider.Contents)
            {
                if (string.IsNullOrEmpty(file.Headers.ContentDisposition.FileName))
                {
                    continue;
                }

                var filename = file.Headers.ContentDisposition.FileName.Trim('\"');
                var buffer   = await file.ReadAsByteArrayAsync();

                dwgService.Save(filename, buffer);
                _service.SaveVisioPath(btsId, filename);
            }

            return(Ok(new { Result = 1 }));
        }
Ejemplo n.º 3
0
        public FileResultMessage View(string directory, string btsId, string filename)
        {
            var dwgService = new BtsDwgService(directory, btsId);

            var file = filename;

            if (file.EndsWith(".vsd") || file.EndsWith(".vsdx"))
            {
                file = dwgService.GetPdfOfVisio(file);
            }

            return(!File.Exists(dwgService.DirectoryPath + "/" + file)
                ? new FileResultMessage {
                Error = "文件不存在", File = ""
            }
                : new FileResultMessage {
                Error = "", File = file
            });
        }
Ejemplo n.º 4
0
        public string Get(string btsId)
        {
            var service = new BtsDwgService("Common", btsId);

            return(service.DirectoryPath);
        }
Ejemplo n.º 5
0
        public IList <DwgInfo> Get(string directory, string btsId)
        {
            var service = new BtsDwgService(directory, btsId);

            return(service.GetList());
        }
Ejemplo n.º 6
0
        public bool Delete(DWGDeleteView dwg)
        {
            var dwgService = new BtsDwgService(dwg.Directory, dwg.BtsId);

            return(dwgService.Delete(dwg.FileName));
        }