HelloWorld in .Net Core really takes less than 10 minutes!

Intro

I have been paying attention to the development of the .NET Core framework and the great features coming out of it. Things like cross-platform compatibility are very appealing and open a whole new window of opportunities to the developer community. I never decided to start experimenting with this until now, and since I saw how easy it was to setup, I decided to share my experience here. In this post I will list the required steps to write a HelloWorld console application using .NET Core framework. It literally took me less than 10 minutes to see “Hello World” in the output window!

Steps to create HelloWorld console application in .NET Core

1. Go to dot.net and download the .NET Core SDK

– Download and install .NET Core SDK for Windows
I am using Windows, but the same steps can be applied to Mac and Linux.

2. Open a command line

c:\Users\luis.carrazana\Documents>
I like Windows PowerShell, but you could use the windows command line, or Terminal if using a Mac.

3. Check if .NET Code SDK was successfully installed

Execute the following command:

c:\Users\luis.carrazana\Documents> dotnet
You should see something like this:
dotnetcore

4. Create a folder for the project and navigate to it

c:\Users\luis.carrazana\Documents> cd "MyProjects"
c:\Users\luis.carrazana\Documents\MyProjects> md "DotNetCore101"
c:\Users\luis.carrazana\Documents\MyProjects> cd "DotNetCore101"
c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101>

5. Create a new project

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet new
Two files should be created:
Program.cs  (contains the program logic).
project.json  (contains project configuration, including dependencies).
DotNetCore-dir.PNG
This is the simplest boilerplate for a console application, and it contains the required logic to print “Hello World” to the console.

6. Restore dependencies and prepare the project for execution

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet restore
DotNetCore_restore.PNG
This step generates a new file: project.lock.json
This file should not be touched or checked into source control. Its purpose is to cache the result of analyzing project dependencies, so it is faster the next time. More details abut this file here.

7. Run the program

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet run
The logic should get executed and the “Hellow World” message should be displayed.
dotnetcore-helloworld

That’s it! You have a full .NET Core program running.

Editing the program

The steps above are useful for setting up the minimal required infrastructure to execute .NET Core logic. From this point, you will certainly want to start choosing developer tools that will allow you to write code in a very efficient way.
You can choose any text editor (including Notepad), or you may wanna choose a more robust IDE to make the development workflow more efficient. Coming from a pure .NET background, my immediate choice is the lightweight Visual Studio Code, which offers some nice integrations and can be executed in Windows, Mac and Linux.
So to edit and extend this program, I would manually open Visual Studio Code and load the project folder. However, I learned a very useful tip from Scott Hanselman in one of his training videos: from the command line, type “code .” and it will open Visual Studio Code with the current folder already loaded, ready to go. Pretty neat.
c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> code .

Summary

This post described the required steps to provision and execute a quick console application using .NET Core. This framework is currently in Preview mode, and any developer can start using it to write code and run it on any platform. Being a Consultant working for big enterprises, I don’t see myself leveraging this framework for production in the near future. However, it is a good idea to pay attention to the great amount of innovation coming out of it. This is opening up a whole new world for writing great applications.

Reference

How to rename an Azure subscription

Intro

This post will provide the steps to rename an Azure subscription.

Why is this needed?

When managing several Azure subscriptions, keeping the default name may not be very desirable because you would like to quickly identify the customer, website, or any other association you have when managing resources and billing.

I recently ran into this issue myself, where I had to create a new subscription for managing the resources and billing for a production website separately from my own development and testing. When creating the subscription, I chose the Pay-As-You-Go type, and I wanted to rename it with the website name. So my naming convention is:”<websitename> Pay-As-You-Go”. This way, I’ll be able to get the exact billing for each production website in my account, and I could even decide to use different credit cards for each one.

The option for renaming a subscription is not available from the Azure portal. This is available from the windows azure account page. I’d be interested to know why Microsoft hasn’t decided to unify this and allow the action from the portal itself, at least for service administrators.

Renaming an Azure Subscription

  1. Navigate to the Windows Azure account page at: https://account.windowsazure.com and click on SUBSCRIPTIONS on top
    capture
  2. Select the subscription you want to rename, and click “Edit Subscription Details” from the right menu
    capture1
    Capture2.PNG
  3. Enter the new name and save it
    Capture3.PNG
  4. Navigate back to the  Azure portal and you should see the new name reflected under your subscriptions
    Capture4.PNG

