2. Building a software solution – Where will it run?

As I was deciding to build this, I was torn on where to begin. Should I build the front-end? Maybe I should model out the data entities, and build the API? After reading Clean Code by Uncle Bob, I quickly realized that my days of building a solution by starting at the database are over. I might feel more comfortable in the 3rd normal form, and be able to query anything when the data normalized, but that is not where my application will start.

Furthermore, clean architecture shows that items like the database are “accessory” items. I’ll eventually be making use of Entity Framework Core, but by using a code-first approach, I won’t have to worry myself much with building the database and tables ahead of time. I may have to build tables and views for the “Query” side of my CQRS design, but that will come later. The first thing I should build is the environment where my application will run.

My initial plan for my app

This application will run in Azure, so the first thing I did was create a resource group (using PowerShell and Azure CLI):

az login
az group create --location eastus --name LeagueTrackr_DEV --subscription SUBSCRIPTION_GUID

The az login command will pop open a web browser and look ask you to sign in to your Azure account. When that is successful, you can close the browser window, your terminal/PowerShell will then be authenticated. The next command creates a resource group. In Azure, all resources need a resource group and a subscription. I am going to assume you have a subscription already, that is usually set up when you create your Azure account.

az appservice plan create --name LeagueTrackrAppPlan_DEV --resource-group LeagueTrackr_DEV --is-linux --location eastus --sku B1 --subscription SUBSCRIPTION_GUID

This command creates what is called an App Service Plan. An App Service Plan determines what kind of “server” will be used to run my code. I put the server in quotes because I am making use of Azure’s Platform as a Service (PAAS) offering. I am not creating a VM with Linux or Windows, even though there will be one somewhere running my code. I am also telling my “server” to be on the basic 1 tier and be a Linux server. I chose the basic 1 tier because it is the cheapest just above the free tier. I would have preferred to use the free tier, but you cannot have two free app plans in one resource group.

az webapp create --name LeagueTrackr_DEV --plan LeagueTrackrAppPlan_DEV --resource-group League-Trackr_DEV --runtime "node|LTS"

Now I will do both of these steps again to create my API. Both the API and Web App could run in the same App Service plan, but in the event that I ever need to scale one and not affect the other, it would be difficult. For that purpose, I am going to split them out now.

Next, I will create the Azure SQL Server and the Azure SQL Database for my project:

az sql server create --admin-password PASSWORD --admin-user ADMINUSER --name leaguetrackrsql-dev --resource-group League-Trackr_DEV --location eastus --subscription SUBSCRIPTION_GUID
az sql db create --name LeagueTrackrDB_DEV --resource-group --server leaguetrackrsql-dev --edition Basic --subscription SUBSCRIPTION_GUID

Once this is complete, a dev environment will exist. However, the problem with this is that I don’t need to keep a dev environment around forever. If I am not actively developing, I’ll want to delete this environment to save me some money. I do want to be able to recreate this environment quickly if needed. I also want to be able to script any changes and push those to production when it is created. To do this, I’ll make use of Azure Resource Manager (ARM) templates and deploy them using Azure DevOps. I’ll look at this in my next post.

1. Building a software solution – Intro

Recently I was challenged to upgrade my level of knowledge regarding web-based solutions. My experience has been in building business solutions making use of many technologies like SSRS, SSIS, ASP.NET Web API’s, SQL Server, Power BI, Microsoft Dynamics, and more. I’ve built portions that all exist in a full web application, and I’ve even deployed solutions to Azure. Still, I have don’t have much experience putting them all together in a single solution or product. I am accomplishing this, and as I do it, I plan to document my work here on this blog.

The first challenge I ran into was that I needed something to build. I know that if I don’t care about the project, it’ll just go by the wayside, and I’ll never finish it. Also, I didn’t want to take anything on that was going to be over my head. I have kids that play in sports (Baseball/Softball, Basketball, Soccer, and more). Thus far in my parental career, I have yet to interact with a sports league website that just simply allowed parents to keep track of practices and games, and know what is going on with their child’s sporting event. I’m sure there is a decent solution out there, I’ve just never seen it. So, I’m going to build one. A sports league solution should be a reasonably straightforward (famous last words) solution. I need to learn React, so my solution will be a React front end, with a .NET Core 3 Web API back-end.

Furthermore, I was given the challenge to build the solution using the CQRS pattern. I’ve never explicitly implemented that pattern before, but I will be figuring out how to during this project. The back-end database will be an Azure SQL instance. All components will be deployed to Azure, with a CI/CD pipeline built using Azure DevOps.

Here are the links to what I am going to be building:

I know I don’t have the repositories yet but there will also be one for the Web API, and the database. When I create those, I will come back and update the links.

As I am writing this, I am also open to suggestions, as long as they aren’t in the realm of Use x framework instead of y, or deploy to a cloud provider instead of b. If a suggestion is provided, I ask that a good logical reason be provided. This is a learning journey

I hate Microsoft… (this is such an annoying phrase)

