Posts

Showing posts from 2017

ADO.Net Async with Transactions... A Lesson Learned

Image
Last night I was testing out a new WebApi Filter I've added to a project, its fairly simple, log some data that comes from a HTTP header to the DB.

This particular project has no Entity Framework or anything, just simple ADO.Net, in fact I think the project has 3 stored proc's in total.

I tend to Async all the things by default so when I originally wrote my DB code I had:

using (var conn = new SqlConnection(_connectionString))
{
     await conn.OpenAsync();
     using (var transaction = conn.BeginTransaction())
     {
          var command = conn.CreateCommand();
          command.CommandText = "[Api].[LogDeviceRequest]";
          command.CommandType = System.Data.CommandType.StoredProcedure;
          command.Transaction = transaction;

          command.Parameters.AddWithValue(//etc          try
          {
             await command.ExecuteNonQueryAsync();
          }
          catch
          {
             transaction.Rollback();
             throw;
          }
          transacti…

Playing further with ASP.Net Core whilst on my hols... VSCode fun and cool new Anti Forgery Validation

I'm on vacation, 10 days in Norfolk with extremely limited connectivity and action packed days with the kids. Whilst here on two nights everyone has fallen asleep before me so I decided it would be a good time to poke around further at ASP.Net Core as I've still not produced any production code with it yet, only small samples.

Now I don't have my laptop on me but I do an old one that's here purely for any work emergencies and for childcare emergencies, (you know the ones, its 6am and the 2 year old is awake, peppa pig at 6am is an emergency!). This means I have literally nothing on me and I can only tether internet via my wife's iPhone 6 which has barely a bar of signal, this rules out a cloud VM running VS. So I turned to VSCode, its sooo lightweight its easy to download, install and run on this laptop. Get the .Net Core 2.0 SDK and the VSCode C# extension and you are literally running within 30 mins.

I won't go to much into the projects setup and stuff as it…

Code therapy brought to you this week by .Net Core 2

Image
So the last week has been hard going so tonight I decided to have some code therapy. I've been meaning to explore .Net Core 2 further and decided tonight was the time to port a library I had written in Mono for Raspbian over to .Net Core land.

It's worth noting that .Net Core 2 is only in preview on Raspbian but thats good enough for me ;)
Getting Started First things first I updated VS2017 to the latest update 3 release. My Visual Studio wasn't telling me the update was available so I simply got the web installer again from VisualStudio.com and it advised VS was already installed and could be updated. This took about 35 mins on my Dell XPS 13 laptop but on my SurfacePro 3 its taken nearly an hour.
I then chose to create a new .Net Standard project but found I couldn't target .Net Standard 2. Turns out Update 3 doesn't include .Net Core 2 you need to go get this from: https://www.microsoft.com/net/core#windowscmd
You can now choose .Net Standard 2.0
I then created …

Its the little things...

In the history of C# we have been spoiled by every version having excellent new language features in. We had Generics, Linq, Tasks, async/await which were massive hitters and transformed the way we worked and wrote code.

C#7 however I found has given us lots of little improvements that make things smoother and easier which has been great. One feature I hadn't really used yet though was the new Pattern Matching, this wasn't because I hadn't wanted to but more I hadn't seen a time to really use it.

That was until tonight.

A year or so ago I had a scenario where I had to take a base type and then1 return the appropiate mobile view to render. Prior to Pattern Matching I ended up with something like:
if (value is HoldingPage)
return new LoadingView();
}
var listingPage = value as ListingPage;
if (listingPage != null)
{
return new ListingView(listingPage);
} Tonight I needed to add a new view into this code and decided it needed tidying up. Pattern Matching allows us to test…

Fixing a Quirky "Xamarin.Forms ListView Bug" That Led Me Back to Basics And How Most Bugs Are Written By Users!

Image
For the last two evenings I've been chasing what seemed a random bug. The crux of it came down to scrolling large lists within a ListView, 1000's of items, which were grouped, would muddle up the items and often duplicate an item a couple of times.

An example output:

First page of results:
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Test 11
Test 12 The second page would then render:

Test 13
Test 14
Test 1
Test 15
Test 16
Test 4
Test 17
Test 18
Test 19
Test 20
Test 6 At first glance this looked like a random error. I considered that maybe my list parsing code (the app takes HTML and makes in easier to use) but my unit tests checked out. So I went over these again with a toothcomb. All checked out.

Next I considered the code that grouped the items, again unit tests all good, toothcomb said still good.

So I sat pondering. Was there something similar about all of the duplicated items. There was, they were all items that didn't then link to a separate…

A First Foray into Alexa Skills Using AWS Lambda's with C#

Image
Tonight I decided to try out something new that I had been meaning to for a while rather than continue poking around on my app.

Since Alexa's release I've been itching to play with it, I decided whilst I was learning one thing why not learn three things so decided to use AWS Lambdas with .Net Core as well.

I've used AWS extensively with work but never used Lambdas although I was aware of them and knew they were similar to Azure Functions, Ben Godwin's show on .Net Rocks also convinced me it was time to give them a proper look.

.Net Core I've also played with and had some great training from the .Net Core guys at NDC London from this year but I've never published anything. Tonight this was all going to change :)

A quick note before I continue, I'm writing this as I go so a few things might feel disjointed but hopefully it will all make sense.

First Steps - 1st Hour In order to get going I set my self up a personal Amazon account, you can go do this..., once h…