Skip to content

Instantly share code, notes, and snippets.

View jlattimer's full-sized avatar

Jason Lattimer jlattimer

View GitHub Profile
string secretUrl = "https://myvaulttest.vault.azure.net/secrets/MyPassword/00000000000000000000000000000000";
//Retrieve a secret by its url
var getKeyByUrlTask1 = Task.Run(async () => await GetSecretByUrl(token, secretUrl));
Task.WaitAll(getKeyByUrlTask1);
if (getKeyByUrlTask1.Result == null)
throw new InvalidPluginExecutionException("Error retrieving secret value from key vault");
//Deserialize the vault response to get the secret
GetSecretResponse getSecretResponse1 = DeserializeResponse<GetSecretResponse>(getKeyByUrlTask1.Result);
//returnedValue is the Azure Key Vault Secret
string vaultName = "https://myvaulttest.vault.azure.net";
string secretName = "MyPassword";
//Retrieve the latest version of a secret by name
var getKeyByNameTask = Task.Run(async () => await GetSecretByName(token, vaultName, secretName));
Task.WaitAll(getKeyByNameTask);
if (getKeyByNameTask.Result == null)
throw new InvalidPluginExecutionException("Error retrieving secret versions from key vault");
var retrievedSecretUrl = getKeyByNameTask.Result;
// Retrieve a secret by its url
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
MethodTimeLogger.Tracer = tracer;
// What manually setting up method timing might look like
ManualTimer(tracer);
// What using IL weaving to inject logging looks like
@jlattimer
jlattimer / CRMAuth.cs
Last active January 17, 2018 08:48
Dynamics CRM C# SOAP only authentication
using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
namespace CRMSoapAuthCSharp
{
class CrmAuth
@jlattimer
jlattimer / MSFlow_AITrace.json
Last active March 12, 2018 03:05
Application Insights Trace body #blog
{
"data": {
"baseData": {
"application_Version": "9.0.0.2090",
"dependencies": null,
"exceptions": null,
"measurements": null,
"message": "Hello world",
"metrics": null,
"properties": {
@jlattimer
jlattimer / MSFlow_AIEvent.json
Created March 12, 2018 03:05
Application Insights Event body #blog
{
"data": {
"baseData": {
"application_Version": "9.0.0.2090",
"dependencies": null,
"exceptions": null,
"measurements": {
"SomethingTrackableNumber": 100
},
"message": null,
@jlattimer
jlattimer / MSFlow_AIMetric.json
Created March 12, 2018 03:10
Application Insights Metric body #blog
{
"data": {
"baseData": {
"application_Version": "9.0.0.2090",
"dependencies": null,
"exceptions": null,
"measurements": null,
"message": null,
"metrics": [
{
@jlattimer
jlattimer / MSFlow_AIDependency.json
Created March 12, 2018 03:25
Application Insights Dependency body #blog
{
"data": {
"baseData": {
"application_Version": "9.0.0.2090",
"properties": {
"orgName": "test.crm.dynamics.com",
"source": "Microsoft Flow"
},
"severityLevel": null,
"ver": 2,
@jlattimer
jlattimer / GetDuration.csx
Created March 12, 2018 03:26
Application Insights / Flow duration calculator #blog
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("Starting Function");
string start = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "start", true) == 0)
.Value;
@jlattimer
jlattimer / BuildTimeToAppInsights.ps1
Created January 5, 2019 23:21
Send Azure DevOps build time to Application Insights as a custom metric #blog
$startBuild = Get-Date -Date "$Env:System_PipelineStartTime"
Write-Host "Start time: $startBuild"
$endBuild = Get-Date
Write-Host "End time: $endBuild"
$ts = New-TimeSpan -Start $startBuild -End $endBuild
$tm = [math]::Round($ts.TotalMinutes, 2)
Write-Host "Build time (min): $tm"
# $(AppInsightsKey) should be your Application Insights Instrumentation Key
if (-Not ('$(AppInsightsKey)' -match("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")))