Saturday, April 20, 2019

25th Anniversary Cruise Part 1: Barcelona

Last year, my wife Becky and I celebrated our 25th anniversary with a 2-week European cruise. In this post I'll review what we did, share some cruising tips, and point out things we did (or didn't) like about the cruise. Here in Part 1 I'll cover the first leg of our trip, Barcelona.

Cruise Planning

The cruise we took was on Princess Cruise Lines and is called the 14-Day Mediterranean & Aegean Medley. Why Princess? They had the itinerary we were looking for. I wanted to see some classic art and architecture in cities like Venice, Florence, or Rome; Becky was also keen to visit the Greek Isles. This cruise gave us a route that started in Spain and went to France, Italy, and Greece. Specifically, the cruise would take us to Barcelona (Spain), Gibraltar, Marseilles (France), Genoa (Italy), Florence, Rome, Pompeii, Kotor (Montenegro), Corfu (Greece), Crete, Mykonos, and Athens.

We'd cruised before. On our honeymoon in 1993 we took an NCL cruise to the Caribbean. In 2008 for our 15th anniversary we took the family (five of us) to the Hawaiian Islands, also on NCL. Since a 25th anniversary is special, we splurged on this cruise, including flying business class. And we decided to leave the kids at home, hoping our 15-year old son supervised by his 19-year old sister could get by for two weeks without any major incidents (they did).

Our ship was the Crown Princess, a 952-ft long vessel which accommodates 3080 guests and 1200 crew. We had a balcony cabin on Aloha deck, strategically chosen not to be near noisy areas of the ship; and on the left side in order to get a good view of the European shoreline for most of the cruise. Princess was the first cruise line to offer private cabin balconies, which has since become a cruise ship standard.

Crown Princess

If you're going to take a cruise, expect to spend time doing a lot of planning. Once you've settled on your cruise line and itinerary and decided when to go and locked in a reservation, you have to choose a cabin, line up shore excusions, and make air travel arrangements. We scheduled our cruise in June because July or August would have been stiflingly hot in the Mediterranean. If you want to do any sightseeing at the starting or ending point of your cruise, you'll want to add a few days on land. We scheduled ourselves to fly in to Barcelona a day early, and to stay an extra day in Athens at the end. Cruise lines sometimes throw in goodies depending on how early you book. We received full beverage packages just for booking our cruise early, which otherwise would have cost somewhere around $700 per person.

Flight From LAX to Barcelona

With final assurances that our teenagers would be fine at home—and the many reminder notes I left around the house to feed the dog, take out the trash, etc.—we left from Los Angeles International airport. We flew on a KLM 747 on the upper level. In general you have much better service on international flights than domestic, especially so if you're flying a premium class. Flying in the upper level of a 747 was a fun and unique experience.



The business class on KLM is pretty sweet. Good service by flights attendants, excellent food and drink, a great selection of video entertainment. A flight attendant did accidentally spill a drink on Becky, but she took it in stride and changed her top. For me, this was a nice contrast to the constant economy flights to and from DC that I'd been flying all year for work.





Our flight had a stop-over in Amsterdam. Our second leg to Barcalona was delayed, and we spent several hours in the KLM Lounge at Schiphol Aiport. We had planned to spend the afternoon and evening exploring Barcelona before boarding the cruise ship the next day, but now our time was evaporating.

Finally we boarded our second flight—an A320—for the short flight to Barcelona, Spain. Although this was also business class, it wasn't nearly as lavish as the international flight had been. I was particularly surprised to find out that soft drinks aren't free on domestic European flights.

Barcelona (★★★★)

We arrived in Barcelona significantly tired, but determined to see something of Barcelona while we had the chance. Barcelona is famous for its architecture by Antoni Gaudi, so we took a taxi to Park Güell. Park Güell is a community that Gaudi started in 1900; today is a public park. It is full of interesting and whimsical architecture.




Park Güell, Barcelona, Spain

We really were too exhausted to really appreciate what we were seeing, but according out our photos we had a great time! There's a lot of other Gaudi architecture in the city but sadly we didn't have time to see it. On a future visit it would be great to see the Familia Sagrada and other Gaudi sites.

For dinner, we walked a few blocks from our hotel and enjoyed tapas (small plates), which are a big deal in Barcelona. We had all sorts of interesting things to eat: bravas (potatoes with a spicy tomato sauce), croquettes, stuffed cherry peppers, local breads, and Catalan cream, a dessert similar to Creme Brulee. It was delicious. After ordering so many small items, I wondered out loud what the bill might come to. Somehow Becky predicted the amount and when the bill came she was within 1 Euro! 





Tapas

