Skip to content

Instantly share code, notes, and snippets.

View jpda's full-sized avatar
🤔
ok

John Patrick Dandison jpda

🤔
ok
View GitHub Profile
@jpda
jpda / provision.ps1
Created September 24, 2015 18:17
Windows 10 IoT Password/Name Change
Param (
[string]$IP,[string]$Name,[string]$Password
)
$stockPass = ConvertTo-SecureString "p@ssw0rd" -AsPlainText -Force # Default password
$securePass = ConvertTo-SecureString $Password -AsPlainText -Force # new target password
$stockCreds = New-Object System.Management.Automation.PSCredential("$IP\Administrator", $stockPass)
$newCreds = New-Object System.Management.Automation.PSCredential("$IP\Administrator", $securePass)
Get-Service -Name WinRM | Start-Service -Verbose # Ensure WS-Man is started
@jpda
jpda / DelayManager.cs
Created May 13, 2015 15:40
DelayManager.cs
internal class Delay
{
public TimeSpan DelayTime { get; set; }
public int Multiplier { get; set; }
public TimeSpan ResetTime { get; set; }
public int TerminationThreshold { get; set; }
}
internal class DelayManager
{
@jpda
jpda / IndexManager.cs
Created April 8, 2015 05:41
Create Index Schema from Type
public static void CreateIndexFromType(Type t)
{
var indexName = t.Name.ToLower();
if (SearchClient.Indexes.Exists(indexName))
{
Trace.WriteLine("Found existing index, deleting...");
SearchClient.Indexes.Delete(indexName);
}
try
@jpda
jpda / SomeEntity.cs
Created April 8, 2015 05:33
Attribute Metadata
public class SomeEntity : TableEntity
{
[IndexMetadata("Id", IsKey = true, IsRetrievable = true, IsSearchable = true, IsSortable = true)]
public string Id
{
get { return RowKey; }
set { RowKey = value; }
}
[IndexMetadata("Title", IsKey = false, IsRetrievable = true, IsSearchable = true, IsSortable = true)]
public string Title { get; set; }
@jpda
jpda / Silly.cs
Last active August 29, 2015 14:18
Attribute Metadata Silliness
public async static void AddDocuments<T>(IList<T> things) where T : class, new()
{
var indexClient = new SearchIndexClient(ConfigurationManager.AppSettings["SearchServiceName"], things.First().GetType().Name.ToLower(), new SearchCredentials(ConfigurationManager.AppSettings["SearchServiceApiKey"]));
try
{
Trace.WriteLine($"Adding {things.Count()} documents to the index...");
var thingsToIndex = things.Where(x => x.GetType().GetProperties().Any(prop => prop.GetCustomAttribute<IndexMetadataAttribute>() != null));
var newThings = thingsToIndex.Select(x =>
{
@jpda
jpda / manifest.json
Created January 12, 2015 22:07
manifest.json
"oauth2Permissions": [
{
"adminConsentDescription": "Allow the application access to the service",
"adminConsentDisplayName": "Have full access to the service",
"id": "b69ee3c9-c40d-4f2a-ac80-961cd1534e40",
"isEnabled": true,
"origin": "Application",
"type": "User",
"userConsentDescription": "Allow the application full access to the service on your behalf",
"userConsentDisplayName": "Have full access to the service",
var a = new Auth.AuthServiceClient();
a.Endpoint.AddAuthorizationEndpointBehavior();
var me = a.WhoAmI();
Console.WriteLine(me);
Console.ReadLine();
@jpda
jpda / EndpointExtension.cs
Created January 12, 2015 21:53
EndpointExtension.cs
public static class EndpointExtension
{
public static void AddAuthorizationEndpointBehavior(this ServiceEndpoint endpoint)
{
endpoint.EndpointBehaviors.Add(new AuthorizationHeaderEndpointBehavior());
}
}
@jpda
jpda / AuthorizationHeaderEndpointBehavior.cs
Created January 12, 2015 21:52
AuthorizationHeaderEndpointBehavior.cs
public class AuthorizationHeaderEndpointBehavior : IEndpointBehavior
{
public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
{
clientRuntime.ClientMessageInspectors.Add(new AuthorizationHeaderMessageInspector(AzureAdToken.Get()));
}
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{
}
@jpda
jpda / AzureAdToken.cs
Created January 12, 2015 21:47
AzureAdToken.cs
public static class AzureAdToken
{
public static string Get()
{
const string clientSecret = "CLIENT_SECRET";
const string clientId = "CLIENT_ID";
var ctx = new AuthenticationContext("https://login.windows.net/TENANT_NAME_OR_ID");
var token = ctx.AcquireToken("TARGET_RESOURCE", new ClientCredential(clientId, clientSecret));
return token.AccessToken;
}