Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Assemblers.Automation/AutomationScriptBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ private void ProcessLibAssemblies(EditXml.XmlElement editExe, BuildResultItems b

foreach (string dir in directoriesWithExplicitDllImport)
{
string packageName = dir.Split('\\').First(); // Fixed to windows directory separator
string packageName = ExtractPackageName(dir);

LogDebug($"ProcessLibAssemblies|Build nugetPackages|Dir: {dir}|PackageName: {packageName}");
nugetPackages.Add(packageName);
}

foreach (string dir in nugetAssemblyData.DllImportDirectoryReferences)
{
string packageName = dir.Split('\\').First(); // Fixed to windows directory separator
string packageName = ExtractPackageName(dir);

LogDebug($"ProcessLibAssemblies|DllImportDirectoryReferences|Check to add|Dir: {dir}|PackageName: {packageName}");
if (nugetPackages.Contains(packageName))
Expand All @@ -279,6 +279,11 @@ private void ProcessLibAssemblies(EditXml.XmlElement editExe, BuildResultItems b
buildResultItems.Assemblies.Add(libItem);
}
}

string ExtractPackageName(string dir)
{
return dir.StartsWith("SolutionLibraries\\") ? dir.Split('\\')[1] : dir.Split('\\').First(); // Fixed to windows directory separator
}
}

private void AddAssemblyParamReferences(EditXml.XmlElement editExe, HashSet<string> directoriesWithExplicitDllImport, Dictionary<string, string> potentialRemainingDirectoryImports, Dictionary<string, List<PackageAssemblyReference>> assemblies)
Expand Down
98 changes: 96 additions & 2 deletions Assemblers.AutomationTests/AutomationScriptBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using FluentAssertions;
Expand Down Expand Up @@ -786,7 +787,7 @@ public async Task SLDisCompiler_AutomationScriptBuilder_Yle_Library()
}

[TestMethod]
public async Task AutomationScriptBuilder_SolutionLibraries()
public async Task AutomationScriptBuilder_SolutionLibraries_SingleStandalone()
{
var baseDir = FileSystem.Instance.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var dir = FileSystem.Instance.Path.GetFullPath(FileSystem.Instance.Path.Combine(baseDir, @"TestFiles\Projects\Project1"));
Expand All @@ -805,11 +806,104 @@ public async Task AutomationScriptBuilder_SolutionLibraries()
result.Should().NotBeNull();
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\ModSolutionLib\\Skyline.DataMiner.Dev.Utils.ModSolutionLib.dll</Param>");
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\DummySolutionLib\\Skyline.DataMiner.Dev.Utils.DummySolutionLib.dll</Param>");

// Only needs to be referenced, shouldn't be part of the script itself
result.Assemblies.Should().BeEmpty();
result.DllAssemblies.Should().BeEmpty();
}

[TestMethod]
public async Task AutomationScriptBuilder_SolutionLibraries_StandAlone_DependingOnAnother()
{
var baseDir = FileSystem.Instance.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var dir = FileSystem.Instance.Path.GetFullPath(FileSystem.Instance.Path.Combine(baseDir, @"TestFiles\Projects\Project2"));
var path = FileSystem.Instance.Path.Combine(dir, "Project2.csproj");

var projects = new Dictionary<string, Project>
{
{ "Project2", Project.Load(path) },
};

Script script = Script.Load(FileSystem.Instance.Path.Combine(dir, "Project2.xml"));
AutomationScriptBuilder builder = new AutomationScriptBuilder(script, projects, new List<Script> { script }, directoryForNuGetConfig: null);

var result = await builder.BuildAsync().ConfigureAwait(false);

result.Should().NotBeNull();
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\DummySolutionLib\\Skyline.DataMiner.Dev.Utils.DummySolutionLib.dll</Param>");
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\DummySolutionLib.Automation\\Skyline.DataMiner.Dev.Utils.DummySolutionLib.Automation.dll</Param>");

// Only needs to be referenced, shouldn't be part of the script itself
result.Assemblies.Should().BeEmpty();
result.DllAssemblies.Should().BeEmpty();
}

