The Case of Custom Ouf Of Office

In 2006-07, when I was writing Windows Mobile apps, I really enjoyed using MessageInterceptor type. Using that, we could build our own workflows based on Text Messaging. For example, send an SMS to the device and if SMS contains “Play”, play a song. If SMS contains “Stop”, stop playing the song. And what not. Oh, and I could say if the message is from my parents, reply “I’m in college” and if from friends reply as “I’m waiting outside the movie theater”.

However, I missed this functionality for a long time with different devices (lack of message intercepting API on some platforms). And recently I eagerly wanted to have it for the email, considering the heavy influx of emails in my new role. I got to know about Azure Logic App Service and thought, perhaps let’s go ahead and build something similar. And for me, this is a fantastic way to learn something new.

Scenario: Let’s build a solution which will read incoming email messages and if the message is from one particularly annoying friend, let’s reply with an equally annoying message. If it is from my manager, let’s reply with some positive update and if from a customer we’ll reply with actual OOF. Well, a lot of email service providers allow you to setup OOF, but it is not customizable for different emails. Outlook in Office 365 allows 2 separate OOF messages, one for members within your organization and one for outside organization. Our solution will provide more customizations.

Step 1: Create Azure Logic App Service

Navigate to Azure Portal and Create a resource. Search for Logic App and click on ‘Create’. Give it a name, select the subscription, create Resource Group and finally select a location near to you.

01. Create Logic App

Once Logic App is created, scroll down the next screen and click on ‘Blank Logic App’. This will allow you to add the logical functionality to the just created app.

02. Blank Logic App

Step 2: Design Logic App – Use Connector & Trigger

Connectors allow you to connect your logic app with the desired service. In our case, we’ll use Office 365 Outlook connector to connect to the mail service. And once you connect to the service, there will be a Trigger to activate the logic app. Again, in our case, it will be an email arriving in our inbox.

03. Logic App Connector & Trigger Webhook

Once you select the connector and trigger, sign in with your credentials and connect the email service with your logic app.

Step 3: Setup the Rule and Switch Case

On this screen select the folder in your mailbox to monitor and other aspects of the email. Click on ‘+ Next step’ and write define your logic.

04. Logic App Switch Case

Depending on the connector selected, you’ll see different options for the switch case. For example, in case of Outlook connector and Email trigger, there can be conditions to check for who has sent the email, if it has attachments, if it has importance set or if it has been sent directly to me or to any distribution list to which I’m subscribed.  These conditions will vary depending on trigger and connector.

05. Logic App Switch Options

Once the Switch is set, let’s set up the cases. Here, I’m checking if the email is from Vikram (Oh, he isn’t the annoying friend :) ) and setting up a reply for him. I can also repeat this for many more senders.

06. Logic App Case Vikram

The next one is for my manager Joao,

06. Logic App Case Joao

You can add as many cases as you want and ultimately add a default case. At the end, the logic app designer will look something like this:

06. Logic App Entire Logic

Finally, once this step is done, Run the logic app and wait for the magic to happen :)

07. Logic App Run

In this situation, if a user sends you an email and if the user falls under the cases, the user will receive the response accordingly and if not, user will receive the default response.

Conclusion:

Logic Apps Service makes it easy to write workflows and automate tasks. And even though we used Logic Apps for email workflow, there are connectors available for different services which you can find here. If this list doesn’t cover your service, you can write one on your own connector and documentation for the same is available here.
Don’t forget to ‘nuke’ the resource group once done with it or you’ll keep replying to all your emails – automagically. :)

Happy coding (or designing workflows :) ).
Namaste,
Mayur Tendulkar

 

 

 

 

 

 

 

Advertisements

Xamarin.Forms And The Case of Failed NuGet Packages – Part 2

Most enterprise mobile apps require enterprise-level authentication mechanism. In that case, people use tried and tested Active Directory Authentication Library (ADAL) or Microsoft Authentication Library (MSAL). ADAL is in GA and it works fine with cross-platform mobile apps built using Xamarin. However, MSAL is in ‘preview’ and it offers nightly builds to try out. I wanted to try the latest nightly build (ver: 1.1.1-alpha0417) as it uses updated Android Support Package and old preview bits of MSAL (ver: 1.1.0-preview) were not compatible with latest  Xamarin.Forms anymore. Here, I was trying to build one app over holidays and I got stuck on one interesting issue. Let’s discuss it in this blog post.

The Problem:

When you create a blank Xamarin.Forms app, it automatically references Xamarin.Forms NuGet along with all the required dependencies.

