More to Package Manger Console than Packages…

The package manger console in visual studio is capable of far more than just adding and removing nuget packages.

It is in fact a full powershell scripting environment with direct access to the Visual Studio IDE Management Api.

This is not just read-only:

$dte.StatusBar.Text = “Hello”

You can find out about the dte’s properties here:

$dte | get-member | out-gridview

The following is a great way of finding what commands are available to visual studio

$dte.Commands | Out-GridView

And this shows the local environment variables:

gci variable:* | out-gridview

I am wondering if this could be used to add command-line refactoring to visual studio.

Beyond Bugs

A developers life can consist of new features, change requests and bugs.

The basic approach to bugs is to fix them in priority order.

A more sophisticated technique is to identify that cause of the bug, and introduce a change in the process to prevent it from happening again.

For example, if you are using mvc you may have a convention based set of images.
A simple powershell script can check that the images exist in the correct location from a simple list of pages.
This list could be hardcoded in the tests, but will probably be available from somewhere else in the system.

A similar approach can be taken with logs. It can be assumed at minimum that you are logging errors.

If you only look at the logs when you have a specific error then you are missing out on a lot of data.

Simple analysis of the logs data, such as obtaining counts of each of the types of errors within an hour, will provide massive benefits.
Firstly you will be able to find the most frequent errors – even if the users are not reporting them.
If the error is not a real problem, downgrade it to a warning. If it is a real problem then it should become a priority to resolve.
Secondly it will show you areas where there are missing errors, especially if the users are reporting errors that the logs do not show.

7digital and powershell

The following shows how to query the 7digital api from powershell.

[xml]$data = (invoke-webrequest -uri http://api.7digital.com/1.2/release/details?releaseid=951886`&country=gb`&oauth_consumer_key=$my7digitalKey | select -ExpandProperty Content)

This provides an in memory object that you can walk the tree.

This is how I investiagate most xml/json feeds.

I am not publishing my key so get your own and set it in your profile:

ii $profile

Views and Beyond – Templates

Views and Beyond are a set of architecture patterns for documenting a software system.

They have three categories of view styles:

  1. Module
    • Decomposition
    • Uses
    • Generalization
    • Layered
    • Aspects
    • Data Model
  2. Component & Connector
    • Call-Return
    • Data Flow
    • Event-Based
    • Repository
  3. Allocation View
    • Deployment
    • Install
    • Work Assignment
    • Other Allocation

The following link provides a word template for views and beyond documentation:

http://www.sei.cmu.edu/architecture/tools/document/viewsandbeyond.cfm

Adding EventIds when logging to WADLogs

This is a great article on how to include an event id in the WADLogs table.

The trick is to use a custom trace source as follows

TraceSource ts = new TraceSource(“My Custom Event Source Name”, SourceLevels.Information);

ts.TraceEvent(TraceEventType.Warning, 102, “This is a test log using trace source”);

and then to configure the azure listener to get this into the appropriate log file:

This gets added to the appropriate system.diagonstics section:

<sources>

<source name=”MyTraceSource” switchName=”sourceSwitch” switchType=”System.Diagnostics.SourceSwitch”>

<listeners>

<add type=”Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ name=”AzureDiagnostics”>

<filter type=”” />

</add>

</listeners>

</source>

</sources>

<switches>

<add name=”sourceSwitch” value=”Warning”/>

</switches>

The big advantage of this is that you get to assign your own error codes to the messages.

Practically all of the default Azure stuff will be coded as zero.

This means that you can assign defined ranges of code to indicate that these are for example:

Timing Messages.

Notification for information.

Notification for action.

These make analysing the logs much easier.

Btw are you aware of the WADLogs powershell trick:

“0” + [DateTime]::UtcNow.AddHours(-1).Ticks

This gives a partition key of an hour ago.

This is great for getting extracted logs.

Extract the logs into csv and use the powershell import-csv command.

This is an amazingly fast way of analysing logs.

New Home

This is a continuation of the blog at devrants.blog.com

I have been forced to move to a new host due to the appallingly service that I have been getting from blog.com. They seem to have revoked my access to the blog, but keep the content up.

I plan to migrate some of my previous articles.  I had been blogging for over 10 years.