Replace string in Azure Logic Apps - c#

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.

Related

Take settings from nested local settings.json in Azure Functions

I have got a local.settings.json like this
{
"IsEncrypted": false,
"ServiceBusSettings": {
"TransformedJson": {
"ConnectionString": "connectionstring2"
},
"ServiceLogs": {
"ConnectionString": "connectionstring3"
}
},
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
First of all is it acceptable to have nested JSON in Azure Functions Local.settings.json? I have that confusion because in Azure we dont have a json file instead we have environment variables as key val pair. (Please correct I am wrong)
If above json is acceptable, how can I get a specific key from the nested settings
For getting IsEncryped I can just use
bool IsEncryped= configuration.GetValue<bool>("IsEncrypted")
Also in function parameter if I need to use value I can Just use
%IsEncrypted%
In my case if I need to get the connection string under TransformedJson attribute and get its values and also I'd like to use that in my parameter with percentage notation.
Please suggest how can I accomplish that?

Visual Studio / TFS Api to work with test explorer / cyclomatic complexity [closed]

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.

TFS Capacity plan reading from c#

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.

Azure Functions how to add application settings to bindings

I'm trying to add some custom binding using my app settings for my Azure Function. I need to receive only string a string from my settings.
I would like to get simpleValue from my settings.
{
"bindings": [
{
"name": "someValue",
"type": "stringSetting",
"connection": "simpleValue",
"direction": "in"
}
],
"disabled": false
}
and the get it in Run method:
static void GetOrders(TraceWriter log, string someValue)
{
log.Info(someValue);
}
Is it even possible. Maybe there is other way to do it?
I already found the solution. Just add:
using System.Configuration;
and add this line to code with the key ("simpleValue") value:
ConfigurationManager.AppSettings["simpleValue"]
App Settings configurations can be referred in binding json as %MY_CUSTOM_CONFIG% - enclosed within percent symbols.
Note that the connection property of triggers and bindings is a
special case and automatically resolves values as app settings,
without percent signs.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings

How to create a C# class structure based on a json structure?

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.

Categories