At this time, when you’ll try to install MSAL, you may get stuck at this issue of versioning.

The reason being Xamarin.Forms NuGet requires a specific version of Android Support Packages whereas Microsoft Authentication Library requires anything above Ver. 25.3.1.

The Solution:

Sometimes, things are very simpler than it looks. I spent a lot of time on solving this issue but was unable to fix it. Thanks to my friend Nish, who helped me with his ‘ problem-solving skills’ and we got this working.

The solution is simple:

  1. Remove all NuGet packages from Android project. For the sake of it, close and restart Visual Studio.
  2. Open the solution and Install MSAL NuGet package first.
  3. After installing MSAL NuGet, install Xamarin.Forms NuGet package.

Bingo!

Now you can build Xamarin.Forms apps with Microsoft Authentication Library. If you want to know more about how to use the SDK, follow the blog post here on Xamarin blog.

Even though I’m talking about Xamarin.Forms and MSAL here, this blog post is very much applicable wherever you’re trying to use any NuGet package which has updated dependency on Android Support Package.

Setup info:
Visual Studio Enterprise 2017 Preview (15.5.2)
Xamarin (4.8.0.753)
Xamarin.Forms (2.5.0.121934)
Microsoft Authentication Library (1.1.1-alpha0417)

Namaste,
Mayur Tendulkar

 

Learn Mobile App Dev & Mobile DevOps Here

DevOps Meme

My friend Prachi tagged me on this meme on Facebook and I couldn’t agree more with her. When I started my career, my entire version control was folders – zipped, tagged and stored on multiple hard-disks. But then things changed. My guru Raj, enlightened me about advantages of version control systems. I learned about how multiple people can collaborate on projects or how errors can be reversed by going through code history if version controls like Team Foundation Server or GitHub are used. I started using those and these days, all my projects and samples are either in Visual Studio Team Services or in GitHub repository.  Going one step ahead, I’m using Visual Studio Mobile Center for DevOps along with these version control systems.

But what is this all about? How it helps in building successful mobile applications? And I thought about answering these questions in a video series. The goal is to explain mobile DevOps and different steps in mobile DevOps in small (less than 10 mins) videos.  After completing this series, you’ll be able to build cross-platform Xamarin.Forms mobile application, which will consume Microsoft Cognitive Service and set-up mobile DevOps for the same.

To follow along with this series, I’m recommending following minimum hardware/software combination:

  • Intel i5, 8GB, 50GB machine with Hyper-V support & Windows 10 Professional
  • MacBook or MacMini with i5, 4GB, 50GB for compiling iOS apps
  • Visual Studio 2017 Community Preview

With these hardware/software additional services used in this series are:

Watch the 1st video here about activating these tools & services to set-up mobile DevOps.

In 2nd video learn about how to setup build automation, using Visual Studio Mobile Center.

I’ll update this blog post in coming weeks with the 3rd video in this series, which will be about building mobile applications.

Stay tuned and subscribe to my blog/channel :)

Namaste.
Mayur Tendulkar

Mobile Mindset for five star mobile applications

These days anyone can write mobile applications. With tools like Xamarin & Visual Studio, it has become a lot easier. But for successful mobile applications, developers need to have what I call a ‘mobile mindset‘. Mobile mindset is developed gradually after using various devices and numerous mobile applications. One can learn many things from developing this mindset. So, what is this ‘mobile mindset’ all about? Let’s discuss it in this blog post.

Before Developer, Be a Consumer

The idea is to use a hell lot of mobile applications. Try breaking the boundary of famous apps and use applications which you’ve never used before. Observe the user experience. As, a number of applications you will use in daily life, you’ll get an idea of how your application needs to be designed. You can get inspired by some applications or learn from mistakes of others.

Mobile Apps != Web or Desktop Apps

In large organizations, a pool of web/desktop developers are trained to develop mobile applications. However, there is a huge difference in mobile applications and web or desktop applications. There are constraints on screen size and resolution, battery power, processing power, network connectivity and multitasking when it comes to mobile devices. Think about all these challenges before architecting mobile applications.

Screens & Navigations

In the case of desktop/web applications, users can navigate to any page or screen anytime easily because there are menus, navigation & address bars. They can even launch another application or site for some task and come back to your application. However, this luxury isn’t available in mobile apps and if the user needs to tap or swipe in your mobile app for more than 3 times to complete 1 task, perhaps it is a high time for you to redesign the flow of your application. When it comes to screen, try to avoid distractions. Heavy use of multiple navigations, controls on the screen, advertisement banners can lead to bad user experience. There are guide available for user experience and navigation patterns. Learn about them and see which one suits for your application. And remember, more screens, more swipes and bad user experience can lead to unhappy users.

