[PT] O meu primeiro podcast…

Hoje foi publicado o meu primeiro podcast, que foi gravado pelo 10Web.pt, e desta agradeço ao Vitor e ao Ricardo pelo convite e oportunidade para participar neste programa.

O podcast pode ser ouvido na página do programa.

web10.pt

Podem também ouvir outros podcast, da 10Web, aqui.

Resources from my presentation about NDepend

Today I did a talk in  NetPonto Community at Microsoft Portugal, and here are all resources from my presentation:

The slides

The recorded:

More details about it, read me article:
Analyzing C# code using NDepend

Azure Mobile Services: How to see the WebConfig file published

Scope

This article has the goal to show how to see the WebConfig file published in Azure Mobile Services.

 Introduction

In Azure Mobile Services is possible to have different environments, for example an application can require the “Dev” and “Prod” environments to allow different versions. To have support to many environments the tips are to use conditional directives and transform files, like is described in the article Azure Mobile Services: How to creating a Dev and Prod environments.

Transform filesFigure 1: Transform Files

In the deployment, based in the build configuration the WebConfig is transformed, like we can see in Figure 2:

PublishingFigure 2: Publishing

The Azure Portal allow to create Azure Mobile Services, monitoring, configure and is possible to see the logs, but for some reason we need to see the WebConfig in server, where is it? In this article we will see how to see it.

Description

Kudu is the engine behind Git deployments in Azure Web Sites, and Azure Mobile Services is not more that an extension of ASP.Net WebApi, this way the deployment used in both is the same.

The Kudu project is available in GitHub in this reference github.com/projectkudu/kudu which wiki has all documentation about it. For each Azure Mobile Service is possible to access its Kudu using something like https://<Azure Mobile Service Base Url>.scm.azure-mobile.net and the Azure Portal credentials.

Let’s use the Menu App Sample, where the Azure Mobile Service is defined in https://mymenuapp.azure-mobile.net/ to access the Kudo page we need to use  https://mymenuapp.scm.azure-mobile.net and we will get something like in Figure 3:

Kudu Main Page
Figure 3:Kudu main page

To see the WebConfig we need to click in “Debug Console” and then we need to choose one of the options, let’s choose “PowerShell” as following:

Selecting PowerShellFigure 4: Selecting PowerShell

The following page will be showed
PowerShell pageFigure 5: PowerShell page

In console do “cd site” and “cd wwwroot” as following in Figure 6:

Navigate to wwwrootFigure 6: Navigate to wwwroot

At the end we will see the follow table

Now is possible to download, edit or delete the WebConfig file, using the options in the left. If we click in edit we will have something like

WebConfig FileFigure 7: WebConfig File

 Conclusion

In conclusion, we can conclude to get the WebConfig in Azure Mobile Service server is very simple and in some cases can be useful, but each developer should be aware the changes made has impact in production.

Azure Mobile Services: How to see the log files in server

Scope

This article has the goal to show how to see the log files from an Azure Mobile Service.

Introduction

In Azure Portal, each Azure Mobile Service has a separator that show all logs registered (Figure 1), and in possible to see the details for each one (Figure2):

The logs

Figure 1: The logs

The log details

Figure 2: The details

This information is very useful and allow to know why the system is down or allow to verify if there is any issue. This page allow to list and see the details for each one, but if we want to export logs, the Azure Portal do not allow it. In this article we will see a solution to get all the log files.

 Description

Kudu is the engine behind Git deployments in Azure Web Sites, and Azure Mobile Services is not more that an extension of ASP.Net WebApi, this way the deployment used in both is the same.

The Kudu project is available in GitHub in this reference github.com/projectkudu/kudu which wiki contains all documentation about it. For each website is possible to access its Kudu using something like https://<Azure Mobile Service Base Url>.scm.azure-mobile.net and the Azure Portal credentials.

Let’s use the Menu App Sample, where the Azure Mobile Service is defined in https://mymenuapp.azure-mobile.net/ to access the Kudo page we need to use https://mymenuapp.scm.azure-mobile.net and we will get
something like in Figure 3:

