How to create URL parameters from JSON structure in C# - c#

:) For my app I need to generate URL for HTTP GET Request. I've prepared JSON data, because I will be working with them, so I would like to generate these URLs for filtering data from my JSON data structures in C# code.
For example I have this JSON structure:
{
"filter": {
"logic": "and",
"filters": [
{
"field": "created",
"operator": "gte",
"value": "2016-09-19+00:00:00"
},
{
"field": "created",
"operator": "lte",
"value": "2016-09-19+59:59:59"
}
]
}
}
I would like to have this URL:
.../api/v6/tickets?filter[logic]=and&filter[filters][0][field]=created&filter[filters][0][operator]=gte&filter[filters][0][value]=2016-09-19+00:00:00&filter[filters][1][field]=created&filter[filters][1][operator]=lte&filter[filters][1][value]=2016-09-19+59:59:59
I thought that there could be some method in HttpWebRequest to do that for me, but I didn't find anything. I've tried to pass on JSON data in body, but it's not working (because I need to create Request before that?).
Do you know something (some standardized method or something else) what I could use for generating dynamically URL by JSON structure?
Thank you very much!

Related

How do I import a Json file into a django database whilst maintaining object references

I have a C# desktop app and a django webapp that share a set of common class/model types. The C# app is exporting json files containing instances of these models, and I am trying to import these into the django database.
The complication is that the parent model contained within the json file has properties that may reference the same sub-model in multiple places. For example, the json file looks something like this:
{
"$id": "1",
"SubModels": {
"$id": "2",
"$values": [
{
"$id": "3",
"name": "Dave",
"value": "123"
},
{
"$id": "4",
"name": "John",
"value": "42"
}
]
},
"PreferredSubModel: {
"$ref": "4"
}
}
Which was created using the using System.Text.Json.Serialization C# library with the ReferenceHandler = ReferenceHandler.Preserve serialisation option. In django, I've converted the json file into a dictionary using model_dictionary = JSONParser().parse(json_file).
Are there any existing functions (in the django Python environment) that can handle this $id/$ref system to maintain class instances, or do I need to code my own deserializer? If the latter, does anyone have any suggestions for the best way to handle it?
I'm new to django and json files, so hopefully I've just been googling the wrong terms and something exists...

how to run exe file in azure data factroy with input parameters?

i have a console application. i built this application and uploaded it to the Azure blob storage. Then i run this application Azure data factory pipeline. All are fine but the problem is if i want to add new parameters(get input) to console application how can i do that? Is there any specific way to do it?
{
"name": "samplebatch",
"type": "Custom",
"policy": {
"timeout": "7.00:00:00",
"retry": 0,
"retryIntervalInSeconds": 30,
"secureOutput": false
},
"typeProperties": {
"command": "SampleApp.exe",
"folderPath": "customactv2/SampleApp",
"resourceLinkedService": {
"referenceName": "StorageLinkedService",
"type": "LinkedServiceReference"
}
"linkedServiceName": {
"referenceName": "dataloadbatchservice",
"type": "LinkedServiceReference"
}
}
This is what i have done so far in the data factory pipeline code.
Please refer to the extendedProperties property in typeProperties, you could use it.
User-defined properties that can be passed to the custom application
in JSON format so your custom code can reference additional properties
Doc: https://learn.microsoft.com/en-us/azure/data-factory/transform-data-using-dotnet-custom-activity#custom-activity
Sample:https://github.com/Azure/Azure-DataFactory/blob/master/Samples/ADFv2CustomActivitySample/MyCustomActivityPipeline.json

.NET Core 2.0 Avro CodeGenerator cannot handle nested structures or IDL

I am trying to use the Microsoft.Hadoop.Avro.Utils library in a C# .NET Core 2.0 application to generate C# class for my Avro schema, but I cannot get it to handle nested records when creating a simple Avro JSON schema.
In general, I would much more like to use the Avro IDL format to describe my data structure as it is a bit complex and I am reusing my records different places. I have tried finding documentation on the .NET Core Avro library with no luck and I cannot see if it is even possible to auto generate complex structures in the C# library.
Do anyone have experience with this library or how to auto generate C# classes for Avro. Below is a very simple example of an Avro schema that I cannot get nested Address class into the final output.
{
"type": "record",
"name": "Person",
"fields": [
{
"name": "name",
"type": "string"
},
{
"name": "address",
"type": {
"type": "record",
"name": "Address",
"fields": [
{
"name": "address",
"type": "string"
},
{
"name": "zipcode",
"type": "string"
}
]
}
}
]
}

acess tfs to get capacity information

I am trying to get project information from tfs server programitaically.I want to know how to acess the capacity information.Ive serached for it online and it says that that capacity info is stored in [dbo].[tbl_TeamConfigurationCapacity].
But am not understanding how to query for the table using wiql.Anyone have any idea about it ?
This table is only available in the Project Collection database and querying that table is not supported through SQL nor WIQL. While technically possible through SQL, any direct access of the Project Collection database is unsupported and the underlying structure may change between major versions, updates and even hotfixes.
Instead of directly accessing the capacity in the database, the supported method is to use the REST api to query the capacity.
Example:
GET https://{instance}/DefaultCollection/{project}/{team}/_apis/work/TeamSettings/Iterations/{iterationid}/Capacities?api-version={version}
GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber/_apis/work/teamsettings/iterations/2ec76bfe-ba74-4060-970d-4567a3e997ee/capacities?api-version=2.0-preview.1
{
"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"
}
]
}

