Skip to content

Instantly share code, notes, and snippets.

View garima2510's full-sized avatar

Garima Agrawal garima2510

View GitHub Profile
$ErrorActionPreference = "Stop"
#Name of pfx file that needs to be password protected with extension
$pfxFileName = Read-Host -Prompt 'Input pfx file name'
if($pfxFileName) {
#Replace .\ with actual path where .pfx is stored. Do not include file name
$pfxFilePath = (Get-Item -Path ".\").FullName
@garima2510
garima2510 / CustomDbContext.cs
Last active September 16, 2020 04:28
Partial class to override SaveChanges of DbContext and use it for creating audit trail
public partial class CustomDbContext: DbContext
{
public override int SaveChanges()
{
// Get all Added/Deleted/Modified entities (not Unmodified or Detached)
//you can get updated and deleted in same collection. I am doing so for ease of purpose
//getting added entries in different collection to fetch their generated ids and then log them
var addedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();
var updatedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified).ToList();
var deletedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted).ToList();
@garima2510
garima2510 / RefreshAASModel.ps1
Last active February 21, 2020 06:48
Powershell to asynchronously refresh analysis server model in azure
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Init defaults
$status = [HttpStatusCode]::BadRequest
$ErrorActionPreference = "STOP"
$RequestBody = $Request.Body
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
/// <summary>
/// code to delete data from logs table
/// </summary>
/// <param name="numberOfDays">days before which all data should be deleted</param>
@garima2510
garima2510 / DeleteOldTables.cs
Last active August 20, 2019 15:23
Code to delete old storage tables from Azure
using System;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
/// <summary>
/// delete old metrics table both PT1H and PT1M
/// </summary>
/// <param name="tablepPrefix">WADMetricsPT1HP10DV2S and WADMetricsPT1MP10DV2S</param>
@garima2510
garima2510 / HomeController.cs
Last active July 31, 2019 02:40
Code to invoke MIP SDK for SharePoint files
private void InvokeMIP()
{
//this client id is for Azure AD app and NOT of SharePoint app
private static readonly string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static readonly string appName = ConfigurationManager.AppSettings["app:Name"];
private static readonly string appVersion = ConfigurationManager.AppSettings["app:Version"];
private static readonly string mipData = ConfigurationManager.AppSettings["MipData"];
private readonly string mipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, mipData);
try
{
@garima2510
garima2510 / App.css
Last active January 6, 2017 14:49
Demo of Knockout.js with Sharepoint 2013
.tableStyle {
border-collapse:collapse;
border: 1px solid black;
text-align:center;
width:50%;
padding:15px;
}
@garima2510
garima2510 / App.css
Last active December 28, 2015 20:39
Demo of Knockout.js with SharePoint 2013 - Removing Items
/* Place custom styles below */
.tableStyle {
border-collapse:collapse;
border: 1px solid black;
text-align:center;
width:50%;
padding:15px;
}
@garima2510
garima2510 / App.css
Last active December 28, 2015 18:09
Demo of Knockout.js with Sharepoint 2013 - Adding Items
.tableStyle {
border-collapse:collapse;
border: 1px solid black;
text-align:center;
width:50%;
padding:15px;
}
.messages {
display:none;
public class HomeController : Controller
{
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; //clientId
private static string appKey = ConfigurationManager.AppSettings["ida:AppKey"]; //clientSecret
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"]; //https://login.windows.net/{0}
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"]; //TenantName.onmicrosoft.com
private const string ResourceUri = "https://onenote.com";
public static readonly string Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);//https://login.windows.net/TenantName.onmicrosoft.com
Uri returnUri = new Uri("https://localhost:44327/Home/ReturnFlow");