The Kudu main page
Figure 3: The Kudu main page

To see the log files we need to click in “Debug Console” and then we need to choose one of the options, let’s choose “PowerShell” as following:

Selecting PowerShellFigure 4: Selecting PowerShell

The following page will be showed

Selecting PowerShell
Figure 5: The powershell

Like we can see in the table, we have a LogFiles folder but this contains some logs (logs from Kudu and logs from the application). To see the log, we saw in the Azure Portal, we need to do “cd logfiles” and “cd application” as in the following Figure 6:

Selecting PowerShell
Figure 6: the log file

Using the options in the left we can see the logs and then get it, as following:

Selecting PowerShell
Figure 7: The log file

Conclusion 

In conclusion, we can conclude to get the log files in Azure Mobile Service server is very simple and in some cases can be useful, but each developer should be aware the changes made has impact in the logs separator in the Azure Portal.

Windows Store apps: Invoke ScriptNotify event when we click a button inside a WebView

Scope

This article has the goal to show a solution to invoke the ScriptNotify event when we click in a button from a web page hosted in a WebView.

Introduction

In Windows Store apps is possible to use a WebView control to show web pages and sometimes we may need to intercept between the web page and the code behind of the XAML page, to do others task based in the action.

There are some changes from Windows 8.0 to Windows 8.1 related with the WebView control. These differences can be find here What’s new in WebView in Windows 8.1 and there is an interesting sample: How to intercept JavaScript alert in WebView in universal Windows apps from OneCode Team. In this sample, we will see a solution for when we click in a button from a web page hosted in a WebView.

Description

To start, we need to create a Windows Store App, we can select the Blank Template, and then we need to create a basic html page with a button, as following:

<!--<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->DOCTYPE html&gt;


    <button id="MyButton" type="button">Click here...</button>

After it, we need to define a WebView in the MainPage, as following:

  <WebView Name="WebView"
                 Margin="100"
                 NavigationCompleted="WebView_OnNavigationCompleted"
                 ScriptNotify="WebView_OnScriptNotify"
                 Source="ms-appx-web:///HtmlPage.html" />

And in code behind, we need define the NavigationCompleted event handler as following:

   private async void WebView_OnNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
        {
            await WebView.InvokeScriptAsync("eval", new[]
            {
                "var signButton=document.getElementById(\"MyButton\");" +
                "if (signButton.addEventListener) {" +
                    "signButton.addEventListener(\"click\", MyButtonClicked, false);" +
                "} else {" +
                    "signButton.attachEvent('onclick', MyButtonClicked);" +
                "}  " +
                "function MyButtonClicked(){" +
                    " window.external.notify('%%' + location.href);"+
                 "}"
            });
        }

Here we are injecting JavaScript code to the web page, that will add the event click to the “MyButton” button defined in the html page. Each time the click event is fired the function “MyButtonClicked” will be called and it will fire the ScriptNotify event providing the url.

Now, we need to define the ScriptNotify event handler, as following

 private void WebView_OnScriptNotify(object sender, NotifyEventArgs e)
{
   var url = e.Value;
}

When this event occurs we will get the value returned by the web page.

Running the Application

The webview

And clicking in the button we will get the url value, as we can see in the following image:

The webview's scriptnotify event handler

I was Technical Guru in 3 categories in December 2014

The The Microsoft TechNet Guru Awards! (December 2014) is out! And I could not be more happy! :)

Here are my 3 gold medals:

Technical Guru
Technical Guru
Technical Guru

51ª Reunião Presencial da Comunidade NetPonto em Lisboa

No dia 24-01-2015 será realizada a 51ª Reunião Presencial da Comunidade NetPonto em Lisboa. Para participar, efectue o registo de acordo com as instruções abaixo.

Agenda

