Skip to content

Commit

Permalink
Changed the way the context menu works. Now you can more easily add/r…
Browse files Browse the repository at this point in the history
…emove repos from automation scripts.
  • Loading branch information
ArneMaes0 committed Oct 4, 2023
1 parent edf2248 commit c651e59
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 71 deletions.
7 changes: 7 additions & 0 deletions Github Repositories.sln
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QAction_20002", "QAction_20
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QAction_1000", "QAction_1000\QAction_1000.csproj", "{F7D9E6DA-41CE-4E67-A97A-B488A1C90789}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QAction_992", "QAction_992\QAction_992.csproj", "{85D4D206-8B0B-43BA-8418-DA33830C89CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -100,6 +102,10 @@ Global
{F7D9E6DA-41CE-4E67-A97A-B488A1C90789}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7D9E6DA-41CE-4E67-A97A-B488A1C90789}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7D9E6DA-41CE-4E67-A97A-B488A1C90789}.Release|Any CPU.Build.0 = Release|Any CPU
{85D4D206-8B0B-43BA-8418-DA33830C89CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85D4D206-8B0B-43BA-8418-DA33830C89CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85D4D206-8B0B-43BA-8418-DA33830C89CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85D4D206-8B0B-43BA-8418-DA33830C89CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -115,6 +121,7 @@ Global
{E4642BA2-9203-4C98-AB7D-3EBABC459A4C} = {77F7B07D-4C5F-4834-BEC5-125EF4CE7826}
{47B6EC15-12BC-4E67-B2A4-A1A50444CFD7} = {77F7B07D-4C5F-4834-BEC5-125EF4CE7826}
{F7D9E6DA-41CE-4E67-A97A-B488A1C90789} = {77F7B07D-4C5F-4834-BEC5-125EF4CE7826}
{85D4D206-8B0B-43BA-8418-DA33830C89CD} = {77F7B07D-4C5F-4834-BEC5-125EF4CE7826}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EFA33921-4F58-45A6-8D24-D32EC63BAF90}
Expand Down
15 changes: 15 additions & 0 deletions QAction_1/Tables/RepositoriesTable/AddRepositoriesTableRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Skyline.Protocol.Tables
{
public class AddRepositoriesTableRequest : IRepositoriesTableRequest
{
public AddRepositoriesTableRequest(string owner, string name)
{
Action = RepositoryTableAction.Add;
Data = new[] { owner, name };
}

public RepositoryTableAction Action { get; }

public string[] Data { get; }
}
}
15 changes: 15 additions & 0 deletions QAction_1/Tables/RepositoriesTable/IRepositoriesTableRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Skyline.Protocol.Tables
{
public enum RepositoryTableAction
{
Add,
Remove,
}

public interface IRepositoriesTableRequest
{
RepositoryTableAction Action { get; }

string[] Data { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Skyline.Protocol.Tables
{
public class RemoveRepositoriesTableRequest : IRepositoriesTableRequest
{
public RemoveRepositoriesTableRequest(params string[] keys)
{
Action = RepositoryTableAction.Remove;
Data = keys;
}

public RepositoryTableAction Action { get; }

public string[] Data { get; }
}
}
2 changes: 1 addition & 1 deletion QAction_2/QAction_2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Run(SLProtocol protocol)
{
try
{
PollManager.InitPollManagerTableSettings(protocol);
PollManager.InitPollManagerTableSettings(protocol, true);
}
catch (Exception ex)
{
Expand Down
73 changes: 4 additions & 69 deletions QAction_990/ContextMenuRepositoriesTable.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace QAction_990
{
using Newtonsoft.Json;

using Skyline.DataMiner.Scripting;
using Skyline.DataMiner.Utils.Table.ContextMenu;
using Skyline.Protocol.Extensions;
using Skyline.Protocol.Tables;
using System;
using System.Linq;
using SLNetMessages = Skyline.DataMiner.Net.Messages;

internal enum Action
{
Expand All @@ -27,81 +25,18 @@ public override void ProcessContextMenuAction()
{
case Action.Add:
Protocol.Log("QA" + Protocol.QActionID + "|ContextMenuRepositoriesTable|ProcessContextMenuAction|Add", LogType.DebugInfo, LogLevel.NoLogging);
Add();
Protocol.SetParameter(Parameter.repositories_changerequest, JsonConvert.SerializeObject(new AddRepositoriesTableRequest(Data[1], Data[0])));
break;

case Action.Deleteselectedrow_40_s_41_:
Protocol.Log("QA" + Protocol.QActionID + "|ContextMenuRepositoriesTable|ProcessContextMenuAction|Deleteselectedrow_40_s_41_", LogType.DebugInfo, LogLevel.NoLogging);
Delete();
Protocol.SetParameter(Parameter.repositories_changerequest, JsonConvert.SerializeObject(new RemoveRepositoriesTableRequest(Data)));
break;

default:
Protocol.Log("QA" + Protocol.QActionID + "|ContextMenuRepositoriesTable|Process|Unexpected ContextMenu value '" + ActionRaw + "'", LogType.Error, LogLevel.NoLogging);
break;
}
}

private void Add()
{
var row = new RepositoriesTableRow
{
FullName = $"{Data[1]}/{Data[0]}",
Name = Data[0],
Owner = Data[1],
};

row.SaveToProtocol(Protocol);
}

private void Delete()
{
Protocol.DeleteRow(Parameter.Repositories.tablePid, Data);
Protocol.Log($"QA{Protocol.QActionID}|Delete|Repositories|Deleting '{Data.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);

foreach (var rowId in Data)
{
// Delete Linked Tags
var tagsIdx = new uint[]
{
Parameter.Repositorytags.Idx.repositorytagsid,
Parameter.Repositorytags.Idx.repositorytagsrepositoryid,
};
var tagRows = ((object[])Protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositorytags.tablePid, tagsIdx))
.Select(col => Array.ConvertAll((object[])col, Convert.ToString))
.ToRows()
.Where(row => row[1] == rowId)
.Select(row => row[0]);
Protocol.Log($"QA{Protocol.QActionID}|Delete|{rowId}|Tags|Deleting '{tagRows.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);
Protocol.DeleteRow(Parameter.Repositorytags.tablePid, tagRows.ToArray());

// Delete Linked Releases
var releasesIdx = new uint[]
{
Parameter.Repositoryreleases.Idx.repositoryreleasesinstance,
Parameter.Repositoryreleases.Idx.repositoryreleasesrepositoryid,
};
var releaseRows = ((object[])Protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositoryreleases.tablePid, releasesIdx))
.Select(col => Array.ConvertAll((object[])col, Convert.ToString))
.ToRows()
.Where(row => row[1] == rowId)
.Select(row => row[0]);
Protocol.Log($"QA{Protocol.QActionID}|Delete|{rowId}|Releases|Deleting '{releaseRows.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);
Protocol.DeleteRow(Parameter.Repositoryreleases.tablePid, releaseRows.ToArray());

// Delete Linked Issues
var issuesIdx = new uint[]
{
Parameter.Repositoryissues.Idx.repositoryissuesinstance,
Parameter.Repositoryissues.Idx.repositoryissuesrepositoryid,
};
var issuesRows = ((object[])Protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositoryissues.tablePid, issuesIdx))
.Select(col => Array.ConvertAll((object[])col, Convert.ToString))
.ToRows()
.Where(row => row[1] == rowId)
.Select(row => row[0]);
Protocol.Log($"QA{Protocol.QActionID}|Delete|{rowId}|Issues|Deleting '{issuesRows.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);
Protocol.DeleteRow(Parameter.Repositoryissues.tablePid, issuesRows.ToArray());
}
}
}
}
1 change: 1 addition & 0 deletions QAction_990/QAction_990.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ProjectReference Include="..\QAction_Helper\QAction_Helper.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Skyline.DataMiner.Dev.Protocol" Version="10.3.9" />
<PackageReference Include="Skyline.DataMiner.Utils.Table.ContextMenu" Version="1.0.0.1" />
</ItemGroup>
Expand Down
119 changes: 119 additions & 0 deletions QAction_992/QAction_992.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

using Newtonsoft.Json;

using Skyline.DataMiner.Scripting;
using Skyline.Protocol.Extensions;
using Skyline.Protocol.Tables;

using SLNetMessages = Skyline.DataMiner.Net.Messages;

/// <summary>
/// DataMiner QAction Class.
/// </summary>
public static class QAction
{
/// <summary>
/// The QAction entry point.
/// </summary>
/// <param name="protocol">Link with SLProtocol process.</param>
public static void Run(SLProtocol protocol)
{
try
{
var param = Convert.ToString(protocol.GetParameter(Parameter.repositories_changerequest));
var request = JsonConvert.DeserializeObject<RepositoryTableRequest>(param);
switch (request.Action)
{
case RepositoryTableAction.Add:
Add(protocol, request);
break;

case RepositoryTableAction.Remove:
Delete(protocol, request);
break;

default:
throw new NotSupportedException("The give action is not supported yet.");
}
}
catch (Exception ex)
{
protocol.Log($"QA{protocol.QActionID}|{protocol.GetTriggerParameter()}|Run|Exception thrown:{Environment.NewLine}{ex}", LogType.Error, LogLevel.NoLogging);
}
}

private static void Add(SLProtocol protocol, IRepositoriesTableRequest request)
{
var row = new RepositoriesTableRow
{
FullName = $"{request.Data[0]}/{request.Data[1]}",
Owner = request.Data[0],
Name = request.Data[1],
};

row.SaveToProtocol(protocol);
}

private static void Delete(SLProtocol protocol, IRepositoriesTableRequest request)
{
protocol.DeleteRow(Parameter.Repositories.tablePid, request.Data);
protocol.Log($"QA{protocol.QActionID}|Delete|Repositories|Deleting '{request.Data.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);

foreach (var rowId in request.Data)
{
// Delete Linked Tags
var tagsIdx = new uint[]
{
Parameter.Repositorytags.Idx.repositorytagsid,
Parameter.Repositorytags.Idx.repositorytagsrepositoryid,
};
var tagRows = ((object[])protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositorytags.tablePid, tagsIdx))
.Select(col => Array.ConvertAll((object[])col, Convert.ToString))
.ToRows()
.Where(row => row[1] == rowId)
.Select(row => row[0]);
protocol.Log($"QA{protocol.QActionID}|Delete|{rowId}|Tags|Deleting '{tagRows.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);
protocol.DeleteRow(Parameter.Repositorytags.tablePid, tagRows.ToArray());

// Delete Linked Releases
var releasesIdx = new uint[]
{
Parameter.Repositoryreleases.Idx.repositoryreleasesinstance,
Parameter.Repositoryreleases.Idx.repositoryreleasesrepositoryid,
};
var releaseRows = ((object[])protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositoryreleases.tablePid, releasesIdx))
.Select(col => Array.ConvertAll((object[])col, Convert.ToString))
.ToRows()
.Where(row => row[1] == rowId)
.Select(row => row[0]);
protocol.Log($"QA{protocol.QActionID}|Delete|{rowId}|Releases|Deleting '{releaseRows.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);
protocol.DeleteRow(Parameter.Repositoryreleases.tablePid, releaseRows.ToArray());

// Delete Linked Issues
var issuesIdx = new uint[]
{
Parameter.Repositoryissues.Idx.repositoryissuesinstance,
Parameter.Repositoryissues.Idx.repositoryissuesrepositoryid,
};
var issuesRows = ((object[])protocol.NotifyProtocol((int)SLNetMessages.NotifyType.NT_GET_TABLE_COLUMNS, Parameter.Repositoryissues.tablePid, issuesIdx))
.Select(col => Array.ConvertAll((object[])col, Convert.ToString))
.ToRows()
.Where(row => row[1] == rowId)
.Select(row => row[0]);
protocol.Log($"QA{protocol.QActionID}|Delete|{rowId}|Issues|Deleting '{issuesRows.Count()}' rows", LogType.DebugInfo, LogLevel.NoLogging);
protocol.DeleteRow(Parameter.Repositoryissues.tablePid, issuesRows.ToArray());
}
}
}

internal class RepositoryTableRequest : IRepositoriesTableRequest
{
public RepositoryTableAction Action { get; set; }

public string[] Data { get; set; }
}
21 changes: 21 additions & 0 deletions QAction_992/QAction_992.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<Company>Skyline Communications</Company>
<Copyright>© Skyline Communications</Copyright>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\QAction_1\QAction_1.csproj" />
<ProjectReference Include="..\QAction_Helper\QAction_Helper.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Skyline.DataMiner.Dev.Protocol" Version="10.3.9" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties DisLinkedXmlFile="..\protocol.xml" DisProjectType="qactionProject" DisLinkId="992" />
</VisualStudio>
</ProjectExtensions>
</Project>
12 changes: 12 additions & 0 deletions QAction_Helper/QAction_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public static class Parameter
public const int addrepositoryowner_502 = 502;
/// <summary>PID: 502 | Type: read</summary>
public const int addrepositoryowner = 502;
/// <summary>PID: 992 | Type: read</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public const int repositories_changerequest_992 = 992;
/// <summary>PID: 992 | Type: read</summary>
public const int repositories_changerequest = 992;
/// <summary>PID: 996 | Type: read</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public const int repositoriesoverview_996 = 996;
Expand Down Expand Up @@ -862,6 +867,8 @@ public interface SLProtocolExt : SLProtocol
object Addrepositoryowner_602 { get; set; }
object Repositories_contextmenu_990 { get; set; }
object Repositories_contextmenu { get; set; }
object Repositories_changerequest_992 { get; set; }
object Repositories_changerequest { get; set; }
object Repositoriesoverview_996 { get; set; }
object Repositoriesoverview { get; set; }
object Repositoriesfullname_1001 { get; set; }
Expand Down Expand Up @@ -1131,6 +1138,11 @@ public class ConcreteSLProtocolExt : ConcreteSLProtocol, SLProtocolExt
public System.Object Repositories_contextmenu_990 {get { return GetParameter(990); }set { SetParameter(990, value); }}
/// <summary>PID: 990 | Type: write | DISCREETS: Add... = 1, Delete selected row(s) = 2</summary>
public System.Object Repositories_contextmenu {get { return Write.Repositories_contextmenu; }set { Write.Repositories_contextmenu = value; }}
/// <summary>PID: 992 | Type: read</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public System.Object Repositories_changerequest_992 {get { return GetParameter(992); }set { SetParameter(992, value); }}
/// <summary>PID: 992 | Type: read</summary>
public System.Object Repositories_changerequest {get { return GetParameter(992); }set { SetParameter(992, value); }}
/// <summary>PID: 996 | Type: read</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public System.Object Repositoriesoverview_996 {get { return GetParameter(996); }set { SetParameter(996, value); }}
Expand Down
Loading

0 comments on commit c651e59

Please sign in to comment.