powershell

Open Live Writer + Syntax Highlighting

I have been trying to get the open source fork of Windows Live Writer to recognize plugins for ages now, have tried

Nothing seemed to work. Then I was just about to give up, then I came across this post : https://blogs.technet.microsoft.com/simonbrown/2017/06/23/using-open-live-writer/ by Simon Brown that just rained unicorns on my rather gloomy day

Simon has written this PowerShell script that you run once, and then just Restart Open Live Writer, and bingo by plugin now works.

Here is his script, thanks Simon you rock

#download zip file for syntax highlighting
$url = "https://richhewlett.blob.core.windows.net/blogdownloads/SyntaxHighlight_WordPressCom_OLWPlugIn_V2.0.0.zip" 
$path = (Get-Item -Path ".\" -Verbose).FullName + "\SyntaxHighlight_WordPressCom_OLWPlugIn_V2.0.0.zip"

Write-Host "Downloading [$url]`nSaving at [$path]" 
$client = new-object System.Net.WebClient 
$client.DownloadFile($url, $path ) 
      
#create destination directory
$LocalAppDir = [Environment]::GetFolderPath("LocalApplicationData")
$OpenliveWriterDir = $LocalAppDir + "\OpenLiveWriter"

#just in case there are multiple versions installed, or there's an upgrade, enumerate the application binary folders
$appDirectories = Get-ChildItem $OpenliveWriterDir | Where-Object {$_ -like "app-*"};

foreach ($appDirectory in $appDirectories) {

    #Create destination directory
    $targetDir = $appDirectory.FullName + "\Plugins"
    if(!(Test-Path -Path $targetDir )){
        Write-Host "Creating path $targetDir"
        New-Item -ItemType directory -Path $targetDir
    }


    #decompress file into target directory
    Write-Host "Expanding $path to $targetDir"
    Expand-Archive $path -DestinationPath $targetDir

    #update config file
    $configFileName = $appDirectory.FullName + "\OpenLiveWriter.exe.config"
    [xml] $xml = gc $configFileName

    #create the new element
    $newitem = $xml.CreateElement("loadFromRemoteSources")
    $newitem.SetAttribute("enabled","true")

    #if it doesn't already exist in the file, add it and save
    if (!$xml.SelectSingleNode("//loadFromRemoteSources")) {
        $xml.DocumentElement.LastChild.AppendChild($newitem)
        $xml.Save($configFileName)
    }    
}

Woohoo

Advertisements
AWS

AWS : Initial Setup

 

I am fairly good with Azure, and have used many of its services over the years. I have just started a new job where they used AWS, my aim is to get as good with AWS as I am with Azure.

 

To this end I am going to document this along the way, and shall be producing new projects (either C# or Scala depending on how I feel) that demonstrate the topics. I will start off simple where I may look at a topic in isolation (what I mean is 1 AWS service in isolation), but then there may be some posts that will use a whole raft of integrated AWS services.

 

So that’s the plan

 

Where is the code?

There is no code for this post, but all code will reside in self contained solutions inside this GitHub repo : https://github.com/sachabarber/AWS

 

So What Is This Post About?

Well before you can get started using AWS, there are a number of different things you need to do, namely:

 

 

  • Register for free account
  • Setting up an IAMs account, give permissions, download credentials for use with Profile
  • Enable IAM to view billing (under root account)
  • Install .NET/Java/Scala SDK
  • Install AWS toolkit

 

So lets dive into these and see what you need to do

 

Register For Free Tier Account

AWS has a great free tier that you can sign up for here : https://portal.aws.amazon.com/billing/signup#/start, this is a fairly straight forward process, but be warned you will need to give you credit card details here. This account that you create here is known as your “root account”, and this account has pretty much unrestricted access. So we want to keep this account safe. We will see how to do that in a minute.

 

Setup An IAM Account

Assuming you have created a root account, you should be able to login to the AWS console:

 

image

 

We now want to search for the “IAM” service, and when it launches in the console you should create a user. This user will be the user that is used to associate with the AWS services that you will use, we never ever want to give out our root user access privs. You can chose how you want to organize this one type of user per service, per project. That is up to you. For me, I will be keeping it simple, and creating 1 new user, and adding permissions to it for other AWS services as I need them. Essentially the users are groups/permission based.

image

 

You should also give it programmatic access

image

 

So once you have done with creating your IAM user, you need to do the following

 

1. Download the credentials.CSV file : KEEP IT SAFE

 

image

2. You will need to login to the AWS console using you main root user. We want to allow the IAM user access to see billing information etc. To do this we need to find this menu for the root user : https://console.aws.amazon.com/billing/home?#/account

 

Then you want to enable this setting:

 

image

 

 

Install The SDK Of Your Choice

Next up you will want to install the SDK of your choice. So as I say for me this will either be C#/Scala, so any of these

 

AWS Toolkit For VS2017

There is also a toolkit for VS2017 that you can install : https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.AWSToolkitforVisualStudio2017

 

So with all that in place, we should be able to launch VS2017. There are many ways that the credentials can work when using AWS, such as

  • Directly in App.Config (this is not recommended)
  • Using Profile Store
  • Using well known path for credentials file
  • Using exact path for credentials file

 

For this series of posts, we will use the Profile Store and just import the “credentials.csv” file that you downloaded for your user in the steps above. So lets see how we do that:

 

Using the AWS Explorer, we can edit the profile using the button provided

 

image

 

This will show this from where you can import the downloaded “credentials.csv” from above. This will then associate this user with the “Default” profile, and you should be able to use the AWS services via code, providing you have also enabled the IAM user access to the relevant permission. Don’t worry if you haven’t, permissions can be added later.

 

image

 

With all this in place you should be able to write some new C# AWS project. Yay