diff --git a/DemoServer.sln b/DemoServer.sln new file mode 100644 index 0000000..dc9335b --- /dev/null +++ b/DemoServer.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33530.505 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DemoVB", "DemoVB\DemoVB.vbproj", "{96266312-9739-4F12-A6C2-16C1CAFDDA6E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeebDoorCreator.SDK", "WeebDoorCreator.SDK\WeebDoorCreator.SDK.csproj", "{4A07ADFC-CA24-4135-BA97-3B8E5D49BC09}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {96266312-9739-4F12-A6C2-16C1CAFDDA6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96266312-9739-4F12-A6C2-16C1CAFDDA6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96266312-9739-4F12-A6C2-16C1CAFDDA6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96266312-9739-4F12-A6C2-16C1CAFDDA6E}.Release|Any CPU.Build.0 = Release|Any CPU + {4A07ADFC-CA24-4135-BA97-3B8E5D49BC09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A07ADFC-CA24-4135-BA97-3B8E5D49BC09}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A07ADFC-CA24-4135-BA97-3B8E5D49BC09}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A07ADFC-CA24-4135-BA97-3B8E5D49BC09}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A4FC2F6F-69CF-4644-81BC-1C3B546DA61F} + EndGlobalSection +EndGlobal diff --git a/WebDoorCreator.API/Controllers/AliveController.cs b/WebDoorCreator.API/Controllers/AliveController.cs new file mode 100644 index 0000000..745c06d --- /dev/null +++ b/WebDoorCreator.API/Controllers/AliveController.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace WebDoorCreator.API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class AliveController : ControllerBase + { + // GET: api/Alive + [HttpGet] + public string Get() + { + return "OK"; + } + + //// GET: api/Alive/Clock + //[HttpGet("Clock")] + //public string GetClock(string id) + //{ + // return DateTime.Now.ToString($"yyyy-MM-dd HH:mm:ss.fff - ID: {id}"); + //} + } +} diff --git a/WeebDoorCreator.SDK/CalcResultDTO.cs b/WeebDoorCreator.SDK/CalcResultDTO.cs new file mode 100644 index 0000000..20c2adb --- /dev/null +++ b/WeebDoorCreator.SDK/CalcResultDTO.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WeebDoorCreator.SDK +{ + /// + /// Oggetto contenitore esiti calcolo + /// + public class CalcResultDTO + { + /// + /// UID (DoorId.Version) + /// + public string DoorIdVers { get; set; } = ""; + /// + /// Validated = true / error found = false + /// + public bool Validated { get; set; } = true; + /// + /// Error message (optional) + /// + public string ErrorMsg { get; set; } = ""; + /// + /// SVG generated + /// + public string SvgGen { get; set; } = ""; + /// + /// Articat path (ex 3d zip/pack) + /// + public string artifactPath { get; set; } = ""; + } +} diff --git a/WeebDoorCreator.SDK/Properties/AssemblyInfo.cs b/WeebDoorCreator.SDK/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4b1207a --- /dev/null +++ b/WeebDoorCreator.SDK/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WeebDoorCreator.SDK")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WeebDoorCreator.SDK")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4a07adfc-ca24-4135-ba97-3b8e5d49bc09")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WeebDoorCreator.SDK/WDC.cs b/WeebDoorCreator.SDK/WDC.cs new file mode 100644 index 0000000..eadd7e2 --- /dev/null +++ b/WeebDoorCreator.SDK/WDC.cs @@ -0,0 +1,223 @@ +using Newtonsoft.Json; +using RestSharp; +using System.Collections.Generic; +using System.Net.NetworkInformation; + +namespace WeebDoorCreator.SDK +{ + public class WDC + { + #region Public Constructors + + /// + /// Classe per effettuare comunicazioni con NKC + /// + /// IP di base x ping + /// URL di base x chiamate REST + /// Codice workstation di calcolo + public WDC(string baseIp, string baseUrl, string wksCode) + { + _baseIp = baseIp; + apiUrl = baseUrl; + _wksCode = wksCode; + } + + #endregion Public Constructors + + #region Public Properties + + /// + /// Effettua test alive all'indirizzo del server + /// + public bool testAlive + { + get + { + bool answ = false; + var rawData = callUrl(urlAlive); + string returnData = JsonConvert.DeserializeObject(rawData); + answ = returnData == "OK"; + // rendo! + return answ; + } + } + + /// + /// Effettua test ping all'indirizzo del server + /// + public PingReply testPing + { + get + { + Ping myPing = new Ping(); + // timeout a 1 sec! + PingReply answ = myPing.Send(_baseIp, 1000); + // rendo! + return answ; + } + } + + /// + /// Numero di chiamate in coda da processare + /// + public int numTask2proc + { + get + { + int answ = 0; + var rawData = callUrl(urlActLenght); + var returnData = JsonConvert.DeserializeObject>(rawData); + // rendo! + if (returnData.ContainsKey(pendQueue)) + { + answ = (int)returnData[pendQueue]; + } + return answ; + } + } + /// + /// Status delle code chiamate + /// + public Dictionary queueStatus + { + get + { + var rawData = callUrl(urlActLenght); + var returnData = JsonConvert.DeserializeObject>(rawData); + return returnData; + } + } + + #endregion Public Properties + + #region Public Methods + + public static PingReply testPingDevice(string address) + { + Ping myPing = new Ping(); + // timeout a 1 sec! + PingReply answ = myPing.Send(address, 2000); + // rendo! + return answ; + } + + #endregion Public Methods + + #region Protected Fields + + protected const string urlAlive = "/api/Alive"; + protected const string urlActLenght = "api/Queue/ActLenght"; + protected const string urlStatusList = "api/Queue/StatusList"; + protected const string urlSaveProcRes = "api/Queue/SaveProcResult"; + protected const string urlTakeNextItems = "api/Queue/TakeNextItems"; + protected const string pendQueue = "pending"; + + #endregion Protected Fields + + #region Protected Properties + + /// + /// DnsName/IP di base x chaimate + /// + protected string _baseIp { get; set; } = "seriate.steamware.net"; + + /// + /// Cod Workstation che effettua i calcoli + /// + protected string _wksCode { get; set; } = ""; + + /// + /// URL di base per la comunicazione + /// + /// PROD: https://iis01.egalware.com/WDC/SRV/ + /// DEV: https://localhost:7043/ + /// + protected string apiUrl { get; set; } = @"https://iis01.egalware.com/WDC/SRV/"; + + #endregion Protected Properties + + #region Protected Methods + + /// + /// Effettua chiamata URL e restituisce risultato + /// + /// + /// + protected string callUrl(string URL) + { + string answ = ""; + // cerco online + RestClient client = new RestClient(apiUrl); + var request = new RestRequest(URL); + var response = client.Get(request); + // controllo status code risposta + if (response.StatusCode == System.Net.HttpStatusCode.OK) + { + // deserializzo risposta + answ = response.Content; + } + else + { + answ = "KO"; + } + // restituisco valore! + return answ; + } + + #endregion Protected Methods + +#if false + /// + /// Effettua chiamata URL e restituisce risultato + /// + /// + /// + /// + public static string callUrl(string URL, string payload) + { + string answ = ""; + var client = new WebClientWT(); + client.Headers.Add("user-agent", "NKC_SDK"); + try + { + answ = client.UploadString(URL, payload); + } + catch (Exception exc) + { + Log.Instance.Error($"Eccezione durante callUrl per URL: {URL} | payload: {payload}{Environment.NewLine}{exc}"); + answ = exc.Message; + } + // restituisco valore! + return answ; + } + + /// + /// Effettua chiamata PUT + /// + /// + /// + /// + public static string putData(string URL, string payload) + { + string answ = ""; + var client = new WebClientWT(); + client.Headers.Add("user-agent", "NKC_SDK"); + // importante x evitare errore 415 di dataType non ammesso + client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); + try + { + // va messo "PUT" e va configurato IIS per accettare PUT + answ = client.UploadString(URL, "PUT", payload); + answ = "ok"; + } + catch (Exception exc) + { + Log.Instance.Error($"Eccezione durante putData per {URL}{Environment.NewLine}{exc}"); + answ = exc.Message; + } + // restituisco valore! + return answ; + } +#endif + } +} \ No newline at end of file diff --git a/WeebDoorCreator.SDK/WeebDoorCreator.SDK.csproj b/WeebDoorCreator.SDK/WeebDoorCreator.SDK.csproj new file mode 100644 index 0000000..f9086ed --- /dev/null +++ b/WeebDoorCreator.SDK/WeebDoorCreator.SDK.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {4A07ADFC-CA24-4135-BA97-3B8E5D49BC09} + Library + Properties + WeebDoorCreator.SDK + WeebDoorCreator.SDK + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WeebDoorCreator.SDK/app.config b/WeebDoorCreator.SDK/app.config new file mode 100644 index 0000000..1696df6 --- /dev/null +++ b/WeebDoorCreator.SDK/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/WeebDoorCreator.SDK/packages.config b/WeebDoorCreator.SDK/packages.config new file mode 100644 index 0000000..5b27960 --- /dev/null +++ b/WeebDoorCreator.SDK/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file