Hello everyone.  I want to write an article that discusses an issue that drives me insane.  Recently I heard a developer claim “I hate Microsoft…” and proceeded on a tirade of this reason or that reason why they are frustrated.  In the world of technology, Microsoft has been around long enough that we should realize they aren’t going anywhere any time soon.  Whenever I hear a tech person proclaim that they hate Microsoft, in my ears, it sounds like a mechanic saying: “I hate metric tools.”  It is a pointless thing to hate.  When I hear that someone is frustrated with Microsoft, what it usually comes down to, is that they are not aware of what the right setting is they are looking for.  The product is doing exactly what it is supposed to, and the developer just doesn’t know what setting to change.  In the past several years, since Satya took over, Microsoft has taken a 180-degree turn and started building some fantastic tools.  They say it is hard for a rudder to turn a large ship, but Satya has done it.  In fact, Microsoft seems to have the attitude that I would want to see out of any tech company: “Check out what we have, but if you don’t like it, we’ll support you using what you want.”  The next time you hear someone proclaim they don’t like Microsoft, just remind them that it doesn’t make sense to not like your tool, you just need to learn how to use your tool.

I just want to clarify, I am not paid by Microsoft, nor am I saying that they are the best tool for everything.  However, they are a prevalent force in the tech industry and that means if you want to be good at Tech, you need to know how to use Microsoft products.

Azure.Mobile.Server.EntityData ModelState is invalid… why?

So, I have been building an ASP.NET MVC 5 web application making use of the Azure.Mobile.Server SDK.  So I created my model objects, and everything is excellent.  I used the scaffolding to generate my Controllers and Views.  From there I spent some time customizing my views, which I hate to do.  I’m not a very good front-end developer, and I have all the respect in the world for those who are skilled at making things look pretty.  So I went to test the various CRUD operations and starting at Create, I failed.  I set a breakpoint and found out that my model state was invalid.  The default code does something like this:

When I was clicking the submit button on my form, the check of ModelState.IsValid was coming back false.  This is because in my form, I was only adding data to “ModelProperty.”  The rest of the bindings (Id, Version, CreatedAt, UpdatedAt, Deleted) are all part of the Microsoft.Azure.Mobile.Server.EntityData object type which I inherited in my model.  I use this data type because I have an accompanying mobile app and the Mobile SDK does a great job of offline syncing my data.  So… I had to remove those bindings from the [Bind(Include = “…”)] statement.  Once I removed those, my ModelState was valid, and life continued.

The next tech bust

The internet is a wonderful source of information.  Videos and volumes of text exist to provide information for just about any imaginable topic.  In 1990 the World Wide Web was born.  In the past 28 years, we have managed to fill hard drives with data from almost all recorded parts of human history.  Why did people put forth the effort to compile all of this information?  It started as an academic endeavor, but it quickly became a method of making money.  Fast forward to present day, and everyone with a computer and a blog can start making money.  How is it so easy to start making money?  It is because money is being earned on false pretense.

Continue reading → The next tech bust

Finding the last date a date stamped item shows up in a table (SQL)

So, I was writing a query to retrieve data from a Dynamics GP table.  There was a question about when certain codes were last used.  So, my thought process took me down the path of saying I could write a query that pulls all of the distinct codes from the table like so:

However, there is also a date column for when the code is used.  This is because it is a transaction table.  So, if I add in the date stamp, I will get tons of rows returned as a result of the query.  I needed some way to only get the last date stamp that each code was used.  For that I used the following code:

So how does this work?  According to the Microsoft Docs:

You can use the OVER clause with functions to compute aggregated values such as moving averages, cumulative aggregates, running totals, or a top N per group results.

I guess this is a good time as ever to say that I am using SQL Server, and this applied to SQL Server 2008 and beyond.  So, this essentially makes a group of each code, and then uses the aggregate function MAX to find the maximum date used per group of code.  Now I can say when the last time a specific code was used.

Greatest Common Denominator/Divisor/Factor (Geek Style – Euclidean Algorithm)

I recall learning about performing fractional math when I was young.  To be completely honest, I never actually learned an efficient way of determining greatest common denominator.  I brute forced it most of the time, meaning I just kept trying numbers until it seemed like I got the right denominator.  My method was very similar to what you see here at Kahn Academy.  As part of an algorithms course, I needed to write a function to determine the Greatest Common Denominator.  Any time you start talking about writing code

Any time you start talking about writing code, and you consider performing a function that “brute forces” an answer, your code will not run very fast.  Sometimes, you have no choice but to brute force a solution.  Sometimes there is a better way.  In this case, brute force is not the best way.  Here is how a brute force method would look:

Continue reading → Greatest Common Denominator/Divisor/Factor (Geek Style – Euclidean Algorithm)

Shuffle a list C# (Fisher-Yates shuffle)

So, recently I was writing some code, and I was presented with a problem.  I had a List<CustomObject> in C#.  I needed to jumble that list up and still use those items.  Keeping in mind that I am not one of these prodigies that went to MIT, and I do not memorize algorithms for fun, I set about like most good programmers to Stack Overflow.  I came across this post which provided me this code: Continue reading → Shuffle a list C# (Fisher-Yates shuffle)

Offline Visual Studio 2017 Install

It is very easy to forget that many people have development environments that do not have internet access.  In this day and age, it’s easy to install frameworks and IDE’s from the web.  Recently I wanted to start using Visual Studio 2017 for a project.  My environment is completely isolated from the internet, and getting access is not feasible.  So how was I going to get Visual Studio 2017 from the internet to a computer with no internet access?  In the past this was easy, just download an iso and either burn it to a disc or just copy and mount the iso.  With Visual Studio 2017 Professional edition’s total download size is 27.1 GB. Continue reading → Offline Visual Studio 2017 Install