How to get a C# Arcanist linter working?

Here is what it says when I run arc linters --verbose:
AVAILABLE csharp (C#)
Configuration Options
severity (optional map<string|int, string>)
Provide a map from lint codes to adjusted severity levels: error,
warning, advice, autofix or disabled.
severity.rules (optional map<string, string>)
Provide a map of regular expressions to severity levels. All matching
codes have their severity adjusted.
discovery (map<string, list<string>>)
Provide a discovery map.
binary (string)
Override default binary.
What is a discovery map? It doesn't tell you what it is, but you MUST have it. Unfortunately, the source code did not enlighten me.
binary... I don't want to override the default binary... What is the default binary? I HAVE to override it, so I need to get one? Where do I get a C# linter binary compatible with Arcanist? The only one I could find is https://github.com/hach-que/cstools, but it throws an exception.
Let me know if I can add more info.
cstools is the one you need;you can see this if you look into the ArcanistCSharpLinter.php, where it looks for cslint.exe as the default binary.
--- Edit ---
Not sure if you're looking at the right tool; the one being referred to is this one developed by hach-que, here:
https://github.com/hach-que/cstools
I'm not super-familiar with this linter (don't do any serious C# development myself), but a quick peek in the source code suggests that the discovery map is simply a string map called "discovery", that has settings for the linter.
See also: https://github.com/hach-que/cstools/issues/1
Copy Pasting examples here since that seems to be SO policy:
Sample .arcconfig:
{
"project_id": "Tychaia",
"conduit_uri": "https://code.redpointsoftware.com.au/",
"arc.autostash": true,
"load": [
"Build/Arcanist"
],
"unit.engine": "XUnitTestEngine",
"unit.csharp.xunit.binary": "packages/xunit.runners.1.9.1/tools/xunit.console.clr4.exe",
"unit.csharp.cscover.binary": "cstools/cscover/bin/Debug/cscover.exe",
"unit.csharp.coverage.match": "/^Tychaia.*\\.(dll|exe)$/",
"unit.csharp.discovery": {
"([^/]+)/(.*?)\\.cs": [
[ "$1.Tests/$1.Tests.Linux.csproj", "$1.Tests/bin/Debug/$1.Tests.dll" ],
[ "$1.Tests/$1.Tests.Windows.csproj", "$1.Tests/bin/Debug/$1.Tests.dll" ]
],
"([^\\\\]+)\\\\(.*?)\\.cs": [
[ "$1.Tests\\$1.Tests.Windows.csproj", "$1.Tests\\bin\\Debug\\$1.Tests.dll" ]
],
"([^/]+)\\.Tests/(.*?)\\.cs": [
[ "$1.Tests/$1.Tests.Linux.csproj", "$1.Tests/bin/Debug/$1.Tests.dll" ],
[ "$1.Tests/$1.Tests.Windows.csproj", "$1.Tests/bin/Debug/$1.Tests.dll" ]
],
"([^\\\\]+)\\.Tests\\\\(.*?)\\.cs": [
[ "$1.Tests\\$1.Tests.Windows.csproj", "$1.Tests\\bin\\Debug\\$1.Tests.dll" ]
]
}
}
Sample .arclint:
{
"linters": {
"csharp": {
"type": "csharp",
"include": "(\\.cs$)",
"exclude": [ "(\\.Designer\\.cs$)", "(Phabricator\\.Conduit(.*+))", "(TychaiaProfilerEntityUtil\\.cs)" ],
"binary": "cstools/cslint/bin/Debug/cslint.exe",
"discovery": {
"([^/]+)/(.*?)\\.cs": [
"$1/$1.Linux.csproj"
],
"([^\\\\]+)\\\\(.*?)\\.cs": [
"$1\\$1.Windows.csproj"
]
}
},
"license": {
"type": "tychaialicense",
"include": "(\\.cs$)",
"exclude": [ "(\\.Designer\\.cs$)", "(Phabricator\\.Conduit(.*+))", "(TychaiaProfilerEntityUtil\\.cs)" ]
}
}
}
Anyway, if you're having trouble getting cstools to work, I'd recommend opening an issue on the Github repo; he seems to be pretty responsive. Plus, as an open-source developer, it's always great to hear that others are using your work.

Categories

Resources