Basic for setting up a new angular application

These are the basic steps involved in creating a new project in Angular 2.

Step 1 Initial setup

Install Node

Install TypeScript

Run the node command npm install -g typescript

Step 2 Create a new project

Here are 2 options from many for creating the new project

If using ASP.NET

  1. If you are using ASP.NET then there are SPA templates that can be used.  See https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/
  2. Install templates with command dotnet new –install Microsoft.AspNetCore.SpaTemplates::* 
  3. Created new application
  4. Create empty folder and run node command dotnet new angular

If using Angular CLI

  1. Install Angular CLI – starter project from scratch npm install -g @angular/cli
  2. Be sure to be in the project’s parent folder
  3. Run command ng new ApplicationName
  4. >This will create a new folder with the name and it will install all the dependencies
  5. https://scotch.io/tutorials/use-the-angular-cli-for-faster-angular-2-projects
  6.   https://cli.angular.io/

Step 3 Install dependencies

npm install

Step 4 Build

ng Build

Step 5 Run

Run this command: npm start – same as npm run prod, ng serve, ng serve –e dev

Stop is ctrl-c

SoapHttpClientProtocol

I had a task where I needed to add basic authorization to a soap call and I found that I couldn’t set the network credentials nor the authorization header.  In order to do this you have to create another class that inherits the proxy class and then override the GetWebRequest method.  Here is sample code:

using System;
using System.Net;
using System.Text;

namespace MyNamespace
{
    public class MyProxyOverride : TheProxy
    {
        string _url = null;
        string _username = null;
        string _password = null;

        public MyProxyOverride(string url, string userName, string password)
        {
            _url = url;
            _username = userName;
            _password = password;
        }

        protected override System.Net.WebRequest GetWebRequest(Uri uri)
        {
            var request = (HttpWebRequest)base.GetWebRequest(new Uri(_url));
            var netCredential = new NetworkCredential(_username, m__password);
            var networkCredentials = netCredential.GetCredential(new Uri(_url), "Basic");

            if (networkCredentials != null)
            {
                byte[] credentialBuffer = new UTF8Encoding().GetBytes(
                networkCredentials.UserName + ":" +
                networkCredentials.Password);
                request.Headers["Authorization"] =
                "Basic " + Convert.ToBase64String(credentialBuffer);
            }
            else
            {
                throw new ApplicationException("Missing authentication information.");
            }
            return request;
        }
    }
}

 


Basic React Component Structure

Here is some sample code to create a basic react component

<pre>

<div>import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
render(){
return (
<HelloWorld />
)
}
}

class HelloWorld extends React.Component {
render(){
return (

<div>

<h2>Hello World</h2>

</div>

)
}
}

export default App</div>


<div>//or ReactDOM.render(<App />, document.getElementById('app'));</div>

</pre>

Azure Functions

I created my first Azure Function today.  It was pretty simple to create.  The short-cut URL to get to these is functions.azure.com.

I just clicked the new function button and I chose HttpTrigger in C#.  Azure created a sample app to work with.

I decided to create a function that calls Google Translate.  It accepts some text to translate, language in and a language out.

Azure generates and displays the URL to the function for you.

I modified the generated code to accept json parameters.  I added some code I found to call the Google API.  I had to add a using statement for Newtonsoft.Json.  I also had to add the statement ‘#r “Newtonsoft.Json”’ at the top.  I assume that creates some kind of reference to the Newtonsoft library.

To call the function I used a restful API extension tool in chrome.  I added the header values for Accept and Content-Type and added the body and that was all that is needed to call the API.

I look forward to finding uses for the cool feature.

Here is a screen shot of the Azure Function code screen

pic1

Here is a screen shot of my rest client

pic2

 

 

Windows 10 Taskbar Auto hide issues

My Dell laptop regularly looses the windows taskbar when I disconnect and reconnect to my dual monitors.  This is very frustrating because the only solution I know of is to restart my PC.  I came across this article http://www.makeuseof.com/tag/5-steps-fix-windows-10-taskbar-issues/ which has an easy solution.

