Skip to content

Commit

Permalink
Added wait logic on performing a service connect/disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesVH committed Aug 29, 2023
1 parent ccfbb32 commit eeab98d
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 22 deletions.
30 changes: 30 additions & 0 deletions CancelService_1/CancelService_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace CancelService_1
/// </summary>
public class Script
{
private static string[] primaryKeysCurrentServices = new string[0];
private static Element nevionVideoIPathElement;

/// <summary>
/// The script entry point.
/// </summary>
Expand All @@ -77,7 +80,17 @@ public static void Run(IEngine engine)
return;
}

nevionVideoIPathElement = engine.FindElementsByProtocol("Nevion Video iPath", "Production").FirstOrDefault();
if (nevionVideoIPathElement == null)
{
engine.ExitFail("Nevion Video iPath element not found!");
return;
}

primaryKeysCurrentServices = nevionVideoIPathElement.GetTablePrimaryKeys(1500); // Used to check if new connection entries has been added after the ConnectServices.

CancelCurrentServices(engine, serviceIds);
VerifyCancelService(engine, serviceIds);
}
catch (Exception e)
{
Expand Down Expand Up @@ -122,5 +135,22 @@ private static bool TryGetIdsFromInput(string input, out List<string> ids)
return false;
}
}

private static void VerifyCancelService(IEngine engine, List<string> serviceIds)
{
int retries = 0;
bool allEntriesFound = false;
int tableEntriesExcludingCurrentDestination = primaryKeysCurrentServices.Length - serviceIds.Count;
while (!allEntriesFound && retries < 100)
{
engine.Sleep(60);

var allPrimaryKeys = nevionVideoIPathElement.GetTablePrimaryKeys(1500);

allEntriesFound = allPrimaryKeys.Length == tableEntriesExcludingCurrentDestination;

retries++;
}
}
}
}
4 changes: 2 additions & 2 deletions CancelService_1/CancelService_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
Expand All @@ -64,7 +64,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\CancelService.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\CancelService.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
43 changes: 36 additions & 7 deletions ConnectServices_1/ConnectServices_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,30 @@ namespace ConnectServices_1
{
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading;
using Newtonsoft.Json;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Core.DataMinerSystem.Automation;
using Skyline.DataMiner.Core.DataMinerSystem.Common;

/// <summary>
/// Represents a DataMiner Automation script.
/// </summary>
public class Script
{
private static string[] primaryKeysCurrentServices = new string[0];
private static Element nevionVideoIPathElement;

/// <summary>
/// The script entry point.
/// </summary>
/// <param name="engine">Link with SLAutomation process.</param>
public static void Run(IEngine engine)
{
engine.SetFlag(RunTimeFlags.NoKeyCaching);

try
{
var sourceDescriptorLabelInputParameter = engine.GetScriptParam("SourceName").Value;
Expand Down Expand Up @@ -123,7 +132,17 @@ public static void Run(IEngine engine)
return;
}

nevionVideoIPathElement = engine.FindElementsByProtocol("Nevion Video iPath", "Production").FirstOrDefault();
if (nevionVideoIPathElement == null)
{
engine.ExitFail("Nevion Video iPath element not found!");
return;
}

primaryKeysCurrentServices = nevionVideoIPathElement.GetTablePrimaryKeys(1500); // Used to check if new connection entries has been added after the ConnectServices.

ConnectServices(engine, sourceName, destinationNames, profileName);
VerifyConnectService(engine, destinationNames);
}
catch (Exception e)
{
Expand All @@ -133,13 +152,6 @@ public static void Run(IEngine engine)

private static void ConnectServices(IEngine engine, string sourceName, List<string> destinationNames, string profile)
{
var nevionVideoIPathElement = engine.FindElementsByProtocol("Nevion Video iPath", "Production").FirstOrDefault();
if (nevionVideoIPathElement == null)
{
engine.ExitFail("Nevion Video iPath element not found!");
return;
}

if (!nevionVideoIPathElement.IsActive)
{
engine.ExitFail("Nevion Video iPath element not active!");
Expand Down Expand Up @@ -168,5 +180,22 @@ private static bool TryGetInputValue(string input, out List<string> labels)
return false;
}
}

private static void VerifyConnectService(IEngine engine, List<string> destinationNames)
{
int retries = 0;
bool allEntriesFound = false;
int tableEntryCountIncludingNewEntries = primaryKeysCurrentServices.Length + destinationNames.Count;
while (!allEntriesFound && retries < 100)
{
engine.Sleep(50);

var allPrimaryKeys = nevionVideoIPathElement.GetTablePrimaryKeys(1500);

allEntriesFound = allPrimaryKeys.Length == tableEntryCountIncludingNewEntries;

retries++;
}
}
}
}
7 changes: 5 additions & 2 deletions ConnectServices_1/ConnectServices_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Core.DataMinerSystem.Automation">
<Version>1.1.0.5</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
Expand All @@ -64,7 +67,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\ConnectServices.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\ConnectServices.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
32 changes: 32 additions & 0 deletions DisconnectServices_1/DisconnectServices_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ namespace DisconnectServices_1
/// </summary>
public class Script
{
private static string[] primaryKeysCurrentServices = new string[0];
private static Element nevionVideoIPathElement;

/// <summary>
/// The script entry point.
/// </summary>
/// <param name="engine">Link with SLAutomation process.</param>
public static void Run(IEngine engine)
{
engine.SetFlag(RunTimeFlags.NoKeyCaching);

try
{
var destinationIdsParameter = engine.GetScriptParam("DestinationIds").Value;
Expand All @@ -79,7 +84,17 @@ public static void Run(IEngine engine)
return;
}

nevionVideoIPathElement = engine.FindElementsByProtocol("Nevion Video iPath", "Production").FirstOrDefault();
if (nevionVideoIPathElement == null)
{
engine.ExitFail("Nevion Video iPath element not found!");
return;
}

primaryKeysCurrentServices = nevionVideoIPathElement.GetTablePrimaryKeys(1500); // Used to check if new connection entries has been added after the ConnectServices.

DisconnectDestinations(engine, destinationIds);
VerifyDisconnectService(engine, destinationIds);
}
catch (Exception e)
{
Expand Down Expand Up @@ -139,5 +154,22 @@ private static bool TryGetIdsFromInput(string input, out List<string> ids)
return false;
}
}

private static void VerifyDisconnectService(IEngine engine, List<string> destinationNames)
{
int retries = 0;
bool allEntriesFound = false;
int tableEntriesExcludingCurrentDestination = primaryKeysCurrentServices.Length - destinationNames.Count;
while (!allEntriesFound && retries < 100)
{
engine.Sleep(60);

var allPrimaryKeys = nevionVideoIPathElement.GetTablePrimaryKeys(1500);

allEntriesFound = allPrimaryKeys.Length == tableEntriesExcludingCurrentDestination;

retries++;
}
}
}
}
4 changes: 2 additions & 2 deletions DisconnectServices_1/DisconnectServices_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Version>1.1.0.5</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
Expand All @@ -70,7 +70,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\DisconnectServices.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\DisconnectServices.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
Expand All @@ -61,7 +61,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\GQI_NevionVideoIPath_GetDestinations.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\GQI_NevionVideoIPath_GetDestinations.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
Expand All @@ -61,7 +61,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\GQI_NevionVideoIPath_GetSources.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\GQI_NevionVideoIPath_GetSources.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
Expand All @@ -61,7 +61,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\GQI_NevionVideoIPath_GetTags.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\GQI_NevionVideoIPath_GetTags.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
26 changes: 25 additions & 1 deletion ScheduleServices_1/ScheduleDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ScheduleDialog : Dialog
private readonly Element nevionVideoIPathElement;

