I am using a Javascript library which expects data to be in a certain json format as show below. I will use .NET to get the data and feed it to the library using json deserialization. However I am not sure how C# classes are serialized to json. Will the built-in .NET json serializer support this json structure or do I have to invest in a more advanced library like json.net? I never used json.net. My approach is to do several trial and error approaches creating different C# classes and looking at the output json until the json structure matches the format below. This seems inefficient and time consuming and I wanted to know if there's a better approach.
Note: Each second level node can have 1 or more children. For example: the ones with playcount 276, 271.
{
"children": [
{
"children": [
{
"children": [],
"data": {
"playcount": "276",
"$color": "#8E7032",
"image": "http://userserve-ak.last.fm/serve/300x300/11403219.jpg",
"$area": 276
},
"id": "album-Thirteenth Step",
"name": "Thirteenth Step"
},
{
"children": [],
"data": {
"playcount": "271",
"$color": "#906E32",
"image": "http://userserve-ak.last.fm/serve/300x300/11393921.jpg",
"$area": 271
},
"id": "album-Mer De Noms",
"name": "Mer De Noms"
}
],
"data": {
"playcount": 547,
"$area": 547
},
"id": "artist_A Perfect Circle",
"name": "A Perfect Circle"
},
.....
Or.. you could just do it the other way around:
http://json2csharp.com/
Throw your Json in there and it will spit out C# classes.. thereby mimicking the Json format.. not you having to manually trial-and-error it.
Use this http://jsonclassgenerator.codeplex.com/
I have been using this for quite some time now and it is the best method of generating the C# class from your JSON.
After you generate the class you can then serialize it using JSON.NET to get the desired JSON.
Related
I amp attempting to create a new mapbox style via the mapbox api. When the create process completes, I am getting a success confirmation back, but I cannot use or view the style after it is created. Based on these docs and these docs, I am sending a payload to this api endpoint:
https://api.mapbox.com/styles/v1/[accountname]
The payload I am sending is this:
{
"version": 8,
"name": "mystyle via api",
"sprite": "mapbox://sprites/mapbox/bright-v8",
"metadata": null,
"sources": {
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
},
"glyphs": null,
"layers": []
}
After sending this payload to the mapbox api, I receive this message back:
{
"version": 8,
"name": "mystyle via api",
"metadata": null,
"sources": {
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
},
"sprite": "mapbox://sprites/[accountname]/ckby5s52p2r9v1hmwgkrzenvw/3teom2ial2ryn2u97lclizpce",
"glyphs": "mapbox://fonts/[accountname]/{fontstack}/{range}.pbf",
"layers": [],
"created": "2020-06-27T21:30:49.047Z",
"id": "ckby5s52p2r9v1hmwgkrzenvw",
"modified": "2020-06-27T21:30:49.047Z",
"owner": "[accountname]",
"visibility": "private"
}
Then I proceed to my account in the portal and I see my new style:
However, something is wrong. The preview icon shows just a transparent graphic. And when I click on the style to view/edit it, I get this cryptic error message "Cannot read property 'mapbox:decompiler' of null":
What am I missing here? I am finding the documentation for this process very spread out through several documents. But I am copying the examples in the snippets verbatim
This is a "valid" style, but it has no layers (see the last field of the JSON), that's why it doesn't display anything. (I know this is verbatim from the example in the Create a style docs)
The key concept here to master is the difference between Sources and Layers. Sources are "data sources": you won't see them unless you have a Layer displaying it. Some types of Sources can contain many layers (see the source-layer property in the Layer object), and/or you might want to display the same source with different stylings across different maps. That's one reason they are separated.
Or, as the Sources docs put it:
Adding a source isn't enough to make data appear on the map because sources don't contain styling details like color or width. Layers refer to a source and give it a visual representation. This makes it possible to style the same source in different ways, like differentiating between types of roads in a highways layer.
Combining the Style object sample with the Layer object sample would give you something like this:
{
"version": 8,
"name": "mystyle via api",
"sprite": "mapbox://sprites/mapbox/bright-v8",
"metadata": null,
"sources": {
"mapbox-streets": {
"type": "vector",
"url": "mapbox://mapbox.mapbox-streets-v6"
}
},
"glyphs": null,
"layers": [
{
"id": "water",
"source": "mapbox-streets",
"source-layer": "water",
"type": "fill",
"paint": {
"fill-color": "#00ffff"
}
}
]
}
Now, keep in mind that the global Mapbox styles contain several layers (maybe up to a couple dozen), with very fine settings such as what type of features should show at which zoom level and with what configurations, etc. Most applications should not need to recreate those from scratch.
If you want to overlay dynamic data (to be decided at runtime), you can use one of the global styles and dynamically add a Layer on top of an untouched default style. The link is for Mapbox GL JS, assuming the UI is browser-based. If the UI is a mobile app, there are corresponding methods in the iOS and Android SDKs.
Now, if you don't need dynamic data at all, consider Mapbox Studio instead. This will allow you to create a custom style (with the default styles as templates if you want) and add/remove layers. For example, if mapbox://styles/mapbox/streets-v11 is almost a perfect fit, but you don't need to (say) show small town names, you can create a custom template in Mapbox Studio and remove just that. In the end, it will you give you a style ID which you can just put into your map like a default (global) style.
Also note that, depending on your case, you may combine both approaches.
when i am trying to replace string value in Azure logic app
it throwing error that you can't give self reference of variable
"Set_variable": {
"inputs": {
"name": "Images",
"value": "#replace(variables('Images'), 'cdn.gomasterkey.com/images/watermark.aspx?imageurl=/uf/', '~~')"
},
"runAfter": {
"Append_to_array_variable": [
"Succeeded"
]
},
"type": "SetVariable"
}
when i save above code i got this error it doesn't allow me to give self reference although i wanna replace from same variable and again put into it.
You could do self reference in logic app, however you could use workflow functions to get the value, then replace it with the string you want.
I use actions('Initialize_variable').inputs.variables[0].value to get the variable.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to write a small app that integrates with Visual Studio or TFS.
I want to be able to run cyclomatic complexity and/or C# unit tests through my app and then push the result to excel.
Google gave me this but it does not help me.
My questions:
1. Is this possible? (API integration part)
2. If so, what APi can I use to accomplish this.
p.s I have not started with a project so I dont have sample code. I want to do an initial investigation to make sure it worth a try.
I know there is a few projects out there that does this but I want to create my own
On TFS side, if you want to run unit tests, you need to create a build definition, and add VS build and VS test tasks in the build definition, so, you need to refer create a build definition API from website below, and specify the tasks in the api:
https://www.visualstudio.com/en-us/docs/integrate/api/build/definitions#create-a-build-definition
Add an example of create a build definition with rest api for your reference:
POST http://tfsserver:8080/tfs/DefaultCollection/TeamProject/_apis/build/definitions?api-version=3.2
Content-Type: application/json
{
"name": "myDefinition",
"type": "build",
"quality": "definition",
"queue": {
"id": 1
},
"build": [
{
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "Build solution **\\*.sln",
"task": {
"id": "71a9a2d3-a98a-4caa-96ab-affca411ecda",
"versionSpec": "*"
},
"inputs": {
"solution": "**\\*.sln",
"msbuildArgs": "",
"platform": "$(platform)",
"configuration": "$(config)",
"clean": "false",
"restoreNugetPackages": "true",
"vsLocationMethod": "version",
"vsVersion": "latest",
"vsLocation": "",
"msbuildLocationMethod": "version",
"msbuildVersion": "latest",
"msbuildArchitecture": "x86",
"msbuildLocation": "",
"logProjectEvents": "true"
}
},
{
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "Test Assemblies **\\*test*.dll;-:**\\obj\\**",
"task": {
"id": "ef087383-ee5e-42c7-9a53-ab56c98420f9",
"versionSpec": "*"
},
"inputs": {
"testAssembly": "**\\*test*.dll;-:**\\obj\\**",
"testFiltercriteria": "",
"runSettingsFile": "",
"codeCoverageEnabled": "true",
"otherConsoleOptions": "",
"vsTestVersion": "14.0",
"pathtoCustomTestAdapters": ""
}
}
],
"repository": {
"id": "278d5cd2-584d-4b63-824a-2ba458937249",
"type": "tfsgit",
"name": "Fabrikam-Fiber-Git",
"localPath": "$(sys.sourceFolder)/MyGitProject",
"defaultBranch": "refs/heads/master",
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_git/Fabrikam-Fiber-Git",
"clean": "false"
},
"options": [
{
"enabled": true,
"definition": {
"id": "7c555368-ca64-4199-add6-9ebaf0b0137d"
},
"inputs": {
"parallel": "false",
"multipliers": "[\"config\",\"platform\"]"
}
}
],
"variables": {
"forceClean": {
"value": "false",
"allowOverride": true
},
"config": {
"value": "debug, release",
"allowOverride": true
},
"platform": {
"value": "any cpu",
"allowOverride": true
}
},
"triggers": [],
"comment": "my first definition"
}
as mentioned by Cece Dong you need to run your tests as part of a build definition.
I assume your app will always trigger the same build definition? So I personally would create the build definition in TFS and then Queue this definition. Once you have your definition created you can queue a build of it as described in the API here: https://www.visualstudio.com/en-us/docs/integrate/api/build/builds#queue-a-build
When running tests you can specify the Test Run Title by which you can later on identify "your" tests. The test management is described in the API docs here: https://www.visualstudio.com/en-us/docs/integrate/api/test/overview
You can fetch your test runs and the cases within those tests and create files in whatever format you need them in.
I know you said you want to create your own application and not use something existing, but in case you would need some code samples you could look at the following build tasks, as they are open source and you could see how certain things were implemented:
- Trigger Build Task (Allows you to queue new builds)
- Testrun Perfromance Analyzer (Will fetch the last n TestRuns and creates CSV files for you)
- tfsrestservice (service that abstracts REST API calls to TFS/VSTS - both tasks mentioned above are based on this)
So I think it is definetly possible to achieve this. The two links pointing to the REST API documentation should help you in order to achieve it.
If you need inspiration I think the tfsrestservice might be helpful to really see what calls are made to the api in order to receive test runs and test cases.
I hope I could help.
Am doing a reporting tool out of tfs. i was able to read the work item and iteration related information from tfs. How to get the iteration capacity plan information from tfs. using WIQL or any other option. i need to get the information in my c# code.
Thanks in advance for all the help.
It's not able to do this through Client Object Model. Please refer this similar question: TFS 11 2012 API Questions : query capacity and days off
These values are only available from the Server Object Model (there is no Client Object Model equivalent at the moment). The interfaces and objects are all made Internal so even on the server you can't access these values.
internal TeamCapacity GetTeamIterationCapacity(Guid teamId, Guid iterationId);
Declaring Type: Microsoft.TeamFoundation.Server.WebAccess.WorkItemTracking.Common.DataAccess.TeamConfigurationComponent
Assembly: Microsoft.TeamFoundation.Server.WebAccess.WorkItemTracking.Common, Version=12.0.0.0
You could either directly query from the ProjectCollection database from the tables mentioned by James Tupper in this thread.
Or you could also use Rest API to Get a team's capacity or Get a team member's capacity will get a response as below:
{
"values": [
{
"teamMember": {
"id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"displayName": "Chuck Reinhart",
"uniqueName": "fabrikamfiber3#hotmail.com",
"url": "https://fabrikam-fiber-inc.vssps.visualstudio.com/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"imageUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
},
"activities": [
{
"capacityPerDay": 0,
"name": null
}
],
"daysOff": [],
"url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/6d823a47-2d51-4f31-acff-74927f88ee1e/748b18b6-4b3c-425a-bcae-ff9b3e703012/_apis/work/teamsettings/iterations/2ec76bfe-ba74-4060-970d-4567a3e997ee/capacities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
}
]
}
Iteration objects are part of Project settings, you might need to query the iteration details from there and not from work item.
I've been working on converting my ElasticSearch (ES) 0.9 code to work with ES 1.0. This has required an upgrade of NEST to the latest pre-release version.
I've been trying to bulk index a set of child documents. I've set up their mapping as:
"stocks": {
"_parent": {
"type": "products"
},
"_timestamp": {
"enabled": true
},
"properties": {
"id": {
"type": "integer",
"index": "not_analyzed"
},
"stock": {
"type": "integer",
"index": "not_analyzed"
}
}
}
This was created in ES 0.9. When I've put this into ES 1.0, it automatically adds a Routing property with 'Required' set to 'true'. A search on Google suggests that this was always required to enable a parent-child document setup but the property never explicitly appeared when I examined the documents in my 0.9 shard.
"Ok..." I think to myself. Next, I have the following code block for NEST:
var bulkParams = postQueue.Select(p => new BulkParameters<Stock>(p) { Parent = p.id.ToString()});
IElasticsearchResponse c = ec.IndexMany(bulkParams, null, "stocks").ConnectionStatus;
This returns a NullReferenceException. After some guesswork I added the Id parameter into the BulkParameters:
var bulkParams = postQueue.Select(p => new BulkParameters<Stock>(p) { Id = p.id.ToString(), Parent = p.id.ToString()});
Which seems to work, but the request returns a error response from ES:
400 Bad Request with JSON error message:
error=RoutingMissingException[routing is required for [test_index]/[stocks]/[xx]]
(where xx is the id of the document)
I'm assuming I have to insert a Routing string somewhere, but I do not know where. I've tried adding a 'Routing' parameter into the BulkParameters but that did not work at all. Can anyone please advise?
The support for IndexMany() with wrapped BulkParameters has been removed in NEST 1.0.0 beta 1
If you want to use a bulk with more advanced parameters you now have to use the Bulk() command.
The beta sadly still shipped with the BulkParameters class in the assembly
This has since been removed in the develop branch and will be released in the next beta update.
So what happens now is that you are actually indexing "bulkparameters``1``" type documents and not "stock" with proper individual bulk metadata set.
See here for an example on how to use Bulk() to index many objects at once while configuring advanced parameters for individual items.