List Projects
These samples list all projects in a controller and print basic information about each project.
C#
//-----------------------------------------------------------------------
// <copyright file="ListProjects.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Samples
{
using System;
using Microsoft.Windows.Kits.Hardware.ObjectModel;
using Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection;
class ListProjects
{
public static void Main(string[] args)
{
string controllerName = args[1];
// first, connect to the server
ProjectManager manager = new DatabaseProjectManager(controllerName);
// list all projects
Console.WriteLine("Listing all projects");
foreach (string name in manager.GetProjectNames())
{
Console.WriteLine("Project {0}", name);
}
// list all projects, and get the basic status of each
Console.WriteLine("\nGetting all project status");
foreach (ProjectInfo info in manager.GetProjectInfoList())
{
Console.WriteLine("Project {0}", info.Name);
Console.WriteLine("\t status : {0}", info.Status);
Console.WriteLine("\t not run: {0}", info.NotRunCount);
Console.WriteLine("\t passed : {0}", info.PassedCount);
Console.WriteLine("\t Failed : {0}", info.FailedCount);
Console.WriteLine("\t Running: {0}", info.RunningCount);
}
// list all the tests for each project
Console.WriteLine("\nGetting all projects and their tests");
foreach (string name in manager.GetProjectNames())
{
Project project = manager.GetProject(name);
Console.WriteLine("Project name : {0}, status: {1}", project.Name, project.Info.Status);
foreach (ProductInstance pi in project.GetProductInstances())
{
Console.WriteLine("Product Instance : {0}, Machine Pool : {1}, Platform type : {2}", pi.Name, pi.MachinePool.Name, pi.OSPlatform.Description);
foreach (Target target in pi.GetTargets())
{
Console.WriteLine("Target Name : {0}", target.Name);
foreach (Test test in target.GetTests())
{
Console.WriteLine("\tTest : {0}, status : {1}", test.Name, test.Status);
}
}
}
}
}
}
}
Windows PowerShell®
$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dll")
$ObjectModel = [Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "microsoft.windows.Kits.Hardware.objectmodel.dbconnection.dll")
$ControllerName = $args[0]
write-Host "Usage: %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -file ListProjects.ps1 <<ControllerName>>"
# connect to the server
if ($ControllerName -eq $null -OR $ControllerName -eq "")
{
write-host "Need to supply the controller Name as a parameter to this script"
return
}
else
{
write-host connecting to the controller $ControllerName
}
$Manager = new-object -typename Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.DatabaseProjectManager -Args $ControllerName, DTMJobs
$RootPool = $Manager.GetRootMachinePool();
# first, get a list of all projects
write "All project names on this controller"
$Manager.GetProjectNames()
# list all projects, and get the basic status of each
$Manager.GetProjectInfoList() | foreach {
write-host "Name : " $_.Name
write-host "`tStatus : " $_.Status
write-host "`tNotRun : " $_.NotRunCount.ToString()
write-host "`tPassed : " $_.PassedCount
write-host "`tFailed : " $_.FailedCount
write-host "`tRunning: " $_.RunningCount
}
# list all the tests for each project
$Manager.GetProjectNames() | foreach {
$Project = $Manager.GetProject($_)
write-host "Project Name : " $Project.Name
write-host "`tProject Status: " $Project.Info.Status
# list all the product instances
$Project.GetProductInstances() | foreach {
write-host "Product Instance : " $_.Name
write-host "`tMachine pool : " $_.MachinePool.Name
write-host "`tOS Platform : " $_.OSPlatform.Description
$_.GetTargetFamilies() | foreach {
write-host "Target Family : " $_.Family.Name
# get target data
$_.GetTargets() | foreach {
write-host "Target : " $_.Name
write-host "`tType : " $_.TargetType
write-host "`tKey : " $_.Key
# there's more information if this is a device type
$DeviceData = $_ –AS [Microsoft.Windows.Kits.Hardware.ObjectModel.IDeviceTargetData]
if ($DeviceData -ne $null)
{
write-host "`tManufacturer : " $DeviceData.Manufacturer
write-host "`tVendorId : " $DeviceData.VendorId
write-host "`tDeviceClass : " $DeviceData.DeviceClass
write-host "`tInBox : " $DeviceData.AllInboxDrivers
write-host "`tDriver : "
$DeviceData.Drivers
write-host "`tDriverHash : "
$DeviceData.DriverHash
}
# there's more infomation if this is a system type
$SystemData = $_ -AS [Microsoft.Windows. Kits.Hardware.ObjectModel.ISystemTargetData]
if ($SystemData -ne $null)
{
write-host "`tManufacturer : " $SystemData.Manufacturer
write-host "`tModel : " $SystemData.Model
}
# there's more infomation if this is a system type
$FilterData = $_ -AS [Microsoft.Windows. Kits.Hardware.ObjectModel.IFilterTargetData]
if ($FilterData -ne $null)
{
write-host "`tManufacturer : " $FilterData.Manufacturer
write-host "`tVersion : " $FilterData.Version
write-host "`tAllInbox : " $FilterData.AllInboxDrivers
}
write-host "`tFeatures : "
$_.GetFeatures() | foreach {
write-host "`t`t" $_.FullName
$_.GetRequirements() | foreach {
write-host "`t`t`tRequirement: " $_.FullName
}
}
}
# now, list all the tests for this family
write-host "Tests:"
$_.GetTests() | foreach {
write-host "`t" $_.Name -NoNewline
if ($_.GetTestTargets().Count -ne 1)
{ write-host " - shared" }
else
{ write-host " - not shared" }
}
}
}
}