From 5fc70d430a68ef461fed7255d636f928f6ff049d Mon Sep 17 00:00:00 2001 From: Flavio Meneses <121137893+fsmeneses@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:14:54 +0000 Subject: [PATCH] review source and output conditions for 2022-7 --- .../MWCore-AdHoc-E2E-Streams_1.cs | 616 +----------------- MWCore-AdHoc-E2E-Streams_1/Misc/EdgeTable.cs | 11 + .../Misc/ElementCache.cs | 27 + MWCore-AdHoc-E2E-Streams_1/Misc/Hop.cs | 49 ++ MWCore-AdHoc-E2E-Streams_1/Misc/Iotable.cs | 29 + MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs | 598 +++++++++++++++++ .../MWCoreDownloadThumbnails_1.cs | 69 +- MWCoreStatisticsEnable.xml | 11 +- .../MWCoreStatisticsEnable_1.cs | 24 +- 9 files changed, 770 insertions(+), 664 deletions(-) create mode 100644 MWCore-AdHoc-E2E-Streams_1/Misc/EdgeTable.cs create mode 100644 MWCore-AdHoc-E2E-Streams_1/Misc/ElementCache.cs create mode 100644 MWCore-AdHoc-E2E-Streams_1/Misc/Hop.cs create mode 100644 MWCore-AdHoc-E2E-Streams_1/Misc/Iotable.cs create mode 100644 MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs diff --git a/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs b/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs index 0d416a1..5a61266 100644 --- a/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs +++ b/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs @@ -55,23 +55,10 @@ namespace GQIIntegrationSPI using System.Collections.Generic; using System.IO; using System.Linq; + using MWCoreAdHocE2EStreams_1.Misc; using Skyline.DataMiner.Analytics.GenericInterface; - using Skyline.DataMiner.Net.Helper; using Skyline.DataMiner.Net.Messages; - internal enum IOType - { - Input = 0, - Output = 1, - } - - internal enum MWCorePids - { - SourcesTablePid = 9600, - OutputsTablePid = 8900, - EdgesTablePid = 8500, - } - [GQIMetaData(Name = "MWCore E2E Stream")] public class GQIDataSourceAdHocE2EStreams : IGQIDataSource, IGQIInputArguments, IGQIOnInit { @@ -81,9 +68,7 @@ public class GQIDataSourceAdHocE2EStreams : IGQIDataSource, IGQIInputArguments, private bool _debug = false; private GQIDMS _dms; private string _edgeName; - private InputOuput[] _edgesTable; private string _elementName; - private InputOuput[] _iotable; private string _streamName; private string file = $"C:\\Users\\FlavioME\\Downloads\\e2eLog-{DateTime.Now.ToOADate()}.txt"; @@ -128,24 +113,8 @@ public GQIPage GetNextPage(GetNextPageInputArgs args) try { - var responseElement = _dms.SendMessage(new GetElementByNameMessage(_elementName)) as ElementInfoEventMessage; - - _edgesTable = EdgesTable(responseElement); - - if (_edgesTable == default) - { - throw new ArgumentException("Edges table not found!"); - } - - _iotable = IOTable(responseElement); - if (_iotable == default) - { - throw new ArgumentException("Sources or Outputs table not found!"); - } - - // Get previous hop - look for outputs connected to the started inputs - // Get next hop - look for inputs that are connected to the started outputs - var hops = GetHops(); + var streams = StreamsIO.Instance(_dms, _elementName); + var hops = StreamsIO.GetHops(streams, _edgeName, _streamName); if (_debug) { @@ -237,584 +206,5 @@ public OnInitOutputArgs OnInit(OnInitInputArgs args) _dms = args.DMS; return default; } - - private bool ContainsIoIp(string edgeName, string ioip) - { - var edge = _edgesTable.FirstOrDefault(x => x.Name == edgeName); - - if (edge == default) - { - return false; - } - - bool valid = false; - var ips = ioip.Split(';'); - foreach (var ip in ips) - { - valid = edge.Ip.Contains(ip.Split(':')[0]); - if (valid) - { - break; - } - } - - return valid; - } - - private bool ContainsIoPort(string addresses, string port) - { - bool valid = false; - var addrs = addresses.Split(';'); - foreach (var addr in addrs) - { - var tmp = addr.Split(':'); - - if (tmp.Length < 2) - { - continue; - } - - valid = tmp[1] == port; - if (valid) - { - break; - } - } - - return valid; - } - - private InputOuput[] EdgesTable(ElementInfoEventMessage responseElement) - { - var responseEdgesTable = _dms.SendMessage(new GetPartialTableMessage - { - DataMinerID = responseElement.DataMinerID, - ElementID = responseElement.ElementID, - ParameterID = 8500, // MWEdges, - Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, - }) as ParameterChangeEventMessage; - - if (!responseEdgesTable.NewValue.IsArray) - { - return default; - } - - var table = new List(); - - var cols = responseEdgesTable.NewValue.ArrayValue[0].ArrayValue; - for (int idxRow = 0; idxRow < cols.Length; idxRow++) - { - // start of row 'idxRow' - table.Add(new InputOuput - { - Id = responseEdgesTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(), - Name = responseEdgesTable.NewValue.GetTableCell(idxRow, 1)?.CellValue.GetAsStringValue(), - Ip = responseEdgesTable.NewValue.GetTableCell(idxRow, 9)?.CellValue.GetAsStringValue(), - }); - } - - if (_debug) - { - foreach (var item in table) - { - File.AppendAllText(file, $"EDGES|| Id: {item.Id}|Name: {item.Name}|Ip: {item.Ip}|\n"); - } - } - - return table.ToArray(); - } - - private bool FindNextHop(List hops, IEnumerable startOutputsId, int depth, int maxDepth = 10) - { - if (depth > maxDepth) - { - return false; - } - - if (!startOutputsId.Any()) - { - return false; - } - - List nextInputsId = new List(); - startOutputsId.ForEach(output => FindNextInput(hops, output, nextInputsId, depth)); - - if (nextInputsId.Count < 1) - { - return false; - } - - List nextOutputs = new List(); - nextInputsId.Distinct().ForEach(input => FindNextOutput(hops, input, nextOutputs, depth)); - - return FindNextHop(hops, nextOutputs.Distinct(), ++depth); - } - - private void FindNextInput(List hops, InputOuput output, List startInputsId, int depth) - { - InputOuput[] inputs; - if (output.Type == "1") // push - { - inputs = _iotable.Where(input => - (input.IOType == IOType.Input && input.Ip == output.Ip && input.Port == output.Port) || - (input.IOType == IOType.Input && ContainsIoIp(input.MWEdge, output.Ip) && input.Port == output.Port)) - .ToArray(); - } - else - { - // listener - inputs = _iotable.Where(input => - (input.IOType == IOType.Input && input.Ip == output.Ip && input.Port == output.Port) || - (input.IOType == IOType.Input && ContainsIoIp(output.MWEdge, input.Ip) && (input.Port == output.Port || ContainsIoPort(input.Ip, output.Port)))) - .ToArray(); - } - - if (_debug) - { - foreach (var input in _iotable) - { - File.AppendAllText(file, $"FIND INPUT| output {output.Type} (1=PUSH/0=LISTENER) | input ip: {input.Ip} | input port: {input.Port}|| contains > IP:{ContainsIoIp(output.MWEdge, input.Ip)} PORT:{ContainsIoPort(input.Ip, output.Port)}\n"); - - if (input.IOType == IOType.Input && input.Ip == output.Ip && input.Port == output.Port) - { - File.AppendAllText(file, $"FIND INPUT 1| output Listener | input ip: {input.Ip} | input port: {input.Port}\n"); - } - else if (input.IOType == IOType.Input && ContainsIoIp(output.MWEdge, input.Ip) && input.Port == output.Port) - { - File.AppendAllText(file, $"FIND INPUT 2| output Listener | input ip: {input.Ip} | input port: {input.Port}|| contains: {ContainsIoIp(output.MWEdge, input.Ip)}\n"); - } - else - { - File.AppendAllText(file, $"FIND INPUT|No matches found!\n"); - } - } - - foreach (var item in inputs) - { - File.AppendAllText(file, $"FOUND INPUT | input:{item.Name}| input:{item.Stream} | input:{item.MWEdge}\n"); - } - } - - foreach (var input in inputs) - { - hops.Add(new Hop - { - Bitrate_Dst = input.Bitrate, - Bitrate_Src = output.Bitrate, - Id_Dst = input.Id, - Id_Src = output.Id, - IOType = IOType.Output, - Ip_Dst = input.Ip, - Ip_Src = output.Ip, - MWEdge_Dst = input.MWEdge, - MWEdge_Src = output.MWEdge, - Name_Dst = input.Name, - Name_Src = output.Name, - Port_Dst = input.Port, - Port_Src = output.Port, - Stream_Dst = input.Stream, - Stream_Src = output.Stream, - Type_Dst = input.Type, - Type_Src = output.Type, - Status_Dst = input.Status, - Status_Src = output.Status, - Hop_Number = depth + 1, - IsActive = output.Status == "False", - }); - } - - startInputsId.AddRange(inputs); - } - - private void FindNextOutput(List hops, InputOuput input, List nextOutputs, int depth) - { - if (_debug) - { - File.AppendAllText(file, $"FIND OUTPUT|| INPUT MWEDGE: {input.MWEdge}|Stream: {input.Stream}\n"); - } - - var outputs = _iotable.Where(output => - (output.IOType == IOType.Output && output.MWEdge == input.MWEdge && output.Stream == input.Stream)) - .ToArray(); - - foreach (var output in outputs) - { - hops.Add(new Hop - { - Bitrate_Dst = output.Bitrate, - Bitrate_Src = input.Bitrate, - Id_Dst = output.Id, - Id_Src = input.Id, - IOType = IOType.Input, - Ip_Dst = output.Ip, - Ip_Src = input.Ip, - MWEdge_Dst = output.MWEdge, - MWEdge_Src = input.MWEdge, - Name_Dst = output.Name, - Name_Src = input.Name, - Port_Dst = output.Port, - Port_Src = input.Port, - Stream_Dst = output.Stream, - Stream_Src = input.Stream, - Type_Dst = output.Type, - Type_Src = input.Type, - Status_Dst = output.Status, - Status_Src = input.Status, - Hop_Number = depth + 1, - IsActive = input.InputState == "True", - }); - } - - nextOutputs.AddRange(outputs); - } - - private bool FindPreviousHop(List hops, IEnumerable startInputsId, int depth, int maxDepth = 10) - { - if (depth > maxDepth) - { - return false; - } - - if (!startInputsId.Any()) - { - return false; - } - - List previousOutputs = new List(); - startInputsId.ForEach(input => FindPreviousOutput(hops, input, previousOutputs, depth)); - - if (previousOutputs.Count < 1) - { - return false; - } - - List previousInputsId = new List(); - previousOutputs.Distinct().ForEach(output => FindPreviousInput(hops, output, previousInputsId, depth)); - - return FindPreviousHop(hops, previousInputsId.Distinct(), ++depth); - } - - private void FindPreviousInput(List hops, InputOuput output, List startInputsId, int depth) - { - if (_debug) - { - File.AppendAllText(file, $"FIND OUTPUT|| INPUT MWEDGE: {output.MWEdge}|Stream: {output.Stream}\n"); - } - - var inputs = _iotable.Where(input => - (input.IOType == IOType.Input && input.MWEdge == output.MWEdge && input.Stream == output.Stream)) - .ToArray(); - - foreach (var input in inputs) - { - hops.Add(new Hop - { - Bitrate_Dst = output.Bitrate, - Bitrate_Src = input.Bitrate, - Id_Dst = output.Id, - Id_Src = input.Id, - IOType = IOType.Input, - Ip_Dst = output.Ip, - Ip_Src = input.Ip, - MWEdge_Dst = output.MWEdge, - MWEdge_Src = input.MWEdge, - Name_Dst = output.Name, - Name_Src = input.Name, - Port_Dst = output.Port, - Port_Src = input.Port, - Stream_Dst = output.Stream, - Stream_Src = input.Stream, - Type_Dst = output.Type, - Type_Src = input.Type, - Status_Dst = output.Status, - Status_Src = input.Status, - Hop_Number = -depth - 1, - IsActive = input.InputState == "True", - }); - } - - startInputsId.AddRange(inputs); - } - - private void FindPreviousOutput(List hops, InputOuput input, List previousOutputs, int depth) - { - InputOuput[] outputs; - if (input.Type == "1") // listener - { - outputs = _iotable.Where(output => - (output.IOType == IOType.Output && input.Ip == output.Ip && input.Port == output.Port) || - (output.IOType == IOType.Output && ContainsIoIp(input.MWEdge, output.Ip) && input.Port == output.Port)) - .ToArray(); - } - else - { - // pull - outputs = _iotable.Where(output => - (output.IOType == IOType.Output && input.Ip == output.Ip && input.Port == output.Port) || - (output.IOType == IOType.Output && ContainsIoIp(output.MWEdge, input.Ip) && (input.Port == output.Port || ContainsIoPort(input.Ip, output.Port)))) - .ToArray(); - } - - if (_debug) - { - foreach (var output in _iotable) - { - File.AppendAllText(file, $"FIND INPUT| output {input.Type == "1"} (1=PUSH/0=LISTENER) | input ip: {output.Ip} | input port: {output.Port}|| contains: {ContainsIoIp(input.MWEdge, output.Ip)}\n"); - - if (output.IOType == IOType.Input && output.Ip == input.Ip && output.Port == input.Port) - { - File.AppendAllText(file, $"FIND INPUT 1| output Listener | input ip: {output.Ip} | input port: {output.Port}\n"); - } - else if (output.IOType == IOType.Input && ContainsIoIp(input.MWEdge, output.Ip) && output.Port == input.Port) - { - File.AppendAllText(file, $"FIND INPUT 2| output Listener | input ip: {output.Ip} | input port: {output.Port}|| contains: {ContainsIoIp(input.MWEdge, output.Ip)}\n"); - } - else - { - File.AppendAllText(file, $"FIND INPUT|No matches found!"); - } - } - - foreach (var item in outputs) - { - File.AppendAllText(file, $"FOUND INPUT | input:{item.Name}| input:{item.Stream} | input:{item.MWEdge}\n"); - } - } - - foreach (var output in outputs) - { - hops.Add(new Hop - { - Bitrate_Dst = input.Bitrate, - Bitrate_Src = output.Bitrate, - Id_Dst = input.Id, - Id_Src = output.Id, - IOType = IOType.Output, - Ip_Dst = input.Ip, - Ip_Src = output.Ip, - MWEdge_Dst = input.MWEdge, - MWEdge_Src = output.MWEdge, - Name_Dst = input.Name, - Name_Src = output.Name, - Port_Dst = input.Port, - Port_Src = output.Port, - Stream_Dst = input.Stream, - Stream_Src = output.Stream, - Type_Dst = input.Type, - Type_Src = output.Type, - Status_Dst = input.Status, - Status_Src = output.Status, - Hop_Number = -depth - 1, - IsActive = output.Status == "False", - }); - } - - previousOutputs.AddRange(outputs); - } - - private List GetHops() - { - List hops = new List(); - - var inputs = _iotable.Where(input => - (input.IOType == IOType.Input && input.MWEdge == _edgeName && input.Stream == _streamName)) - .ToArray(); - - var outputs = _iotable.Where(output => - (output.IOType == IOType.Output && output.MWEdge == _edgeName && output.Stream == _streamName)) - .ToArray(); - - if (_debug) - { - File.AppendAllText(file, $"GET HOPS||inputs count: {inputs.Length}|outputs count:{outputs.Length}|edge:{_edgeName}|stream:{_streamName}\n"); - } - - foreach (var input in inputs) - { - foreach (var output in outputs) - { - hops.Add(new Hop - { - Bitrate_Dst = output.Bitrate, - Bitrate_Src = input.Bitrate, - Id_Dst = output.Id, - Id_Src = input.Id, - IOType = IOType.Input, - Ip_Dst = output.Ip, - Ip_Src = input.Ip, - MWEdge_Dst = output.MWEdge, - MWEdge_Src = input.MWEdge, - Name_Dst = output.Name, - Name_Src = input.Name, - Port_Dst = output.Port, - Port_Src = input.Port, - Stream_Dst = output.Stream, - Stream_Src = input.Stream, - Type_Dst = output.Type, - Type_Src = input.Type, - Status_Dst = output.Status, - Status_Src = input.Status, - Starting_Point = true, - Hop_Number = 0, - IsActive = input.InputState == "True", - }); - } - } - - FindPreviousHop(hops, inputs.Distinct(), 0); - FindNextHop(hops, outputs.Distinct(), 0); - - return hops; - } - - private InputOuput[] IOTable(ElementInfoEventMessage responseElement) - { - var responseInputsTable = _dms.SendMessage(new GetPartialTableMessage - { - DataMinerID = responseElement.DataMinerID, - ElementID = responseElement.ElementID, - ParameterID = 9600, // inputsPid, - Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, - }) as ParameterChangeEventMessage; - - var responseOutputsTable = _dms.SendMessage(new GetPartialTableMessage - { - DataMinerID = responseElement.DataMinerID, - ElementID = responseElement.ElementID, - ParameterID = 8900, // outputsPid, - Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, - }) as ParameterChangeEventMessage; - - if (!responseInputsTable.NewValue.IsArray || - !responseOutputsTable.NewValue.IsArray) - { - return default; - } - - var iotable = new List(); - - var cols = responseInputsTable.NewValue.ArrayValue[0].ArrayValue; - for (int idxRow = 0; idxRow < cols.Length; idxRow++) - { - // start of row 'idxRow' - iotable.Add(new InputOuput - { - Id = responseInputsTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(), - Name = responseInputsTable.NewValue.GetTableCell(idxRow, 1)?.CellValue.GetAsStringValue(), - Status = responseInputsTable.NewValue.GetTableCell(idxRow, 20)?.CellValue.GetAsStringValue(), - IOType = IOType.Input, - Stream = responseInputsTable.NewValue.GetTableCell(idxRow, 23)?.CellValue.GetAsStringValue(), - MWEdge = responseInputsTable.NewValue.GetTableCell(idxRow, 59)?.CellValue.GetAsStringValue(), - Ip = responseInputsTable.NewValue.GetTableCell(idxRow, 58)?.CellValue.GetAsStringValue(), - Port = responseInputsTable.NewValue.GetTableCell(idxRow, 7)?.CellValue.GetAsStringValue(), - Type = responseInputsTable.NewValue.GetTableCell(idxRow, 5)?.CellValue.GetAsStringValue(), - Bitrate = responseInputsTable.NewValue.GetTableCell(idxRow, 33)?.CellValue.DoubleValue, - InputState = responseInputsTable.NewValue.GetTableCell(idxRow, 55)?.CellValue.GetAsStringValue(), - }); - } - - cols = responseOutputsTable.NewValue.ArrayValue[0].ArrayValue; - for (int idxRow = 0; idxRow < cols.Length; idxRow++) - { - // start of row 'idxRow' - iotable.Add(new InputOuput - { - Id = responseOutputsTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(), - Name = responseOutputsTable.NewValue.GetTableCell(idxRow, 1)?.CellValue.GetAsStringValue(), - Status = responseOutputsTable.NewValue.GetTableCell(idxRow, 2)?.CellValue.GetAsStringValue(), - IOType = IOType.Output, - Stream = responseOutputsTable.NewValue.GetTableCell(idxRow, 9)?.CellValue.GetAsStringValue(), - MWEdge = responseOutputsTable.NewValue.GetTableCell(idxRow, 10)?.CellValue.GetAsStringValue(), - Ip = responseOutputsTable.NewValue.GetTableCell(idxRow, 4)?.CellValue.GetAsStringValue(), - Port = responseOutputsTable.NewValue.GetTableCell(idxRow, 5)?.CellValue.GetAsStringValue(), - Type = responseOutputsTable.NewValue.GetTableCell(idxRow, 15)?.CellValue.GetAsStringValue(), - Bitrate = responseOutputsTable.NewValue.GetTableCell(idxRow, 27)?.CellValue.DoubleValue, - }); - } - - if (_debug) - { - File.AppendAllText(file, "Finished getting sources and outputs \n"); - - foreach (var item in iotable) - { - File.AppendAllText(file, $"IOTYPE: {item.IOType}|Id: {item.Id}|Name: {item.Name}|Status: {item.Status}|Stream: {item.Stream}|MWEdge: {item.MWEdge}|Ip: {item.Ip}|Port: {item.Port}|Type: {item.Type}|\n"); - } - } - - return iotable.ToArray(); - } - } - - internal class Hop - { - public double? Bitrate_Dst { get; set; } - - public double? Bitrate_Src { get; set; } - - public int Hop_Number { get; set; } - - public string Id_Dst { get; set; } - - public string Id_Src { get; set; } - - public IOType IOType { get; set; } - - public string Ip_Dst { get; set; } - - public string Ip_Src { get; set; } - - public bool IsActive { get; set; } - - public string MWEdge_Dst { get; set; } - - public string MWEdge_Src { get; set; } - - public string Name_Dst { get; set; } - - public string Name_Src { get; set; } - - public string Port_Dst { get; set; } - - public string Port_Src { get; set; } - - public bool Starting_Point { get; set; } - - public string Status_Dst { get; set; } - - public string Status_Src { get; set; } - - public string Stream_Dst { get; set; } - - public string Stream_Src { get; set; } - - public string Type_Dst { get; set; } - - public string Type_Src { get; set; } // pull, listener/push - } - - internal class InputOuput - { - public double? Bitrate { get; set; } - - public string Id { get; set; } - - public string InputState { get; set; } - - public IOType IOType { get; set; } - - public string Ip { get; set; } - - public string MWEdge { get; set; } - - public string Name { get; set; } - - public string Port { get; set; } - - public string Status { get; set; } - - public string Stream { get; set; } - - public string Type { get; set; } // pull, listener/push } } \ No newline at end of file diff --git a/MWCore-AdHoc-E2E-Streams_1/Misc/EdgeTable.cs b/MWCore-AdHoc-E2E-Streams_1/Misc/EdgeTable.cs new file mode 100644 index 0000000..1726d2c --- /dev/null +++ b/MWCore-AdHoc-E2E-Streams_1/Misc/EdgeTable.cs @@ -0,0 +1,11 @@ +namespace MWCoreAdHocE2EStreams_1.Misc +{ + internal class EdgeTable + { + public string Id { get; set; } + + public string Ip { get; set; } + + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/MWCore-AdHoc-E2E-Streams_1/Misc/ElementCache.cs b/MWCore-AdHoc-E2E-Streams_1/Misc/ElementCache.cs new file mode 100644 index 0000000..9e98550 --- /dev/null +++ b/MWCore-AdHoc-E2E-Streams_1/Misc/ElementCache.cs @@ -0,0 +1,27 @@ +namespace MWCoreAdHocE2EStreams_1.Misc +{ + using System; + + internal class ElementCache + { + public ElementCache(StreamsIO instance, DateTime lastRun) + { + if (instance is null) + { + throw new ArgumentNullException(nameof(instance)); + } + + if (lastRun == default) + { + throw new ArgumentNullException(nameof(lastRun)); + } + + Instance = instance; + LastRun = lastRun; + } + + public StreamsIO Instance { get; set; } + + public DateTime LastRun { get; set; } + } +} \ No newline at end of file diff --git a/MWCore-AdHoc-E2E-Streams_1/Misc/Hop.cs b/MWCore-AdHoc-E2E-Streams_1/Misc/Hop.cs new file mode 100644 index 0000000..eeaf8b6 --- /dev/null +++ b/MWCore-AdHoc-E2E-Streams_1/Misc/Hop.cs @@ -0,0 +1,49 @@ +namespace MWCoreAdHocE2EStreams_1.Misc +{ + internal class Hop + { + public double? Bitrate_Dst { get; set; } + + public double? Bitrate_Src { get; set; } + + public int Hop_Number { get; set; } + + public string Id_Dst { get; set; } + + public string Id_Src { get; set; } + + public IOType IOType { get; set; } + + public string Ip_Dst { get; set; } + + public string Ip_Src { get; set; } + + public bool IsActive { get; set; } + + public string MWEdge_Dst { get; set; } + + public string MWEdge_Src { get; set; } + + public string Name_Dst { get; set; } + + public string Name_Src { get; set; } + + public string Port_Dst { get; set; } + + public string Port_Src { get; set; } + + public bool Starting_Point { get; set; } + + public string Status_Dst { get; set; } + + public string Status_Src { get; set; } + + public string Stream_Dst { get; set; } + + public string Stream_Src { get; set; } + + public string Type_Dst { get; set; } + + public string Type_Src { get; set; } // pull, listener/push + } +} \ No newline at end of file diff --git a/MWCore-AdHoc-E2E-Streams_1/Misc/Iotable.cs b/MWCore-AdHoc-E2E-Streams_1/Misc/Iotable.cs new file mode 100644 index 0000000..181d40a --- /dev/null +++ b/MWCore-AdHoc-E2E-Streams_1/Misc/Iotable.cs @@ -0,0 +1,29 @@ +namespace MWCoreAdHocE2EStreams_1.Misc +{ + internal class Iotable + { + public double? Bitrate { get; set; } + + public string Id { get; set; } + + public string InputState { get; set; } + + public IOType IOType { get; set; } + + public string Ip { get; set; } + + public string MWEdge { get; set; } + + public string Name { get; set; } + + public string Port { get; set; } + + public string Protocol { get; set; } + + public string Status { get; set; } + + public string Stream { get; set; } + + public string Type { get; set; } // pull, listener/push + } +} \ No newline at end of file diff --git a/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs b/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs new file mode 100644 index 0000000..5d360fe --- /dev/null +++ b/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs @@ -0,0 +1,598 @@ +namespace MWCoreAdHocE2EStreams_1.Misc +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Skyline.DataMiner.Analytics.GenericInterface; + using Skyline.DataMiner.Net.Helper; + using Skyline.DataMiner.Net.Messages; + + internal enum IOType + { + Input = 0, + Output = 1, + } + + internal enum MWCorePids + { + SourcesTablePid = 9600, + SourcesStatisticsTablePid = 11200, + OutputsTablePid = 8900, + OutputsStatisticsTablePid = 11400, + EdgesTablePid = 8500, + } + + internal sealed class StreamsIO + { + private const double _cachingTime = 300; + private static readonly object _padlock = new object(); + private static Dictionary _instances = new Dictionary(); + private readonly GQIDMS _dms; + + private StreamsIO(GQIDMS dms, string elementName) + { + _dms = dms; + + var responseElement = dms.SendMessage(new GetElementByNameMessage(elementName)) as ElementInfoEventMessage; + + var edgesTable = GetEdgesTable(responseElement); + + if (edgesTable == default) + { + throw new ArgumentException("Edges table not found!"); + } + + EdgesTable = edgesTable; + + var inputsTable = GetInputsTable(responseElement); + if (inputsTable == default) + { + throw new ArgumentException("Sources table not found!"); + } + + InputsTable = inputsTable; + + var outputsTable = GetOutputsTable(responseElement); + if (outputsTable == default) + { + throw new ArgumentException("Outputs table not found!"); + } + + OutputsTable = outputsTable; + } + + public IEnumerable EdgesTable { get; } + + public IEnumerable InputsTable { get; } + + public IEnumerable OutputsTable { get; } + + /// + /// Get previous hop - look for outputs connected to the started inputs. + /// Get next hop - look for inputs that are connected to the started outputs. + /// + /// + /// + /// + /// + public static List GetHops(StreamsIO instance, string edgeName, string streamName) + { + List hops = new List(); + + var inputs = instance.InputsTable.Where(input => + (input.Stream == streamName && input.MWEdge == edgeName && !input.Protocol.Equals("2022-7"))) + .ToArray(); + + var outputs = instance.OutputsTable.Where(output => + (output.Stream == streamName && output.MWEdge == edgeName && !output.Protocol.Equals("2022-7"))) + .ToArray(); + + foreach (var input in inputs) + { + foreach (var output in outputs) + { + hops.Add(new Hop + { + Bitrate_Dst = output.Bitrate, + Bitrate_Src = input.Bitrate, + Id_Dst = output.Id, + Id_Src = input.Id, + IOType = IOType.Input, + Ip_Dst = output.Ip, + Ip_Src = input.Ip, + MWEdge_Dst = output.MWEdge, + MWEdge_Src = input.MWEdge, + Name_Dst = output.Name, + Name_Src = input.Name, + Port_Dst = output.Port, + Port_Src = input.Port, + Stream_Dst = output.Stream, + Stream_Src = input.Stream, + Type_Dst = output.Type, + Type_Src = input.Type, + Status_Dst = output.Status, + Status_Src = input.Status, + Starting_Point = true, + Hop_Number = 0, + IsActive = input.InputState == "True", + }); + } + } + + // Get previous hop - look for outputs connected to the started inputs. + FindPreviousHop(instance, hops, inputs.Distinct(), 0); + + // Get next hop - look for inputs that are connected to the started outputs. + FindNextHop(instance, hops, outputs.Distinct(), 0); + + return hops; + } + + public static StreamsIO Instance(GQIDMS dms, string elementName) + { + var now = DateTime.UtcNow; + ElementCache instance; + + if (!_instances.TryGetValue(elementName, out instance) || + (now - instance.LastRun) > TimeSpan.FromSeconds(_cachingTime)) + { + lock (_padlock) + { + if (!_instances.TryGetValue(elementName, out instance) || + (now - instance.LastRun) > TimeSpan.FromSeconds(_cachingTime)) + { + instance = new ElementCache(new StreamsIO(dms, elementName), now); + _instances[elementName] = instance; + } + } + } + + return instance.Instance; + } + + private static bool ContainsIoIp(StreamsIO streamsIO, string edgeName, string ioip) + { + var edge = streamsIO.EdgesTable.FirstOrDefault(x => x.Name == edgeName); + + if (edge == default) + { + return false; + } + + bool valid = false; + var ips = ioip.Split(';'); + foreach (var ip in ips) + { + valid = edge.Ip.Contains(ip.Split(':')[0]); + if (valid) + { + break; + } + } + + return valid; + } + + private static bool ContainsIoPort(string addresses, string port) + { + bool valid = false; + var addrs = addresses.Split(';'); + foreach (var addr in addrs) + { + var tmp = addr.Split(':'); + + if (tmp.Length < 2) + { + continue; + } + + valid = tmp[1] == port; + if (valid) + { + break; + } + } + + return valid; + } + + private static bool FindNextHop(StreamsIO streamsIO, List hops, IEnumerable startOutputsId, int depth, int maxDepth = 10) + { + if (depth > maxDepth) + { + return false; + } + + if (!startOutputsId.Any()) + { + return false; + } + + List nextInputsId = new List(); + startOutputsId.ForEach(output => FindNextInput(streamsIO, hops, output, nextInputsId, depth)); + + if (nextInputsId.Count < 1) + { + return false; + } + + List nextOutputs = new List(); + nextInputsId.Distinct().ForEach(input => FindNextOutput(streamsIO, hops, input, nextOutputs, depth)); + + return FindNextHop(streamsIO, hops, nextOutputs.Distinct(), ++depth); + } + + private static void FindNextInput(StreamsIO streamsIO, List hops, Iotable output, List startInputsId, int depth) + { + + Iotable[] inputs; + if (output.Type != "0") // push or NA -7 + { + inputs = streamsIO.InputsTable.Where(input => + (input.Ip == output.Ip || ContainsIoIp(streamsIO, input.MWEdge, output.Ip)) + && input.Port == output.Port) + .ToArray(); + } + else + { + // listener + inputs = streamsIO.InputsTable.Where(input => + (input.Ip == output.Ip || ContainsIoIp(streamsIO, output.MWEdge, input.Ip)) + && input.Port == output.Port) + .ToArray(); + } + + /* + var inputs = streamsIO.InputsTable.Where(input => + (input.Ip == output.Ip || ContainsIoIp(streamsIO, output.MWEdge, input.Ip)) + && input.Port == output.Port) + .ToArray(); + */ + + if (inputs.Length > 0) + { + foreach (var input in inputs) + { + hops.Add(new Hop + { + Bitrate_Dst = input.Bitrate, + Bitrate_Src = output.Bitrate, + Id_Dst = input.Id, + Id_Src = output.Id, + IOType = IOType.Output, + Ip_Dst = input.Ip, + Ip_Src = output.Ip, + MWEdge_Dst = input.MWEdge, + MWEdge_Src = output.MWEdge, + Name_Dst = input.Name, + Name_Src = output.Name, + Port_Dst = input.Port, + Port_Src = output.Port, + Stream_Dst = input.Stream, + Stream_Src = output.Stream, + Type_Dst = input.Type, + Type_Src = output.Type, + Status_Dst = input.Status, + Status_Src = output.Status, + Hop_Number = depth + 1, + IsActive = output.Status == "False", + }); + } + } + else + { + hops.Add(new Hop + { + Bitrate_Dst = 0, + Bitrate_Src = output.Bitrate, + Id_Dst = string.Empty, + Id_Src = output.Id, + IOType = IOType.Output, + Ip_Dst = string.Empty, + Ip_Src = output.Ip, + MWEdge_Dst = string.Empty, + MWEdge_Src = output.MWEdge, + Name_Dst = string.Empty, + Name_Src = output.Name, + Port_Dst = string.Empty, + Port_Src = output.Port, + Stream_Dst = string.Empty, + Stream_Src = output.Stream, + Type_Dst = string.Empty, + Type_Src = output.Type, + Status_Dst = string.Empty, + Status_Src = output.Status, + Hop_Number = depth + 1, + IsActive = output.Status == "False", + }); + } + + startInputsId.AddRange(inputs); + } + + private static void FindNextOutput(StreamsIO streamsIO, List hops, Iotable input, List nextOutputs, int depth) + { + var outputs = streamsIO.OutputsTable.Where(output => + output.Stream == input.Stream && output.MWEdge == input.MWEdge) + .ToArray(); + + foreach (var output in outputs) + { + if (output.Port == "-1") + { + continue; + } + + + if (output.Protocol == "2022-7") + { + // TODO RESUME + } + + hops.Add(new Hop + { + Bitrate_Dst = output.Bitrate, + Bitrate_Src = input.Bitrate, + Id_Dst = output.Id, + Id_Src = input.Id, + IOType = IOType.Input, + Ip_Dst = output.Ip, + Ip_Src = input.Ip, + MWEdge_Dst = output.MWEdge, + MWEdge_Src = input.MWEdge, + Name_Dst = output.Name, + Name_Src = input.Name, + Port_Dst = output.Port, + Port_Src = input.Port, + Stream_Dst = output.Stream, + Stream_Src = input.Stream, + Type_Dst = output.Type, + Type_Src = input.Type, + Status_Dst = output.Status, + Status_Src = input.Status, + Hop_Number = depth + 1, + IsActive = input.InputState == "True", + }); + } + + nextOutputs.AddRange(outputs); + } + + private static bool FindPreviousHop(StreamsIO streamsIO, List hops, IEnumerable startInputsId, int depth, int maxDepth = 10) + { + if (depth > maxDepth) + { + return false; + } + + if (!startInputsId.Any()) + { + return false; + } + + List previousOutputs = new List(); + startInputsId.ForEach(input => FindPreviousOutput(streamsIO, hops, input, previousOutputs, depth)); + + if (previousOutputs.Count < 1) + { + return false; + } + + List previousInputsId = new List(); + previousOutputs.Distinct().ForEach(output => FindPreviousInput(streamsIO, hops, output, previousInputsId, depth)); + + return FindPreviousHop(streamsIO, hops, previousInputsId.Distinct(), ++depth); + } + + private static void FindPreviousInput(StreamsIO streamsIO, List hops, Iotable output, List startInputsId, int depth) + { + var inputs = streamsIO.InputsTable.Where(input => + input.Stream == output.Stream && input.MWEdge == output.MWEdge) + .ToArray(); + + foreach (var input in inputs) + { + hops.Add(new Hop + { + Bitrate_Dst = output.Bitrate, + Bitrate_Src = input.Bitrate, + Id_Dst = output.Id, + Id_Src = input.Id, + IOType = IOType.Input, + Ip_Dst = output.Ip, + Ip_Src = input.Ip, + MWEdge_Dst = output.MWEdge, + MWEdge_Src = input.MWEdge, + Name_Dst = output.Name, + Name_Src = input.Name, + Port_Dst = output.Port, + Port_Src = input.Port, + Stream_Dst = output.Stream, + Stream_Src = input.Stream, + Type_Dst = output.Type, + Type_Src = input.Type, + Status_Dst = output.Status, + Status_Src = input.Status, + Hop_Number = -depth - 1, + IsActive = input.InputState == "True", + }); + } + + startInputsId.AddRange(inputs); + } + + private static void FindPreviousOutput(StreamsIO streamsIO, List hops, Iotable input, List previousOutputs, int depth) + { + Iotable[] outputs; + if (input.Type == "1") // listener + { + outputs = streamsIO.OutputsTable.Where(output => + (input.Ip == output.Ip || ContainsIoIp(streamsIO, input.MWEdge, output.Ip)) + && input.Port == output.Port) + .ToArray(); + } + else + { + // pull + outputs = streamsIO.OutputsTable.Where(output => + (input.Ip == output.Ip || ContainsIoIp(streamsIO, input.MWEdge, output.Ip)) + && input.Port == output.Port) + .ToArray(); + } + + foreach (var output in outputs) + { + hops.Add(new Hop + { + Bitrate_Dst = input.Bitrate, + Bitrate_Src = output.Bitrate, + Id_Dst = input.Id, + Id_Src = output.Id, + IOType = IOType.Output, + Ip_Dst = input.Ip, + Ip_Src = output.Ip, + MWEdge_Dst = input.MWEdge, + MWEdge_Src = output.MWEdge, + Name_Dst = input.Name, + Name_Src = output.Name, + Port_Dst = input.Port, + Port_Src = output.Port, + Stream_Dst = input.Stream, + Stream_Src = output.Stream, + Type_Dst = input.Type, + Type_Src = output.Type, + Status_Dst = input.Status, + Status_Src = output.Status, + Hop_Number = -depth - 1, + IsActive = output.Status == "False", + }); + } + + previousOutputs.AddRange(outputs); + } + + private IEnumerable GetEdgesTable(ElementInfoEventMessage responseElement) + { + var responseEdgesTable = _dms.SendMessage(new GetPartialTableMessage + { + DataMinerID = responseElement.DataMinerID, + ElementID = responseElement.ElementID, + ParameterID = 8500, // MWEdges, + Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, + }) as ParameterChangeEventMessage; + + if (!responseEdgesTable.NewValue.IsArray) + { + return default; + } + + var table = new List(); + + var cols = responseEdgesTable.NewValue.ArrayValue[0].ArrayValue; + for (int idxRow = 0; idxRow < cols.Length; idxRow++) + { + // start of row 'idxRow' + table.Add(new EdgeTable + { + Id = responseEdgesTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(), + Name = responseEdgesTable.NewValue.GetTableCell(idxRow, 1)?.CellValue.GetAsStringValue(), + Ip = responseEdgesTable.NewValue.GetTableCell(idxRow, 9)?.CellValue.GetAsStringValue(), + }); + } + + return table; + } + + private IEnumerable GetInputsTable(ElementInfoEventMessage responseElement) + { + var responseInputsTable = _dms.SendMessage(new GetPartialTableMessage + { + DataMinerID = responseElement.DataMinerID, + ElementID = responseElement.ElementID, + ParameterID = (int)MWCorePids.SourcesTablePid, // inputsPid, + Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, + }) as ParameterChangeEventMessage; + + /* + var responseInputsStatisticsTable = _dms.SendMessage(new GetPartialTableMessage + { + DataMinerID = responseElement.DataMinerID, + ElementID = responseElement.ElementID, + ParameterID = (int)MWCorePids.SourcesStatisticsTablePid, + Filters = new[] { "forceFullTable=true" }, + }) as ParameterChangeEventMessage; + */ + + if (!responseInputsTable.NewValue.IsArray) + { + return default; + } + + var iotable = new List(); + string pk; + var cols = responseInputsTable.NewValue.ArrayValue[0].ArrayValue; + for (int idxRow = 0; idxRow < cols.Length; idxRow++) + { + // start of row 'idxRow' + //pk = responseInputsTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(); + //var telemetryPk = responseInputsStatisticsTable.NewValue.GetTableCell(idxRow, 33); + iotable.Add(new Iotable + { + Id = responseInputsTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(), + Name = responseInputsTable.NewValue.GetTableCell(idxRow, 1)?.CellValue.GetAsStringValue(), + Status = responseInputsTable.NewValue.GetTableCell(idxRow, 20)?.CellValue.GetAsStringValue(), + IOType = IOType.Input, + Stream = responseInputsTable.NewValue.GetTableCell(idxRow, 23)?.CellValue.GetAsStringValue(), + MWEdge = responseInputsTable.NewValue.GetTableCell(idxRow, 31)?.CellValue.GetAsStringValue(), + Ip = responseInputsTable.NewValue.GetTableCell(idxRow, 30)?.CellValue.GetAsStringValue(), + Port = responseInputsTable.NewValue.GetTableCell(idxRow, 7)?.CellValue.GetAsStringValue(), + Type = responseInputsTable.NewValue.GetTableCell(idxRow, 5)?.CellValue.GetAsStringValue(), + Bitrate = 0, //responseInputsStatisticsTable.NewValue.GetTableCell(idxRow, 33)?.CellValue.DoubleValue//responseInputsTable.NewValue.GetTableCell(idxRow, 33)?.CellValue.DoubleValue, + InputState = responseInputsTable.NewValue.GetTableCell(idxRow, 27)?.CellValue.GetAsStringValue(), + Protocol = responseInputsTable.NewValue.GetTableCell(idxRow, 3)?.CellValue.GetAsStringValue(), + }); + } + + return iotable; + } + + private IEnumerable GetOutputsTable(ElementInfoEventMessage responseElement) + { + var responseOutputsTable = _dms.SendMessage(new GetPartialTableMessage + { + DataMinerID = responseElement.DataMinerID, + ElementID = responseElement.ElementID, + ParameterID = (int)MWCorePids.OutputsTablePid, // outputsPid, + Filters = new[] { "forceFullTable=true" }, + }) as ParameterChangeEventMessage; + + if (!responseOutputsTable.NewValue.IsArray) + { + return default; + } + + var iotable = new List(); + var cols = responseOutputsTable.NewValue.ArrayValue[0].ArrayValue; + for (int idxRow = 0; idxRow < cols.Length; idxRow++) + { + // start of row 'idxRow' + iotable.Add(new Iotable + { + Id = responseOutputsTable.NewValue.GetTableCell(idxRow, 0)?.CellValue.GetAsStringValue(), + Name = responseOutputsTable.NewValue.GetTableCell(idxRow, 1)?.CellValue.GetAsStringValue(), + Status = responseOutputsTable.NewValue.GetTableCell(idxRow, 2)?.CellValue.GetAsStringValue(), + IOType = IOType.Output, + Stream = responseOutputsTable.NewValue.GetTableCell(idxRow, 9)?.CellValue.GetAsStringValue(), + MWEdge = responseOutputsTable.NewValue.GetTableCell(idxRow, 10)?.CellValue.GetAsStringValue(), + Ip = responseOutputsTable.NewValue.GetTableCell(idxRow, 4)?.CellValue.GetAsStringValue(), + Port = responseOutputsTable.NewValue.GetTableCell(idxRow, 5)?.CellValue.GetAsStringValue(), + Type = responseOutputsTable.NewValue.GetTableCell(idxRow, 15)?.CellValue.GetAsStringValue(), + Protocol = responseOutputsTable.NewValue.GetTableCell(idxRow, 3)?.CellValue.GetAsStringValue(), + Bitrate = 0,//responseOutputsTable.NewValue.GetTableCell(idxRow, 27)?.CellValue.DoubleValue, + }); + } + + return iotable; + } + } +} \ No newline at end of file diff --git a/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.cs b/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.cs index 695f174..74d1f2e 100644 --- a/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.cs +++ b/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.cs @@ -51,6 +51,9 @@ DATE VERSION AUTHOR COMMENTS namespace DownloadThumbnails_1 { + using Newtonsoft.Json; + using Skyline.DataMiner.Automation; + using Skyline.DataMiner.Net.Messages; using System; using System.Collections.Generic; using System.IO; @@ -59,9 +62,6 @@ namespace DownloadThumbnails_1 using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading.Tasks; - using Newtonsoft.Json; - using Skyline.DataMiner.Automation; - using Skyline.DataMiner.Net.Messages; /// /// Represents a DataMiner Automation script. @@ -79,39 +79,46 @@ public class Script /// Link with SLAutomation process. public void Run(IEngine engine) { - var element = engine.GetDummy("MWCore Element"); - - if (!element.IsActive) + try { - engine.GenerateInformation("[Techex MWCore Thumbnails] Techex MWCore element is not active."); - return; - } + var element = engine.GetDummy("MWCore Element"); - var responseTable = engine.SendSLNetSingleResponseMessage(new GetPartialTableMessage - { - DataMinerID = element.DmaId, - ElementID = element.ElementId, - ParameterID = 8700, // streams, - Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, - }) as ParameterChangeEventMessage; + if (!element.IsActive) + { + engine.GenerateInformation("[Techex MWCore Thumbnails] Techex MWCore element is not active."); + return; + } - if (!responseTable.NewValue.IsArray) - { - engine.GenerateInformation("[Techex MWCore Thumbnails] Thumbnails column empty."); - return; - } + var responseTable = engine.SendSLNetSingleResponseMessage(new GetPartialTableMessage + { + DataMinerID = element.DmaId, + ElementID = element.ElementId, + ParameterID = 8700, // streams, + Filters = new[] { "forceFullTable=true" /*, "column=xx,yy"*/ }, + }) as ParameterChangeEventMessage; + + if (!responseTable.NewValue.IsArray) + { + engine.GenerateInformation("[Techex MWCore Thumbnails] Thumbnails column empty."); + return; + } + + var cols = responseTable.NewValue.ArrayValue[0].ArrayValue; + string[] thumbnails = new string[cols.Length]; + for (int idxRow = 0; idxRow < cols.Length; idxRow++) + { + // start of row 'idxRow' + thumbnails[idxRow] = responseTable.NewValue.GetTableCell(idxRow, 9)?.CellValue.GetAsStringValue().Replace(@"http://https//", "https://"); + } - var cols = responseTable.NewValue.ArrayValue[0].ArrayValue; - string[] thumbnails = new string[cols.Length]; - for (int idxRow = 0; idxRow < cols.Length; idxRow++) + string token = string.Empty; + Task.Run(async () => { token = await Thumbnail.Login(_loginEntrypoint, _user, _password); }).Wait(); + RequestStreamThumbnail(engine, thumbnails, token); + } + catch (Exception ex) { - // start of row 'idxRow' - thumbnails[idxRow] = responseTable.NewValue.GetTableCell(idxRow, 9)?.CellValue.GetAsStringValue().Replace(@"http://https//", "https://"); + engine.ExitFail($"[Techex MWCore Thumbnails] Exception: {ex}"); } - - string token = string.Empty; - Task.Run(async () => { token = await Thumbnail.Login(_loginEntrypoint, _user, _password); }).Wait(); - RequestStreamThumbnail(engine, thumbnails, token); } private static void RequestStreamThumbnail(IEngine engine, IEnumerable thumbnails, string token) @@ -160,7 +167,7 @@ public static string GetStreamName(string url) public static async Task Login(string url, string user, string password) { string token = string.Empty; - using (HttpClient client = new HttpClient()) + using (HttpClient client = new HttpClient(CreateInsecureHandler())) { //login var request = new HttpRequestMessage(HttpMethod.Post, url); diff --git a/MWCoreStatisticsEnable.xml b/MWCoreStatisticsEnable.xml index 6063fec..9d1f348 100644 --- a/MWCoreStatisticsEnable.xml +++ b/MWCoreStatisticsEnable.xml @@ -8,12 +8,6 @@ Techex MWCore - - MWCore Element - Techex MWCore - Production - - @@ -21,7 +15,10 @@ - MWCore Server + MWCore Server ID + + + MWCore Element Name diff --git a/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.cs b/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.cs index 744f2c8..f13b0bc 100644 --- a/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.cs +++ b/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.cs @@ -65,17 +65,19 @@ public class Script /// Link with SLAutomation process. public void Run(IEngine engine) { - var element = engine.GetDummy("MWCore Element"); + var mwcoreServer = engine.GetScriptParam("MWCore Server ID").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); + var mwcoreElementName = engine.GetScriptParam("MWCore Element Name").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); - if (!element.IsActive) + var element = engine.FindElement(mwcoreElementName); + + if (element == null || + !element.IsActive) { - engine.GenerateInformation("[Techex MWCore Statistics] Techex MWCore element is not active."); + engine.GenerateInformation($"[Techex MWCore Statistics] Techex MWCore element is not active! Element Name: {mwcoreElementName}"); return; } string[] servers; - var mwcoreServer = engine.GetScriptParam("MWCore Server").Value; - if (string.IsNullOrWhiteSpace(mwcoreServer) || mwcoreServer.ToUpper() == "ALL") { @@ -88,15 +90,11 @@ public void Run(IEngine engine) foreach (var server in servers) { - var state = Convert.ToString(element.GetParameter(1417, server)); // statistics column - - if (state == "1") // enable - { - continue; - } + var state = Convert.ToString(element.GetParameterByPrimaryKey(1417, server)); // statistics column + var currentState = state.Equals("1"); - engine.GenerateInformation($"[Techex MWCore Statistics] Enable statistics for {server.Replace("[\"", string.Empty).Replace("\"]", string.Empty)}."); - element.SetParameterByPrimaryKey(1417, server.Replace("[\"", string.Empty).Replace("\"]", string.Empty), 1); // enable statistics + engine.GenerateInformation($"[Techex MWCore Statistics] Update statistics connection for {server}."); + element.SetParameterByPrimaryKey(1417, server, currentState ? 0 : 1); // invert state (toggle button) } } }