Find all the child test suites in TFS using C# - c#

I would like get all the child test suites under a parent test suite in TFS using C# code. Let me know if anyone has done this.

I have create the simple app based on Microsoft.TeamFoundationServer.ExtendedClient
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string teamProjectName = "TFSCMMI";
int parentTestSuiteId = 819; // or test plan id
var TFSCurrentProjectCollection = new TfsTeamProjectCollection(new Uri("http://tfs-srv:8080/tfs/defaultcollection"));
var testStore = TFSCurrentProjectCollection.GetService<ITestManagementService>();
var teamProject = testStore.GetTeamProject(teamProjectName);
var testSuite = teamProject.TestSuites.Find(parentTestSuiteId);
if (testSuite.TestSuiteType == TestSuiteType.StaticTestSuite)
{
var staticSuite = testSuite as IStaticTestSuite;
foreach (var childSuite in staticSuite.Entries)
{
Console.WriteLine("Test suite id " + childSuite.Id + " name '" + childSuite.Title + "'");
}
}
}
}
}

Related

System.NullReferenceException in HRESULT[] results = group.Write(items, values) //TitaniumAS OPCda

i need an opc client for work, i used TitaniumAS as it's really simple, the read works fine but the write doesnt, i have the exception in the title
The tagID is correct as it works when i read it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TitaniumAS.Opc.Client.Common;
using TitaniumAS.Opc.Client.Da;
using TitaniumAS.Opc.Client.Da.Browsing;
using System.Threading;
namespace OPCDA
{
class Program
{
static void Main(string[] args)
{
TitaniumAS.Opc.Client.Bootstrap.Initialize();
Uri url = UrlBuilder.Build("Kepware.KEPServerEX.V6");
using (var server = new OpcDaServer(url))
{
server.Connect();
//creating tag group
OpcDaGroup group = server.AddGroup("MyGroup");
group.IsActive= true;
//Write
OpcDaItem int2 = group.Items.FirstOrDefault(i => i.ItemId == "Channel1.Device1.Woord");
OpcDaItem[] items = { int2 };
object[] values = { 15601 };
HRESULT[] results = group.Write(items, values);
}
}
}
}

Find category's parameter's and combine them in the right order

This code filters elements of certain category and finds and concatenates parameters although what needed is something a little more complex.
First of all, a person needs to be able to choose a category (out of a drop down list) or search and find the necessary ones.
And the second thing is that a user is supposed to specify what parameters he would like to combine (we have shared parameters txt fyi) and choose the order in which they are going to follow one another. Any resource on it or something similar to it would help greatly!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace CombineParameters
{
[Transaction(TransactionMode.Manual)]
public class Class : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
//Application app = uiapp.Application;
Document doc = uidoc.Document;
//Create Filtered Element Collector and Filter
FilteredElementCollector collector = new FilteredElementCollector(doc);
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_DuctFitting);
//Applying Filter
IList <Element> ducts = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
foreach (Element e in ducts)
{
//Get Parameter values
string parameterValue1 = e.LookupParameter("AA").AsString();
string parameterValue2 = e.LookupParameter("BB").AsString();
string parameterValue3 = e.LookupParameter("CC").AsString();
string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;
using (Transaction t = new Transaction(doc, "Set Parameter name"))
{
t.Start();
e.LookupParameter("DD").Set(newValue).ToString();
t.Commit();
}
}
return Result.Succeeded;
}
}
}
You want to combine user selected parameters in a specific order? Why dont you use a simple windows form gui.
Example
command.cs
#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace combineParameters
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Form1 form = new Form1(doc);
//Show Dialouge form
form.ShowDialog();
return Result.Succeeded;
}
}
}
Forms1.cs
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace combineParameters
{
public partial class Form1 : System.Windows.Forms.Form
{
//Class variable
Document revitDoc { get; set; }
public Form1(Document doc)
{
InitializeComponent();
this.revitDoc = doc;
//Create a list of the parameters you want your user to choose from
List<string> stringParameters = new List<string>
{
"textParameter1",
"textParameter2",
"textParameter3",
"textParameter4"
};
//Add list to comboboxes on form
foreach (string parameterName in stringParameters)
{
comboBox1.Items.Insert(0, parameterName);
comboBox2.Items.Insert(0, parameterName);
comboBox3.Items.Insert(0, parameterName);
}
}
private void button1_Click(object sender, EventArgs e)
{
FilteredElementCollector collector = new FilteredElementCollector(revitDoc);
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_DuctFitting);
//Applying Filter
IList<Element> ducts = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
using (Transaction t = new Transaction(revitDoc, "Set Parameter name"))
{
//Use a try and catch for transactions
try
{
t.Start();
foreach (Element duct in ducts)
{
//Get Parameter values
string parameterValue1 = duct.LookupParameter(comboBox1.Text).AsString();
string parameterValue2 = duct.LookupParameter(comboBox2.Text).AsString();
string parameterValue3 = duct.LookupParameter(comboBox3.Text).AsString();
string newValue = parameterValue1 + "-" + parameterValue2 + "-" + parameterValue3;
//do not need .ToString() when setting parameter
duct.LookupParameter("NewParameter").Set(newValue);
}
t.Commit();
}
//Catch with error message
catch (Exception err)
{
TaskDialog.Show("Error", err.Message);
t.RollBack();
}
}
}
}
}
Snip of this example inside Revit:
Example photo