The next morning, after an excellent breakfast at the Hotel Hesperia Presidente, we took advantage of a few hours in the morning to explore further. We walked Las Ramblas, a large pedestrian walkway full of tourists and restaurants and merchants which ends in a statue of Christopher Columbus. You may recall hearing in the news in 2017 there was an incident where terrorists drove a van onto Las Ramblas killing 15 people and injuring 100 others--this is where that happened.



Las Ramblas

Along Last Ramblas, we stopped at the Boqueria Market, a public market just overflowing with fresh goods. Barcelona is all about jamon (ham) and Manchego cheese. Fun discovery at the market: in the last picture below, see the guy serving espresso at the Notxo Bar? If you watch the Rich Steves Europe episode on Barcelona, the exact same guy is in it.




La Boqueria Market

Barcelona is part of a region called Catalonia. The Catalans have long been seeking independence from Spain, and this is readily apparent by all the red-and-yellow Catalan flags that are all over the place.

Catalan Flag

By mid-morning, it was time to head back to the hotel and get taken over to the cruise ship. 

We really enjoyed Barcelona and give it 4 stars. It's a vibrant and friendly city, and a place we'd like to visit again, there's so much more to see here. Plus we're hooked on tapas.

Boarding On the Ship

By mid-morning we were on a bus with other passengers being ferried to the pier to board the Crown Princess. There was the airport-like security screening, then waiting until our group was called. Once on board, we had to wait an hour or so for our cabin to be ready. We waited that time out looking around the ship, which was beautiful. Crown Princess has a large atrium that serves as the community center of the ship. It's adjacent to cafes and the dining room and there is regular entertainment. We particularly liked a music group named X-Trio that performed regularly throughout our voyage.



Crown Princess Atrium

Our cabin was what we expected: not overly large, but workable. Having a balcony was nice. One minor disappoinment: on previous cruises there were always towel animals left by the steward; not so on this cruise.




Balcony Stateroom

Well, that sums up our first leg: flying to Europe, visiting Barcelona, and getting on board our ship. We were only getting started and had another 13 days ahead of us!




Monday, April 15, 2019

Create a Cross-Platform Console Command in .NET Core

In this post, I'm going to show how you can effortlessly create a console command in .NET Core that runs on Windows, Linux, and MacOS. I'll do this step-by-step in detail with the assumption you may be new to .NET Core.

To those diehard .NET developers who have been resisting .NET Core, let me give you some words of encouragement. You've no doubt been hearing more and more about .NET Core, and perhaps you haven't liked everything you've heard ("Config files are no longer XML?"). At this point, there's no denying that .NET Core has momentum: companies all over are making the switch. If you haven't learned .NET Core yet, you probably should: it's where Microsoft is now investing their development platform efforts, and the world is moving to it. On the plus side, there are some exciting new capabilities such as the cross-platform support we'll be focusing on in this post.

To illustrate a cross-platform .NET Core console command, we'll create an updated version of a command I wrote about last year named release. The purpose of the release command is to create and verify software release manifests in the form of directory files with hashes. Two files with the same content will have the same hash; even a one-character difference between two files will cause them to have wildly different hashes. The release command supports these actions:

release : displays help
release hash file : displays a hash code for a single file
release create manifest-file : creates a manifest file listing files and hash codes
release verify manifest-file : reads the manifest file and compares against the file system

Prerequisites

Our first step is to download and install the .NET Core SDK. At the time I'm writing this, the latest stable release of .NET Core is 2.2, so that's what we're using here.

While optional, I'll also suggest you download Visual Studio Code. You can in fact use any editor / IDE you prefer, including traditional Visual Studio, but if your interest in .NET Core is cross-platform support then it makes sense to also use Visual Studio Code. With it and the .NET Core SDK, not only can you target non-Windows platforms; you can also do the development and building itself on any of those platforms.

Creating a Console Project with the Dotnet Command

To create our starter console project, we use the dotnet command. In .NET Core, you can do lots of things from the command line, including creating new projects from templates; building them; and running them. On Windows, open a command prompt as an Administrator and set your directory to a folder where you want to be doing .NET Core development.

To create our console project, use the command dotnew new console -o project-name:

dotnet new console -o release













This generates a small number of files in a release folder. Program.cs is our started code, and release.csproj is our project file.

Create the Project Code

Open the Project in Visual Studio Code

Next, launch Visual Studio Code and open the folder we just created. If you're new to Visual Studio Code, you'll probably expext to be opening .csproj and .sln files, but it doesn't work that way in Visual Studio Code. Just open the release folder you created in the prior step, and trust that we'll be doing our building and running with the dotnet command.

Write the Console Program Code

If you examine the generated Program.cs, you'll see it just outputs Hello World! to the console. We need to replace this with our desired code. In my case, we'll paste in the Program.cs source code from my original .NET Framework implementation.

