Posts

Showing posts with the label F#

Setup Continuous Integration and Deployment for dotnet library with Appveyor and FAKE

Setup Continuous Integration and Deployment for dotnet library with Appveyor and FAKE Last week we saw a flow to manage versioning and releases . As a continuation of last week, today I will show how we can setup versioning and releases for open source projects by configuring Appveyor and using FAKE to setup a build script. Configure AppVeyor FAKE 1. Configure AppVeyor Configuring AppVeyor is done via a yaml file appveyor.yml at the root of the repository. Then from the site https://www.appveyor.com/ , we can sign in with our GitHub credentials and add the repository to the AppVeyor projects. All the settings in the settings tab can be configured in the yaml file. appveyor.yml settings can be seen in multiple sections: global environment build test artifact deploy The global configuration is where we configure the context of the build, # 1. version: '{build}' image: Visual Studio 2017 skip_branch_with_pr: true skip_commits: files: - docs/**/* - ...

Create a simple form engine with WebSharper.UI.Next in F#

Create a simple form engine with WebSharper.UI.Next in F# WebSharper came out with WebSharper.Forms. It is a terse DSL to build form, I posted a tutorial on it few months ago https://kimsereyblog.blogspot.co.uk/2016/03/create-forms-with-websharperforms.html . It’s very powerful as the abstraction handles most of the scenarios. Today I would like to show anothe way to create forms by building a form engine. This post will be composed by 4 parts: Define the domain Implement the renderers Use it 1. Define the domain Defining a model is tricky. It needs to be both flexible enough to handle all needed scenario but it also needs to be simple enough that there aren’t too many options which would make the domain messy. I will give an example later to illustrate this. For a form engine, the domain model is composed by the elements of form and the submission behaviors. Form elements For this example we will just implement the input and input area . Implementing the rest of the con...

Use Local storage with ListModel with WebSharper.UI.Next in F#

Image
Use JS local storage with ListModel with WebSharper UI.Next in F# Last week I wanted to use the browser local storage to store a list of elements. I wanted to update the resource split project to have the data stored (temporarily) so that it will be easier to add or remove resources. The browser local storage is ideal for this kind of scenario. Turns out WebSharper.UI.Next has the feature built in to persist ListModel so today I will explain how to do it. This post is composed by two parts: 1. Use local storage with ListModel UI.Next 2. Debug values stored in Chrome 1. Use local storage with ListModel in UI.Next I started to browse WebSharper code and found that ListModel exposed a function named CreateWithStorage and that the default implementation was set to be used with local storage (ha! exactly what I wanted). The definition can be found here . So to use the storage we must use CreateWithStorage and Storage.default . CreateWithStorage<'Key, 'T when 'Ke...

Fix ‘The method or operation is not implemented Visual Studio’ when referencing project in F# solution

Image
Fix ‘The method or operation is not implemented Visual Studio’ when referencing project in F# solution Yesterday, when trying to reference a project within my solution, I had an error from VS with the following message. The problem was that I was referencing another project which was unloaded. When expanding the list of references, there is a warning sign for problematic references: Most of the time, for me at least, it indicates a mismatch of F# version between the two libraries. But a mismatch of F# version doesn’t cause the not implemented exception on Visual Studio. The issue was that the library referenced was unloaded . Once I made sure it was loaded, the sign disappeared and VS allowed me to add a reference.

How to avoid input lost focus with ListModel WebSharper F#

Image
20170202_listmodel_websharper_lostfocus.md How to avoid input lost focus with ListModel WebSharper F# Few months ago, I explained how ListModel worked . Today I would like to share a recurring issue that I used to have - lost of focus on input every time the ListModel values change . There’s an easy solution to that which I will demonstrate by first showing the initial code and explaining what is going on, why the focus is lost, then I will explain how we can work around it. This post will be composed by two parts: 1. Why the inputs lose focus? 2. How to prevent it I thought about sharing this when I saw that someone else has had the same issue - http://try.websharper.com/cache/0000Bj . 1. Why the inputs lose focus? The code is the following: [<JavaScript>] module Lensing = let aliases = ListModel.Create id [ "Bill"; "Joe" ] let lensIntoAlias aliasKey = aliases.LensInto id (fun a n -> n) aliasKey let Main = d...

Authentication for WebSharper sitelet with JWT token in F#

Image
Authentication for WebSharper sitelet with Jwt token in F# Authentication is an important part of any Web applications. Today I will explain how we can create the essential modules required to authenticate a user. This post will be composed by four parts: 1. What is needed for authentication 2. Password encryption and storage 3. JWT token 4. OWIN auth middleware and WebSharper OWIN selfhost 5. Glue it all together 1. What is needed for authentication In this blog post we will see how to authenticate users with credentials userid and password. First, we will see how to store encrypted password and how we can verify credentials against the one contained in database. Then we will see how we can authenticate users while communicating between client (browser) and server with Jwt token. Lastly we will see how both glued together provide a reliable authentication story. 2. Password encryption and storage 2.1 Storage To store data I will be using Sqlite via Sqlite net pcl. If yo...

Output logs in Console, File and Live stream for your WebSharper sitelet

Image
Output logs in Console, File and Live stream for your WebSharper sitelet Logs are an important part of development. Extracting and analysing debug output and errors is very important especially when the web server goes live. In this post I will show how we can setup a Console target , a File target and a Live stream on a static HTML page using NLog . NLog is a log framework which can be configured to output logs on different “target”. https://github.com/nlog/NLog/wiki/Targets This post is composed by 4 parts: 1. Get NLog on your sitelet 2. Define a Console target 3. Define a File target 4. Define a Live stream target - WebSharper part 1. Get NLog on your sitelet First start by getting NLog and NLog.Configuration packages from nuget. This will install NLog package in your project and also add an xml configuration nlog.xml file with an xsd. To start logging, simply get the logger instance via let logger = LogManager.GetCurrentClassLogger() and start logging by using any o...