Thursday, 28 June 2018

Auto Complete Incremental Search with ReactiveUI ?

A Winforms UserControl had an incremental search TextBox and a list. A detail view is set from the selected value in the list. This works when I click on a particular list item.

I want to get the last string value from the incremental AutoCompleteSearch TextBox too. To fire a command and also set the user in the Detail view. But:

 Couldn't find a Command Binder for System.Windows.Forms.AutoCompleteStringCollection 

listUsers is the compound UserControl with a property SearchAutoCompleteCustomSource:

    public AutoCompleteStringCollection SearchAutoCompleteCustomSource
    {
        get { return tbAutoCompleteSearch.AutoCompleteCustomSource; }
        set { tbAutoCompleteSearch.AutoCompleteCustomSource = value; }
    }

MyView:

    this.BindCommand(this.ViewModel, vm => vm.UserToFind,
                                      v => v.listUsers.SearchAutoCompleteCustomSource);

MyViewModel:

private readonly ReactiveCommand userToFind;
public ReactiveCommand UserToFind => this.userToFind;

public MyViewModel()
{
    this.userToFind = ReactiveCommand.Create(userName => this.SetUserSelected(userName));
}

private bool SetUserSelected(string userName)
{
    User user = userManager.GetUserByName(userName);
    bool userFound = (user != null);

    if (userFound)
    {
        SetDetailView(user);
    }
    return userFound;
}

Monday, 24 April 2017

Locating an element to test with FlaUI

The WinForms application I'm trying to test is legacy in more ways than I'd like.

Here is FlaUI Inpect looking at a login form I want to test. I need access to 4 items. Each has an AutomationId. The ids are: textUser, textPINCode, buttonHalt, buttonLogin

These 4 controls are custom controls derived from Krypton controls. I think the Krypton controls derive from Windows Forms 2.0

Suppose I have a handle on the top level window ("FormSplashScreen"). What is the XPath to get one of the 4 I want (say textUser)?

Thursday, 6 April 2017

AOP - Aspect Oriented Programming

Aspect-oriented programming was first described 20 years ago due to work of a team led by legendary programmer Gregor Kiczales [who also co-authored the book "The Art of the Metaobject Protocol" ]

What is it?

AOP aims to eliminate the noise of cross-cutting concerns, CCC, by putting them all in one place while still allowing the code previously "tangled" up with CCC to work just as before. The business logic is clearer, easier to read and maintain.

AOP concepts

  • cross-cutting concern, CCC: Is code which applies all over the place and often relates to getting an application to work rather than to any business concern. It cuts across an application. e.g. authentication, logging, exception handling, caching data, wrapping a transaction around something, auditing, ...
  • join point - a place in code where it can be 'cut', joined to, or intercepted. e.g. just before I call svc.SaveName()
  • Pointcut - a set of join points. e.g. just before any SaveName() method in project UI is called.
  • advice - some code to be applied by AOP
  • aspect - a combination of Pointcuts with advice
  • tangling - when CCC(s) are mixed with business or core logic like spaghetti such that the core logic is confusing to read.
  • scattering - having CCCs in multiple methods and classes
  • weaving - how AOP applies aspects to core logic.

Potential applications for ApoG

  • Authentication and Authorization : by putting this all together in one place the problem of security is not confused with other business logic.
  • Data caching
  • Exception handling - hopefully including all unhandled exceptions. ApoG currently has 991 exceptions.
  • Logging - There are over 2000 of these
  • Transaction wrap-around e.g. to save a unit of work. ApoG currently does not have unit of work transactions but these will be needed in future.
  • Auditing? - i.e. The process of saving PDF files and entries to the database can be put in one place.

Advantages

  • Cleaner code
  • DRY - It applies Don't repeat yourself. It reduces code duplication
  • SRP - It applies the Single Responsibility Principle. Ensures a method or class does only one job.
  • Readability is improved - because one can read the core logic without being distracted by the CCCs
  • Maintenance is easier - because code relating to a CCC is in only one place it is easier to update. Because core logic is cleaner and uncluttered by tangential concerns it is easier to change just the core logic without interfering with anything else.
  • Money is no object because every AOP tool but one is free. Dozens of AOP tools have been written.

Disadvantages

  • ????

Software

Top 20 AOP tools

Interception, code. License: MIT OSS

NConcern: Is a relative newcomer. License: OSS

PostSharp: This has been the main .net AOP package since it arrived on the scene. License: Commercial software. Licenses are up to £449 per developer for a lifetime license. Limited licences are less. Not so expensive. Consider: If AOP improves productivity by 5%, the saving is at least £2500 per year, when one considers the average annual cost of a programmer is certainly over £50k/year. PostSharp Express is free but limited.

Training:

More articles:

AOP with the RealProxy Class | Principles of AOP, from 2015

Examples

Also see book listed above: AOP in .net. Although it may look like many AOP packages are not well documented, they often use similar implementation patterns. Like dependency injection, once one understands the principle, changing tools is relatively easy.

Thursday, 9 February 2017

F-sharp books.

