Posts

Showing posts from 2017

My #PolymerSummit 2017, day 2 takeaways

Image
During day 1 of the Polymer Summit , we learnt about the Polymer 3 shift to JavaScript Modules and the NPM package manager. We were introduced to the template property getter, which returns your component's Shadow DOM, rather than using a template tag: static get template() {   return `<div>My component contents,  with tags and everything! ${interpolated_value_here}</div> `; } On day 2, we got introduced to the lit-html template library which gives us the html template tag and a render function: const helloTemplate = ( name ) => html ` < div >Hello ${ name } !</ div > ` ; // renders <div>Hello Steve!</div> to the document body render ( helloTemplate ( ' Steve ' ), document . body ); // updates to <div>Hello Kevin!</div>, but only updates the ${name} part render ( helloTemplate ( ' Kevin ' ), document . body ); This library can also be used with a component system that renders your component

My #PolymerSummit 2017, day 1 takeaways

Good news everyone! The live stream from day 1 is available on YouTube ! In version 3, Polymer will transition from using Bower as a package manager, to using NPM. This to "reduce the weirdness" within in the Project, i.e. align it to the rest of the world, as the Bower project is being deprecated. Pointing out that Bower still was a technically sound choice, the speaker stressed that there was no immediate hurry to get off it right now  (more on that later). Version 3 will also change module loader from HTML Imports to JS Modules. This is due to the fact that HTML Imports have failed to take off in the community of browser vendors. With these two changes, Polymer will work better alongside UI Frameworks and will be easier to adopt, since it uses technology you might already know. Given these two major changes, the Polymer team has decided to chill on the API changes. As such, they are also working on a converter tool that will take your Polymer 2 project and rewrite it

Getting started with Polymer 2 on Windows and the Shadow DOM

Image
*update* The very first code lab during the summit explained this so much better than I! Check it out here ! I'm writing this super-excitedly on my way to Polymer Summit in Copenhagen! In order to get ready for tomorrow's teachings, I figured I'd get my machine ready to Polymer. Following the getting started guide at https://www.polymer-project.org/2.0/start/install-2-0 on a fairly fresh install, I ran into the following issues: 1. Bower wasn't installed ( npm install -g bower ) 2. Git wasn't installed ( https://git-scm.com/download/win ) (I already had node.js installed ) After I'd installed git for Windows , I opted to just run the rest of the tutorial from the git bash. It worked a lot better! (I chose to overwrite the previously generated files when prompted, since it had failed). Reading https://www.polymer-project.org/2.0/docs/devguide/shadow-dom , something that struck me that I hadn't realized earlier, was that you can style Polymer

Json.NET is not deserializing my pretty object!

This stumped me for a while, so I figured I'd share. I had this type     public struct ChangeNameEvent : IEvent     {         public string Name { get; private set; }         public uint Id { get; private set; }         public ChangeNameEvent(string name, uint id)         {             Name = name;             Id = id;         }     } ... and this Unit Test ...         [TestMethod]         public void TestMethod4()         {             var serializationSettings = new JsonSerializerSettings             {                 TypeNameHandling = TypeNameHandling.All             };             const string serializedObject = "{\"$type\":\"Domain.ChangeNameEvent, ProperDomani\",\"Name\":\"Admin\",\"Id\":42}";             var evt = (IEvent)JsonConvert.DeserializeObject(                 serializedObject, serializationSettings);             Assert.AreEqual(42u, evt.Id);             Assert.IsInstanceOfTy

Unit testing your Azure functions - part 2: Queues and Blobs