private List<string> destinationNames;
private string[] primaryKeysCurrentServices = new string[0];

public ScheduleDialog(IEngine engine) : base(engine)
{
Expand All @@ -57,10 +58,16 @@ public ScheduleDialog(IEngine engine) : base(engine)
return;
}

primaryKeysCurrentServices = nevionVideoIPathElement.GetTablePrimaryKeys(1500); // Used to check if new connection entries has been added after the ConnectServices.

startRadioButtonList.Changed += (s, o) => HandleStartOptionChanged();
endRadioButtonList.Changed += (s, o) => HandleEndOptionChanged();

ConnectButton.Pressed += (s, o) => TriggerConnectOnElement();
ConnectButton.Pressed += (s, o) =>
{
TriggerConnectOnElement();
VerifyConnectService(); // Temproary untill real time updates are fully supported in the apps.
};

GenerateUI();
}
Expand Down Expand Up @@ -195,6 +202,23 @@ public void TriggerConnectOnElement()
nevionVideoIPathElement.SetParameter(2309, visioString);
}

private void VerifyConnectService()
{
int retries = 0;
bool allEntriesFound = false;
int tableEntryCountIncludingNewEntries = primaryKeysCurrentServices.Length + DestinationNames.Count;
while (!allEntriesFound && retries < 100)
{
Engine.Sleep(50);

var allPrimaryKeys = nevionVideoIPathElement.GetTablePrimaryKeys(1500);

allEntriesFound = allPrimaryKeys.Length == tableEntryCountIncludingNewEntries;

retries++;
}
}

private void HandleStartOptionChanged()
{
var startSelection = startRadioButtonList.Selected;
Expand Down
7 changes: 5 additions & 2 deletions ScheduleServices_1/ScheduleServices_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Core.DataMinerSystem.Automation">
<Version>1.1.0.5</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Dev.Automation">
<Version>10.3.6</Version>
<Version>10.3.9</Version>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Utils.InteractiveAutomationScriptToolkit">
<Version>6.1.0</Version>
Expand All @@ -68,7 +71,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\ScheduleServices.xml" DisProjectType="automationScriptProject" DisLinkId="1" />
<UserProperties DisLinkId="1" DisProjectType="automationScriptProject" DisLinkedXmlFile="..\ScheduleServices.xml" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit eeab98d

Please sign in to comment.