diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index d2ed74f7..28560c0b 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/Config/serverConfig.xml b/Step.Config/Config/serverConfig.xml index ec1bcc1e..6536bb0a 100644 --- a/Step.Config/Config/serverConfig.xml +++ b/Step.Config/Config/serverConfig.xml @@ -1,7 +1,7 @@ - DEMO + SIEMENS true localhost 8080 diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index 0f1933d3..aab82083 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -1,119 +1,112 @@ -using Step.Model.DTOModels; -using Step.NC; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Web.Http; -using static CMS_CORE_Library.DataStructures; - -namespace Step.Controllers.WebApi -{ - - [RoutePrefix("api/file_manager")] - - public class NcFileController : ApiController - { - - [Route("files"), HttpGet] - public IHttpActionResult GetFileList(string filePath = "") - { - using (NcHandler ncHandler = new NcHandler()) - { - ncHandler.Connect(); - - CmsError cmsError = ncHandler.GetFileList(filePath, out List fileList); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - return Ok(fileList); - } - } - - - [Route("file/info"), HttpGet] - public IHttpActionResult GetFileInfo([FromUri]string filePath) - { - using (NcHandler ncHandler = new NcHandler()) - { - ncHandler.Connect(); - - CmsError cmsError = ncHandler.GetFileInfo(filePath, out InfoFile fileInfo); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - return Ok(fileInfo); - } - } - - [Route("file/active"), HttpPut] - public IHttpActionResult SetActiveProgram([FromUri]string filePath) - { - using (NcHandler ncHandler = new NcHandler()) - { - ncHandler.Connect(); - - CmsError cmsError = ncHandler.SetActiveProgramInfo(filePath, out DTOActiveProgramDataModel fileInfo); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - return Ok(fileInfo); - } - } - - [Route("file/deactivate"), HttpPut] - public IHttpActionResult DeactivateProgram() - { - using (NcHandler ncHandler = new NcHandler()) - { - ncHandler.Connect(); - - CmsError cmsError = ncHandler.DeactivateProgram(out DTOActiveProgramDataModel fileInfo); - if (cmsError.IsError()) - return BadRequest(cmsError.localizationKey); - - return Ok(fileInfo); - } - } - - [Route("upload"), HttpPost] - public async Task AddAttachment() - { - // Check whether the POST operation is MultiPart? - if (!Request.Content.IsMimeMultipartContent()) - throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); - - // Create CustomMultipartFormDataStreamProvider - CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider("C:\\CMS\\STEP\\"); - // MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(MAINTENANCE_ATTACHMENT_PATH); - List files = new List(); - - // Read all contents of multipart message into CustomMultipartFormDataStreamProvider. +using Step.Model.DTOModels; +using Step.NC; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Web.Http; +using static CMS_CORE_Library.DataStructures; + +namespace Step.Controllers.WebApi +{ + [RoutePrefix("api/file_manager")] + public class NcFileController : ApiController + { + [Route("files"), HttpGet] + public IHttpActionResult GetFileList(string filePath = "") + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.GetFileList(filePath, out List fileList); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(fileList); + } + } + + [Route("file/info"), HttpGet] + public IHttpActionResult GetFileInfo([FromUri]string filePath) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.GetFileInfo(filePath, out InfoFile fileInfo); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(fileInfo); + } + } + + [Route("file/active"), HttpPut] + public IHttpActionResult SetActiveProgram([FromUri]string filePath) + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.SetActiveProgramInfo(filePath, out DTOActiveProgramDataModel fileInfo); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(fileInfo); + } + } + + [Route("file/deactivate"), HttpPut] + public IHttpActionResult DeactivateProgram() + { + using (NcHandler ncHandler = new NcHandler()) + { + ncHandler.Connect(); + + CmsError cmsError = ncHandler.DeactivateProgram(out DTOActiveProgramDataModel fileInfo); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + + return Ok(fileInfo); + } + } + + [Route("upload"), HttpPost] + public async Task AddAttachment() + { + // Check whether the POST operation is MultiPart? + if (!Request.Content.IsMimeMultipartContent()) + throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); + + // Create CustomMultipartFormDataStreamProvider + CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider("C:\\CMS\\STEP\\"); + // MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(MAINTENANCE_ATTACHMENT_PATH); + List files = new List(); + + // Read all contents of multipart message into CustomMultipartFormDataStreamProvider. var result = await Request.Content.ReadAsMultipartAsync(provider); - - // Send OK Response along with saved file names to the client. - return Ok(); - } - - // Override MultipartFormDataStreamProvider to override the GetLocalFileName - public class CustomMultipartFormDataStreamProvider : MultipartFormDataStreamProvider - { - public CustomMultipartFormDataStreamProvider(string path) : base(path) - { - } - - public override string GetLocalFileName(HttpContentHeaders headers) - { - var fileName = headers.ContentDisposition.FileName.Replace("\"", string.Empty); - - return Path.GetFileNameWithoutExtension(fileName) + Guid.NewGuid() + Path.GetExtension(fileName); - } - } - } -} + + // Send OK Response along with saved file names to the client. + return Ok(); + } + + // Override MultipartFormDataStreamProvider to override the GetLocalFileName + public class CustomMultipartFormDataStreamProvider : MultipartFormDataStreamProvider + { + public CustomMultipartFormDataStreamProvider(string path) : base(path) + { + } + + public override string GetLocalFileName(HttpContentHeaders headers) + { + var fileName = headers.ContentDisposition.FileName.Replace("\"", string.Empty); + + return Path.GetFileNameWithoutExtension(fileName) + Guid.NewGuid() + Path.GetExtension(fileName); + } + } + } +} \ No newline at end of file