This function (called “GetCustomer”) could be available at the following URL (with function authorization enabled): https://dontcodetireddemos.azurewebsites.net/api/GetCustomer?id=42&code=rEQKsObGFDRCCiVuLhOnZ1Rdfn/XGgp5tfC1xHrhAqxvWqzHSQszCg==

Notice in the URL the name of the function is prefixed with “api” i.e. “api/GetCustomer”

Calling this URL would result in the following JSON being returned:

{
"Id": 42,
"Name": "Amrit"
}

Function proxies allow the “api” part to be replaced, for example to create a URL: “https://dontcodetireddemos.azurewebsites.net/customer?id=42&code=rEQKsObGFDRCCiVuLhOnZ1Rdfn/XGgp5tfC1xHrhAqxvWqzHSQszCg==”

This proxy defines a name “CustomerGet”, a route template of “customer”, the actual URL to maps to “https://dontcodetireddemos.azurewebsites.net/api/GetCustomer”, and limited to only GET HTTP verbs.

If we had another function e.g. called PostCustomer we could also setup a POST proxy for that function:

Now we can issue both POSTs and GETs to the customer “resource” at: https://dontcodetireddemos.azurewebsites.net/customer (code key omitted).

Using Kudu for example, we can see a proxies.js file created in the wwwroot folder with the following contents:

In part 1 we crated a Flow to enable/disable the sending of push notifications and in part 2 we created an Azure Function to generate random phrases of positivity.

In this third and final part of this series we’ll go and create the second Flow that sends the push notifications to the phone.

This Flow will be automatically triggered every 15 minutes by using a Recurrence action followed by an action to get the blob content containing whether or not we should send a notification as the following screenshot shows:

Now that we have the blob content, we can examine it in an If condition. If the content of the blob is “enabled” we can continue the Flow:

If the condition is satisfied (“IF YES”) two actions are performed: the first an HTTP GET to the Azure function, the second a push notification action that as content uses what was returned in the body of the HTTP GET. Notice in the HTTP GET, the URI includes the function authorization key as a query string parameter.

After saving the new Flow, we can head back to the Flow app and hit the button to enable “positivity pushes”:

Then every 15 minutes (until we turn them off by hitting the button again) we’ll get a positivity notification on the phone:

In part 1 we created a Flow to toggle the sending of push notifications on and off by storing the configuration in Azure blob storage.

Now that we have a way of enabling/disabling notifications we can start to build the second Flow.

Before jumping into the Flow designer, we need to consider how to generate random positivity phrases and how to integrate this into the second Flow. One option to do this is to create a simple Azure Function with an HTTP trigger. The Flow can then use an HTTP action to issue a GET to the server that will return the string content to be sent via push notifications.

In the Azure Portal function editor a new function can be created with a HTTP trigger configured to GET only as the following screenshot shows:

Notice in the preceding screenshot the authorization level has bee set to “function”. This means the key needs to be provided when the function is called.

We can now write some code in the function code editor window as follows:

Clicking the Run button will test the function and we can see the random phrases being returned with a 200 status as shown in the following screenshot:

In the final part of this series we’ll go and create the second Flow that uses this function and the configuration value created in the previous article to actually send random positivity push notifications on a 15 minute schedule.

Microsoft Flow allows the creation of serverless cloud workflows. It is similar to services such as If This Then That and has more of a business focus. It allows custom Flows to integrate with Azure services such as blob storage, the calling of arbitrary HTTP services, in addition to a whole host of services such as Facebook, Dropbox, OneDrive, etc.

In addition to executing in the cloud, Flows can create push notification to the Flow app on iOS and Android.

Once installed, the Flow app can be used to design/edit Flows, view Flow activity/recent executions, and initiate the execution of flows via “buttons” as shown in the following screenshot.

Tapping this software button will trigger the Flow in the cloud.

Example Scenario

To see buttons and push notification in action, imagine a scenario where sometimes you want cheering up with regular messages of positivity.

In this scenario, when enabled, you’ll get a push notification on your phone every 15 minutes with a random positive phase such as “Don't worry, be happy :)”.

To accomplish this two separate (but related) Flows can be created. The first Flow uses a button in the phone Flow app to toggle wether the “positivity pushes” will be sent. The second Flow is triggered automatically every 15 minutes and if enabled, sends a push notification.

