Tech Blog

Angular patchValue vs setValue

By: Chris Dunn on Tue Dec 4, 2018

When creating model driven forms in Angular, for CRUD operations, you will need to map a data model to the FormGroup.  You can do this by manually setting each control value or you can use a function to map the entire data model to the FormGroup model.  At first glance of the documentation it looks like a good option would be setValue on the FormGroup object. myForm.setValue(formData, {onlySelf: true}); This will work if you have a matching control in the Form Group model (control name) for eac ...

Configuring Cors Policy in .net core

By: Chris Dunn on Tue Nov 20, 2018

To allow sharing responses cross-origin and allow for more versatile fetches than possible with HTML’s form element, the CORS protocol exists. It is layered on top of HTTP and allows responses to declare they can be shared with other origins. Source They is a lot more in depth information on CORS than I could provide here in my post so I will rely on others if you are unfamiliar with what it's all about. See a good explanation from Mozilla. My goal for this post it to show you how to configure a ...

Cleanup relative paths in Angular/Typescript

By: Chris Dunn on Tue Nov 6, 2018

Angular projects usually start out pretty simple with a similarly simple folder structure.   Most likely in the beginning you simple drop all components, directives and services in the /app folder just to get things working.  As your program grows, you realize (hopefully) that if you're going to survive you will need to apply some sort of structure moving forward. This can cause it's own problems by turning our nice, short import statements from this: Import { MyComponent } from './mycomponent.c ...

Cookie Authentication in .net core

By: Chris Dunn on Tue Oct 16, 2018

Most web applications today, with personalization and integration, require authentication to access the site. One of the more basic and simplest forms of authentication is using cookies. If you have a history with .net, cookie authentication is what you will most be familiar with. As with all things, .net core has a slightly different approach to implementing cookie authentication, so I thought I would walk through a basic implementation you can use as a starting point. Setup Authentication With ...

Fluent Builder Pattern vs Constructor

By: Chris Dunn on Tue Oct 2, 2018

Design patterns are important when developing applications. When people first discover GOF design patterns, they either reject them or are eager to rewrite their code base to make use of the new concepts. The same way I would caution about rejecting Design Patterns out of hand just beause they are trendy, I wouldn't rewrite for the sake of doing something new. I personally like the Fluent interface we find in LINQ, Entity Framework and other libraries. I first read about the interface from Marti ...

Why you can't pass property as out or ref parameter

By: Chris Dunn on Tue Sep 11, 2018

Sometimes compiler or language rules seem arbitrary, but actually make much more sense if you know why they are in place.  It's never a bad idea to peak under the hood, from time to time to get some perspective. If you're writing a method or utilizing a method with a ref or out parameter, like TryParse, you'll soon realize that you can't pass in an object property as the out or ref parameter. You will meet with the following error "A property or indexer may not be passed as an out or ref paramet ...

FormatWithTags Extension Method

By: Chris Dunn on Tue Aug 14, 2018

The string.format(..) method for building strings with variables is useful when you have a string template and want to replace values within the text. The only problem I have with this method is that it uses numeric placeholders for the values. That's fine if you have one or two values to integrate, but if you're dealing with more formatting of the text, it's problematic. string.Format("My name is {0} and I live in {1}.", "Chris", "Indiana");  Note: String interpolation will not work in this ca ...

Parse CVS Data with LINQ

By: Chris Dunn on Tue Jul 10, 2018

In the world of BIG DATA we're dealing with more than just JSON, XML and SQL.  A lot of data comes in raw Comma Separated Values (CSV) format.  A number of times in the past I've imported CSV data into SQL server and queried the data that way.  With LINQ, we now possess that same concise query power (somewhat) in our code. It gives us some more options especially if we don't want the weight of a database (or server) for a client application. Also, if you're starting to get involved in machine le ...

Debug Stopwatch and Performance monitoring

By: Chris Dunn on Tue Jun 12, 2018

If you're into performance analysis you will want to know about .net's Stopwatch class in the System.Diagnostics namespace.  It's great for monitoring the execution time of an operation and identifying performance black holes in your code.  It's also more precise and performant than using repeated DateTime.Now calls (which we're all guilty of doing).  Understand that Stopwatch is not your only option and in certain cases PerformanceCounters may be a better solution. Here's the basic code to get ...

SQL Delete vs Truncate vs Drop

By: Chris Dunn on Tue May 1, 2018

There are three common commands used to remove data from a SQL database.  The commands are DELETE, TRUNCATE and DROP.  I've seen DELETE and TRUNCATE used more interchangeably than they should and threw in DROP to round out the commands.  Each command serves a different use case and so it deserves a bit of attention to understand how they are different. DELETE Delete is a row level command and referred to as DML (Data Manipulation Language).  It allows you to remove rows from a table with the abi ...

StripHtml string extension

By: Chris Dunn on Tue Apr 10, 2018

If you're working on a web project with customizable html content you will need, at some point, a way to strip the Html in order to access the raw text.   One scenario I use often is automatically generating an intro for a listing page for products, by using the html formatted product description.  I do this by cleaning the html out of the description, and then grabbing the first 255 characters to display.  In the case of extracting a preview or description of html text, I suggest you cache or p ...

Web Scraper Data Tool

By: Chris Dunn on Tue Mar 13, 2018

A number of years ago I was migrating and merging a series of websites into a Content Management System.  We were attempting to organize a number of mixed technology sites, some hard-coded html, others ASP or PHP, under a single CMS.  Rather than manually translate each page into the new system, I decided to try parsing sites that followed a template pattern and import sections into the properties of the new system pages.  I developed a web scraping tool to extract that data based on a data map ...

Auto Sign out

By: Chris Dunn on Tue Feb 6, 2018

This functionality seems to be more prominent on financial websites than others, but something all sites should consider.  Even though we automatically expire someones session or login, sensitive information can still exist on the page. Unless the page makes a call to the server, the page won't know the session has expired.  So, if you see auto-sign out show up in your specs, here's how you do it. Setup The following javascript code needs to function in cooperation with your server authenticatio ...

Highlight JS Syntax Highlighter

By: Chris Dunn on Tue Jan 9, 2018

When you're writing a technical blog, you need a good syntax highlighter.  I didn't want to point to external files or even GitHub Gists for every sample or partial piece of code.  While there are probably hundreds of tools for the job, I ended up choosing Highlight JS, and couldn't be happier.  Here's how I went about setting it up including a minor customization I added for the display.   NOTE: If you have a code display option in your CMS or Wiki, I would try give that a try first and see if ...

Copyright 2019 Cidean, LLC. All rights reserved.

Proudly running Umbraco 7. This site is responsive with the help of Foundation 5.