[TestMethod]
public async Task AutomationScriptBuilder_SolutionLibraries_WithDependencies_DependingOnAnother()
{
var baseDir = FileSystem.Instance.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var dir = FileSystem.Instance.Path.GetFullPath(FileSystem.Instance.Path.Combine(baseDir, @"TestFiles\Projects\Project3"));
var path = FileSystem.Instance.Path.Combine(dir, "Project3.csproj");

var projects = new Dictionary<string, Project>
{
{ "Project3", Project.Load(path) },
};

Script script = Script.Load(FileSystem.Instance.Path.Combine(dir, "Project3.xml"));
AutomationScriptBuilder builder = new AutomationScriptBuilder(script, projects, new List<Script> { script }, directoryForNuGetConfig: null);

var result = await builder.BuildAsync().ConfigureAwait(false);

result.Should().NotBeNull();
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\DummySolutionLib.Deps\\Skyline.DataMiner.Dev.Utils.DummySolutionLib.Deps.dll</Param>");
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\DummySolutionLib.Deps.Protocol\\Skyline.DataMiner.Dev.Utils.DummySolutionLib.Deps.Protocol.dll</Param>");

// Only needs to be referenced, shouldn't be part of the script itself
result.Assemblies.Should().HaveCount(1);
result.Assemblies.First().DllImport.Should().Be("newtonsoft.json\\13.0.2\\lib\\net45\\Newtonsoft.Json.dll");
result.DllAssemblies.Should().BeEmpty();
}