Creating the Toggle Positivity Push Flow

This Flow will enable/disable the push notifications. To do this, a manual button trigger will be added to the Flow that will be pushed on the phone. To hold the enabled/disabled state, we can use the content of a blob in Azure blob storage. When triggered, the Flow will retrieve the content of the blob which can be the string “enabled” or “disabled”.

Once the blob content has been retrieved, its content can be examined in a If condition. If the content of the blob is currently “enabled” it will be updated to “disabled” and vice versa. Finally we’ll send a push notification to confirm the state.

Pressing the button in the app a couple of times results in the expected push notifications:

The blob content also gets toggled as expected:

In part 2 of this series we’ll start the process of creating another Flow to actually send the random positivity phrases to the phone.

Marten is a .NET document database library that uses an underlying PostgreSQL database to store objects as JSON. The library has a variety of features that allow the logging of SQL statements issued to the underlying PostgreSQL including previewing LINQ query SQL statements. One of the other logging features available allows custom logging to be created for individual session operations such as successfully issued database SQL commands, failed commands, and changes that were saved. There are also numerous other logging/extension points that can be utilized such as logging schema change SQL and automatically using a logger for all sessions.

The following code shows a console application that writes two customers and then retrieves them:

As another (Gregorian) year edges ever closer, it’s a period that offers a natural reflection time on what happened in the past year and the forging, often weakly, of “New Years Resolutions”.

One interesting question to ask for your work (or personal) life is: “what would easy be like?”.

For example, looking back to the past year where was the pain, sadness, frustration, long hours, constant overtime, feelings of falling behind in new technologies, failed deployments, the same bugs re-occurring over and over again, unsupportive management, mean co-workers, feelings of inadequacy, disappointed customers, etc.

you should feel like you’re doing your best work

Take some time. Make a list. Write them all down.

Now imagine what it would feel like if all of the things on the list did not exist in the upcoming year – what would easy be like?

Fixing some of the things may mean radical decisions such as quitting your job and moving employer.

Some things may not be quite as radical: better automated testing to catch bugs earlier.

You probably won’t be able to fix everything on your list. Starting from the point of view that things should be easy, that you should feel like you’re doing your best work, can be a powerful way to frame where you’re currently at and where you want to be by this time next year.

Marten is a .NET document database library that uses an underlying PostgreSQL database to store objects as JSON. The library has a variety of features that allow the logging of SQL statements issued to the underlying PostgreSQL database in addition to being able to do things such as get the PostgreSQL query plan for a given LINQ query.

One simple way to get the generated SQL for a Marten LINQ query is to use the ToCommand() extension method.

Marten is a .NET document database library that uses an underlying PostgreSQL database to store objects as JSON.

Ordinarily, Marten takes care of retrieving the JSON from the database and deserializing it into an object. We can however instruct Marten to perform a query to retrieve document(s) and not perform the deserialization, instead giving us the JSON as it appears in the underlying PostgreSQL record. If we are exposing documents via a Web API, this feature can be taken advantage of to reduce some processing overhead on the server.

Among other topics, this new course covers how to log/diagnose the SQL that is being issued to PostgreSQL; how to enable offline optimistic concurrency; bulk document inserts; a number of ways to improve query performance; and the customization of database schema objects.

Once this file is saved, the NuGet package will be installed and a using directive can be added: using HtmlAgilityPack;

Now we can download the required HTML page as a string, in the example below the archive page from Don’t Code Tired, use some LINQ to get the post titles, and return this as the HTTP response. Correctly selecting/parsing the required data from the HTML page is likely to be the most time-consuming part of the function creation.

The full function source code is as follows. Notice that there’s no error checking code to simplify the demo code. Screen scraping should usually be a last resort because of its very nature it can often break if the UI changes or unexpected data exists in the HTML. It also requires the whole page of HTML be downloaded which may raise performance concerns.

With over 15 years experience, Jason Roberts is a former 5-time Microsoft .NET MVP, freelance developer, writer, and Pluralsight course author. He has written multiple books and is an open source contributor. In addition to enterprise software development, he has also designed and developed both Windows Phone and Windows Store apps.