I've been playing about with the WorkItem objects from the Microsoft.TeamFoundation schemas in C#, but was wondering if anyone knows how I would refer to an object of type 'Area' or, for that matter, 'Iteration'.
It seems that these are treated as objects in TFS, but I haven't come across any information on how to refer to these in C#.
You can filter WorkItems by [Area] or [Iteration] using WIQL, but what if I wanted to populate a ComboBox with all Areas or Iterations?
Also, how can I view the database structure of my workplace's TFS project?
Thanks guys,
Andy
Have a look at this Blog Post. There's sample code and a demo.
Here's a quick LINQPad Query that should do the job (download VS2010 / VS2012):
void Main()
{
const String CollectionAddress = "http://tfsserver:8080/tfs/MyCollection";
const String ProjectName = "MyProject";
using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri(CollectionAddress)))
{
tfs.EnsureAuthenticated();
var server = tfs.GetService<ICommonStructureService>();
var projectInfo = server.GetProjectFromName(ProjectName);
var nodes = server.ListStructures(projectInfo.Uri).Dump();
// You should be able to re-factor this with "Iteration"
// for getting those too.
var nodesXml = server.GetNodesXml(
nodes
.Where(node => node.Name == "Area")
.Select(node => node.Uri).ToArray(),
true);
var areaPathAndId =
XElement.Parse(nodesXml.OuterXml)
.Descendants("Node")
.Select(xe => new
{
Path = xe.Attribute("Path").Value,
ID = xe.Attribute("NodeID").Value,
})
.Dump();
}
}
Related
public void ScrapeData(string page)
{
var web = new HtmlWeb();
var doc = web.Load(page);
var Articles = doc.DocumentNode.SelectNodes("//*[#class = 'b-product-grid-tile js-tile-container']");
foreach (var article in Articles)
{
var Sneaker = HttpUtility.HtmlDecode(article.SelectSingleNode(".//span[#class ='b-product-tile-link js-product-tile-link']").InnerText);
var Preis = HttpUtility.HtmlDecode(article.SelectSingleNode(".//div[#class ='b-product-tile-price']").InnerText);
var hrefList = doc.DocumentNode.SelectNodes("//a").Select(p => p.GetAttributeValue("href", "not found"));
Debug.Print(Sneaker + Preis + hrefList);
_entries.Add(new EntryModel { Products = Sneaker, Preis = Preis, Link = hrefList }); // canĀ“t convert string implicitly (Sory i have Visual Studio in German i try to translate the Error)
}
All the Links But how can i access to them? and get them in my DataGrid
I found the Links but idk how i access to them and get it into my DataGrid
After i add .ToArray i got the same problem the Debugger Print alwayse (System.Linq.Enumerable+WhereSelectEnumerableIterator`2[HtmlAgilityPack.HtmlNode,System.String])
Here some screenshots of the edited code
Same Problem
The Edit Code
And again i am very sorry how i ask my questions i am very new and i am happy if you correct me
It's not completely clear which of the links you want; you've highlighted only one. However if you do:
var hrefList = doc.DocumentNode.SelectNodes("//a")
.Select(p => p.GetAttributeValue("href", "not found"))
.ToArray();
(added .ToArray())
Then you can access e.g. the second one via hrefList[1]
If you only ever want the second one you;d be better off doing:
var href = doc.DocumentNode.SelectNodes("//a")
.Select(p => p.GetAttributeValue("href", "not found"))
.Skip(1)
.First();
No need to copy the whole lot to an array if all you want is one
I am using following code to index document and test results using NEST in .net core application.
But it is not returning any record.
So either I am doing wrong indexing or I have query problem.
Very new to elastic search. So don't know what is wrong with following code as I am trying to index text of text file and searching it for testing.
private static void Index()
{
var settings = new ConnectionSettings().DefaultIndex("ProjectDocuments");
var client = new ElasticClient(settings);
//First, you need to make the routing required when you are creating your index, like this:
client.CreateIndex("ProjectDocuments", d => d
.Mappings(mapping => mapping
.Map<Document>(map => map
.RoutingField(routing => routing
.Required(true))
.AutoMap())
));
Routing routingFromInt = 1;
Document document = new Document()
{
Id = 1,
Content = "Some Text File Text"
};
IIndexResponse result = client.Index<Document>(document, selector => selector
.Id(1)
.Routing(routingFromInt));
//TODO: Following returns 0. so might be issue with indexing itself.
ISearchResponse<Document> searchResponse = client.Search<Document>(query => query.Query(q => q.MatchAll()).Routing(routingFromInt));
var documents = searchResponse.Documents;
}
Issue was with default index name. Index name with Uppercase is not supported in elastic search.
so "ProjectDocuments" was causing issue. Changed it to "project_documents" and started working.
I'm trying to port over JavaScript code that interacts with a MongoDb to C# .NET and having problems with a delete/pull operation. I can't seem to figure out how to iterate over the Ponies array and remove a single ObjectId by matching to a passed in ObjectId.
{
"_id" : ObjectId("388e8a66fe2af4e35c60e"),
"Location" : "rainbowland",
"Ponies" : [
ObjectId("388e8a66fe2af4e35c24e83c"),
ObjectId("388e8a66fe2af4e35c24e860"),
ObjectId("388e8a66fe2af4e35c24e83d")
]
}
I've tried several different ways based on what I've found online but nothing seems to work. When I check the collection to see if 388e8a66fe2af4e35c24e860 was removed from the Ponies array I see that it wasn't removed. Everytime I execute the code and look at the ModifiedCount for resultPonies it shows zero. Two examples of what I've tried doing are below.
var pony = new Pony() { Id = new ObjectId("388e8a66fe2af4e35c24e860") }
var pullPonies = Builders<Ranch>.Update.PullFilter(x => x.Ponies,
y => y.Id == pony.Id);
var filterPonies = Builders<Ranch>.Filter.Where(x => true);
var resultPonies = _context.Ranches.UpdateMany(filterPonies, pullPonies);
OR
var pullPonies = Builders<BsonDocument>.Update.PullFilter("Ponies",
Builders<ObjectId>.Filter.Eq("ObjectId", pony.Id));
var filterPonies = Builders<BsonDocument>.Filter.Where(x => true);
var resultPonies = _context.Ranches.UpdateMany(filterPonies, pullPonies);
Here is the JavaScript code that I believe works but haven't been able to test yet.
db.collection("Ranches").update({}, {$pull: {Ponies: pony._id}}, {multi: true});
Ok, I found a solution for the problem. Since I'm not actually going to be filtering within the array of objects, they are all ObjectIds in a BsonArray, I need to find where the value in the array matches the given ObjectId. In those cases the array item should be pulled out. If the object in the array had other properties then I would probably want to use the PullFilter. But in this case I don't need to filter the additional level. That is at least what I believe I was doing wrong. Here are the solutions
var ponyId = new ObjectId("388e8a66fe2af4e35c24e860");
var pullPonies = Builders<Ranch>.Update.Pull(x => x.Ponies, ponyId);
// This line is to retrieve all Ranch objects in the collection
var filterPonies = Builders<Ranch>.Filter.Where(x => true);
var resultPonies = _context.Ranches.UpdateMany(filterPonies, pullPonies);
Or
var ponyId = new ObjectId("388e8a66fe2af4e35c24e860");
var pullPonies = Builders<BsonDocument>.Update.Pull("Ponies", ponyId));
// This line is to retrieve all Ranch objects in the collection
var filterPonies = Builders<BsonDocument>.Filter.Where(x => true);
var resultPonies = _context.Ranches.UpdateMany(filterPonies, pullPonies);
Hi,
I have a problem with getting data from youtube xml:
address of youtube xml: http://gdata.youtube.com/feeds/api/videos?q=keyword&orderby=viewCount
I try this, but the program doesn't go into the linq inquiry.
key = #"http://gdata.youtube.com/feeds/api/videos?q="+keyword+#"&orderby=viewCount";
youtube = XDocument.Load(key);
urls = (from item in youtube.Elements("feed")
select new VideInfo
{
soundName = item.Element("entry").Element("title").ToString(),
url = item.Element("entry").Element("id").ToString(),
}).ToList<VideInfo>();
Anyone has idea, how to solve this?
Thanks!
Searching for elements in Linq to XML requires that you fully qualify with the namespace. In this case:
var keyword = "food";
var key = #"http://gdata.youtube.com/feeds/api/videos?q="+keyword+#"&orderby=viewCount";
var youtube = XDocument.Load(key);
var urls = (from item in youtube.Elements("{http://www.w3.org/2005/Atom}feed")
select new
{
soundName = item.Element("{http://www.w3.org/2005/Atom}entry").Element("{http://www.w3.org/2005/Atom}title").ToString(),
url = item.Element("{http://www.w3.org/2005/Atom}entry").Element("{http://www.w3.org/2005/Atom}id").ToString(),
});
foreach (var t in urls) {
Console.WriteLine(t.soundName + " " + t.url);
}
Works for me. To avoid writing out the namespace, one option is to search by local name (e. g. youtube.Elements().Where(e => e.LocalName == "feed"). I'm not sure if there's a more elegant way to be "namespace agnostic".
I know a similar question has already been asked, but that retrieves all the items for Choice field using Sharepoint Object Model. I dont have object model available to me. I want to do this using CAML or something. I couldnt figure out a CAML query to get all the items for a choice field.
Any pointers in the right direction will be really appreciated.
Regards.
Can you use web service calls? This thread explains reading multi-choice choices from a web service: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/04a00936-7102-4ddc-aa7d-0be7e14e7692
This follow-up post might be useful, too: http://mysharepointwork.blogspot.com/2009/10/sharepoint-web-services-get-choice.html
There is actually another way of getting the values using Xelements
using (var service = new SharePoint.Services.ListsSoapClient())
{
service.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var listName = "MyList";
var xelement = service.GetList(listName);
var fieldName = "Category"; //My Field name
XNamespace ns = "http://schemas.microsoft.com/sharepoint/soap/";
var selectedField = xelement.Descendants(ns + "Fields").Elements().Where(x => x.Attribute("Name").Value == fieldName).FirstOrDefault();
if (selectedField != null)
{
var choices = selectedField.Elements(ns + "CHOICES").Elements().Where(x => x.Name == ns + "CHOICE").Select(x => x.Value).ToList();
//Do something with choices
}
}