mobile-mindset-02

User-Friendly Interface

As compared to desktop or laptops, mobile devices have a small screen. It is often called as ‘screen real estate’. Use it wisely. Make controls and ‘next steps‘ discoverable. Use controls which can expand and contract depending on usage. Give hints to the user. Your app has failed if the user has to ‘google’ next steps or read the user manual to use your app.

mobile-mindset-01

Data – As & When Required

If the user is going to launch your app for the first time, treat him with respect. Don’t collect all the user details. If needed, by providing ‘privacy policy‘, ask for only required details to register with your app or service (e.g. age, email, phone, password) and get him onboard. Once onboarding is complete, depending on requirements gather the necessary information (e.g. preferences, network, etc).

On the other side, when required, download contextual data. It doesn’t make sense to download the entire brochure of products when the user is only interested in check out with the items in his cart. Use paging, pull-to-refresh mechanisms to download the data while confirming available bandwidth. A user may be connected to a high-speed wifi network or may be connected to 4G network on roaming. This can be a costly affair.

Having said that, remember, if it takes more than a minute to get to the first screen of your application when the user launches it for the first time, probably, he’ll switch to other similar application or service.

Use Feedback Channels

Before publishing your application to the store, use tools like HockeyApp to conduct beta testing. Distribute your application privately and check the impact. Include crash analytics. And once testing phase is complete, release it to the store. Because once the application is available in the store, users will download it, use it. But when it will crash, seldom they will report it. But definitely, rate it 1 star. Without annoying, ask user to rate your app. Users talking about your apps is the best marketing for your app you can get for free.

Analyse

Don’t just publish your app in the store and leave it for sinking. Use tools like Application Insights, HockeyApp, etc… which can provide details about app launches, app crashes, unique visitors. You can add code to customize the data collected like gender, age, location, preferences of the user. Consider providing ‘privacy policy‘ and notify user about collecting this information. Once you collect that data, analyze it and depending on that provide customized services to your users. Your users will be happy to receive customized offerings. But don’t overdo it.

These are some of the basics of mobile application development, which helps to build ‘mobile mindset’. Thanks to Dipankar, Pooja & Prashant for their valuable feedback over this post. Try these tips in your next mobile app and let us know your feedback through comments.

Enjoy building mobile apps. Happy coding.

Namaste,
Mayur Tendulkar

Xamarin Studio – Visual Studio Goodness on Mac

During Evolve 2016, Xamarin released Xamarin Studio (XS) for Mac as a Release Candidate. This release of XS provides more goodness like Visual Studio on Mac. Let’s see some of the features that are available in this release.

1. Dark Theme
For people like me, who work late at night, this is a boon. You can easily switch the theme and get ‘Dark Theme’ for your IDE. You can change the theme by going to
Xamarin Studio > Preferences > Environment > Visual Styles

XS-Dark-ThemeYou’ll need to restart the IDE to see the effects.

2. New Icons and Graphics
You can see lot of new improvements in terms of graphics and icons when you open a project.
XS-Icons-Graphics

3. Roslyn Support with IntelliSense / Code Completion
XS is rewritten to support Roslyn. It allows code- refactoring and better IntelliSense in IDE. This is like a ReSharper for me :)

XS-IntelliSense

4. Xamarin.Form Previewer
Xamarin.Forms Previewer will allow you to see your XAML design right next to it. It is live, so changes in XAML can reflect in UI. You can see the UI results for iOS and Android for both Phone and Tablet mode in both Portrait or Landscape mode. To see the preview, click on ‘Preview’ button on top right corner.
XS-Forms-Preview
Note: You’ll need Xamarin.Forms v2.3x Pre NuGet package to get this working.

5. Better NuGet Support
You could always add specific version of NuGet package in XS by appending ver in query string while on ‘Add Packages’ window. However, now it has became more easier as XS provides a drop-down for version selector. Small feature, but very helpful.
XS-Nuget-Versions

These are the top 5 features which I can think about when it comes to new Xamarin Studio release. There are many more and you can read about them in release documentation. I’m sure, you’ll enjoy this release.

Namaste,
Mayur Tendulkar

Xamarin.Forms And The Case of Failed NuGet Packages

When you create a Xamarin.Forms project, chances are there will be updates available for Xamarin.Forms libraries and associated packages. You can check for updates to NuGet packages manually or these will be restored before “build”.

