Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Tuesday, August 22, 2017

Dotnet Core 1.1 to 2.0 conversion

Microsoft recently released Dotnet core 2.0.  I was eager to convert my Core 1.1 code so I jumped right in.  Just a bit of background on what I was dealing with (all Core 1.1):

- Around 18 class libraries
- Two MVC Core websites
- Entity Framework Core
- Identity Authentication
- MailKit (for SMTP email)

It took me probably four (4) hours to do the migration.  Not too painful, but I wanted to share several of the other websites that I bookmarked to help me get through it all.  Hopefully these will help you as well.





I think the issue that caused me the most pain (i.e. changes) was the Identity stuff.  It was a large number of changes, but just working to determine the differences between what the Core 1.1 template originally added vs. what Core 2.0 template had (which BTW, the 2.0 template still used Core 1.1 except for ASP.NET).

I was also able to remove MailKit totally once SmtpClient support came back to Dotnet Core.

Best of luck!

Monday, June 3, 2013

Parsing string to C# DateTime from specific time zone into UTC

If you need to parse a string representation of a DateTime into a specific time zone, use the DateTimeOffset in C# to assist.  For example, assume your code is executing in PST and you have a string like "1/6/2013 11:00:21 AM" that represents a time in EST.  How to do you convert this into UTC format?

Use the TimeZoneInfo.BaseUtcOffset member to create a DateTimeOffset structure.  Using this structure, you can then easily convert to UTC by by calling DateTimeOffset.UtcDateTime.


private void CalculateTimeToEastern()
{
  DateTime utc = ParseToTimeZone("1/6/2013 11:00:21 AM", "Eastern Standard Time").UtcDateTime;
}

private DateTimeOffset ParseToTimeZone(string s, string timeZoneName)
{
  TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneName);
  DateTimeOffset offset = new DateTimeOffset(DateTime.Parse(s), easternZone.BaseUtcOffset);

  return offset;
}

Note from MSDN (which is interesting)
These uses for DateTimeOffset values are much more common than those for DateTime values. As a result, DateTimeOffset should be considered the default date and time type for application development.

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...