Toolset for a Software Developer

Intro

The following list shows some of the tools I have used (and still do) on my daily activities as a Software Developer.

Password Management

Task & Time Management

Online Storage

  • Google Drive
  • OneDrive
  • DropBox

Software Development

  • Visual Studio
  • Visual Studio Code
  • Visual Studio Online
  • SQL Management Studio
  • PowerShell

Continuous Integration

Virtualization

Training

Brainstorming

Prototyping

  • Balsamic
  • PowerPoint Story Board
  • Microsoft Visio

Project Management

  • Visual Studio Online
  • Microsoft TFS
  • Trello

Team Work / Collaboration

 

 

 

How To: Compare two text files with PowerShell

Intro

This post shows the code to compare two text files and determine whether the content is identical or not, as well as listing a line by line comparison. This utility could be useful to verify some scenarios, such as migrations, upgrades.

Comparing two files with PowerShell

The script below takes two files stored in the Desktop, compares their content, and prints a message to determine whether they are identical or not.

$desktopFolder = [Environment]::GetFolderPath("Desktop")
$fileA = "$desktopFolder\FileA.txt"
$fileB = "$desktopFolder\FileB.txt"

If (Compare-Object -ReferenceObject $(Get-Content $fileA) -DifferenceObject $(Get-Content $fileB))
{
  Write-Host "Different" -foregroundcolor red
}
Else
{
  Write-Host "Identical" -foregroundcolor green
}

The second script compares two files and provides a line by line comparison.

$desktopFolder = [Environment]::GetFolderPath("Desktop")
$fileA = "$desktopFolder\FileA.txt"
$fileB = "$desktopFolder\FileB.txt"

Compare-Object $(Get-Content $fileA) $(Get-Content $fileB) -includeequal

Reference

Using the Compare-Object Cmdlet – TechNet

How To: Decode user name from claims format in SharePoint 2013

Intro

After converting a SharePoint web application to Claims Authentication mode, it is often required to write some code to decode and extract the regular user name in the way of domain\username. This is due to the fact that calling  SPContext.Web.CurrentUser.LoginName will now return an encoded string.

E.g: “i:0#.w|mydomain\luis.carrazana”.

A great explanation about how claims are formatted and how to identify the different claim types is provided by my colleague Wictor Wilén here.

In this post I’ll share a method for getting the regular user name without having to manually parse the encoded claim identity, and leveraging SharePoint built-in API. Here, I’m extending an original solution provided by Tobias Zimmergren, in order to address an issue when using HttppContext instead of SPContext.

Context about my scenario

In my case, I was maintaining a custom ASP.NET solution, which was originally built on top of SharePoint 2010. The platform was being upgraded to SharePoint 2013, and the web application was migrated to use claims authentication. The custom ASP.NET components made heavy used of the current logged in user name, which in some cases was retrieved using SPContext.Web.CurrentUser.LoginName and in other cases using HttpContext.Current.Identity.User.Name.

Tobias Zimmergren posted a great solution for getting the user name by leveraging the SharePoint built-in functions. I leveraged this solution in my project, but I faced the following issue:

When HttpContext.Current.Identity.User.Name is used to get the current user name, the encoded formatted string doesn’t contain the claim’s identity identifier. In this case, the encoded claim format for the user name will be something like “0#.w|mydomain\luis.carrazana” instead of “i:0#.w|mydomain\luis.carrazana” (notice how the “i:” is missing from the string). For this reason, the SharePoint built-in function SPClaimProviderManager.IsEncodedClaim will not work as intended.

Please share your comments if you know the reason behind this behavior and a better solution to address it.

Solution

To completely address this scenario and support both SPContex and HttpContext, I updated Tobias’ solution and added  another condition in case IsEncodedClaim method doesn’t work as expected. I check if the user name contains the ‘|’ character, in which case the string is converted back to the proper claims format and then decoded.

See the code below with my updated version.