Our Program.cs in Visual Studio Code now looks like this:















We don't really need to do anything else: the original release command consisted of just Program.cs and didn't have any application configuration. We may need to make some changes later on when we test on other operating systems, but for now we can proceed as we are on Windows.

Build and Test the Project

Build the Project

Now we can build the project, for which we'll again be using the dotnet command. You can issue the build command from the command prompt as we did earlier, but for those new to Visual Studio Code you also have the option of using the integrated Terminal window in the editor. Just select Terminal > New Terminal from the menu, and you have a console window below your code.

dotnet build 

Execute the dotnet build command.















If you examine the release folder, you'll see there is a bin folder that contains a Debug folder that contains a netcoreapp2.2 folder. In /bin/Debug/netcoreapp2.2 we see a release.dll (not a .exe as you might expect), a release.pdb, and several json files.

The reason we don't see an .exe is that by default a .dll is generated, which you can execute using the dotnet command. Don't be worried: t is possible to generate an .exe, and we'll do so shortly.

Run the Project

Now that we have built our program we can try running it, using the dotnet run command. Once again you can issue this from a command prompt or a Visual Studio Code Terminal window.

dotnet run

Our command appears to run.  With no command line parameters, all release does is display help. We haven't done any real work yet but it's encouraging that our .NET Framework code has not needed any changes to work in .NET Core.

Now we can try the various actions available in the release command to test that they work.

We again use the dotnet run command to execute our command, but we can pass the same parameters we would give to release.exe.

dotnet run hash file

The hash file parameters tell the release command to display the hash code for the specified file. This works fine.

dotnet run create 0001.dir

Next we'll try the create manifest-file edition of the release command, which creates a release manifest file containing filenames and hash codes.

This again works as expected, generating the following ouput in manifest file 0001.dir:

dotnet verify 0001.dir

The last version of the release command we'll test is verify manifest-file, which reads a manifest and checks its hash codes against what it sees in the file systems, reporting any differences or missing files.

Once again, the command is working great. 

Publishing to Windows

At this point, we've rather effortlessly imported our original .NET Framework code for the release command into .NET Core via Visual Studio Code, built it, and tested it. 

We would now like to generate an actual .exe so that we can run this command on any Windows system without needing to use the dotnet run command. To do this, we use the dotnet publish command, specifying  parameters targeting a particular environmentin this case, 64-bit Windows 10:

dotnet publish -r win10-x64

If we look in our /bin/Debug/netcoreapp2.2 folder, there is now a win10-x64 subfolder which contains our release.exe. If we copy the files in this folder (release.exe, all .dlls, all .json files) to c:\Windows\System32 or better yet to a folder contained in our PATH, we can now run the release command the way it was intended to be used from any Windows command prompt:

What we just did works, but involves a larger number of files than we would like. We can reduce the number of output files by creating a Self-Contained Deployment. We can generate an SCD by specifying the -c Release option to dotnet publish. This generates a smaller number of files in a Release/Win10-x64 folder.

dotnet publish -c Release -r win10-x64

Now that we've got our .NET Core console program working in Windows, it's time to publish it to additional platforms.

Publishing to Linux

With .NET Core, we can stay right where we are on our Windows machine and generate a Linux release.

To create a Linux executable, we will again use the  dotnet publish command just as we did a moment ago, but with different parameters. The -r parameter targets the particular Linux distribution and version we have in mind. In this case, I'll target Ubuntu 18 64-bit because that's available for the AWS free tier:

dotnet publish -c Release --self-contained -r ubuntu.18.04-x64

This produces a set of files under bin/Release/netcoreapp2.2\ubuntu.18.04-x64

We can't test this without a Linux instance. I did the following to create an Ubuntu Linux instance on AWS and install .NET Core and my application:

1. Allocate a Linux instance on AWS. In my case, running Ubuntu 18.04,64-bit. Wait for it to initialize.

2. Connect to the instance from the AWS console via SSH. In my case, I used the PuTTY utility for Windows. Note that connecting from the AWS Console via PuTTY on Windows did not work until I made some permission changes on my .pem key file as per the instructions here.

3. On the Linux instance, in a browser, install the Dotnet Core Runtime. I did this by following the instructions here. Once completed verify the dotnet command works. 


4. Copy the files in the publish folder (/bin/Release/netcoreapp2.2/ubuntu.18.04-x64/publish) generated by the dotnet publish command up to the Linux instance. If you're a Linux newbie, you might struggle mightily with transfer commands like SCP and PSCP (I certainly have). I like to use the WinSCP tool for file transfers, as described here.

5. On the Linux machine (via SSH or PuTTY), from the folder containing the publish files, you can now run the command with dotnet release.dll. At first glance, things seem to be working wellbut we need to be exhaustive in our testing.

