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
22 changes: 13 additions & 9 deletions Sdk/Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>SkylineCommunications</Authors>
<Company>Skyline Communications</Company>
<Description>The Skyline.DataMiner.Sdk is a development kit designed to streamline the creation and management of DataMiner Installation Packages (.dmapp).
By integrating this SDK into your build process, you can easily generate installation packages for DataMiner through a simple project build or compile step. Additionally, it provides tools to publish these packages directly to the DataMiner Catalog, ensuring a smooth and efficient development pipeline.
</Description>
<Description>
The Skyline.DataMiner.Sdk is a development kit designed to streamline the creation and management of DataMiner Installation Packages (.dmapp).
By integrating this SDK into your build process, you can easily generate installation packages for DataMiner through a simple project build or compile step. Additionally, it provides tools to publish these packages directly to the DataMiner Catalog, ensuring a smooth and efficient development pipeline.
</Description>
<RepositoryUrl>https://github.com/SkylineCommunications/Skyline.DataMiner.Sdk</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<NoWarn>1701;1702;NU5100</NoWarn>
<PackageType>MSBuildSdk</PackageType>
<BuildOutputTargetFolder>Sdk</BuildOutputTargetFolder>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
<PackageVersion>0.1.0</PackageVersion>
<PackageVersion>0.0.149</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -41,12 +42,15 @@ By integrating this SDK into your build process, you can easily generate install
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.7" />
<PackageReference Include="Nito.AsyncEx.Tasks" Version="5.1.2" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.1.3" />
<PackageReference Include="Skyline.DataMiner.CICD.Assemblers.Automation" Version="1.2.0" />
<PackageReference Include="Skyline.DataMiner.CICD.Assemblers.Common" Version="1.2.0" />
<PackageReference Include="Skyline.DataMiner.CICD.DMApp.Common" Version="3.0.1" />
<PackageReference Include="Skyline.DataMiner.CICD.Assemblers.Automation" Version="1.1.5" />
<PackageReference Include="Skyline.DataMiner.Core.AppPackageCreator" Version="3.0.2" />
<PackageReference Include="Skyline.DataMiner.Core.ArtifactDownloader" Version="3.0.2" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.3.0" />
<PackageReference Include="Skyline.DataMiner.CICD.Parsers.Common" Version="1.1.3" />
<PackageReference Include="Skyline.DataMiner.Core.AppPackageCreator" Version="3.1.1" />
<PackageReference Include="Skyline.DataMiner.Core.ArtifactDownloader" Version="3.1.1" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.4.0" />
<PackageReference Include="Skyline.DataMiner.CICD.Parsers.Common" Version="1.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Sdk/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Debug="$(SkylineDataMinerSdkDebug)"
/>
</Target>

<Target Name="CatalogInformation" AfterTargets="Build" Condition="'$(GenerateDataMinerPackage)' == 'true'">
<CatalogInformation
ProjectDirectory="$(MSBuildProjectDirectory)"
Expand Down
49 changes: 49 additions & 0 deletions Sdk/Shell/IShell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace Skyline.DataMiner.Sdk.Shell
{
using System;
using System.Runtime.InteropServices;
using System.Threading;

/// <summary>
/// Allows running commands on the shell.
/// </summary>
internal interface IShell
{
/// <summary>
/// Runs the given command on the shell.
/// </summary>
/// <param name="command">The command to run.</param>
/// <param name="output">Any output from running the command.</param>
/// <param name="errors">Any error from the command.</param>
/// <param name="cancellationToken"><see cref="CancellationToken"/> that controls the cancellation of the command.</param>
/// <param name="workingDirectory">Optional working directory in which the command should be run.</param>
/// <returns><see cref="bool.TrueString"/> if there were no errors with the command.</returns>
bool RunCommand(string command, out string output, out string errors, CancellationToken cancellationToken, string workingDirectory = "");
}

/// <summary>
/// Helper methods for <see cref="IShell"/>.
/// </summary>
internal static class ShellFactory
{
/// <summary>
/// Get your shiny shells here! Tailored specifically to your OS!
/// </summary>
/// <returns>Shiny shell.</returns>
/// <exception cref="NotSupportedException">Can't create a shell for this OS.</exception>
public static IShell GetShell()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return new WindowsShell();
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return new UnixShell();
}

throw new NotSupportedException($"The current operating system ({System.Runtime.InteropServices.RuntimeInformation.OSDescription}) is not supported.");
}
}
}
54 changes: 54 additions & 0 deletions Sdk/Shell/UnixShell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace Skyline.DataMiner.Sdk.Shell
{
using System.Diagnostics;
using System.Text;
using System.Threading;

/// <summary>
/// Allows running commands on the unix shell.
/// </summary>
internal class UnixShell : IShell
{
/// <inheritdoc/>
public bool RunCommand(string command, out string output, out string errors, CancellationToken cancellationToken, string workingDirectory = "")
{
StringBuilder outputStream = new StringBuilder();
StringBuilder errorStream = new StringBuilder();
string escapedArgs = command.Replace("\"", "\\\"");
bool success = true;
using (Process cmd = new Process
{
StartInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory
}
})
{
cmd.OutputDataReceived += (_, args) => { outputStream.AppendLine(args.Data); };
cmd.ErrorDataReceived += (_, args) => { errorStream.AppendLine(args.Data); };
cmd.Start();
cmd.BeginOutputReadLine();
cmd.BeginErrorReadLine();
cmd.WaitForExit(300000);// 5 min max wait
if (!cmd.HasExited)
{
success = false;
cmd.Kill();
}

output = outputStream.ToString();
errors = errorStream.ToString();

success &= cmd.ExitCode == 0;
return success;
}
}
}
}
60 changes: 60 additions & 0 deletions Sdk/Shell/WindowsShell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace Skyline.DataMiner.Sdk.Shell
{
using System.Diagnostics;
using System.Text;
using System.Threading;

/// <summary>
/// Allows running commands on the windows shell.
/// </summary>
internal class WindowsShell : IShell
{
/// <inheritdoc/>
public bool RunCommand(string command, out string output, out string errors, CancellationToken cancellationToken, string workingDirectory = "")
{
StringBuilder outputStream = new StringBuilder();
StringBuilder errorStream = new StringBuilder();

bool success = true;
using (Process cmd = new Process
{
// You got to put the entire thing in quotes so the WindowsShell can remove the quotes
// and think there's no quotes while there are quotes which get removed.
// If you don't put the quotes, you have to put more quotes which is too confusing.
// See https://ss64.com/nt/cmd.html
StartInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "runas",
FileName = "cmd.exe",
Arguments = $"/S /C \"{command}\"",
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory
}
})
{

cmd.OutputDataReceived += (_, args) => { outputStream.AppendLine(args.Data); };
cmd.ErrorDataReceived += (_, args) => { errorStream.AppendLine(args.Data); };
cmd.Start();
cmd.BeginOutputReadLine();
cmd.BeginErrorReadLine();
cmd.WaitForExit(300000);// 5 min max wait
if (!cmd.HasExited)
{
success = false;
cmd.Kill();
}

output = outputStream.ToString();
errors = errorStream.ToString();

success &= cmd.ExitCode == 0;
return success;
}
}
}
}
Loading
Loading