The Problem:

When you create a new Xamarin.Forms app or open existing one, if you’ve fresh formatted machine with fresh VS and Xamarin installation, the build may last for longer than expected. The reason for this being, it downloads NuGet packages along with its dependencies like Android Support Packages. If in between, VS hangs or there are interruptions in network, you’ll see some errors in build like this:

XF-NUGET-02

The solution:

Well, at first you may think it is issue with Xamarin or Visual Studio or NuGet. But this all has to do with lot of NuGet packages and their dependencies download. So it all depends on machine config and network connectivity. If ever you see above errors follow the below steps:

1) Start from fresh. Close Visual Studio instances and delete everything under %appdata%local/Xamarin (e.g. C:\Users\mayur\AppData\Local\Xamarin)

2) Launch Visual Studio and open the solution. Right click each project and update NuGet packages. Android is the one which will take longer to update.

XF-NUGET-03

3) Wait till all packages are downloaded. Make sure the %appdata% folder contents all the necessary directories and files.

XF-NUGET-04

4) Build the solution. And if you still get issues about some missing some resources. Open Android SDK Manager from Tools > Android and make sure right API levels (in this case API Level 23) is installed.

XF-NUGET-05

Now run the project and it should run without any issues.

XF-NUEGT-06

Namaste,
Mayur Tendulkar

The Case of REST & Azure Resource Manager APIs

There are two kinds of people in this world. One who love ready made SDKs and then there are others who love to work on pure REST APIs. I’m from the 1st category. :)

The reason behind using SDKs is they include pure abstracted API calls. For example, if you use Active Directory Authentication Library (ADAL), it has AcquireTokenAsync method. This method, if you call, takes just couple of lines of code and makes your life much more easier.

However, behind the scenes, this method does a lot of stuff. For example, in case of Windows apps: calling WebAuthenticationBroker, launching Web UI, handling app navigation, etc. Similarly, it does same thing, in iOS and Android. But that entire code base is repetitive in every app which is going to use Active Directory for login. Now, one may ask, why so many calls are made just to authenticate and acquire token or as we progress through this blog post, why so many calls are required to perform basic operations. The answer lies in purity of REST APIs. And ADAL makes life easier here by providing one method doing all this for you while abstracting all the details.

When I was working on my blog post Monitor Azure Resource Usage and Predict Expenses, there was no SDK available for Azure Resource Manager (ARM) and the old API was not an ideal way to handle Resource Management APIs.

So, I had to write an app from scratch to get ARM working in my sample and here my friend Gaurav Mantri (@gmantri) helped me a lot. Gaurav founded Cloud Portam, which helps to manage resources in Azure like Storage, Search, etc… Thanks to him, I could understand the flow and I’m going to put it here on this blog post.

Step 1: Authenticate with Common

ARM allows you to manage resources within subscription and subscription is now part of your Active Directory. So, the first thing that you need to do is to authenticate with right Active Directory. This is simple if you’ve just one subscription and one Active Directory in your subscription, but if you’ve multiple subscriptions/active directories, you may want to iterate through them and get separate access tokens. To avoid this, first we hit the ‘common’ endpoint and then get the Tenants available.

Step 2: Get Tenants

As a user, your user account may be associated with multiple active directories. A tenant is nothing but an active directory to which you have access. Here, in this step we get all active directories first by calling below method. Later on we’ll try to fetch subscription (if available) from each directory.

Step 3: Get Subscriptions

Once we get tenants, each tenant may have subscription on which we may want perform some actions. To do so, we pass each tenant ID from GetTenants() to this method and acquire new token silently (without login prompt)

Step 4: Call ARM APIs

In order to perform management operations on an Azure Subscription, a user must be authenticated and authorized. Authentication part is handled by Azure Active Directory. There is a one to many relationship between an Azure AD and Azure Subscription. i.e. an Azure AD can be used as an authentication store for many Azure Subscriptions however authentication for an Azure Subscription can happen only with a single Azure AD. Once a user is authenticated with an Azure AD, next step is to find out a list of Azure Subscriptions the logged in user has access to. This is what we’re doing in this step. What a user can do in each of these subscriptions (i.e. the authorization part) can be accomplished by using Azure Resource Manager (ARM) API’s Role-based access control (RBAC).

Now you can replace your code in Step 4 to manage or monitor resources in your Azure subscription, but the flow will not change. The entire list of APIs covering resources and possible operations on them is available here

I hope this post will helps you to understand the model behind ARM API calls.

Namaste,
Mayur Tendulkar