dotnet release.dll

dotnet release.dll hash mscorlib.dll

dotnet release.dll create 0001.dir

dotnet release.dll verify 001.dir

Here we ran into trouble: the verify operation thought every file in the manifest directory file did not match the local file system. A quick inspection of the code revealed why: it was written for Windows, and presumes that backslashes are used to separate folders in paths.

Well, that's easy enough to correct. We modified our code to support both backslash and forward-slash paths. Here's an example of one of the areas of code that had to be augmented:

With the above change in place, we again teston both Windows as well as Linuxto confirm the release command is now fully working. It is! Below is a a run of the verify operation on Ubuntu Linux after posting an updated release where a few of the files have changed. The release command is working just as it supposed to, confirming 193 files checked and 2 files different.

Our release command now works on Linux!

Publishing to MacOS

We can publish to MacOS by specifying an OSX release. To deploy, I'll be borrowing my wife's Macbook Air which is running OSX 10.14; the publish command we need to use therefore is:

dotnet publish -c Release -r osx.10.14-x64

The steps to deploy our application on MacOS are:

1. Run the above dotnet publish command (adjusted for the version of MacOS you are targeting) to generate a publish folder for MacOS.

2. On the Mac, in a browser, visit http://dotnet.microsoft.com/download and download the .NET Core Runtime for MacOS. Open the download to install. Test it works by opening a Terminal window and entering dotnet.

3. Transfer your application files to the Mac. First copy the application files from your Windows PC OSX publish folder (in /bin/Release/netcoreapp2.2/osx.10.14-x64/publish) to a thumbdrive. Then plug the thumbdrive into the Mac. Create a new folder under Applications and copy the publish files there. For my application that folder is Applications/Release.

























4. In a Terminal window, CD to the folder from Step 3 where the files were placed. Run the release command with dotnet release.dll followed by any command line arguments.

dotnet release.dll

The dotnet release.dll command (with no arguments) simply displays help, and tells us our program is intact and able to execute on MacOS:


















dotnet release.dll create 0001.dir

The create manifest-file operation hashes files in the current working directory and any subfolders and created a manifest directory file with has codes.


















cat 0001dir

Here's the manifest file that was created:















dotnet release.dll verify 0001.dir

Finally, here's the verify manifest-file operation, which reads the manifest file and verifies it against the file system. 

Our release command now works on MacOS!


Post-Mortem: Cross-Platform Support for .NET Core

In this post, we've shown how .NET Core code can generate output that runs not only on Windows but also on Linux and MacOS. We ported a .NET Framework console program to .NET Core and proved it could run on all three operating systems.

Our initial development was on Windows, but needn't have been. Everything that was done on Windows in this article could just as easily been done on Linux or MacOS using the .NET Core SDK and Visual Studio Code.

We demonstrated Linux support by targeting Ubuntu Linux with the dotnet publish command. On AWS, I instantiated a Linux server. On the server we ran some terminal commands to install .NET Core Runtme, then copied our files from the Ubuntu publish folder to a folder on the Linux box. Adminittedly, this took several hours: I struggled with setting up ssh and trying to copy files with scp.  There were lots of little gotchas, such as having to change permissions on the AWS .pem (key) file. Ultimately, the PuTTY and winscp tools made things easier for this longtime Windows developer. With the Linux-basics learning curve behind me, I'm confident my next time around deploying .NET Core apps to Linux will go much more rapidly.

As the console program we ported was a release utility that accesses the file system, we did need to make some changesbut only because the original code presumed Windows file pathing with backslashes. The modified code is far more useful because it can work across multiple operating systems. It only took about an hour to modify the code and test that the program still worked correctly on each OS.

To get up and running on the Mac, things went quite quickly. Rather than connecting remotly to an AWS VM, I had the Mac in front of me. I used a browser to download .NET Core Runtime, and a thumbdrive to transfer files using the Finder. In a Terminal window, testing the program on MacOS went smoothly and everything worked the very first time I tried it.

Conclusion

.NET has certainly come a long way from its debut in 2000. .NET Core does introduce some changes, not all of them pleasant, but the changes are there for good reasons. If you've been dragging your feet on .NET Core, I urge rethinking your position. .NET Core adoption is rampant. Microsoft is producing platforms like .NET Core and tools like Visual Studio Code in order to win over developers regardless of their preferred operating system, and it is working because they are very well done.

Being able to use .NET Core and C# for development yet target other operating systems is huge. Not only are many companies using .NET Core, many of them are using for non-Windows deployments: a clear sign of that, if you peruse job postings, is how many companies are advertising for .NET Core skills targeting deployment to Linux.