09:45  – Recepção dos participantes
10:00  – Como analizar o código C# com o NDependSara Silva [MVP]
Boas práticas no desenvolvimento é o caminho correto para obter boa qualidade no Software produzido, e hoje em dias os programadores, arquitetos e gestores tem cada mais consciência sobre isto. Atualmente existem várias ferramentas para avaliar a qualidade do desenvolvimento de Software,NDepend é uma delas.Nesta sessão a Sara Silva vai explicar em que consiste o NDepend, que tipo de regras suporta, como podemos criar as nossas próprias regras e queries, que relatórios podemos obter e como os devemos analisar, para que desta forma consigamos melhorar o Software que produzimos.
11:30  – Intervalo
12:00  – Personalização do Backoffice de UmbracoAndré Santos
Umbraco é umContentManagementSystem,opensource, desenvolvido sobre tecnologias Microsoft.Desde a sua génese que o foco principal foi criar um CMS que permita gerir conteúdos facilmente, que não afecte de maneira alguma o HTML e CSS criado e que seja extensível disponibilizando para isso APIs poderosas.

Com o lançamento da versão 7, assistiu-se a uma mudança radical na tecnologia usada no backoffice. Com AngularJS, o backoffice de Umbraco passou a ser uma single page application, e a forma de o personalizar também é naturalmente diferente.

Nesta sessão vamos falar sobre as novidades mais interessantes de Umbraco 7 e desenvolver um plugin para o seu novo backoffice

13:30  – Painel de Discussão e Sorteio de Prémios
Nota: Ao final da reunião, escolhemos um restaurante próximo e fazemos um almoço em grupo para continuar o convívio e aproximar as pessoas. A participação é opcional.

Registo / Inscrição

Para participar, basta efectuar a inscrição através do site:
http://netponto-lisboa-janeiro-2015.eventbrite.co.ukA entrada é gratuita.

Qualquer questão / esclarecimento, entre em contacto connosco.


Local

Microsoft Portugal – Auditório
Rua do Fogo de Santelmo, Lote 2.07.02
1990-110 Lisboa
Portugal

Clique para ampliar o mapa.

Patrocinador “Gold


Patrocinadores “Silver


Patrocinador “Bronze


Mais ComunidadeNetPonto:

Avoid nightmares updating Azure Mobile Services projects

Scope

This article has the goal to show how to update a .Net Backend project from Azure Mobile Services, this mean we will update the references added to the project using Nuget packages.

Introduction

Microsoft Azure Mobile Services is an Azure service offering designed to make it easy to create highly-functional mobile apps using Azure. Mobile Services brings together a set of Azure services that enable backend capabilities for your apps.
When a developer create a .Net Backend project from Azure Mobile Services, it has several Nuget packages installed, for example, if the project is created in Visual Studio 2013 – Update 4, like we can see in the Image 1

Creating the Azure Mobile Service

Image 1 Creating the Azure Mobile Service

The default package files will something like as following:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Autofac" version="3.5.2" targetFramework="net45" />
  <package id="AutoMapper" version="3.2.1" targetFramework="net45" />
  <package id="EntityFramework" version="6.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Cors" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.0.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.0.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />
  <package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />
  <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.ActiveDirectory" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Jwt" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
  <package id="RazorEngine" version="3.4.1" targetFramework="net45" />
  <package id="System.IdentityModel.Tokens.Jwt" version="3.0.2" targetFramework="net45" />
  <package id="System.Spatial" version="5.6.2" targetFramework="net45" />
  <package id="WindowsAzure.MobileServices.Backend" version="1.0.405" targetFramework="net45" />
  <package id="WindowsAzure.MobileServices.Backend.Entity" version="1.0.405" targetFramework="net45" />
  <package id="WindowsAzure.MobileServices.Backend.Tables" version="1.0.405" targetFramework="net45" />
  <package id="WindowsAzure.ServiceBus" version="2.3.4.0" targetFramework="net45" />
</packages>

 

But if we “Manage Nuget Packages” and select “Updates”, the windows will show that there are updates that we can do, like we can see in the Image 2

Manage Nuget Packages - Available updates

