Certainly! You can write the same logic in C# or C++ as well. Below are examples in C# and C++ for automating the process of running an HLK sub-test:
C# example:
-
First, you'll need to add a reference to the Microsoft.Hpc.Scheduler.Properties COM library in your C# project.
-
Then, use the following C# code to implement the automation:
using System;
using Microsoft.Hpc.Scheduler;
namespace HLKAutomation
{
class Program
{
static void Main(string[] args)
{
string controllerName = "YourControllerName";
string controllerPass = "YourControllerPassword";
string productId = "YourProductId";
string desiredSubTestName = "YourSubTestName";
// Connect to HLK Controller
HpcClient hpcController = new HpcClient();
bool isConnected = hpcController.Connect(controllerName, controllerPass, "HpcTask", string.Empty);
if (!isConnected)
{
Console.WriteLine("Failed to connect to HLK Controller");
return;
}
Console.WriteLine("Connected to HLK Controller");
// Create a test selection
int selectionId = hpcController.CreateTestSelection(productId, string.Empty);
Console.WriteLine($"Created test selection with ID: {selectionId}");
// Find the sub-test
System.Data.DataTable subTests = hpcController.QueryDataTable($"SELECT * FROM item WHERE parent={selectionId} AND criteriaName='{desiredSubTestName}'");
if (subTests.Rows.Count == 0)
{
Console.WriteLine($"Failed to find sub-test: {desiredSubTestName}");
return;
}
int subTestId = (int)subTests.Rows[0]["id"];
// Set the sub-test to 'Selected' status
hpcController.ChangeSelectionItemsState("item", subTestId, "Selected");
Console.WriteLine($"Selected sub-test: {desiredSubTestName}");
// Run the test selection
int testResultId = hpcController.RunSelection(selectionId);
Console.WriteLine($"Running test selection with ID: {testResultId}");
}
}
}
C++ example:
- First, import the Microsoft HPC Scheduler library by adding the following line at the beginning of your C++ source file:
#import "libid:F45054ED-F71E-4FBE-B094-C25F3D6E3272" raw_interfaces_only
- Then, implement the automation using C++:
#include <iostream>
#include <comdef.h>
#include <string>
int main()
{
HRESULT hr;
CoInitialize(NULL);
std::string controllerName = "YourControllerName";
std::string controllerPass = "YourControllerPassword";
std::string productId = "YourProductId";
std::string desiredSubTestName = "YourSubTestName";
// Connect to HLK Controller
HpcScheduler::IHpcClientPtr hpcController;
hr = hpcController.CreateInstance(CLSID_HpcClient);
VARIANT_BOOL isConnected = hpcController->Connect(_bstr_t(controllerName.c_str()), _bstr_t(controllerPass.c_str()), L"HpcTask", L"");
if (!isConnected)
{
std::cout << "Failed to connect to HLK Controller" << std::endl;
return 1;
}
std::cout << "Connected to HLK Controller" << std::endl;
// Create a test selection
int selectionId = hpcController->CreateTestSelection(_bstr_t(productId.c_str()), L"");
std::cout << "Created test selection with ID: " << selectionId << std::endl;
// Find the sub-test
std::string query = "SELECT * FROM item WHERE parent=" + std::to_string(selectionId) + " AND criteriaName='" + desiredSubTestName + "'";
_variant_t result = hpcController->QueryDataTable(_bstr_t(query.c_str()));
_variant_t index = 0;
_variant_t index2 = 1;
System::Data::IDataReaderPtr dataReader = result;
_recordsetPtr recordSet = result;
// Check if record is found
if (recordSet->EndOfFile)
{
std::cout << "Failed to find sub-test: " << desiredSubTestName << std::endl;
return 1;
}
int subTestId = recordSet->Fields->GetItem(L"id")->Value;
// Set the sub-test to 'Selected' status
hpcController->ChangeSelectionItemsState(L"item", subTestId, L"Selected");
std::cout << "Selected sub-test: " << desiredSubTestName << std::endl;
// Run the test selection
int testResultId = hpcController->RunSelection(selectionId);
std::cout << "Running test selection with ID: " << testResultId << std::endl;
CoUninitialize();
return 0;
}
These code snippets demonstrate automation using C# and C++. Replace the placeholders with your actual values before running the program.