[TestMethod]
public async Task AutomationScriptBuilder_SolutionLibraries_WithDependencies_CustomDependency()
{
var baseDir = FileSystem.Instance.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var dir = FileSystem.Instance.Path.GetFullPath(FileSystem.Instance.Path.Combine(baseDir, @"TestFiles\Projects\Project4"));
var path = FileSystem.Instance.Path.Combine(dir, "Project4.csproj");

var projects = new Dictionary<string, Project>
{
{ "Project4", Project.Load(path) },
};

Script script = Script.Load(FileSystem.Instance.Path.Combine(dir, "Project4.xml"));
AutomationScriptBuilder builder = new AutomationScriptBuilder(script, projects, new List<Script> { script }, directoryForNuGetConfig: null);

var result = await builder.BuildAsync().ConfigureAwait(false);

result.Should().NotBeNull();
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\newtonsoft.json\\13.0.4\\lib\\net45\\Newtonsoft.Json.dll</Param>");
result.Document.Should()
.ContainEquivalentOf(
"<Param type=\"ref\">C:\\Skyline DataMiner\\ProtocolScripts\\DllImport\\SolutionLibraries\\DummySolutionLib.Deps\\Skyline.DataMiner.Dev.Utils.DummySolutionLib.Deps.dll</Param>");

// Only needs to be referenced, shouldn't be part of the script itself
result.Assemblies.Should().HaveCount(2);
result.Assemblies.Should().Contain(a => a.DllImport == "newtonsoft.json\\13.0.4\\lib\\net45\\Newtonsoft.Json.dll");
result.Assemblies.Should().Contain(a => a.DllImport == "newtonsoft.json\\13.0.2\\lib\\net45\\Newtonsoft.Json.dll");
result.DllAssemblies.Should().BeEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Skyline.DataMiner.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<DataMinerType>AutomationScript</DataMinerType>
<GenerateDataMinerPackage>False</GenerateDataMinerPackage>
<MinimumRequiredDmVersion>10.3.0.0 - 12752</MinimumRequiredDmVersion>
<Version>1.0.0</Version>
<VersionComment>Initial Version</VersionComment>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.3.0.25" />
<PackageReference Include="Skyline.DataMiner.Utils.SecureCoding.Analyzers" Version="2.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Skyline.DataMiner.Dev.Utils.ModSolutionLib" Version="1.0.0" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<DataMinerType>AutomationScript</DataMinerType>
<GenerateDataMinerPackage>False</GenerateDataMinerPackage>
<MinimumRequiredDmVersion>10.3.0.0 - 12752</MinimumRequiredDmVersion>
<Version>1.0.0</Version>
<VersionComment>Initial Version</VersionComment>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.3.0.25" />
<PackageReference Include="Skyline.DataMiner.Dev.Utils.DummySolutionLib" Version="1.0.1" />
<PackageReference Include="Skyline.DataMiner.Utils.SecureCoding.Analyzers" Version="2.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
107 changes: 107 additions & 0 deletions Assemblers.AutomationTests/TestFiles/Projects/Project2/Project2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
****************************************************************************
* Copyright (c) 2025, Skyline Communications NV All Rights Reserved. *
****************************************************************************

By using this script, you expressly agree with the usage terms and
conditions set out below.
This script and all related materials are protected by copyrights and
other intellectual property rights that exclusively belong
to Skyline Communications.

A user license granted for this script is strictly for personal use only.
This script may not be used in any way by anyone without the prior
written consent of Skyline Communications. Any sublicensing of this
script is forbidden.

Any modifications to this script by the user are only allowed for
personal use and within the intended purpose of the script,
and will remain the sole responsibility of the user.
Skyline Communications will not be responsible for any damages or
malfunctions whatsoever of the script resulting from a modification
or adaptation by the user.

The content of this script is confidential information.
The user hereby agrees to keep this confidential information strictly
secret and confidential and not to disclose or reveal it, in whole
or in part, directly or indirectly to any person, entity, organization
or administration without the prior written consent of
Skyline Communications.

Any inquiries can be addressed to:

Skyline Communications NV
Ambachtenstraat 33
B-8870 Izegem
Belgium
Tel. : +32 51 31 35 69
Fax. : +32 51 31 01 29
E-mail : info@skyline.be
Web : www.skyline.be
Contact : Ben Vandenberghe

****************************************************************************
Revision History:

DATE VERSION AUTHOR COMMENTS

11/09/2025 1.0.0.1 AMA, Skyline Initial version
****************************************************************************
*/

namespace Project2
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Skyline.DataMiner.Automation;

/// <summary>
/// Represents a DataMiner Automation script.
/// </summary>
public class Script
{
/// <summary>
/// The script entry point.
/// </summary>
/// <param name="engine">Link with SLAutomation process.</param>
public void Run(IEngine engine)
{
try
{
RunSafe(engine);
}
catch (ScriptAbortException)
{
// Catch normal abort exceptions (engine.ExitFail or engine.ExitSuccess)
throw; // Comment if it should be treated as a normal exit of the script.
}
catch (ScriptForceAbortException)
{
// Catch forced abort exceptions, caused via external maintenance messages.
throw;
}
catch (ScriptTimeoutException)
{
// Catch timeout exceptions for when a script has been running for too long.
throw;
}
catch (InteractiveUserDetachedException)
{
// Catch a user detaching from the interactive script by closing the window.
// Only applicable for interactive scripts, can be removed for non-interactive scripts.
throw;
}
catch (Exception e)
{
engine.ExitFail("Run|Something went wrong: " + e);
}
}

private void RunSafe(IEngine engine)
{
// TODO: Define code here
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Skyline.DataMiner.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<DataMinerType>AutomationScript</DataMinerType>
<GenerateDataMinerPackage>False</GenerateDataMinerPackage>
<MinimumRequiredDmVersion>10.3.0.0 - 12752</MinimumRequiredDmVersion>
<Version>1.0.0</Version>
<VersionComment>Initial Version</VersionComment>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.3.0.25" />
<PackageReference Include="Skyline.DataMiner.Dev.Utils.DummySolutionLib.Automation" Version="1.0.1" />
<PackageReference Include="Skyline.DataMiner.Utils.SecureCoding.Analyzers" Version="2.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<DMSScript options="272" xmlns="http://www.skyline.be/automation">
<Name>Project2</Name>
<Description></Description>
<Type>Automation</Type>
<Author>AMA</Author>
<CheckSets>FALSE</CheckSets>
<Folder></Folder>

<Protocols>
</Protocols>

<Memory>
</Memory>

<Parameters>
</Parameters>

<Script>
<Exe id="1" type="csharp">
<Value><![CDATA[[Project:Project2]]]></Value>
<!--<Param type="debug">true</Param>-->
<Message></Message>
</Exe>
</Script>
</DMSScript>
Loading