I can get connected to HP ALM via c# OTA no problem. It's what is supposed to happen next that isn't clear. I have looked all over HPs documentation for OTA but not much there in regards to updating a test run.
I can make a connection to ALM no problem. I then create a TestSetFactory and RunFactory. I don't know what to do from here. I'm trying to add a run for a particular test set in ALM. I want to add a run and set it to either Pass or Fail and add a comment.
TestSetFactory tsFactory = (TestSetFactory)qcConn.TestSetFactory;
RunFactory runFactory = (RunFactory)qcConn.RunFactory();
Does anyone know how to do this? Is there a previous post that I can't find? Please give me the link and I will happily go there.
If anyone else has figured this out can you please post your code?
Okay, after much trial and error I figured it out. I'm sure there are easier ways to do it but I haven't figured them out yet.
To create a run and update it's status and that of it's steps here's what you need to run:
//This assumes you are already connected to ALM and your project.
string testFolder = #"Root\whatever your folder name is";
TestSetFactory tstFactory = (TestSetFactory)qcConn.TestSetFactory;
TestSetTreeManager tsTreeMgr = (TestSetTreeManager)qcConn.TestSetTreeManager;
TestSetFolder tsFolder = (TestSetFolder)tsTreeMgr.get_NodeByPath(testFolder);
List tsList = tsFolder.FindTestSets("MyTestSet", false, null);
foreach (TestSet ts in tsList)
{
TestSetFolder tstFolder = (TestSetFolder)ts.TestSetFolder;
TSTestFactory tsTestFactory = (TSTestFactory)ts.TSTestFactory;
List mylist = tsTestFactory.NewList("");
foreach (TSTest tsTest in mylist)
{
RunFactory runFactory = (RunFactory)tsTest.RunFactory;
Run run = (Run)runFactory.AddItem("Name of your run here");
run.CopyDesignSteps();
run.Status = "Passed";
run.Post();
StepFactory stepFactory = (StepFactory)run.StepFactory;
dynamic stepList = stepFactory.NewList("");
var rstepList = (TDAPIOLELib.List)stepList;
foreach (dynamic rstep in rstepList)
{
rstep.Status = "Passed";
rstep.Post();
}
}
}
Related
I have a lot of VBA automation that interlinks an Outlook and Word solution; it is fine, but time is inexorable... so, I'm start to decorating and extending that old solution, wraping it with C#/VS2017.
Through a conventional Winform I can choose my patients, and from this action I do a lot of actions, including open the correct Outlook contact; that's the problem, because I can't get the correct Store; the patients.pst, depending on the machine, may be the 1st, 2nd, 3rd...
In VBA I do this:
WhichStoreNameToPointAt="patients"
Set myNamespace = myolApp.GetNamespace("MAPI")
For i = 1 To myNamespace.Stores.Count Step 1
If myNamespace.Stores.item(i).DisplayName = WhichStoreNameToPointAt Then
intOutlookItemStore = i
End if
End If
Set myFolderPatients = myNamespace.Stores.item(intOutlookItemStore).GetDefaultFolder(olFolderContacts)
And it always functions like a charm.
In C# I tried a lot of variations, and could not point to the correct store:
public void OpenPatientContact(string patientName)
{
Outlook.Store whichStore = null;
Outlook.NameSpace nameSpace = OlkApp.Session;
int i = 1;
foreach (Outlook.Folder folder in nameSpace.Folders)
{
bool p = false;
if (whichStoreNameToPointAt == folder.Name)
{
p = true;
whichStore = folder.Store;
//Correct Store selected; I can tell because of this watch:
//whichStore.displayname == whichStoreNameToPointAt
}
i++;
if (p)
break;
}
var contactItemsOlk = whichStore.Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Items;
// The problem is below; always the first Store
Outlook.ContactItem contact = (Outlook.ContactItem)contactItemsOlk
.Find(string.Format("[FullName]='{0}'", patientName)); //[1];
if (contact != null)
{
contact.Display(true);
}
else
{
MessageBox.Show("The contact information was not found.");
}
}
Unfortunately, it keeps pointing ever to the same first Store, the one that has no patients...
If I change the Store order I can get past this and test other stuff, but of course it is not the right way.
Any other heads/eyes to see the light?
TIA
While seated writing the question, looking at a yellow rubber duck - and a lot of other stuff that belongs to my 1 yo daughter ;), I realized that whichStore.Session.GetDefaultFolder is a little strange in this context. I only changed this
var contactItemsOlk = whichStore.Session.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Items;
To that:
var contactItemsOlk = whichStore.GetDefaultFolder
(Outlook.OlDefaultFolders.olFolderContacts).Items;
Voilá! Magic happens with C# too!
Session returns the default NameSpace object for the current session.
PS: yellow rubber duck; guys of The Pragmatic Programmer really knows some secrets and tricks ;)
Thanks Thomas and Hunt!
I currently have the problem, that my application using libgit2sharp always crashs witht the message:
1 conflict prevents from checkout
when trying to call repo.Pull
The curious thing is, if i print the status of the local repository, their are no changes in the repository.
I even tried resetting the repository at first, or checking the files out, but nothing helps. This is my code:
using (LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(path))
{
var tipId = repo.Head.Tip.Tree;
Log.LogManagerInstance.Instance.Info("HEAD tree id: " + tipId.Id.ToString());
// Pull changes
PullOptions options = new PullOptions();
options.FetchOptions = new FetchOptions();
options.MergeOptions = new MergeOptions();
// ! Only for trying to fix the bug. Should not be here
options.MergeOptions.FileConflictStrategy = CheckoutFileConflictStrategy.Theirs;
repo.Reset(repo.Head.Tip);
// ! --
options.FetchOptions.CredentialsProvider = CredentialsHandler;
Log.LogManagerInstance.Instance.Info("Try pull from remote repository");
// Pull changes from network
var result = repo.Network.Pull(new LibGit2Sharp.Signature(username, mail, new DateTimeOffset(DateTime.Now)), options);
if (result != null && result.Commit != null)
{
Log.LogManagerInstance.Instance.Info("Pulled from remote branch, new tree id: " + result.Commit.Tree.Id.ToString());
// get difference in the git tree (file-system)
var diffs = repo.Diff.Compare<TreeChanges>(tipId, result.Commit.Tree);
MergeTreeChangesToDatabase(diffs, path);
}
else
{
Log.LogManagerInstance.Instance.Info("Local repository is up-to-date with the remote branch");
}
}
Thank you very much.
EDIT
Using the pre release 0.22 seems to solve my problem.
The Version 0.22 fix all problems.
As the question says, I have an InfoPath form running on SP2010 using a c# workflow upon submission. If the form is rejected during workflow, then I need to reset it. I have everything under control, EXCEPT how to reset digital signatures to null, nill, nada, nothing, non-extant! Any ideas? I'm looking at Google now, but at current, I'm not even sure of an om for digital signatures?
Wow, i notice this question suddenly gaining alot of pop with bounty almost gone. Just putting it out there, I did not intend to not bounty someone, but i needed the answer earlier this week (2nd week Nov 2012) and thus i searched and played and teetered with code as much as possible till i ended up finding my own answer before anyone else answered me. However, for future reference, if someone gives a better answer, i'll gladly come back and rep them. Thank you all for the support and I really hope my answer is as useful to another as it was to me.
NOW Bloggered && Gisted May no one ever again have to search as hard as I did for this answer, :P
¡¡¡ I F O U N D M Y F R I G G I N ' A N S W E R ! ! !
¡¡¡ And it works from the workflow !!!
Through much trial and tribulation I was finally able to come up with a solution. It involves a few steps. One, elevate security! Otherwise, non-admin users will cause the workflow to error. Seems like it should work this way, but ... Secondly, get the right schema! It took me a while to find mine, i forgot the exact steps, but, it's not hard to find. UPDATED: Can be found as an attribute of xmlDoc.Document, see updated code Step through (debug) your workflow, without the namespace/schema and highlight your document when it gets to it. One of the properties is an url that is the schema link. Anyway, you wanna see the solution!? Do ya? Look down!
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPFile formFile = workflowProperties.Item.File;
MemoryStream ms = new MemoryStream(formFile.OpenBinary());
XmlTextReader rdr = new XmlTextReader(ms);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(rdr);
rdr.Close();
ms.Close();
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
String schemaUri = xmlDoc.DocumentElement.GetAttributeNode("xmlns:my") != null ? xmlDoc.DocumentElement.GetAttributeNode("xmlns:my").Value : "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-09-04T20:19:31";
nsm.AddNamespace("my", schemaUri);
XmlNode nodeSignatureCollection = xmlDoc.DocumentElement.SelectSingleNode("my:signatures1", nsm);
if (nodeSignatureCollection != null)
{
if (nodeSignatureCollection.HasChildNodes)
{
foreach (XmlNode nodeSignature in nodeSignatureCollection.ChildNodes)
{
// HERE IT IS!!!
if (nodeSignature.HasChildNodes && !nodeSignature.IsReadOnly) nodeSignature.RemoveAll();
}
}
}
byte[] xmlData = System.Text.Encoding.UTF8.GetBytes(xmlDoc.OuterXml);
formFile.SaveBinary(xmlData);
formFile.Update();
});
Keep in mind, this setup is for going through multiple signatures. Although I doubt anything would change if there was only one signature.
Any suggestions on making this sweeter and smaller are accepted, however, I must request an explanation. Honestly, I barely understand what is going on here!
The following answer only HALF works. It is left here for instructional purpose. (Full working answer can be found here.) It works for admin users, but nothing less. It also only works from the InfoPath form behind code. NOT from the workflow.
Adding elevated privlage seems to have 0 effect
I'm leaving this answer up here along with my other so that someone may learn from both examples or possibly even instruct others (including myself) via comments and what not on why one way may be better than the other. At this point, I really don't care to explain anymore as I really don't care to see any of this code ever again! LoL!
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
string[] actionFields = new string[] { "/my:myFields/my:.../my:...", "/my:myFields/my:.../my:...", etc... };
for (int i = 0; i < actionFields.Length; i++)
{
String field = actionFields[i];
XPathNavigator node = this.MainDataSource.CreateNavigator().SelectSingleNode(field, this.NamespaceManager);
if (node.Value.ToLower() == "reject")
{
XPathNavigator sigNode = this.MainDataSource.CreateNavigator();
if (this.Signed) //then unsign it
{
for (int ii = 2; ii <= 13; ii++)
{
try
{
XPathNavigator xSignedSection = sigNode.SelectSingleNode(String.Format("my:myFields/my:signatures1/my:signatures{0}", ii), this.NamespaceManager);
if (xSignedSection.HasChildren)
{
xSignedSection.MoveToChild(XPathNodeType.Element); xSignedSection.DeleteSelf();
};
}
catch (Exception ex) { };
};
};
};
};
}
I'd like to create a small application that can collect system information (Win32_blablabla) using WinRM as opposed to WMI. How can i do that from C#?
The main goal is to use WS-Man (WinRm) as opposed to DCOM (WMI).
I guess the easiest way would be to use WSMAN automation. Reference wsmauto.dll from windwos\system32 in your project:
then, code below should work for you. API description is here: msdn: WinRM C++ API
IWSMan wsman = new WSManClass();
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();
if (options != null)
{
try
{
// options.UserName = ???;
// options.Password = ???;
IWSManSession session = (IWSManSession)wsman.CreateSession("http://<your_server_name>/wsman", 0, options);
if (session != null)
{
try
{
// retrieve the Win32_Service xml representation
var reply = session.Get("http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt", 0);
// parse xml and dump service name and description
var doc = new XmlDocument();
doc.LoadXml(reply);
foreach (var elementName in new string[] { "p:Caption", "p:Description" })
{
var node = doc.GetElementsByTagName(elementName)[0];
if (node != null) Console.WriteLine(node.InnerText);
}
}
finally
{
Marshal.ReleaseComObject(session);
}
}
}
finally
{
Marshal.ReleaseComObject(options);
}
}
hope this helps, regards
I've got an article that describes an easy way to run Powershell through WinRM from .NET at http://getthinktank.com/2015/06/22/naos-winrm-windows-remote-management-through-net/.
The code is in a single file if you want to just copy it and it's also a NuGet package that includes the reference to System.Management.Automation.
It auto manages trusted hosts, can run script blocks, and also send files (which isn't really supported but I created a work around). The returns are always the raw objects from Powershell.
// this is the entrypoint to interact with the system (interfaced for testing).
var machineManager = new MachineManager(
"10.0.0.1",
"Administrator",
MachineManager.ConvertStringToSecureString("xxx"),
true);
// will perform a user initiated reboot.
machineManager.Reboot();
// can run random script blocks WITH parameters.
var fileObjects = machineManager.RunScript(
"{ param($path) ls $path }",
new[] { #"C:\PathToList" });
// can transfer files to the remote server (over WinRM's protocol!).
var localFilePath = #"D:\Temp\BigFileLocal.nupkg";
var fileBytes = File.ReadAllBytes(localFilePath);
var remoteFilePath = #"D:\Temp\BigFileRemote.nupkg";
machineManager.SendFile(remoteFilePath, fileBytes);
Hope this helps, I've been using this for a while with my automated deployments. Please leave comments if you find issues.
I would like to note that this shows an interop error by default in Visual Studio 2010.
c.f. http://blogs.msdn.com/b/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead.aspx
There appear to be two ways to solve this. This first is documented in the article listed above and appears to be the correct way to handle the problem. The pertinent changes for this example is:
WSMan wsManObject = new WSMan();
This is in lieu of IWSMan wsman = new WSManClass(); which will throw the error.
The second resolution is to go to the VS2010—>Solution Explorer—>Solution—>Project—>References and select WSManAutomation. Right click or hit Alt-Enter to access the properties. Change the value of the "Embed Interop Types" property of the wsmauto reference.
I was wondering if anyone can help me on this cause its driving me mad trying get this working
I was working with the trail of mail.dll from http://www.lesnikowski.com/mail/ which is an extremely fantastic tool which unfortunately i cannot afford being a student (even though its around 150eur, its still very expensive to me :/) and this would be a small module in my thesis and my faculty cannot afford to buy these things for students either :/ so anyway I had to go for a free tool (so please dont suggest any non open source ones - trust me i have tried them ALL)..
Well, i'm trying to explore InterIMAP, and for several hours have been trying to list unread emails from my gmail account but it just doesn't seem to be working. I can connect just fine but finding the unread emails seems to be no easy task.. I have tried countless approaches but non seem to give me unread emails in my inbox (I have loads of emails in my inbox and i just want the unread ones). Would someone please assist me? I have been trying to get this working for ages now, but documentation is rather lacking and my every attempt has resulted in a fail so far.
Please help!!
Some code i currently have:
` IMAPConfig config = new IMAPConfig("myhost", "username", "pass", true, true, "");
config.CacheFile = "";
IMAPClient client = null;
try
{
client = new IMAPClient(config, null, 5);
}
catch (IMAPException e)
{
Console.WriteLine(e.Message);
return;
}
Console.WriteLine(DateTime.Now.ToString());
IMAPFolder f = client.Folders["INBOX"];
IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchNew()); // <--- Gives me no results even though i do have unread messages!
If you did't reach your goal, here we go:
You should code in the following way:
1st: Inside your SearchQuery class, add a new property "unread", for example.
2nd: Add a new Method that returns an IMAPSearchQuery. It'll quick search unread mails. Something like that:
public static IMAPSearchQuery QuickSearchUnread()
{
IMAPSearchQuery query = new IMAPSearchQuery();
query.unread = true;
return query;
}
3td: Inside your class IMAPFolder, you have a method called that will return an IMAPSearchResult type and that receives an IMAPSearchQuery as parameter.
This method "build" your query with IMAP command queries (IMAP based protocol).
To the Unread query you should add:
public IMAPSearchResult Search(IMAPSearchQuery query)
{
...
if (query.Unread)
searchTerms.Add("UNSEEN");
.
.
...
}
4th: Call the Search method with the new QuickSearch:
config.CacheFile = "";
IMAPClient client = null;
try
{
client = new IMAPClient(config, null, 5);
}
catch (IMAPException e)
{
Console.WriteLine(e.Message);
return;
}
Console.WriteLine(DateTime.Now.ToString());
IMAPFolder f = client.Folders["INBOX"];
IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchUnread());
Let me know about your progress.
I hope it can be helpful.
Bye.
I honestly just ended up using Mail.dll trial version as interIMAP was not working properly for me and way to slow because it indexes the emails for some reason :s