Skip to content

Commit c68c7dc

Browse files
Add import action for Midas Civil NX (#400)
2 parents 9c9ab32 + b517e82 commit c68c7dc

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

MidasCivil_Adapter/AdapterActions/Execute.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.Runtime.InteropServices;
3333
using System.Threading.Tasks;
3434
using System.Net.Http;
35+
using System.Net.NetworkInformation;
3536

3637
namespace BH.Adapter.MidasCivil
3738
{
@@ -319,6 +320,52 @@ public async Task<bool> RunCommand(Analyse command)
319320
}
320321

321322
/***************************************************/
323+
public async Task<bool> RunCommand(ImportFile command)
324+
{
325+
if (m_midasCivilVersion == "9.5.0.nx")
326+
{
327+
string endpoint = "";
328+
string filePath = command.FilePath;
329+
330+
if (File.Exists(filePath))
331+
{
332+
string extension = Path.GetExtension(filePath).ToLower();
333+
334+
if (extension == ".mct" || extension == ".mgt" || extension == ".txt")
335+
endpoint = "doc/IMPORTMXT";
336+
337+
else if (extension == ".json")
338+
endpoint = "doc/IMPORT";
339+
340+
else
341+
{
342+
Engine.Base.Compute.RecordError("The given file type is not supported by this Adapter.");
343+
return false;
344+
}
345+
346+
}
347+
348+
else
349+
{
350+
Engine.Base.Compute.RecordError("The given file path does not exist.");
351+
return false;
352+
}
353+
354+
filePath = filePath.Replace("\\", "\\\\");
355+
356+
string jsonPayload = "{\"Argument\": \"" + filePath + "\"}";
357+
358+
await SendRequestAsync(endpoint, HttpMethod.Post, jsonPayload).ConfigureAwait(false);
359+
360+
return true;
361+
}
362+
363+
else
364+
{
365+
Engine.Base.Compute.RecordWarning($"The command {command.GetType().Name} is not supported by this Adapter version.");
366+
return false;
367+
}
368+
}
322369

323370
public bool RunCommand(AnalyseLoadCases command)
324371
{

0 commit comments

Comments
 (0)