0 Comments

logoAzure Blob Bridge for IFTTT provides an easy way to use Azure Blob storage as a IFTTT destination Channel.

In this post I’ll introduce you to the Azure Blob Bridge for IFTTT project. I will follow up with a tutorial which will include:

  • Deploying Azure Blob Bridge for IFTTT
  • Creating a IFTTT recipe using the Maker channel

Background

IFTTT is a web-based service that allows users to create chains of simple conditional statements, called "recipes", which are triggered based on changes to other web services such as Gmail, Facebook, Instagram, and Pinterest. IFTTT is an abbreviation of "If This Then That"…

https://en.wikipedia.org/wiki/IFTTT

Wikipedia's description of IFTTT is accurate: It allows you to chain web services together. For example, I’ve been using it to write new posts from Feedly into our Wordpress.

Unfortunately IFTTT doesn't currently provide Channel for Azure Blob storage. Azure Blob Bridge for IFTTT -project can be used to work around the limitation. The project works as an output Channel (“action”) for IFTTT. Using Azure Blob Bridge for IFTTT as a Trigger is coming later.

Implementation

Azure Blob Bridge works by providing HTTP POST API for uploading blobs to your Azure Storage Account. The project is implemented using Nancy and C#.

The project creates a POST uri based on your configuration’s apiKey. For example, if you set your apiKey to “myKey”, you can access the bridge through /api/myKey/.

The new blob will be created from the request’s content (body). Content-type is set if provided in request headers. File name is automatically generated using DateTime.UtcNow.Ticks + ".dat".

Usage with HTTP POST

To write a blob to your Azure Blob storage, send a HTTP POST Request to the Azure Blob Bridge for IFTT:

POST http://myapp.domain.com/api/apikey HTTP/1.1
Content-Length: 38
Content-type: Application/json

{"author":"hello", "text":"mycontent"}

Configuration

You need to define three configuration settings, either through the Azure Deploy or through Web.config:

  • apiKey = Api key is used to define the URL for your api. NOTE: Use only valid URI characters. Example: apiKey = "hello" -> Your API works through http://yourdomain.com/api/hello
  • storageConnectionString = The Azure Storage connection string. Example: DefaultEndpointsProtocol=https;AccountName=mystoragewe;AccountKey=wjN544545444233rwsdsdddddkkkkkkk999999999923wu3zJXSoBJ4LAWBbtEYKqbwjIQ==
  • container = The Azure container where files will be written. NOTE: Use only valid container character (so no upper cases or numbers). If container is missing, it will be automatically created as private. Example: mycontainer

Code

The Azure Blob Bridge for IFTTT is available through GitHub as an open source project.

License

The project is distributed under the terms of the MIT License (see mit.txt).

0 Comments

Azure’s REST API requires Date or x-ms-date header. As specified by HTTP protocol, the Date (or x-ms-date) header must be in RFC 1123 format.

Example of Date in RFC 1123 format

Wed, 09 Dec 2015 18:59:42 GMT

Converting DateTime to RFC 1123 in C#

In C# DateTime can be converted to RFC 1123 using the “r” format. Example:

var result = DateTime.Now.ToUniversalTime().ToString("r");

Web Tool

Perhaps the easiest way to get the current date time in RFC 1123 format is through the http://http-date.com/. This web tool, created by Leonard Wallentin, provides not just the current date time in correct format but also "30 days from now" and “365 days from now". The tool has proven itself really useful in the last few days when working with the Azure blobs using the REST API.

0 Comments

Recently I blogged about the VB.NET String Concatenation Weirdness. That’s not the only thing which can hit you if you mainly code in C#. Here’s an another example, as pointed out by my co-worker Panu Oksala. This time the weirdness is related to If and nullable fields.

Here’s some simple code:

        Dim myDate As DateTime?

        myDate = Nothing

        If (myDate Is Nothing) Then
            Console.WriteLine("Date is null")
        Else
            Console.WriteLine(myDate)
        End If

As expected, this outputs “Date is null”:

image

But, if we include If-statement in the myDate-assignment:

        Dim myDate As DateTime?

        myDate = If(True, Nothing, DateTime.Today)

        If (myDate Is Nothing) Then
            Console.WriteLine("Date is null")
        Else
            Console.WriteLine(myDate)
        End If

And then run the app, things get interesting:

image

So, we’re not getting “Date is null”. And we’re not getting the other if-option which is DateTime.Today. Instead, myDate is initialized as DateTime.MinValue:

image

Solution to the issue is to use new DateTime? instead of Nothing:

image

The following StackOverflow question contains more info about why this is happening.

0 Comments

NXMLFormatter is an open-source XML Formatter and beautifier written with C#. The DLL is available as a portable class library, so you can use it from UWP, ASP.NET etc.

Usage

  1. Add reference to NXMLFormatter.dll.
  2. var formattedXML = NXMLFormatter.Formatter.Format(originalXML);

Project doesn't have any external references and it uses only the features provided by the .NET Framework.

NuGet

NXMLFormatter is available through the NuGet with the package name NXMLFormatter. Type "install-package NXMLFormatter" to install it.

Example

Input
<catalog><book id="bk101"><author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>
</book>
<book id="bk102">   <author>Ralls, Kim</author>   <title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description></book>
<book id="bk103">   <author>Corets, Eva</author>   <title>Maeve Ascendant</title>   <genre>Fantasy</genre>
   <price>5.95</price>   <publish_date>2000-11-17</publish_date>
   <description>After the collapse of a nanotechnology society in England, the young survivors lay the 
   foundation for a new society.</description></book></catalog>
Output
<catalog>
  <book
    id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications with XML.</description>
  </book>
  <book
    id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-12-16</publish_date>
    <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>
  </book>
  <book
    id="bk103">
    <author>Corets, Eva</author>
    <title>Maeve Ascendant</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-11-17</publish_date>
    <description>After the collapse of a nanotechnology society in England, the young survivors lay the 
   foundation for a new society.</description>
  </book>
</catalog>

Implementation

Under the covers the library uses XmlWriter to format the code.

Licenses

The library is distributed under the terms of the MIT License (see mit.txt).

Source code

NXMLFormatter’s source code is available from GitHub.

0 Comments

Problem

When you create a Universal Windows Platform app and run it in Windows 10, you may notice that the logo displayed on taskbar is not full size.

For example, if you have this beautiful 24x24 logo:

image

And you set that as your taskbar logo:

image

And then run the app, you’ll notice that it looks out of place:

image

Two problems:

  1. The logo is not full size
  2. The remaining space is filled with your accent color

Solution

The problem can be fixed by renaming the logo file. When you set the logo through Package.appxmanifest’s designer, the asset will receive file name Square44x44Logo.targetsize-24.png:

image

Just rename the file to Square44x44Logo.targetsize-24_altform-unplated.png:

image

And now when you ran the app, you should see that your icon fits the taskbar nicely:

image