In our last installment , we discovered how to start unit testing our Azure Functions, looking at the HTTP Trigger (and evaulating the function's HTTP response). This time, we'll take a look at using the QueueTrigger, getting supporting data from table storage and outputting Blobs. Yup, I'm tossing you into the deep end! What are we trying to accomplish? This time, we will test a function that performs some arbitrary business logic on bank accounts. The function responds to a storage queue request, logs each command and ensures that each received command is executed exactly once. Almost like a real-world function, huh? ;-) In the function above, we are introduced to three types that we need to deal with in our unit tests - the IQueryable interface, IAsyncCollector and the CloudBlockBlob concrete type. IQueryable is easy enough to work with: Introducing the Testable Async Collector When I first started exploring this topic, I figured I could just use my favourit

Unit Testing your Azure Functions

Image
You know ... I told myself to stay away from pre-releases and only stick to released software from now on. Well, I failed. Having great experiences from Azure Web Jobs , which I've written about before , I just had  to get my hands on the new Visual Studio tooling for Azure Functions, where you use the same tried and true attributes on your method arguments to bind to external resources as you've been accustomed to. Intellisense is awesome. Visual Studio is awesome. I'm really liking Microsoft these days! Now, one thing that was missing from any guidance that I could get my hands on, were how to properly test your functions. There are guides on how to write code and use tools to call your actual  functions in a host , but I couldn't readily find anything that told me how to test them quickly in isolation. Here's what I did: I created a new Unit Test Project, installed ... ... and ended up creating two constructs that turned out to be helpful: The Ver

Adding some @riotjs_ #webcomponents love ...

Image
In my previous article, I showed how we use Visual Studio to work with web components written with the Polymer 2 library . How much work would it entail to toss in a Riot component into the mix? The whole idea of web components, is that we can combine them, right? Right! Oh, and as a side note, I personally found Riot super easy to get into ! Might be a preference thing, but I'm just tossing that out there. The idea of Riot, is that it works right now with existing browser technologies whereas the Polymer components use Polyfills to bring the future of the web into the present. Groovy. In previous experiments, I've tossed together a few riot components and published them to a blob container: Just like web components written using the Polymer library has it as a dependency, Riot has a runtime that we must include where we consume our component; the riot+compiler.min.js . The cool thing about Riot, however, is that you can include that dependency at the end of your docu

Working with @Polymer 2 in @VisualStudio 2017 #webcomponents

Image
You'll be pleased to know, that we now have excellent support in our favourite IDE for creating and consuming Polymer 2 components! Sure, you could use JetBrains' WebStorm or the cross-platform Code editor from Microsoft. But Visual Studio still has your back! Let's explore the support together: Let's pick a .NET Core project template, choose to create a MVC Web Application and right-click on the bower.json file to manage our bower packages (Polymer is still using Bower): Then, install Polymer and iron-icons : If you get a nasty error message, saying something along the lines of  ECMDERR Failed to execute "git ls-remote --tags --heads git://...", exit code of #128 fatal: unable to connect to github.com ... , then open a command window and type out  git config --global url."https://".insteadOf git://  to connect to github using https instead of the git protocol. Then try installing again  ☺ Alright! Let's do the coding req

JavaScript-Mancy by @vintharas at #DevSum17 @DevSum_swe

Image
I had the great honour to take part in Jaime González García's afternoon dance-and-AngularFire session at this year's Developer Summit and was lucky enough to win his book Getting Started With the Arcane Art of Writing Awesome JavaScript for C# Developers . The book is great! Jaime succeeds in entertaining you (well ... me ;-)) throughout the entire book by taking you on a fantasy adventure as he is teaching you new things (such as the spread operator, Maps and Sets) in ES6 and their equivialent in C# and the, slightly aged, ES5. Now, I'm well versed in ES5, but still - in the first part of the book, I learned something new - while having fun! Oh, and ... check this out: Uh-huh! It's in the book! Get it now ! While reading the book, I found this memory rule for myself - when iterating in JavaScript, for ... in yields the In dex (or key ), while for ... o f yields the O bject. Also, Jaime tought me about different strategies for polymorphic functi

Service Fabric & VSTS: ##[error]Exception while parsing XML file: ... ApplicationManifest.xml

Image
Quite frustrating issue - we built our solution just fine in Visual Studio, but as our Visual Studio Team Services instance were to deploy to Azure, it stumbled upon the ApplicationManifest.xml, saying that it had an exception parsing the document (and not much else). This is how we fixed it: Unload the service fabric project (.sfproj) Edit it Add AddCorrelationIds=false-attributes in the Globals Property Group: Commit! Push! Deploy! ;-D Thanks to Nick Randell for posting his findings at https://github.com/Azure/service-fabric-issues/issues/209  and to  Kenneth Winner  for clarifying some details!

Service Fabric: The project must have its NuGet packages restored (infinite loop)

Image
After you've upgraded your Service Fabric SDK through NuGet, you might find yourself stuck in an infinite loop where Visual Studio asks you to restore NuGet packages: That's no fun! Here's how you fix it: First off, unload your Service Fabric project Then edit it ...  Update the path to the .props  file at the top of the .sfproj (...MSBuild. 1.5.0 ...) Update the path to the .targets  file at the bottom of the .sfproj (...MSBuild. 1.5.0 ... ) Save your project and reload it! Things are great again! No? You might have missing references still: Just use your NuGet package manager to reinstall those: Feeling better? Great :-)

Deadlines vs. Technical debt

Dilemma: We don't want to incur more technical debt, but we do have an important business partner that needs a bunch of development done within (too short of) a time period, which means that we'll need to take shortcuts. What should we do? This reflects a recent discussion within a group of colleagues. After some back-and-forth, we decided to declare a payback period up-front, giving each development team something akin to a credit  which they could use up to get their deliveries done in time. During the development period, the teams will create time-estimated backlog items for any technical debt they incur, thereby discussing the debt on a regular basis and also motivating them to keep their debt low. Finally, visualizing the period after the deadline, will enable management to reorganize teams as needed to deal with debt spikes.

Binding to a container or a list of blobs. #webjobs rocks

Image
So I just learned today, that they (our friends at Microsoft), added support for binding to blob containers or a list of blobs, back in August of 2015. This WebJob thing is becoming more and more comfortable, which is extra nice, since most of the knowledge acquired - at least on a conceptual level - is transferrable to Microsoft's Serverless  offering - it's Azure Functions. Speaking of which - check out the nice documentation over at  https://docs.microsoft.com/en-us/azure/azure-functions/ . What I did, was to download a PDF and then read the docs in peace on my iPad as I commute back and forth to the office. Aaaaanyway... Binding. Check this out:         public static async Task Handler(             [QueueTrigger("input-queue")] Input input,             [Blob("stuff/{BlobFolderNameAsDefinedInInput}")] IEnumerable< CloudBlockBlob> inputBlobs)         {            ... sweet, sweet code ...         } The two bindings above make the WebJobs r

Prototyping bots with Microsoft QnA Maker

Image
Microsoft's QnA Maker allows you to go from FAQ to Bot in minutes!  by copying and pasting the URL to an existing FAQ web page or uploading a set of questions and answers tsv-file (tab-separated file). There's a nice quick start video that you can watch here . In this post, I will focus on using the QnA Maker to prototype a more elaborate bot - one that would need a hefty dose of LUIS and (Microsoft's) other Cognitive Services if built "for real". What I'm talking about, is a pre-written chat script: When we (the human), say "Hello?", the QnA service will return "Ah, hello there! How can I help you today?". As you can imagine, putting these phrases together takes a lot less time than to write a bot (refer to my other articles here )! But yet, with this simple configuration, we have something that is immediately testable, demoable and something we can use as a base for further discussion. Let's step over to the Test  section o

Infer Generics, Implicit new and Significant whitespace

Image
Good afternoon! I made some suggestions on the Visual Studio section of the Uservoice site. Let's go through them in the order of controversy ;-) Implicit new My first suggestion is for a quality of life feature that I originally ran across in the Boo programming language : When referring to a class identifier, presume instantiation: throw ArgumentException(); // read as `throw new ArgumentException()` since there's no `ArgumentException` method in scope, but there is a class var banana = Fruit( "Banana" ); // read as `new Fruit("Banana")` since there's no `Fruit(string)` method in scope, but there is a class https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/18043915-implicit-new Infer Generics My section suggestion identifies a common pattern in my daily life - I've been working with a lot of sequences (lists and dictionaries) in my Web, WebJob, hybrid web app and Bot projects. To make the C# language mo

Exploring your code with NDepend 2017.1.0 Professional Edition

Image
I just got my hands on a license to NDepend 2017 (thanks patrick!). After installing it and opening an arbitrary solution I was working on at the office, it struck me how great it is to have someone - or a tool - to discuss complexity with! Not wanting to attach a NDepend project to my solution (since I share this solution with my colleagues who is not evaluating this tool yet), I opened the stand-alone Visual NDepend from the NDepend menubar Analyzing my solution, the tool highlighted that one of my methods were overly large and complex - a method that evaluated certain column headers in an Excel document against a set of known terms in order to understand its structure. Just by highlighting this complexity nudged me to take a step back and look at our overall solution to see if this particular logic belonged there, or if this entire project, in fact, could be seen as just an extraction process, handling the interpretation elsewhere. THIS is something I appreciate from this tool

Microsoft Bot Framework and the IScorable interface

Using the IScorable interface and hook your implementation into the AutoFac dependency injection container supplied by the Microsoft Bot Framework team, you can create multiple separate global chat logic handlers: BOT: Hi and Welcome! Human: Do you like candy? -> CandyResponseHandler BOT: I certainly do! Licorice is my favourite! Human: How are you feeling today? -> FeelingResponseHandler BOT: Never better! I just had some licorice a little while ago! Let's create the candy response handler together before we move on: public class CandyResponseHandler : IScorable { private readonly IDialogStack _stack; public CandyResponseHandler(IDialogStack stack) { SetField.NotNull(out _stack, nameof(stack), stack); } public async Task PrepareAsync(IActivity item, CancellationToken token) { var message = item?.AsMessageActivity(); var messageText = message?.Text; if (String.IsNullOrWhiteSpace(messageText))