Image 2 Manage Nuget Packages – Available Updates

First thing we can try to do is to click in the “Update All” button, that will make sense for the developers, but then we will get something as we can see in the Image 3

Error updating all
Image 3 Error updating all

And is here the nightmares about updating the Nuget packages from Azure Mobile Services start, because, like we can see in the package file, we have 36 Nuget packages installed in the project and is not so easy to understand the dependencies between the different Nuget packages and if we start updating one by one we will get errors as following in the Image 4, with this is not possible to update one by one, but the main Nuget packages and in this article we will see how to avoid this problem.

Azure Mobile Service with errors

Image 4 Azure Mobile Service with errors

It means the reference added to the project is not the same version used by any Nuget and can be hard to understand which is right version.

Description

To understand the Nuget packages and because our project is an Azure Mobile Service project, we can start by analyzing the packages

In the Nuget website we found

• Microsoft Azure Mobile Services .NET Backend 1.0.405

Has the dependencies

• Microsoft Azure Mobile Services .NET Backend Tables 1.0.405

Has the dependencies

• Microsoft Azure Mobile Services .NET Backend Entity Framework Extension 1.0.405

Has the dependencies

This way, we can conclude the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension 1.0.405 Nuget depends on the WindowsAzure.MobileServices.Backend.Tables Nuget and this depend on the WindowsAzure.MobileServices.Backend Nuget. This mean if we update the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension Nuget the references related with Azure Mobile Service will be updated.

In the “Manage Nuget Package” click in update the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension Nuget, as we can see in the Image 5:

Udpdating Nuget
Image 5 Updating Nuget

And then, click “I Accept”

License

Image 6 License

At the end, we will get

Nuget packages updated

Image 7 Nuget packages updated

With this another question can be raised, “Did we update all Nuget packages we can?” and this question can be find by uninstall the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension Nuget, as in the Image 8

Uninstall Nuget
Image 8 Uninstall Nuget

Uninstall this Nuget will request a confirmation to uninstall all dependencies, as in the Image 9, where we will click in “Yes”.

Nuget packages to remove
Image 9 Nuget packages to remove

The result will beThe service running in localhostImage 10 The service running in localhost

And the package file updated to:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Autofac" version="3.5.2" targetFramework="net45" />
  <package id="AutoMapper" version="3.2.1" targetFramework="net45" />
  <package id="EntityFramework" version="6.1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Cors" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.0.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.0.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.2" targetFramework="net45" />
  <package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />
  <package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />
  <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.ActiveDirectory" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Jwt" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
  <package id="RazorEngine" version="3.4.1" targetFramework="net45" />
  <package id="System.IdentityModel.Tokens.Jwt" version="3.0.2" targetFramework="net45" />
  <package id="System.Spatial" version="5.6.2" targetFramework="net45" />
  <package id="WindowsAzure.MobileServices.Backend" version="1.0.447" targetFramework="net45" />
  <package id="WindowsAzure.MobileServices.Backend.Entity" version="1.0.447" targetFramework="net45" />
  <package id="WindowsAzure.MobileServices.Backend.Tables" version="1.0.447" targetFramework="net45" />
  <package id="WindowsAzure.ServiceBus" version="2.3.4.0" targetFramework="net45" />
</packages>

Returning back to the “Updates”, we will see the Nuget packages, in the Image 11 that we can update, but for the reasons we saw, it is not possible to update all.

Manage Nuget Packages
Image 11 Manage Nuget Packages

Conclusion

In conclusion, each developer should be aware about the dependencies between Nuget packages and more than one package can depend from the same Nuget package but for different versions, this mean is required to keep the versions used by each one.

Greg Duncan talking about my article in “TWC9: Hello 2015, Greg and Nisha too!”

Today was relased the TWC9: Hello 2015, Greg and Nisha too! at Channel 9

And Greg Duncan talked about when I met him at MVP Summit 2014 and about my last article, see it at 18:32 min.

[18:32] How merge different source code generated by AppStudio [Sara Silva]