TitleLevelAuthorsPublisherDatePagesComment
Learn F# (MEAP)IntroIsaac AbrahamManningApr-2017400
Real-World Functional Programming with examples in F# and C#Tomas Petricek with Jon SkeetManningDec-2009560
Beginning F# 4.0Robert Pickering, Kit EasonApress2016309
Friendly F# (Fun with game programming)Costantini, Giulia & Maggiore, GiuseppeO'ReillyAug-2011191
F# SuccinctlyFreeRobert PickeringSyncfu-sion201296Free
Analyzing and Visualizing Data with F#Tomas PetricekO'ReillyOct-201547Free, from publisher
FSharp Specification 4.0Fsharp FoundationFsharp Founda-tion365Free, Not really a book but can be published as such
F# Web ProgrammingCommunity for F#GitBookFree. Not really a book because it's just a set of hints!
F# Survival GuideJohn Puopolo, Sandy SquiresCTO Corner2012171Free.
Suave Music Store example77
The Book of F#Interm-ediateDave FancherNo Starch PressMar-2014312
Professional F# 2.0Ted Neward Aaron, C. Erickson, Talbott Crowell, Richard MinerichWrox2011434
Programming F-sharp 3.0, 2eChris SmithO'ReillyOct-2012476
Testing with F#Mikael LundinPacktFeb-2015286
F# for DevelopersTao LiuMicro-soft2013619
Windows Phone 7.5 Application Development with F#Web / mobileLohith G.N.PacktApr-2013138
Building Web, Cloud, and Mobile Solutions with F#Daniel MohlO'ReillyNov-2012176
F# Applied, A practical guide to Web dev in F# using SuaveTamizhvendan S201696link
Expert F# 4.0ExpertDon Syme, Adam Granicz & Antonio CisterninoApress20155824 editions of this book
F# High PerformanceEriawan KusumawardhonoPacktJan-2017338
Mastering F#Alfonso García-Caro Núñez, Suhaib FahadPacktNov-2016264
F# 4.0 Design PatternsGene BelitskiPacktNov-2016318
F# for Quantitative FinanceJohan AstborgPacktDec-2013286
F# 4.0 Programming CookbookKevin AshtonPacktAug-2017371
F# Deep DivesEdited by Tomas Petricek, Phillip TrelfordManningDec-2014372
F# for Machine Learning EssentialsMachine LearningSudipta MukherjeePacktFeb-2016194
Machine Learning Projects for .NET DevelopersMathias BrandewinderApress2015300
Learning F# Functional Data Structures and AlgorithmsCompu-ter sciencyAdnan MasoodPacktJun-2015206
Fsharp for ScientistsJon D HarropWiley2008334
F# for Technical ComputingJon D HarropFlying frog2010279
Programming Language ConceptsPeter SestoftSpringer2012278
Functional Programming Using F#Michael R. Hansen, Hans Rischel CUPMay-2013372

Of interest. Maybe watch/read

Friday, 28 October 2016

VS code, asp.net core. Microsoft on all 3 platforms.

Microsoft are writing tools to develop and publish their applications on all 3 platforms. asp.net core is a slimmed down open source asp.net with web forms mercifully removed. Visual Studio code is a lightweight (by Microsoft standards), programming editor. It's cross platform (iOS, Linux, Win) and not too fat. The setup file I downloaded was 32Mb, taking 133.6Mb of disk space. It installed seriously fast (compared with other dev software from Microsoft).

I suppose this is a virtue of giving geeks more control over the development side. They will actually write tools for authoring software on any and every platform. There is presumably a Chrome version in the works too? Any application written should be portable across platforms with ease. It's a completely different philosophy from what we've been used to.

This blog is just a log of Shawn Wildermuth's long (> 9 hours) Pluralsight course "Building a Web App with ASP.NET Core, MVC 6, EF Core, and Angular", as I acquaint myself with the latest version. So much of it is command line driven, I feel I should write it down to remind myself what to do next time.

Entering code . from the command line executes VScode at lightning speed. e.g.

F:\code\CSharp\HelloWorld>code .

It loads with the project in that folder "HelloWorld", but without intellisense or coloration because each individual language must have support added separately. To add C# support, Ctrl+Shift+X shows a list of extensions, from which I selected C#. Added it, enabled it, the code editor restarts in less than a second. VSCode does not create projects like full Visual Studio. We need to use nodejs and npm for that. My copies of these two were quite old.

F:\code\CSharp\HelloWorld>node --version v4.4.3 F:\code\CSharp\HelloWorld>npm --version 2.15.1

So I installed a new nodejs from nodejs.org, which seemed to take forever! Snooze. Waking up several minutes later I do:

F:\code\CSharp\HelloWorld>node --version v6.9.1 F:\code\CSharp\HelloWorld>npm --version 3.10.8

Now, I'm happier creating a new project from the command line using yoeman, after first installing yoeman (with the global option), the asp.net generator is also installed

F:\code\CSharp\HelloWorld>npm install yo -g F:\code\CSharp\HelloWorld>npm install generator-aspnet -g

Now I will generate an asp.net application. First moving up a level out of my current project.

F:\code\CSharp\HelloWorld>cd.. F:\code\CSharp>yo aspnet

We see a command line menu system:

? What type of application do you want to create? (Use arrow keys) > Empty Web Application Empty Web Application (F#) Console Application Console Application (F#) Web Application Web Application Basic [without Membership and Authorization] Web Application Basic [without Membership and Authorization] (F#) (Move up and down to reveal more choices)

Pick "Web Application". If the command arrows are not working just enter the number for that choice ( 5 ) Select the Bootstrap option and call it FunWithYo

navigate to it.

F:\code\CSharp>cd FunWithYo F:\code\CSharp\FunWithYo>dir

Attempting to run it at this stage shows it's still missing asp.net. So we must restore it, before running it.

F:\code\CSharp\FunWithYo>dotnet restore F:\code\CSharp\FunWithYo>dotnet run

The whole can be seen in a browser on port 5000 localhost:5000

My frist asp.net core MVC application up. Ctrl+c (from the command line, where it is running) stops it.

Once the new project is complete, code ., opens VS code with the current project loaded. We need to answer Yes to the question
Required assets to build and debug are missing from your project. Add them?