public string GetUserLoginNameFromClaim(string userLoginName)
{
 using (new SPMonitoredScope("GetUserLoginNameFromClaim method called for " + userLoginName))
 {
 try
 {
 SPClaimProviderManager spClaimProviderMgr = SPClaimProviderManager.Local;
 if (spClaimProviderMgr != null)
 {
 if (SPClaimProviderManager.IsEncodedClaim(userLoginName))
 {
 // return the normal domain/username without any claims identification data
 userLoginName = spClaimProviderMgr.ConvertClaimToIdentifier(userLoginName);
 }
 else if (userLoginName.IndexOf('|') > -1)
 {
 //This case will occur if the user name was obtained from calling HttpContext.Current.User.Identity.Name
 //In this case, the encoded claim format for the user name will be something like "0#.w|mydomain\luis.carrazana" instead of "i:0#.w|mydomain\luis.carrazana"

 //This line will convert to the proper claim format, so we can later decode it.
 userLoginName = spClaimProviderMgr.GetUserIdentifierEncodedClaim(userLoginName);

 // return the normal domain/username without any claims identification data
 userLoginName = spClaimProviderMgr.ConvertClaimToIdentifier(userLoginName);
 }
 }
 }
 catch (Exception ex)
 {
 //Log exception here
 }

 return userLoginName;
 }
}

Summary

When a SharePoint web application is converted to use claims authentication, the current user name is encoded. This articles showed some code to properly use the SharePoint built-in methods for decoding the user name. It also addressed the issue when HttpContext is used, and the encoded string doesn’t contain the identity identifier.

Reference

How Claims encoding works in SharePoint 2010 – Wictor Wiléen

Tip: Getting the normal domain username from the claims username in SharePoint 2013 – Tobias Zimmergren

SPClaimProviderManager.GetUserIdentifierEncodedClaim method – MSDN Reference

Programmatically converting login name to claim and vice versa – Waldek Mastykarz

 

Microsoft Azure 101: Azure Subscriptions

Intro

This article describes what an Azure subscription is and how to create one. It also touches on some of the best practices for managing multiple subscriptions.

What is an Azure Subscription?

An Azure subscription allows you to get access to the Azure cloud services through the Windows Azure Platform Management Portal. It is mostly used for recording resource usage and billing services.

How to create an Azure subscription?

If you are new to Azure, the easiest way to get started is to navigate to http://azure.microsoft.com and click “Start free” button. This will walk you through the process of creating a free trial account with some free credit (as of 08/13/2016 they are offering $200 free credits that expire after a month), and you can continue to purchase credits or use their free services.

If you are already registered in the Azure portal and would like to create additional subscriptions, you can navigate to this link . Similarly, if you are logged into the portal, you can click on the account name on the top right corner and select “View My Bill” from the menu. Here you should be able to manage your existing subscriptions and add new ones.

Some best practices

  • It is possible for an organization to have several Azure accounts, each one with one subscription. However, it is generally a better approach to have one Azure account with multiple subscriptions, in order to reduce the management complexity.
  • Use separate subscriptions for different departments, to keep track of usage, spending, and to be able to use different payment methods (very useful for managing cost centers).
  • Assign different co-admins to each subscriptions to be able to delegate management and billing operations. Ensure granular security and use minimal access strategy.
  • It is a good idea to create separate subscriptions for DEV/TEST and Production environments. This will allow you to monitor billing and usage for each of this environment separately. Also, you can leverage free services while in DEV/TEST.

Reference

Create Windows Azure Subscriptions – Arun Rakwal

How Azure subscriptions are associated with Azure Active Directory – Curtis Love

 

Tips for Time Management

Intro

"It's all about working smarter, not harder".

Effective Time Management techniques must be one of the most popular online topics among professionals of all fields. In Software Development specifically, being able to manage time is a critical skill every person should master, since the work usually requires large number of complex (and sometimes abstract) tasks, and the pressure to comply with a specified timeline. Also, good time management will allow developers and team managers to provide better estimates and assessments when facing new projects, as well as identifying unrealistic scenarios. At the same time, no matter how obsessed you are about your work, you would also like to accomplish great things in your personal life, have a healthy life-style, and make sure you spend quality time with your family and friends. In this post I’ll provide several tips that I’ve learned throughout my career from listening and paying attention to other great leaders and highly efficient people.

Select the best tools

You will need tools to capture data and manage time and activities. The first thing I’d suggest is to try several tools and find the perfect combination that works for you. Things you should consider are:

  • Easy access from  anywhere (desktop or mobile)
  • Very simple to use (you wanna make this process very simple and pleasant)
  • Use templates and forms (remove the repetitive areas and only focus on what you need)