Now when I have the issue all I do is start task manager with CTRL+SHIFT+ESC and restart the windows explorer process and the taskbar reappears.

 

 

Read a book in a week

I found this article interesting: https://hbr.org/2016/02/how-to-read-a-book-a-week

I myself am a slow reader, thinking I have to absorb and remember every thought.  I also struggle to remember what I’ve read.

The suggestions in the article seem to be very useful.  I have be aware and practiced a few of them in the past with some success.  I plan to try out #4 and try to speed up my reading.

Of course there is the book “How to read a book” by Mortimer J. Alder that I should revisit.

Just in case the article becomes inaccessible, I’m posting the points here:

  1. Start with the author. Who wrote the book? Read his or her bio. If you can find a brief interview or article online about the author, read that quickly. It will give you a sense of the person’s bias and perspective.
  2. Read the title, the subtitle, the front flap, and the table of contents. What’s the big-picture argument of the book? How is that argument laid out? By now, you could probably describe the main idea of the book to someone who hasn’t read it.
  3. Read the introduction and the conclusion. The author makes their case in the opening and closing argument of the book. Read these two sections word for word but quickly. You already have a general sense of where the author is going, and these sections will tell you how they plan to get there (introduction) and what they hope you got out of it (conclusion).
  4. Read/skim each chapter. Read the title and anywhere from the first few paragraphs to the first few pages of the chapter to figure out how the author is using this chapter and where it fits into the argument of the book. Then skim through the headings and subheadings (if there are any) to get a feel for the flow. Read the first sentence of each paragraph and the last. If you get the meaning, move on. Otherwise, you may want to read the whole paragraph. Once you’ve gotten an understanding of the chapter, you may be able to skim over whole pages, as the argument may be clear to you and also may repeat itself.
  5. End with the table of contents again. Once you’ve finished the book, return to the table of contents and summarize it in your head. Take a few moments to relive the flow of the book, the arguments you considered, the stories you remember, the journey you went on with the author.

Web API Attribute Routing

In my continue research into Web API I came across a new feature in Web API 2 called Attribute Routing.  This feature makes it possible to define routes at the API level.  It makes it easier to define complex RESTful URIs where there are child resources like “/customer/123/orders”.  It also gives you the ability to have multiple GETS, POSTS and PUTS on the same controller.

The traditional style of routing is called Convention-Based Routing and you can mix both in the same application.

On a side note, there is also the ActionName attribute.  It doesn’t give you the ability to define the route but it does make it possible for you to have multiple GETS, POSTS and PUTS on the same controller.

You do have to enable attribute routing.  This is done in the WebApiConfig.Register method: config.MapHttpAttributeRoutes();

This ASP.NET link describes attribute routing in more detail: http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

TSQL ID Columns in Tables

Over my development years, I’ve seen many tables designed with useless ID columns.  The columns serve no purpose.  They are not reference by anything.  Then to make matters worse, a primary clustered key is created on the ID column.

My recommendation is to only add ID columns when you need to create a relationship between tables.  For example, if you have a customer table and a customer orders table, you need the ID field on the customer table to reference on the order table.  But you don’t need the ID on the orders table.  If you have an orderdetails table, then you would need the ID on the orders table.

The extra ID column adds unnecessary storage overhead and you waste your clustered index when you make it a primary clustered key.

It is always beneficial to ponder a little longer about your table designs and determine whether you really need an additional ID column as well which column(s) are the best to create your clustered index on.

Soft Skills by John Sonmez

I’ve just recently purchased the book  Soft Skills by John Sonmez.  I have already been following John’s podcasts and I’ve heard him on .NET Rocks as well as taken his course on PluralSight.  His insight is very helpful.  Some of his ideas comes from a lot of the same books that I have read in the past – like How To Win Friends And Influence People.

The chapters are short enough to read in less than 15 minutes but provide a lot of useful information.  And at the end of each chapter are some actions he recommends.

Basically, the book is about the premise that there is more to being a developer than writing code.  Although I have little to say in a blog and find it difficult to put my thoughts down in writing, his articles and this book are motivating me to step out of my comfort zone.