How do I get list of projects from TFS server using webservice?
Is documentation available for the TFS Webservices?
I concur with bryanjonker as well. Don't call the webservice directly, that's really reserved for internal use. Create your own access layer and call the API.
You can also use the object model to get access to the ICommonStructureService. I've recently started using this, and find it to be cleaner. The code below does the same as bryanjonker's example:
var tfs = TeamFoundationServerFactory.GetServer(serverUri);
var projectCollection = tfs.GetService<ICommonStructureService>();
foreach (var projectInfo in projectCollection.ListProjects())
{
listBox1.Items.Add(projectInfo.Name);
}
Your best bet is to use the TFS DLLs and that API, which is at http://msdn.microsoft.com/en-us/library/bb130146(VS.80).aspx and http://msdn.microsoft.com/en-us/library/bb130334(v=VS.80).aspx . From what I understand, hitting the webservice directly is frowned upon.
To get a list of projects, I think there's multiple ways to do this. I posted code I used: use the GetServer method to get a project collection, then list through the ListProjects() method. I needed to do this because I needed to get the areas and iterations as well. This requires the Microsoft.TeamFoundation.Client namespace.
var tfs = TeamFoundationServerFactory.GetServer(Constants.TEAMFOUNDSERVER);
var projectCollection = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
foreach (var projectInfo in projectCollection.ListProjects())
{
//do stuff here
}
Related
I've a little confusion over here, on this line of code
var cs = ApplicationContext.Current.Services.ContentService.GetById(1000);
cs.GetValue("test");
var nd = new Node(1000);
nd.GetProperty("test");
Both of that code can be used.. What is the different between that two code.. When and Why we use either one of them
Umbraco Services
The service layer of the new umbraco API introduced in umbraco 6 includes a ContentService, a MediaService, a DataTypeService, and a LocalizationService. Check out the umbraco documentation for documentation on those services and the other umbraco services.
The services in umbraco hit the database and don't leverage all of the caching that umbraco provides. You should use these services sparingly. If you are trying to programatically add/update/delete from the database or if you are trying to get unpublished content from the database, you should use these services. If all you need is to query for published content, you should use the UmbracoHelper because it is much faster.
var cs = ApplicationContext.Current.Services.ContentService.GetById(1000);
cs.GetValue("test");
UmbracoHelper
The UmbracoHelper is what you should almost always be using when you want to query content from umbraco. It doesn't hit the database and is much faster than the umbraco services.
var node = Umbraco.TypedContent(1000);
var nodeVal = node.GetPropertyValue<string>("test");
If you find that you don't have access to the UmbracoHelper, you can make your own as long as you have an UmbracoContext:
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var node = Umbraco.TypedContent(1000);
var nodeVal = node.GetPropertyValue<string>("test");
NodeFactory
The NodeFactory is obsolete. If you are using Umbraco 6 or higher, I would highly recommend converting to the UmbracoHelper.
var nd = new Node(1000);
nd.GetProperty("test");
In razor or frontend code, always use the UmbracoHelper
var node = Umbraco.TypedContent(1000);
var value = node.GetPropertyValue<string>("test");
This will query the cache for published nodes
You want to use the ContentService call to query the database, for example if you want information about unpublished nodes (you don't want to do this in your views)
Querying with the Node object is probably legacy (I've never used it)
I'm trying to export Umbraco Forms data to CSV, in the exact format generated when you export from the Entries table UI, and I'm trying to do this strictly from code. End result is I would like to run as a task to export data daily or every few hours, and save that .csv file to a folder on the server. This would be for bulk importing into other systems, and a Forms Workflow won't work in this case.
My original approach was to try and do this in SQL, but Forms data would be difficult to work with since it's a in a mix of JSON and native SQL data. I'm not running SQL Server 2016 so no JSON support.
I've been searching through the Forms API and found a few things that might help, but can't seem to find what I need. So far I've tried:
Umbraco.Forms.Data.Storage.RecordStorage.GetAllRecords()
This gets the records, but unsure where to get the field names. I don't even see them in the UF tables. I can generate JSON output via GenerateRecordDataAsJson() but only get Guids for field names.
I've tried looping through the above Record collection and manually working with individual items, and I've tried the RecordStorage.BuildRecord() method hoping that would assemble the data, but no luck there either.
You have to get the field names using the API. When Forms was still Contour, EVERYTHING was in the database, making it easy(ish) to query stuff like this.
I think you need to use FormStorage to get the details of the form and you should be able to get the fields from that.
Thought I'd share an example for Umbraco 8 and Forms 8.4.1 since I just ran into this same requirement recently.
public class ExportController : UmbracoApiController
{
IRecordReaderService RecordReaderService;
public ExportController(
IRecordReaderService recordReaderService)
{
RecordReaderService = recordReaderService;
}
[HttpGet]
public void Export()
{
var formId = new System.Guid("f9ea767a-0e4e-4c90-85f1-53ef42c60793");
var pageSize = 50;
var formResults = RecordReaderService.GetRecordsFromForm(formId, 1, pageSize);
foreach (var entry in formResults.Items)
{
var firstName = entry.ValueAsString("firstName"); // Use field alias
// Output data or other
}
}
}
I have had to move queries off the main database in order to meet requirements for complex authorization - for example a user with a given authorization role can only view data for individuals in the same institution.
I am using the Breeze .net DocCode sample for guidance, and have copied the premise for the mapping of domain models to DTOs.
get { return ForCurrentUser(Context.Orders).Select(o => new Order {
OrderID = o.OrderID,
....
OrderDetails = o.OrderDetails.Select(od => new OrderDetail
{
ProductID = od.ProductID,
UnitPrice = od.UnitPrice
...
})
The problem is that which mapped properties to .include(entity framework method)/.expand (breeze method) is now a concern of the mapping function (for example, the above code will always return the OrderDetails collection, whether I want them or not). I would like to still only eagerly load/expand properties if the javascript client generated predicate has a .expand directive for that property.
Is this at all possible, or am I stuck with manually defining different mapping functions on the server, depending on what properties I want expanded? (I am happy to use tools such as automapper if that would solve or simplify the problem)
Thank you
You will need to use the ODataQueryOptions as a parameter to your controller method. This gives you the details of the query predicates in your server method, so that you can apply them as needed rather that having them applied automatically. This will let you expand, or not, based upon the query.
See this answer and this answer to see how it works.
I'm experimenting with ServiceStack in MVC, using standard server side controllers creating view models. There are no jquery calls (or any direct calls) to any of the services registered at /api. Since SS lets us resolve services directly using:
using (var dr = HostContext.ResolveService<DataReportService>(base.HttpContext))
I haven't been calling the services using JsonServiceClient. Instead I've been resolving the services and calling their methods directly.
var dataReport = new DataReport
{
IsArchived = false,
ReportDate = DateTime.Now,
ReportType = Model.ReportType
};
var drId = dr.Post(dataReport);
However, I have not been able to find a way to do this with the new AutoQuery feature. I know it creates a service automatically for any class that descends from QueryBase but I have had no luck resolving it. If I try to resolve the name used at run time then I won't compile (obviously). If I try something like this
using (var dr = HostContext.ResolveService<AutoQueryServiceBase>(base.HttpContext))
then it won't work either, because that is just a base class and not the actual registered instance. I know I could do this from JsonServiceClient but I'd really like to experiment with the direct call approach. Creating my own service that wraps any AutoQuery would work but seems like it defeats the purpose of the automatic creation. Still, I don't see any other way to proceed. Would love to hear any ideas.
Rather than using the ResolveService<T> method to get the service and call the executing method yourself, you can use HostContext.ServiceController.Execute method which allows you pass in the request DTO which will execute on the action method.
var dataReport = new DataReport
{
IsArchived = false,
ReportDate = DateTime.Now,
ReportType = Model.ReportType
};
var drId = HostContext.ServiceController.Execute(dataReport);
I hope this helps.
I'm trying to return a JSON list of stuff from my server via an ASP.NET MVC front layer:
var stuff = repo.GetStuff();
return Json(stuff);
However, instead of the expected JSON, I get an error message stating
A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
I think I've found where this happens, but to explain it I need a simple example domain model as follows:
I am (lazily?) loading a selection of documents from NHibernate, like so:
var session = getNHibernateSession();
var query = new NhQueryable<Document>(session.GetSessionImplementation());
var docs = query.ToList().AsEnumerable();
I then pass the documents to return a JsonResult in my controller:
return Json(docs, JsonRequestBehavior.AllowGet);
Now, when Json() serailizes the collection, it walks over the properties of a document, finds a person. It serializes that person, and finds a project. It serializes the project, and finds - that's right - the person again! Since I'm lazy loading, it can just keep walking for ever if nothing stops it, but it's stopped by a circular reference error.
I don't really need to go all these levels down (I'd be fine without loading the project in the first place) - can I somehow affect how Json() serializes this collection, to not go further than, say, 2 levels down? I've googled around a little, but most of what I find seems to be from people who decided to use a serializing library directly, rather than just using the built-in functionality in .NET MVC. (Note: The solution to this problem must be possible to apply specifically to this case, since I might want to get JSON lists of people, including projects, somewhere else in the application...)
If you are retrieving Json, you have a service api. You have to design the api besides the implementation. Does the page that will be using it need all those fields and collections? probably not. What about adding more properties for other features and services? They will start appear in all the requests.
What you need is to use a ViewModel or just an anonymous type with the desired structure:
var session = getNHibernateSession();
var query = new NhQueryable<Document>(session.GetSessionImplementation());
var docs = query.ToList();
var result = query.Select(x => new {
x.Id,
x.Name,
People = new { p.Id,
p.Name,
p.Title
}
});
return Json( result, JsonRequestBehavior.AllowGet);
This way you can control what is being rendered and how.
It's already been answered here.
Also, it's generally a bad idea to expose your domain entities like this. If it's for read-only purposes it might not be so bad, but if any of your action methods accept a domain entity, then a specifically formatted request can overwrite properties on your domain entity that you don't want to (such as your PK).
To preserve object references in JSON, add the following code to Application_Start method in the Global.asax file:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.All;