Eric Rogers

Programming Projects

  • GitHub
  • LinkedIn
  • Twitter
  • Home
  • Projects
  • Blog

Eric Rogers May 15, 2019 Leave a Comment

Setting Up the Initial Budget Code

I have started working on my budget app. I am using this app as an opportunity to learn Angular, especially how it connects with .NET Core.

You can see the overall purpose on this app on my projects page. Basically I want an app to handle the electronic portion of my family’s budget process, which I currently do with spreadsheets. The physical portion of our process will not change.

There is one new requirement I have come up with since I wrote that page. There should be 2 types of monthly expenses, ones that accumulate and ones that don’t.

As an example, let’s say I have 2 categories, eating out and fuel. I want to put $200 in eating out every month no matter what. But I want $200 max in fuel each month.

Now let’s say I have a month where I only spend $175 in each category. The extra $25 in eating out would roll over, giving me $225 for the next month. However, fuel would be allocated $175 for the month to bring the total to $200, giving me that extra $25 to shift to a different category.

Here is the frequency enum I will be using:

public enum FrequencyType : byte {
	OneTime = 1,
	MonthlyCumulative,
	MonthlySet,
	Quarterly,
	Yearly
}

These cover everything I need at this point.

The next step is to start building the code infrastructure. Here is the structure I use in my code:

  • Solution
    • Business Folder
      • Business Projects
    • Data Folder
      • Data Projects
    • Interactive Folder
      • Interactive Projects
    • Tests Folder
      • Tests Projects

This structure helps keep my mind focused on what I am working on at any given moment. If I am in a project in the Interactive folder, for example, I know I am working on an interface of some kind. It might be web based, WPF based, or console based but it involves user interaction. If the code I am writing is business logic, I know I am probably putting it in the wrong place.

The last thing I want to mention is the direction I will be going with the business layer in the app. I have used the Repository pattern in the past. It has always felt lacking in several areas. I recently came across a couple articles by Steven van Deursen covering the command–query separation pattern. I really like how it has simplified my coding, especially on the testing side.

Here are the interfaces I will be using for queries:

public interface IQuery<TResult> { }

public interface IQueryHandler<TQuery, TResult> where TQuery : IQuery<TResult> {
    TResult Handle(TQuery query);
}

And here are the interfaces for commands:

public enum CommandResult {
	Ok,
	Error
}

public interface ICommandResult {
	CommandResult Result { get; }
	ICollection<string> Messages { get; }
}

public interface ICommandHandler<TCommand> {
		Task<ICommandResult> Handle(TCommand command);
}

You will notice one change from Steven’s code. I added a ICommandResult so the commands can return results to the user. While it can be nice to be able to fire and forget a command, I have found this impractical in practice. The user will want to be notified of the result of a command, especially if there was an error. ICommandResult allows me to notify the UI if there was an error so it can display the messages to the user.

In my next post I will be adding a category list to the Angular app. This will allow the user to see all the current categories. I will also be adding the functionality for the user to add a category.

You can check out the current state of this app on GitHub.

Filed Under: Budget App Tagged With: Command/Query Pattern, Design

Eric Rogers May 7, 2019 Leave a Comment

Going back to Visual Studio

Well, my experiment with VSCode has come to an end for now.

I have been using it exclusively on my laptop for the last 2 months. I used my small hard drive as an excuse to uninstall Visual Studio. Total immersion was the goal.

After these 2 months, I am going back to Visual Studio. VSCode is cool and does some neat things. However, the quality of life features Visual Studio and ReSharper provide are too much to ignore. For example:

  • New .cs files in VSCode are created completely blank. Having to type the namespace and class declarations every time is a chore. TDD compounds this since creating test classes doubles this work.
  • ReSharper is extremely helpful when creating variables. The IntelliSense will show you possible types as you are typing even if you have not included the appropriate using statement yet.
  • Speaking of using statements, ReSharper will add these automatically in a lot of situations.
  • I know the keyboard shortcuts for Visual Studio. The biggest one is Alt-Enter, which automatically fixes some things for you, like the above using statement issue. There may be a shortcut for that in VSCode but I couldn’t find it.
  • The IntelliSense in Visual Studio just seems to work better, especially with ReSharper. It is especially smarter when suggesting variable names.

While none of these issues are huge in and of themselves, they stack up to make a more frustrating situation that I am willing to deal with right now. They cause me to think too much about my tools instead of being able to focus exclusively on the problem I am trying to solve.

I wish that JetBrains would release ReSharper for VSCode. That would alleviate most of my problems. However, they have stated this will not happen, since they are focused on their own IDE, Rider.

At this point, I think the only way I would use VSCode again is if I get a Mac. Of course this is a possibility since a Mac is required for iOS app development. But for now, it’s back to Visual Studio.

Filed Under: Development Environment Tagged With: Development Environment, ReSharper, Visual Studio, VSCode

Eric Rogers March 8, 2019 Leave a Comment

Updating Angular

I have decided to start my journey with Angular in the Budget app I want to build. It is simple enough to get me started but also has enough moving parts to make it a good learning tool.

Before I get started, however, I want to make sure I have the latest version of Angular. It is already installed on my machine because I have messed around with it some in the past.

So I opened up a console and typed:

$ ng --version