Access TFS field TC Description

I want to get the values of Description of test cases in TFS as shown in the image using C#. let me know if anyone knows how to get this using C#.
You can use below sample to get the value of Description of a specific test case:
With Nuget package Microsoft.TeamFoundationServer.ExtendedClient intalled
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.VisualStudio.Services.Client;
using System;
namespace RetrieveTestCaseDescription
{
class Program
{
static void Main(string[] args)
{
var u = new Uri("http://server:8080/tfs/DefaultCollection");
var c = new VssClientCredentials();
int TestCaseId = 57;
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(u, c);
tpc.EnsureAuthenticated();
ITestManagementService test_service = (ITestManagementService)tpc.GetService(typeof(ITestManagementService));
ITestManagementTeamProject project = test_service.GetTeamProject("ProjectNameHere");
ITestCase testcase = project.TestCases.Find(TestCaseId);
Console.WriteLine(String.Format("{0} - {1}", testcase.Id, testcase.Description));
Console.Read();
}
}
}

Using Google shortenurl API to make short urls

I am trying to use google shorten url to shorten a lot of urls for our project and keep getting an HTTPRequestException unhandled error. The first time I ran it it was asking to locate a .cs file which was not there so I am guessing it is due to that. I just used nugget installer to get this in visual studio. Any ideas?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Apis.Urlshortener.v1;
using Google.Apis.Oauth2;
using Google.Apis.Services;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
namespace ShortenURL
{
class Program
{
static void Main(string[] args)
{
var originalURL = "https://www.google.com/maps/place/Desert+Christian+Schools/#32.2367293,-110.8339121,16.75z/data=!4m7!1m4!3m3!1s0x86d66f1806d996d7:0xe8ac20e8cebb38b9!2s7525+E+Speedway+Blvd,+Tucson,+AZ+85710!3b1!3m1!1s0x86d66f1806d996d7:0x7b90764e4e6a25d8";
string shortUrl = Shorten(originalURL);
Console.WriteLine(shortUrl);
Console.WriteLine("FINISHED");
Console.ReadLine();
}
private const string key = "AIzaSyB3pfstkvAZzEVOy4dNHaKTuNmtDaG3XsI";
public static string Shorten(string url)
{
UrlshortenerService service = new UrlshortenerService(new BaseClientService.Initializer()
{
ApiKey = key,
ApplicationName = "ShortenUrlAHLI"
});
var m = new Google.Apis.Urlshortener.v1.Data.Url();
m.LongUrl = url;
return service.Url.Insert(m).Execute().Id;
}
}
}
//The code workable in my case :)
//VS2017
private static string shorten(string url)
{
UrlshortenerService service = new UrlshortenerService(
new BaseClientService.Initializer() {
ApiKey = "<google-api-key>",
ApplicationName = "<google-app-id>", });
var m = new Google.Apis.Urlshortener.v1.Data.Url();
m.LongUrl = url;
return service.Url.Insert(m).Execute().Id;
}

how to find printer's flow control whether it is hardware or software

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Printing;
using System.IO.Ports;
namespace Printer
{
public partial class portname : Window
{
PrintServer server = new PrintServer();
public portname()
{
this.InitializeComponent();
foreach (PrintQueue queue in server.GetPrintQueues())
{
com_pinter.Items.Add(queue.FullName);
}
var DefaultPrinter = new LocalPrintServer().DefaultPrintQueue;
string default_name=DefaultPrinter.FullName;
txt_dpn.Text = "Default printe is " + " " + default_name.ToUpper();
string default_port = DefaultPrinter.QueuePort.Name;
txt_pn.Text = "PortName is" + " " + default_port.ToUpper();
}
private void com_pinter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
foreach (PrintQueue queue in server.GetPrintQueues())
{
string selecteditem = com_pinter.SelectedItem.ToString();
string portname = queue.FullName;
SerialPort mySerialPort = new SerialPort(queue.QueuePort.Name);
btn_br.Content = mySerialPort.BaudRate;
btn_db.Content = mySerialPort.DataBits;
btn_pty.Content = mySerialPort.Parity;
btn_sb.Content = mySerialPort.StopBits;
if (selecteditem == portname)
{
string select_portname = queue.QueuePort.Name;
txt_pn.Text = "PortName is" + " " + select_portname.ToUpper();
}
}
}
}
}
But i don't know whether this way is correct or not to get output like this(above figure).I just messed up
with this.if you know the correct way,please tell me that way i just upgrade it.
finally i need to find flow control(software or hardware).as per the above figure the combobox has to devices which are software device.so i have to dynamically find that value(s/w or h/w).

Categories

Resources