In my case, I’ve found the following tools very useful:

  • Microsoft Outlook for managing work calendar
  • Google Calendar for managing personal activities (although some times I mingle work and personal items in Outlook, since the 9-5 schedule is no longer so rigid and we can get work done from anywhere and at any time).
  • Microsoft Outlook Tasks for maintaining a lists of pending items at work and reminders
  • Wunderlist mobile app for maintaining a list of personal pending items
  • Company’s Performance Tool to manage career goals
  • Google Drive to store forms and templates I’ll use throughout the year for personal growth

Tips for Time Management

  1. Set your Goals

    You wouldn’t visit a new country and try to drive without a GPS, would you? If you are really serious about your career, you would want to know your accomplishments and identify your areas needing improvements. You need to set realistic goals and push yourself to meet them, then you can perform an honest assessment and determine why you fell short, or if it was an extremely easy year, how to maximize your potential. You can use the TTT&T list:

    • Set goals for This year
    • Set goals for This month
    • Set goals for This week
    • Set goals for Today

    An interesting variation of this is the “Rule of 3“, proposed by JD Meier.

  2. Break down the goals into actionable and time-bound items.

    Tasks should be small (no more than a day) and outcome should be well-defined so you can measure results.

  3. Prioritize

    To be honest, I stopped worrying about keeping my master list sorted by priority at all times, since requirements tend to change frequently, and therefore priorities are affected. What I like to do is to make sure I have meaningful tasks up in the list and prioritize them based on due date and actual value (what benefits do I get from completing a task).

  4. Block time in calendar for focus time

    Calendar is a great tool, use it properly! Most people only use calendar items for team meetings and online calls. It is a great practice to also block time for focusing and completing a task. This is a great way for optimizing the work day and also letting your boss know that those meetings better be critical, otherwise some work is being pushed back.

  5. Set reminders

    Albert Einstein said: “Never memorize something that you can look up.” I guess this phrase universally applies to many things, but in this case, the bottom line is to free your memory and rely on tools to remind you what needs to get done. In my case, this allows me to go home for the weekend and totally disconnect, since I know that Outlook will tell me where I left off. Also, I never miss any birthday 😉

  6. Work more with a fresh brain

    Most people are more aware in the morning, but you should identify what is your most efficient time of the day (I used to prefer late night for getting stuff done when I was in college, but I now I’m more of a morning person). Choose tasks that require high level of concentration and effort and work on them when your brain is fresh, and leave simpler tasks for later.

  7. Track your daily achievements and reward yourself

    This is not about maintaining a diary, but recording meaningful things that are being completed so you can tell whether you are on track or not, and adjust you workload accordingly (or ask for help). I have to agree that this is not a fun task, as it represent extra work, however, the benefits are clearly visible and will be very helpful. You can try these tips:

    • Dot it the same time each day so it becomes part of the daily routine.
    • Use a template so it is very simple to do.
    • Review achievements on a weekly and monthly basis and reflect on them.
    • Recognize your accomplishments and reward yourself.
    • Identify what areas need more attention in order to meet your goals, and act on them.
  8. Calibrate your plan

    You should try to stick to your plan, even if your ultimate goals look impossible to reach sometimes. Perseverance and hard work is one of the greatest skills that will make a person succeed. However, often times the path we are taking to achieve those goals is not always the most efficient one, hence we need to calibrate and make subtle changes to get back on track. It is a good idea to frequently compare your achievements against your goals and make proper adjustments.

  9. Leverage Productivity Tools

    Here are some of the tools that can assist in becoming more efficient and aware:

    • RescueTime – Automatically tracks time and activities to help you understand daily habits and identity productivity issues.
    • Pomodoro Technique – Allows to organize and split the work day into small intervals, in order to reduce interruption and reach maximum focus.
  10. Say “No” more often

    This sounds bizarre, but it is actually one of the most important things we can do to be more productive and reach desired goals. It is not about insubordination or refusing to help others. This is about clearly defining what activities are more important in a given moment, and staying focused. It is also about avoiding unrealistic schedules that will result in stressful situations and missed deadlines. Every “yes” is actually a “no” to something else.

Summary

Time Management is a very critical skill every software developer should master. There are countless guides, articles, and tools available. The most important part is to recognize how to make efficient use of the time by spending it in meaningful tasks. It is also very important to reach a good work-life balance in order to feel accomplished and energized.

Reference

Productivity vs Guilt and Self Loathing – Scott Hanselman

15 Secrets Successful People Know about Time Management – Kevin Kruse

The 7 Habits of Highly Effective People – Stephen R. Covey

Getting Results the Agile Way – JD Meier