This showed me I have version 6.0.8 installed on my machine. When I checked for the latest version, I saw that it is 7.0. So I needed to update my version.

I searched for “update angular 6 to 7 globally”, which brought up up this article on AppDividend. However, these instructions didn’t quite work for me.

I followed the instructions to uninstall the Angular CLI by running this:

$ npm uninstall -g angular-cli

However, this did not work. All I saw was:

up to date in 0.03s

I searched for “npm uninstall global not working” and came to this StackOverflow question. While it did not quite answer my question, it did lead me down the correct path.

From the top answer, I ran this command:

$ npm ls -g --depth=0

which gave me this output:

+-- @angular/cli@6.0.8
`-- typings@2.1.1

Now I saw my problem. I needed to uninstall @angular/cli instead of angular-cli. When I did it correctly, I saw this:

$ npm uninstall -g @angular/cli
removed 248 packages in 3.341s

Alright, now that I had the old version uninstalled, installing the new version should not have been hard. Back to the AppDividend article and:

$ npm cache verify
$ npm install -g @angular/cli@latest

And there we have it! Right?

Nope.

> @angular/cli@6.0.8 postinstall C:\Users\***\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/ng-update-message.js

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/cli@6.0.8
added 242 packages in 10.904s

Why did it still install the old version? I don’t know. The article says to run this command if the old version is still there:

$ ng update @angular/cli

However, when I run that I get:

Could not find a package.json. Are you in a Node project?

Which is the problem that sent me down this rabbit hole in the first place. I wanted to update Angular globally, not just for a project.

Next I decided to try updating it using npm. Just guessing, I ran this:

$ npm update -g @angular/cli
C:\Users\***\AppData\Roaming\npm\ng -> C:\Users\***\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/cli@6.2.9
added 90 packages, removed 3 packages and updated 12 packages in 12.713s

Progress! Angular has now been updated from 6.0.8 to 6.2.9! But why did it not install that in the first place? I told it to install @latest.

I was really confused. I decided to attempt to install the latest version explicitly instead of through @latest. According to Wikipedia (since I couldn’t find it anywhere else), the latest stable release is 7.2.4

$ npm uninstall -g @angular/cli
$ npm install -g @angular/cli@7.2.4
C:\Users\***\AppData\Roaming\npm\ng -> C:\Users\***\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/cli@7.2.4
added 294 packages in 13.146s

Success! Finally.

I’m still not sure why @latest did not work. But I’m updated to the latest now so I am not going to worry about it.

In my next post, I am going to start building out my Budget project using Angular and VSCode.

Filed Under: Development Environment Tagged With: Angular, Development Environment

Eric Rogers March 7, 2019 Leave a Comment

My Development Environment

The launch of this blog gives me the opportunity to discuss my development environment.

My development environment has not changed much over the 20 years of my career. I started out as an intern in 1998 right around the release of Visual Basic 6. My first job was VB6 using a SQL Server backend.

Since then I moved to C# but continued to work with Visual Studio and SQL Server throughout their subsequent upgrades. Right now my environment looks like this:

  • Windows (7 at my day job, 10 at home)
  • Visual Studio (2015 Pro at work, 2017 Community at home) with ReSharper
  • SQL Server Express (only at home)
  • SQL Management Studio (again only at home)

I have used this environment to build ASP.NET MVC apps, WPF apps, Windows Forms app, ASP.NET Web Forms apps, and Xamarin mobile apps. While it has served me well, I am wanting to shift towards more of a free/open source environment.

The main reason I want to do this is for app development. As you probably know, you have to have a Mac if you want to build iPhone apps. You can do all the development on another machine but you have to have a Mac of some kind to build, test, or deploy.

I worked on mobile apps at a previous position. The Mac requirement meant I was walking around with 2 machines. I had my Alienware laptop for development and then a low end MacBook Pro for when I needed to test or deploy the iPhone app. I would love to be able to have one machine to do it all, which means I have to find a way to do my development on a Mac.

Luckily Microsoft has really embraced open source over the last few years. This makes it possible for me to stick with C#/.NET while not being tied to Windows anymore.

Here is the development environment I am going to be using for the projects I write about on this blog.

  • Windows 10 (For now. I will be looking to get a Mac in the near future to fully make the transition.)
  • VSCode
  • MySQL

I will use these programs to build .NET Core applications. I am also using this as an excuse to finally learn Angular.

I have tried to make this transition a few times in the past but have been tripped up by a couple things.

  • No ReSharper in VSCode – I have come to rely on this plugin a lot, which is probably not a good thing. It will probably be good for me to get away from it. I just have to push through the initial frustration.
  • The command line – It is going to take me some time to get used to doing things through the command line.

These hang-ups are not too much for me to overcome if I just resolve to do it. So that is what I am going to do.

Filed Under: Development Environment Tagged With: .NET Core, Angular, Development Environment, MySQL, ReSharper, SQL Server, Visual Studio, VSCode

Recent Posts

  • Setting Up the Initial Budget Code
  • Going back to Visual Studio
  • Updating Angular
  • My Development Environment

Categories

  • Budget App
  • Development Environment

Tags

.NET Core Angular Command/Query Pattern Design Development Environment MySQL ReSharper SQL Server Visual Studio VSCode

Copyright © 2023 · Streamline Pro Theme on Genesis Framework · WordPress · Log in