f300423d47
New multipart manager Added Siemens file manager
108 lines
3.4 KiB
C#
108 lines
3.4 KiB
C#
using Step.Model.DTOModels;
|
|
using Step.NC;
|
|
using Step.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using static Step.Model.Constants;
|
|
using System.Text;
|
|
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<PreviewFileModel> 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<HttpResponseMessage> Post()
|
|
{
|
|
if (!Request.Content.IsMimeMultipartContent())
|
|
{
|
|
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
|
|
}
|
|
|
|
List<FormItem> formItems = await MultipartHandler.ManageMultiPartFileAsync(Request);
|
|
|
|
foreach (FormItem item in formItems)
|
|
{
|
|
if (item.IsAFile)
|
|
{
|
|
if(item.ParameterName == "file")
|
|
{
|
|
File.WriteAllBytes(TEMP_FILE + item.FileName, item.Data);
|
|
}
|
|
else if(item.ParameterName == "image")
|
|
{
|
|
File.WriteAllBytes(PART_PRG_IMAGES + item.FileName, item.Data);
|
|
}
|
|
}
|
|
}
|
|
|
|
return Request.CreateResponse(HttpStatusCode.OK);
|
|
}
|
|
}
|
|
} |