Академический Документы
Профессиональный Документы
Культура Документы
by
Sara Silva
Table of Contents
Sara Silva studied mathematics in University of Coimbra, but since she finished
her degree she is working in software development using Microsoft
technologies, since 2009 is Microsoft Certified Professional Developer.
Microsoft Most Valuable Professional (MVP) (2013 & 2014 in Visual C# and 2015 in .Net)
Telerik Developer Expert 2015
C# Corner Most Valuable Professional (MVP) 2014
Nokia Developer Champion 2013
Other awards
Nokia Developer Wiki Contributor of the Month for March, November 2013 and August 2014
TechNet Wiki Windows Phone and Windows Store Apps Technical Guru May, June, July,
August, September, October 2014
TechNet Wiki Microsoft Azure Technical Guru July, September, October, December 2014
Bryan Tomlinson is a proud member of the Windows Apps & Store Team focusing
on developer success. Bryan is the product lead for Windows App Studio and has
been with the product from wireframes to now more than 2.5 million users. Bryan
also manages Microsoft employee developer program, which has more than
20,000 members and has spawned great hits like 4th and Mayor, Taptitude, and
Wordament. He also ran 2013's Windows Phone Next App Star campaign, which
awarded one lucky winner (out of 9,167 competing apps) a chance to have their app's live tile featured
on a primetime TV ad!
A tech nerd and creative who lives in Seattle. He is a SME on Windows App
Studio and also the team support lead. Jon loves App Studio, the Green Bay
Packers and hanging with his kids.
Paulo contributes in the Microsoft English and Portuguese forums answering questions about
software development, with special focus on the .NET Framework. He is Microsoft MVP for more than
10 years. Follow him at twitter @paulomorgado.
Alessandro Del Sole has been Microsoft .NET MVP since 2008. He authored many
books about .NET and Visual Basic, he regularly speaks at Italian and international
conferences, and published many apps for Windows 8 and Windows Phone. He
lives in Italy and he loves Alfa Romeo cars. You can reach him on Twitter at
@progalex
To support the eBook is possible to get the source code from the repository, in GitHub,
https://github.com/AppStudioSamples/Menu, and in each chapter is possible to find the reference to
the related source code.
In the chapters is provided notes, tips, references, etc. which will be represented by an icon
to help understand the information type. The following images with respective legend will describe
these icons:
Reference to appendix
A note or a tip
Introduction
Microsoft released Windows Phone AppStudio Beta in 2013, which is a service that allows any
person without programming skills to create applications, for Windows Phone, in just 4 steps: have an
idea, add content, choose the style and use the application. In April 2014, a new version of this service
was released alongside the beta version of Windows AppStudio, which in addition to the Windows
Phone applications, allows the creation of Windows 8.1 applications (based in Universal Applications).
In this eBook, at the 1st Chapter, we will see the main steps to create a Windows AppStudio
application, using the templates: Contoso Ltd Template, Menu Template and Web template. The
application generated by the Menu Template will be our focus and we will analyse its model and data,
and it will be used in the following chapters.
At the 2nd Chapter, you will learn how to develop a .Net Backend from Azure Mobile Service
and how it can be integrated in the Menu App, using the Azure Mobile Service SDK for client
applications. To support this chapter is provided an appendix (Appendix 1) where you can learn how
to create the Azure Mobile Service in the Azure Portal and to create an Azure Mobile Service project
in Visual Studio.
At the 4th Chapter, you will learn how to add support to Push Notification using the Azure
Notification Hubs, which is integrated with Azure Mobile Services. This feature is provided out-of-box
by Azure Mobile Service SDK and you will learn how the SDK for it.
Cortana is one of the main features provided by Windows Phone 8.1, which bring rich
interaction between the user and the application, and we will see how to integrate it with the
application, in the Chapter 5.
Lastly, in the Chapter 6, you will see the main points to submit the Menu Application in the
Store, where will be provided complementary reference to help in the process.
The service can be accessed from appstudio.windows.com.To start with this service, the user is
required to have an Outlook.com account, or in case the user doesn't have an account, any Microsoft
Id will work. For accounts that does not fit with this, the email account can be associated with a
Microsoft Id and for it the user should use the link http://bit.ly/1gywtmO or in the login page, click on
Sign up. The first time we do the login, the website will show a screen to allow the AppStudio to access
our account, which can be changed later if we wish to. After this, we need to accept the terms of use
and we need to define the user for the email account we are using.
After sign in, we only need to click the button Start new project, to start a new project:
App Studio provides a set of templates to help the users create applications. Theses templates are
application demos for a specific context that are more often used.
Noteworthy is that all the templates are C # / XAML applications and are available for both Windows
Phone 8.1 and Windows 8.1. When we select a template of type "Empty App" we are creating an
application from scratch. This template is often used when the other templates do not meet the needs
of the user or for more advanced users who already have some experience with App Studio.
The user will set all kinds of content, styles and will need to use all your creativity to build a "great
app". In the case of the "Web App Template" the user will also create the application from scratch,
but in this case is given a base URL that will be the starting point of the application and have access to
some buttons on "AppBar", this template is ideal for a website that suit mobile devices. On the other
hand, other templates allow a quick guide in the application we are building and we only need to
change the data and customize the application.
After we select the template Contonso Ltd, a screen will be shown where we can have a first look at
the app. This is a simple simulation of the app for Windows Phone 8.1 and Windows 8.1, which does
not allow navigation to the details pages. The follow screen give us an idea of the application without
installing it:
Content
The first separator, the Content, shows the application name and logo (left, at the top) and shows
all definitions for the content of the app, which, in this case, has five sections:
There's a limit of up to six sections. After each section is created we can edit, delete or move the
section position with the goal to define the best order for it.
RSS: A list of sets of information based on an RSS feed that you enter when creating the data
source;
YouTube: A list of videos with titles and descriptions based on a YouTube channel or search
that you enter when creating the data source;
Flickr: A list of images and their corresponding data based on a Flickr UserId or search that
you enter when creating the data source;
Menu: Allows creation of a menu action to be used in other apps (for example: using an
address for Here Maps, using a phone number to make a call phone and others)
Collection: A list of items with columns of characteristics. The collection can be static or
dynamic and if the collection is dynamic then the data can be imported or exported for a CSV
file;
App Studio already has a comprehensive list of data sources, allowing the user to create compelling
apps. However, these data sources are based on RSS feeds that have a limited number of items and
some presentation limitations.
Theme
In this separator, we can define the
background image or the background
color, define the text color and the
application bar color. There are three
options: custom style (using a
background image), dark style and a
light style. The Select button allows
definition of the style and then we
need to save the configuration.
Tile
In the Tiles, we can define tiles for
the application and we can select
one type from the three available
types: Flip Template, Cycle
Template and Icon Template. In this
case was selected the Cycle
Template and the respective
images.
After all the configuration we can finalize the app by clicking the Finish button.
Finish
Clicking on the "Generate" button we get a screen where we can choose which application we want
to generate.
After this step, we can get the application packages that allow testing of the application in our devices,
or we can get the source code and then test the application in the simulator or in a device using Visual
Studio (but that requires a developer account). It is possible to install the application package directly
in the device using the QRCode provided and is possible to share, in social network, the URL for the
application.
Figure 11 Output
To install the Windows 8.1 application is possible through PowerShell, using Admin privileges, as
following:
Download the source code and opening it in Visual Studio, we will get the following structure:
With the source code, each application can be extended in order to add new features such as:
Connect to Backend
Amongst others
Web App Template are now available for both target, Windows Phone 8.1 and Windows 8.1, and it is
an application based in a website provide by URL.
After create the Web App Template we will see the following page:
As we can see, the content of this app is only a reference for a URL, which is a website that supports
mobile devices. For example, this template uses the m.microsoft.com URL, but we can change it for
use any another URL, like: booking.com, m.sapo.pt, m.vodafone.pt, amongst other references.
The definition for Theme, Tile, Publish and Finish are the same as we saw in Contoso Ltd template.
Menu Template is a template provide by Windows AppStudio and it is used for the following purpose
Do you own a restaurant, or have a favorite place you go every week? Use this template to
show your customers or your friends about the delicious meal they'll find there. With easy-to-
navigate sections and pictures for starters, main courses and desserts.
When the template is created, the default data uses static resources.
Windows App Studio allows us to export and import data, but each time we need to edit data, we
need to publish the new version in the Store unless we select dynamic resources. For help in this
process we will create a .Net Backend in Azure Mobile Service that allows us to manage the data that
will be consumed by the Menu App.
See the default Menu App, for Windows Phone 8.1 and Windows 8.1, which was
generated: Step 1: Add default Menu App generated by AppStudio (bit.ly/MenuApp-Step1)
The source code provided has a solution that contains the following projects:
AppStudio.Shared: shared project used for both targets (it allows the reuse of code)
In the AppStudio.Data project it is possible to generate the class diagrams to understand the model
and the data sources used in the application. This will be useful later.
See the Appendix 3 Class Diagram: An easy way to understand code which will provide
additional information about class diagrams.
The model
The model, defined in AppStudio.Data, contains all classes that represent the structure of the data
used in the application.
Each class has more properties (DefaultTitle, DefaultSummary, DefaultImageUrl and DefaultContent).
Which uses the properties showed in the class diagram and them are used in the automation created
by Windows App Studio, for this reason it was ignored.
The data sources contains all classes that will provide the data that will fill the UI
Each data source has a LoadDataAsync method that is called by each target to fill the data in the UI.
See the changes made in the default Menu App: Step 2: Add class diagrams and fixes
issues related with nomenclature (bit.ly/MenuApp-Step2)
It is possible to change code in the solution, but it is not possible to upload those changes
back to Windows App Studio. Any change in AppStudio should be merged with changes made in
Visual Studio. See the Appendix 2 Appendix II: How merge different source code generated by
AppStudio which will provide some tips to merge the code source.
azure.microsoft.com/en-us/downloads.
Figure 22 Azure Portal and downloads
For the details of how to create an Azure Mobile Service in the Azure Portal and how to
create the Visual Studio 2013 project, see the Appendix 1 Appendix I: How to Create the Azure
Mobile Service in Azure Portal which will provide the step by step to create the MyMenuApp Azure
Mobile Service.
In the last chapter, in Menu Template Overview, was analysed the model that define the structure for
the data used in the Menu App and it is very important for the services. Each class represents specific
information inside of the app and the service should allow us to store data for each class (this is the
insert operation) and of course support for getting all items, get item by id, update an item and delete
an item.
Each service ends with the word Controller because this is a pattern from the WebApi (asp.net/web-
api). WebApi is the base for Azure Mobile Services and the controller name starts with the name of
the related object, normally called DTO, and end with the word controller. Each developer should be
aware of this, because these names will be used internally and if it does not match with the kind of
pattern it can cause some problems in consuming the services, in serialization, or even when client
apps request specific queries.
MainSchema
SpecialOffersSchema
DessertsSchema
StartersSchema
BeveragesSchema
Each one will have the same structure as in the client app and they will inherit from EntityData that is
the class from Azure Mobile Service that represents the system properties and are useful for offline
mode. To simplify the sample, we will map the DTOs to the database, using Entity Framework.
Other solutions could be, to have the DTOs mapped with the model. The article Build a service
using an existing SQL database with the Mobile Services .NET backend, shows an example that has
DTOs and a model, that are mapped to each other and the model is related with the database.
DTOs
The first class created is a base class for the DTOs that contain shared properties.
This class inherits from EntityData and not from the DtoBase because it does not share all properties
like the others objects.
All DTOs must be created inside the DataObject folder because when we create the table controller
this object will be searched for there.
Services
Each service will be an Azure Mobile Service Table Controller and can be created as following:
The BeveragesSchemaController
30. {
31. BeveragesSchema current = await InsertAsync(item);
32. return CreatedAtRoute("Tables", new { id = current.Id }, current);
33. }
34.
35. // DELETE tables/BeveragesSchema1/48D68C86-6EA6-4C25-AA33-223FC9A27959
36. public Task DeleteBeveragesSchema(string id)
37. {
38. return DeleteAsync(id);
39. }
For the other services, the process is the same, only change the DTO selected and the name of the
controller and all services should be create inside the Controllers folder.
After create the services is possible to create the class diagram for the services class, as following:
Validating data
Each service should validate the input data, to ensure that the following operation will not fail because
the input is wrong. For example, suppose that the input object wasnt sent in the right way, for this
reason the serialization fails, it can be a request with n null input, that is not correct and it will throw
a NullReferenceException in our service. Another case is when a required property is not filled and the
service tries to save or edit it and then it throws a DbEntityValidationException.
The code to insert a BeverageSchema that validates the data, can be defined as following:
The DomainManager
Each service has an Initialize method, which defines the DomainManager as following:
This property is an IDomainManager and is used internally for all operations in the database, in this
case it will be an EntityDomainManager of Beverages Schema.
The EntityDomainManager<T>
This class is an implementation of IDomainManager that contains the implementation for all
operations required for the database, using the MobileServiceContext.
The MobileServiceContext
This class represents the DbContext for the services that allow us to do the CRUD operations in the
database the easy way. This class will be used by the EntityDomainManager. The MobileServiceContext
was changed because when each service was created, it was also automatically added to the following
DataSets:
To understand more about it, which is related to the Entity Framework, see the documentation
about it, the DbContext Class.
The Database
There are various ways to create the database, it can be created manually in SQL Server Management
Studio, in Visual Studio or can be created using Code First. We will use Code First that means we create
the model first and then create the database based in the model structure. This process happens when
we do deploy. As said earlier, our model is defined by the DTOs class.
When the project was created, we removed some code that was ignored and with it we deleted the
code related with the Database Initializer, that uses the lass DropCreateDatabaseIfModelChanges that
is an implementation of IDatabaseInitializer that will DELETE, recreate and optionally re-seed the
database only if the model has changed since the database was created.
If the model doesn't change we can use it, but Are we sure that the model will not change in the
future?
To create the database and prevent future changes in the model (in our case the DTOs), we will
use Entity Framework Migrations.
There are others IDatabaseInitializer that can be used, but the problem is the same, the data will
be lost if the model changes.
Before we enable migration, we need to get the connection string to connect to the database and
need to allow our IP to access the database.
The connection string must be defined in Web.config and can be a connection string from a local
database (for local usage) or from the database created with the Azure Mobile Service. The connection
string from MyMenuApp_db database, which can be found in the Azure Portal by selecting the
MyMenuApp Azure Mobile Service and then in Configure as in the following:
Figure 1025 The connection strings for the MyMenuApp Azure Mobile Service
In the project, go to the Web.Config file and paste there the connection string from the Azure Portal,
as following:
Later, in the deployment process, this value is overridden with the connection string defined
in the Azure Mobile Service.
The localhost tests required to allow our IP to access the database. We need to go to the Azure Portal,
select the database MyMenuApp_db and then click in Dashboard, as following:
Migration
To add migration support we need to start with Enable-Migration. To do this, open the Tools menu
in Visual Studio and then open the Package Manager Console, as following:
Now, in the Package Manager Console, we need to enable migration and add migration, as following:
The Migration folder was added to the project and it contains the configurations file and the migration
V_0. This migration contains all information to create the database and the tables, it is used to revert
the process if necessary.
Seed
In the Configuration file, it is possible to find the Seed method that fills the database with some initial
data or when there is any change in the model. It can be useful to update data in the database. In our
case, we will use it to fill the database with the static data from the Menu App.
Each data source in the AppStudio.Data project has the _data field that contains it. Here are the
changes made:
This way, the database will be created if it is needed or will be updated based in the current model
and the migration provided.
Be aware that the seed method is called each time this code runs and consequently clone data
can be added to the database. See more about this subject in the article How to make data model
changes to a .NET backend mobile service.
Now that the services are ready, we can run the services in localhost or in the server. For testing it
could useful to use the localhost first.
Localhost
To run the services in localhost, press the key F5. The following page will be shown:
Selecting one service, we will see a new page with a response as example, in this case as JSON,
This allows us to make a request to get all the special offers from the service. Attention, there are a
limit of items we can get, best practice is to request some items and it will request more when they
are needed (it is used to create pagination). Click in the send and we will get the response.
Server
To deploy the services to the server, click on the project and open the context menu, then click on
Publish, as following in Figure 22 and select the publish target as in Figure 23:
Then select Microsoft Azure Mobile Services to associate the project to the MyMenuApp Azure Mobile
Service.
Figure 24 Authentication
Then click on the Publish button and then it is possible to follow the deployment in Web Publish
Activity.
Figure 26 The service is up and running and require a key to see the API Documentation
Errors
When we run the service and we got the following window, which means there are problems. To
understand what happened we can use the Logs from the MyMenuApp to see the errors.
Go to the Azure Portal, then select the MyMenuApp Azure Mobile Service and then click on Logs, as
following:
Select the error and click at the bottom on the details button and we will see the error:
In this case, the error was made by adding an additional property in the model and wasnt added the
migration for update it in the database.
See more about this subject in the article Troubleshoot the Mobile Services .NET Backend.
Remote debugging
When we run the code in localhost we can debug the services, but in some cases it can be useful to
debug the code that is running in the server, it is called remote debugging. In the MyMenuApp Azure
Mobile Service select Configure and be sure you have this on:
For those who use Visual Studio 2013 Update 2 or later, it is turned on automatically.
In Visual Studio, open the View menu and the click in Server
Explorer that will open the window as following:
For it to work we should deploy to the server using Debug Mode, in Release Mode it will not
work. See more about it in Runtime Debugging.
Set the breakpoint and do the request, this way, the breakpoint will be hit as in the following:
See the code created for AppStudion.Menu.Backend Step 4: Changes the BackEnd project:
add the Dtos, add Services, changes the MobileServiceContext and add support for migrations.
(bit.ly/MenuApp-Step4).
Manage Images
In Azure Mobile Service, it is a best practice to use Azure Blob Storage to save the images used in the
client apps and we only need to save, in the Azure SQL Database (MyMenuuApp_db), the image URL.
To see how to implement this feature see the article Upload images to Azure Storage by using
Mobile Services. That covers the topic for .Net Back End & Windows Store and .Net Back End &
Windows Phone.
Select the AppStudio.Data project and then open the "Manage Nuget Packages..." as in the following:
Install the Windows Azure Mobile Services Nuget package as in the following:
It is necessary to install this package in each target (Windows 8.1 and Windows Phone 8.1 apps).
Select the target project and with the mouse open the context menu, then click in Add and
Connect Service
Then login in using your Azure account and you will see your Azure Mobile Services, as following:
By clicking in the MyMenuApp Azure Mobile Service we will add the Nuget package for Azure Mobile
Service, as following:
The MobileService<T>
After it, create the MobileService<T> class in the DataSource folder from the AppStudio.Data
project, as following:
1. // <summary>
2. /// Defines the Mobile Service wrapper.
3. /// </summary>
4. /// <typeparam name="T">The type of the DTO.</typeparam>
5. public sealed class MobileService<T>
6. {
7. private static MobileServiceClient _appStudioBackEnd;
8.
9. /// <summary>
10. /// Gets the application studio back end.
11. /// </summary>
12. /// <value>The application studio back end.</value>
13. private static MobileServiceClient AppStudioBackEnd
14. {
15. get
16. {
17. return _appStudioBackEnd ?? (_appStudioBackEnd = new MobileServiceClien
t("<the service url>", "<the application key from Portal>"));
18. }
19. }
20.
After this, run the Menu App and the following screen will be showed, for the Windows 8.1
application:
Now the app has dynamic data, which can be changed without changing the Menu App.
See the code in Step 5: Changes the client app: add support for consuming MyMenuApp
A Start menu with the following choices: Starters, Mains, Desserts, Beverages and Special
offers
Clicking in each menu item will show a page with list of the items
Clicking in one item in the list will show a page to edit the item
Like the name indicates, this app is empty app and we will define all the structure for the BackOffice.
The following figure will show the start point for a project:
Start by changing the name to BackOffice, in the App Title field at the top, as following:
The first page of the app will have a menu; for that, click in the Menu option and then fill in the
name of the menu.
With this we will have more options available. To create the menu we want, we will use the
collection option, because we want to show a list of items.
Adding collections
Click in the collection menu to create the first menu item, as following:
Define the name of the collection and click in the option Add default columns:
Here we can define if we want dynamic or static data, that it is not important in our case, because we
will use the data from the Azure Mobile Service, as we did in the Menu App. After creating each
collection, it is recommended to save the definitions, using the button Save in the right.
Figure 45 Saving
For Special Offers we need to add the columns manually, because it has a structure different from
the default, for that click in Create new as following:
For each field insert the respective information: field's name, type and if it is multiline. At the end we
will have something like:
Each field name should start with upper case because this way the respective property will well
defined, i.e., using C# Guidelines.
After all collections are defined, we will have the following definition:
These collection can be ordered, deleted and edited but they cannot be more than six. In the code it
is possible to add more or create another menu and add the missed collections. In source code change
it to have only one section.
Editing a collection
It is possible to edit the Starters by clicking in Edit Item, that will show the following screen:
Define the Layout and Bindings for the windows with the list of items
Define the Layout and Bindings and Page Extras for the details of the item
Edit the data to add one dummy starter
We can choose what we want, for the sample we will define the following:
We will now edit the default data, by clicking in the Data separator and then in Edit Data, as
following:
Click in Create new and fill in the item with dummy values as following:
Here, it is not important what we will fill in, it only allows us to see data until we change the BackOffice
to consume the Azure Mobile Service. Insert a similar dummy data for the others collection.
At this moment, we have a starting point for the BackOffice App, it is possible to define the theme,
the tiles, the published info, but this article will not cover it. To see in more depth how to define each
one, see the topic Theme Chapter 1: Introduction.
Now you can click in the Finish button to generate the BackOffice App, and the following screen
will be shown:
See the code in Step 6: Add default BackOffice App generated by AppStudio
(bit.ly/MenuApp-Step6)
The default columns added to the ImageUrl in each collection and each DTO from the service
uses the name Image. There are two options to fix this difference: rename the property ImageUrl
for each collection and in the UI or using JSON attributes for the property ImageUrl that will define
the name as Image.
In the Azure Mobile Services we added the static data from the Menu App, for this reason when we
run the BackOffice App using the Azure Mobile Service it will not show the images, because the
BackOffice App doesnt have these images. To solve it for now, do a copy and paste of these images
(it will be temporary!).
The collection view will be the page that shows a list of objects. In this case, it will be
BeveragesPage.xaml, DessertsPage.xaml, Main1Page.xaml, SpecialOffersPage.xaml and
StartersPage.xaml.
The item view will be the page that shows a specific item, in this case, it will be
BeveragesDetailPage.xaml, DessertsDetailPage.xaml, Main1DetailPage.xaml,
SpecialOffersDetailPage.xaml and StartersDetailPage.xaml.
The others collection has similar views. For now the BackOffice app is only in read mode similar to
the Menu App.
We will only focus on Windows 8.1 App, for the Windows Phone 8.1 the changes are similar and
in some cases the changes are shared.
To add the support to edit the data, we need to change the item view. We should change the
following views (that can be found in the DataTemplate folder):
Each one contains the DataTemplates used in each page. To find which template should be changed,
open the BeveragesDetailPage.xaml, the page for seeing a selected Beverage. We will find the FlipView
that contains the a ItemTemplate defined, called Beverages1DetailDetail.
With the cursor under the string Beverages1DetailDetail press F12 and the BeveragesViews.xaml
will be opened, with focus in:
1. <DataTemplate x:Key="Beverages1DetailDetail">
1. <DataTemplate x:Key="Beverages1DetailDetail">
2. <StackPanel Margin="120,0,0,0">
3. <TextBlock Text="Title:"
4. Style="{StaticResource ItemHeaderTextSnapped}" />
5. <TextBox Grid.Row="0" Margin="0,20,0,0" Grid.Column="1"
6. Text="{Binding Title, Mode=TwoWay}" Width="400" HorizontalAlig
nment="Left"/>
7. <TextBlock Text="Subtitle:" Margin="0,20,0,0"
8. Style="{StaticResource ItemHeaderTextSnapped}" />
9. <TextBox Grid.Row="0" Grid.Column="1"
10. Text="{Binding Subtitle, Mode=TwoWay}" Margin="0,20,0,0" Widt
h="400" HorizontalAlignment="Left"/>
11. <TextBlock Text="Image:" Margin="0,20,0,0"
12. Style="{StaticResource ItemHeaderTextSnapped}" />
13. <TextBox Grid.Row="0" Grid.Column="1" Margin="0,20,0,0"
14. Text="{Binding Image, Mode=TwoWay}" Width="400" HorizontalAlig
nment="Left"/>
15. <Image Grid.RowSpan="2"
16. Source="{Binding Image}" Margin="0,20,0,0"
17. Width="200" Height="200"
18. HorizontalAlignment="Left" Stretch="UniformToFill" />
19. <TextBlock Text="Description:" Margin="0,20,0,0"
20. Style="{StaticResource ItemHeaderTextSnapped}" />
21. <TextBox Grid.Row="1" Grid.Column="1"
22. Margin="0,20,0,0" ScrollViewer.HorizontalScrollBarVisibility="
Auto"
23. ScrollViewer.VerticalScrollBarVisibility="Auto"
24. AcceptsReturn="true" HorizontalAlignment="Left"
25. Height="200" MaxHeight="200" Width="800" MaxWidth="800"
26. Text="{Binding Description, Mode=TwoWay}" />
27. </StackPanel>
28. </DataTemplate>
Do the same changes for Starters, Mains and Desserts. For Special Offers change the data template
for something like:
1. <DataTemplate x:Key="SpecialOffers1DetailDetail">
2. <StackPanel Margin="120,0,0,0">
3. <TextBlock Text="Title:"
4. Style="{StaticResource ItemHeaderTextSnapped}" />
5. <TextBox Grid.Row="0" Margin="0,20,0,0" Grid.Column="1"
6. Text="{Binding Title, Mode=TwoWay}" Width="400" HorizontalAlig
nment="Left"/>
7.
8. <TextBlock Text="Subtitle:" Margin="0,20,0,0"
9. Style="{StaticResource ItemHeaderTextSnapped}" />
10. <TextBox Grid.Row="0" Grid.Column="1"
11. Text="{Binding Subtitle, Mode=TwoWay}" Margin="0,20,0,0" Widt
h="400" HorizontalAlignment="Left"/>
12.
13.
14. <TextBlock Text="Starter1:" Margin="0,20,0,0"
15. Style="{StaticResource ItemHeaderTextSnapped}" />
16. <TextBox Grid.Row="0" Grid.Column="1"
17. Text="{Binding Starter1, Mode=TwoWay}" Margin="0,20,0,0" Widt
h="400" HorizontalAlignment="Left"/>
18.
19. <TextBlock Text="Main1:" Margin="0,20,0,0"
20. Style="{StaticResource ItemHeaderTextSnapped}" />
21. <TextBox Grid.Row="0" Grid.Column="1"
22. Text="{Binding Main1, Mode=TwoWay}" Margin="0,20,0,0" Width="
400" HorizontalAlignment="Left"/>
23. <TextBlock Text="Dessert1:" Margin="0,20,0,0"
24. Style="{StaticResource ItemHeaderTextSnapped}" />
25. <TextBox Grid.Row="0" Grid.Column="1"
26. Text="{Binding Dessert1, Mode=TwoWay}" Margin="0,20,0,0" Widt
h="400" HorizontalAlignment="Left"/>
27. </StackPanel>
28. </DataTemplate>
At this moment, all the data can be edited. Now we need to add options to persist it.
To allow doing the operations Add, Save and Delete it is necessary to add an AppBarButton for
each operation. In the BeveragesDetailPage.xaml add the following app bar:
1. <Page.BottomAppBar>
2. <CommandBar Background="{StaticResource AppBarBackground}">
3. <AppBarButton DataContext="{Binding BeveragesModel}"
4. x:Uid="SaveButton"
5. Command="{Binding SaveCommand}">
6. <AppBarButton.Icon>
7. <BitmapIcon UriSource="ms-appx:///Assets/AppBar/Save.png"/>
8. </AppBarButton.Icon>
9. </AppBarButton>
10. <AppBarButton DataContext="{Binding BeveragesModel}"
11. x:Uid="DeleteButton"
12. Command="{Binding DeleteCommand}">
13. <AppBarButton.Icon>
14. <BitmapIcon UriSource="ms-appx:///Assets/AppBar/Delete.png"/>
15. </AppBarButton.Icon>
16. </AppBarButton>
17. </CommandBar>
18. </Page.BottomAppBar>
That will add the Save and Delete AppBarButton. This XAML can be added to the others object's
pages. To add the Add AppBarButton, open the BeveragesPage.xaml and added the following
XAML:
1. <Page.BottomAppBar>
2. <CommandBar Background="{StaticResource AppBarBackground}">
3. <AppBarButton x:Uid="AddButton"
4. Command="{Binding AddCommand}"
5. DataContext="{Binding BeveragesModel}">
6. <AppBarButton.Icon>
7. <BitmapIcon UriSource="ms-appx:///Assets/AppBar/Add.png"/>
8. </AppBarButton.Icon>
9. </AppBarButton>
10. <AppBarButton x:Uid="RefreshButton" DataContext="{Binding BeveragesMode
l}" Visibility="{Binding RefreshVisibility}"
11. Command="{Binding RefreshCommand}">
12. <AppBarButton.Icon>
13. <BitmapIcon UriSource="ms-appx:///Assets/AppBar/Refresh.png"/>
14. </AppBarButton.Icon>
15. </AppBarButton>
16. </CommandBar>
17. </Page.BottomAppBar>
For now it is missing the commands for each AppBarButton: AddCommand, SaveCommand and
DeleteCommand.
The AppStudio apps uses a pattern called Model-View-ViewModel (MVVM), for this reason
the AppBarButton is using the Command property and not the Click event. To understand more
about this pattern, see the following article Use the Model-View-ViewModel (MVVM) pattern.
The methods CanSave and AddItemAsync will be implemented in the view model for each object,
more specifically the view models BeveragesViewModel, DessertsViewModel, Main1ViewModel,
SpecialOffersViewModel and StartersViewModel. Because it needs to know each object will be
added.
For the DeleteItemAsync method, we need to show a message to the user to confirm the operation,
then the item will be deleted and then the item will be removed from the Items list and will raise
notifications to update the UI.
Where we will add the abstract methods for DeleteAsync and SaveAsync. These methods will be
implemented in all specific data sources, for example in BeveragesDataSource we will do something
like:
For the SaveItemAsync method, we will update the data and then will show a message to the user to
confirm the operation was done and then the UI will be updated.
When an item is saved, it can be new or can be an existing one, for this reason a IsNew property
was created for each object that allows understanding if we will do an Insert or an Update
The UpdateCacheAsync is a method used to update the cache for each collection, this code was
provided by AppStudio, when we generated the app, only was applied a refactoring in the
LoadDataAsync method for reuse of the code.
Each data source must not be static, for it use the property HasStaticData.
The AddItemAsync method
For example, in BeveragesViewModel we will create a BeveragesSchema that is new and it will be
added to the Items list, then the app will navigate to the item view to allow to edit this new object.
And in BeveragesDetailPage.xaml.cs in OnNavigateTo change the code to receive the parameter sent
in the AddItemAsync method as in the following:
The CanSave method will determine if an item can be saved or not, since it uses some validations.
The implementation, for Beverages, Starters and Mains, will be something like:
At this moment, the BackOffice App has support for editing the data received from the Azure Mobile
Service and can persist it.
In the Windows AppStudio we could change the theme and the assets for the BackOffice app, but is
possible do the same in the code. For the BackOffice App we will add the same theme and assets from
the Menu App. For it, go to the Assets folder for Windows 8.1 app and copy and paste the images
related with logos.
To change the theme, go to the Style folder in the Windows 8.1 app, open the file AppStyles.xaml and
replace the following styles:
Now that the BackOffice supports editing the data and has a new look, let's see how it looks.
The main view will be the start page; in this case, it will be the MainPage.xaml.
The collection view will be the pages that show a list of objects; in this case, are: BeveragesPage.xaml,
DessertsPage.xaml, Main1Page.xaml, SpecialOffersPage.xaml and StartersPage.xaml
The item view the pages that show a specific item; in this case, it will be: BeveragesDetailPage.xaml,
DessertsDetailPage.xaml, Main1DetailPage.xaml, SpecialOffersDetailPage.xaml and
StartersDetailPage.xaml.
To an existing item:
To a new item:
To have the app bar opened each time for each navigation to the collection view or the item view we
should add the following definition to the OnNavigationTo for each page:
1. BottomAppBar.IsOpen = true;
2. BottomAppBar.IsSticky = true;
See the source code for the BackOffice App, here: Step 7: Changes the BackOffice app: add
support for edit data from Azure Mobile Service and add new theme and assets. (bit.ly/MenuApp-
Step7)
The MyMenuApp Azure Mobile Service will send the Push Notifications
The Menu App will receive the Push Notifications
The process of adding Push Notification to a Menu App using Azure Mobile Service can be so easy that
we dont need to understand all the process behind it. But it is important to understand at least:
The Windows Phone 8.1 and Windows 8.1 apps uses the Windows Push Notification Services
(WNS). This service enables third-party developers to send toast, tile, badge and raw updates
from their own cloud service. This provides a mechanism to deliver new updates to your users
in a power-efficient and dependable way.
Azure Mobile Service is integrated with Notification Hubs and when the MyMenuApp Azure
Mobile Service was created, in the Azure Portal, was created the MyMenuAppHub-ns
Notification Hub.
An Azure Notification Hubs provide an easy-to-use infrastructure that enables you to send
mobile Push Notifications from any backend (in the cloud or on-premises) to any mobile
platform. Notification Hubs Overview.
A Menu app does not require user authentication, for this reason all notifications sent will be received
by all users.
For applications that use authentication, the process is a little different, because the User X
will not receive the notification for User Y and vice-versa. A good example are the notifications in
Facebook.
To send Push Notification, the AppStudio.Menu.BackEnd must be changed and we should use the
Service.Push.SendAsync method to send the notifications.
In table controllers, we have the Service property that contains a Push property that allows us to send
the notification, here are the options for it:
In the MyMenuApp Azure Mobile Service, we will notify the user when an object is inserted or
updated. For it, in each controller we will change the Post and Patch methods.
To avoid repeated code we create the PushHelper static class that will have the definition for the
message we want to send, which implementation is:
The typeOfOperation will be Insert or Update and the content will be the Title, Subtitle and
Image from the object. And the template for Toast notification was used, more specifically the
ToastText01 and ToastImageAndText03 but could be another template. See the toast template
catalog in this article. The toast template catalog (Windows Runtime apps), the Tile template catalog
in this article. The tile template catalog (Windows Runtime apps) and the badge option in this article
Badge overview (Windows Runtime apps).
Changing controllers
Using GetWindowsPushMessageForToastImageAndText03
For example, the complete implementation for the Insert method in the BeveragesSchemaController
can be
And the complete implementation for the Update method, in the BeveragesSchemaController, is for
example:
Using GetWindowsPushMessageForToastText01
The complete implementation for the Insert method, in the SpecialOffersSchemaController, can be:
And the complete implementation for the Update method, in the SpecialOffersSchemaController, is
for example:
See the source code for the change made in AppStudio.Menu.BackEnd: Step 8: Changes
the AppStudio.Menu.BackEnd app: add the PushHelper and add support for send notification after
an insert or update. (bit.ly/MenuApp-Step8)
There are two ways to do it, automatically and manually. In this article we will use the
automatically way because it simplifies the process, to see how to define it manually see the
article Get started with Push Notifications in Mobile Services.
Select the Windows 8.1 project and open the context menu, then click in Add and then click in
Push Notification
With it we will see a Wizard that will add Push Notification support based on the MyMenuApp Azure
Mobile Service and this wizard will inform us about the changes it will do.
In this screen you can reserve an app name if it does not yet exist.
Now the wizard finishes and we will see two separators in Visual Studio, the read me file is:
At this moment, the Menu App for Windows 8.1 supports Push Notification and we should install
this version on the device.
The same process should be done for the Menu App for Windows Phone 8.1.
Like we mentioned early, Azure Mobile Service is associated with Notification Hubs, for this reason it
is possible to test the Menu App, to see if the app is receiving Push Notifications. This test is
independent of the implementation in the backend and it will allow sending a dummy message to see
if all is okay.
Then expand the Azure item and expand the Notification Hubs item, click in MyMenuAppHub-ns, open
the context menu and click in Diagnose.
Figure 63 Diagnose
With it, a window in Visual Studio will be opened, where it is possible to define the message and the
type of the message that we want to send. In our case the type of the message must be a Windows
(WNS) and we will choose a Toast.
After this selection the message will be filled using a default message for Toast. Here is the message
we will send:
Pressing the button Send we will receive the Toast notification and it is possible to see the message
results.
The test Toast notification for Windows Phone 8.1 will be something like:
With this test we can conclude that the Menu App is okay and the registration to receive Push
Notification is working.
Go to the Azure Portal, select MyMenuAppHub-ns Notification Hub. In the Debug separator we will
have a similar screen from the Visual Studio, where we can send the messages.
After sending the message we will receive the notification and will see the results at the bottom.
Insert notification
In the BackOffice app we will insert a new object and we will receive a notification.
Windows 8.1
Update notification
In the BackOffice app we will update an existing object and we will receive a notification.
Windows 8.1
Using Tags
At this moment, all users will receive notification for all starts, mains, beverages, desserts and
special offer. For how they specify that they want to create an option, here the user can subscribe to
what they want to receive, tags is the solution.
Tag expressions enable to target specific sets of devices, or more specifically registrations, when
sending a Push Notification through Notification Hubs.
1. await App.MyMenuAppClient.GetPush().UnregisterNativeAsync();
In the BackEnd: send the message for the specific tag using:
4. await Services.Push.SendAsync(PushHelper.GetWindowsPushMessageForToastText01
("Update:", dto.Title), "starters");
To send a message for various languages, we can use tags like en_starters or pt_starters and in
the Backend each message will be sent like we saw before, with the difference that the message is in
English or in Portuguese, depending on the tag used.
Using Templates
In the BackEnd the PushHelper class was created that uses a specific template, the ToastText01 and
it was defined in BackEnd. But it is possible to register the device for a specific template and then the
BackEnd can send the template message.
Cortana is not available in all languages, for this reason some non-English users have changed their
devices to support it. For see more about how to have Cortana in our Windows Phone 8.1 devices see
the following article.
Integrating Cortana
In this chapter, you will learn how to integrate Cortana in a Windows Phone Application. Cortana will
use Voice Commands for interacting with the apps, these voice commands are pre-installed in the
apps so Cortana knows how to launch each app.
The first step to integrate Cortana, in the Menu App, is to define the Voice Command Definition (VCD)
file, which represents an XML file with the commands that Cortana will recognize and will match with
the app.
For the Menu App we will define Menu as the name for talking with the Menu App and define the
following two commands:
Show Command: that will allow you to choose which menu we want to see: Beverages,
Starters, Mains, Desserts and Special Offers.
Natural Language Command: that will allow to recognize an expression like I am hungry, I
want to eat and I want to drink.
In this sample, the VCD is defined for English (en-US) but more languages could be added.
Now we define the commands, we need to install it in the app each time the app starts.
7. if (e.NavigationMode == NavigationMode.New)
8. {
9. await InstallVoiceCommandsAsync();
10. }
11. }
We then need to define what the app will be done each time it receives a voice command from
Cortana. When Cortana recognizes a command the Menu App will send the data to the Menu App
and the OnActivated method in App.xaml.cs will be called.
9. if (commandArgs != null)
10. {
11. SpeechRecognitionResult speechRecognitionResult = commandArgs.Res
ult;
12.
13. var voiceCommandName = speechRecognitionResult.RulePath[0];
14. var textSpoken = speechRecognitionResult.Text;
15.
16. switch (voiceCommandName)
17. {
18. case "ShowCommand":
19. if (textSpoken.ToLower().Contains("starters"))
20. {
21. RootFrame.Navigate(typeof (StartersPage));
22. }
23. if (textSpoken.ToLower().Contains("mains"))
24. {
25. RootFrame.Navigate(typeof(Main1Page));
26. }
27. if (textSpoken.ToLower().Contains("desserts"))
28. {
29. RootFrame.Navigate(typeof(DessertsPage));
30. }
31. if (textSpoken.ToLower().Contains("beverages"))
32. {
33. RootFrame.Navigate(typeof(BeveragesPage));
34. }
35. if (textSpoken.ToLower().Contains("special") || textSpoken.
ToLower().Contains("offer"))
36. {
37. RootFrame.Navigate(typeof(MainPage), "SpecialOffers")
;
38. }
39. break;
40.
60. Window.Current.Activate();
61. }
Each possible voice command defined in VCD must be handled so the results shown to the user wont
be weird.
Using Cortana
Before we talk with Cortana, we need to run the Menu App in the device, because we need to install
the VCD. After it, we can start Cortana.
Click in see more to see what we can say, as we can see in following figures:
Each app will show some examples to help users using Cortana. Clicking the Menu App it will show the
samples defined In the VCD file:
Figure 3 Examples
Lets play with Cortana, and for example, lets say: Saying Menu I am hungry.
The result is
The result is
See the code in Step 9: How to integrate Cortana with Menu App (bit.ly/MenuApp-Step9)
The following articles will help to run the app in the simulator or in devices:
For Windows AppStudio apps it is recommended to see the following video for help in the sideloading
process: Generating, Sideloading and Publishing Windows App Studio 8.1 apps for Tablets and PCs.
Sometimes it isn't easy to test our application or we dont know what to test, a simple and good test
is to provide the package to our friends or beta testers so they can provide a feedback about the app,
normally they see issues that the developer does not see. But before that, it is recommended that
each developer does the basic tests provided in the following article: Testing apps for Windows Phone
8.
In the article testing apps for Windows Phone 8, we can find the App certification requirements for
Windows Phone that is very important! If our app does not respect these requirements then the
application will fail the certification and we should make the updates required by the requirements.
To see the last changes read the article the App certification requirements change history for Windows
Phone and finally we could read the Top Windows Phone app certification failures and how to avoid
them. For Windows apps, you should read the App certification requirements for the Windows Store
and the common certification failures.
Each issue we discover from the tests should be fixed and a new version should be created to apply
new tests. After the app looks great you can skip to the next step.
When we click in the Capture button, the screenshot is taken and the image is saved in a folder we
defined.
In Windows AppStudio
The last step before generating the app (in Windows AppStudio) is Publish, where the user can
define the app title, the app description, the language and allows them to connect the app with the
store. The following screen shows the Publish separator:
In the Publish separator (that we saw above), click in Associate App with the Store, it will show the
following form:
To fill in this form, we should open the Dashboard in Windows Phone Dev Center or in Windows Dev
Center to get the information about our account (Publisher GUID, Publisher name).
Figure 82 Options
The information about the Menu App (App identity and App display name) is obtained after we
create the application in the dashboard by clicking in Submit App.
Figure 6 Dashboard
After save all, it's time to generate the app. Click on Finish and then Generate. Now we need to choose
Publish Packages, to create the packages for the Store.
At the end we can download the packages for the store, as we can see in Figure 10.
In Visual Studio
To modify the app in Visual Studio or get the source code in Windows AppStudio, it is possible to
connect the app with the Store, by doing:
At the end we will have an XML file with the store information, like the following:
And we will get another wizard where we can choose if the package will be for the Store and at the
end we can set the package version, the output folder and others.
In this case, the packages are created for submission to store and the last panel will show the output
path for the package and an option to run the Windows App Certification Kit.
Windows App
Certification Kit
is an automatic
process to verify
if the app is
okay and it
allows selecting
which test we
want to run. In
general, we
should select all.
Figure 18 Result
At the end, it will show the result, if it passed or not and provide a report with more details. See the
complete report here: MenuApp-WindowsAppCertificationKit-Report. If the app does not pass these
tests, we should not submit the app to the store until the issues reported in the report are fixed.
An app that passed in this test can fail in other tests that this test does not test, but if the app
does not pass in these tests then it will not pass in the store either. To get more information about
it, see the article: Using the Windows App Certification Kit.
The artwork
Before going to the Dev Center to submit the app, we should prepare all the artwork. The screenshots
are taken, the app title icon with 300x300 should be created and if necessary create the background
image with 1000 x 800, square icon with 358 x 358 and wide icon with 358 x 173.
It is recommended to see this App submission checklist that helps to prepare and organize all the
required info.
Uploading packages
Now it is time to upload the package and fill in the required data (description, keywords,).
Choose the option 2, click Add new and then choose the package.
It will be uploaded and we will be shown the package name, version and package details.
Figure 21 Packages
A form for description, keywords and the options for adding the artwork:
This form needs to be defined for each language supported. And if for some reason you get
any issue when uploading the packages, see the article: Resolving package upload errors.
At this moment all the data was filled in and the app can be submitted to the certification process. If
there is a question about the certification process and the various stages, we can find detailed
info here.
In some cases, it can be useful to add some notes to the testers (from the certification process). To
see how we should do it see the article: Providing info to certification testers.
Now the sky is the limit and our app can be one of the top apps.
To promote your app, see more about that in the article How to market and promote your
apps on Windows Phone and Windows 8.
Appendix
Appendix 1: How to Create the Azure Mobile Service in Azure
Portal
This appendix has the goal to show how to create an Azure Mobile Service in the Azure Portal,
providing tips in the process.
To create an Azure Mobile Service go to the Azure Portal, at manage.windowsazure.com, do the login
and click on + New at the bottom, as following:
A popup will be opened, where we should defined all about the Azure Mobile Service, as following:
In this case we selected a free database with 20 MB, be sure it is enough. Each Azure account
can only have one free database.
At the end of this process we created the Azure Mobile Services and others related items, this mean,
in Azure Account, it was created:
To see the Azure Mobile Service created we need to follow the procedure showed in Figure 5:
Each Azure Mobile Service automatically creates a Notification Hub and the start point to
Notification Hub, related to the Azure Mobile Service created, is showed in Figure 6:
MyMenuuApp_db database
To see the database page, related with the Azure Mobile Service created, we need to follow the
procedure showed in Figure 7:
By default the database created is an Azure SQL Database, but the Azure Mobile Service supports
the MongoDb (www.mongodb.org) database (Non-SQL database). For see more about this subject, see
the following article Creating MongoDB-backed tables in Azure Mobile Services with .NET backend.
Azure SQL Databases has differences from SQL Server Databases, but in general the main features
are supported.
How to create the Azure Mobile Service project for Visual Studio 2013
There are two ways to create the Azure Mobile Service project:
Creating the project in Visual Studio, using Web or Could Template for Mobile Azure Service
Download the project from the Azure Portal, which is generated in MyMenuApp - Azure
Mobile Service web page.
Open the Visual Studio 2013 and create a new Web project, as seen below.
It is possible to define the project for Host in the cloud, but for now it will be ignored. Later the
project will be associated with the MyMenuApp Azure Mobile Service.
When the project is created it gives us some default classes for the To-do list sample, but it will be
removed and ignored. At this moment, the project is completely empty, and it only has:
See the source code related with this appendix: Step 3: Add the base project for
AppStudio.Menu.BackEnd. (bit.ly/MenuApp-Step3)
To download the project from the Azure Portal, go to the Azure Portal, and select the MyMenuApp
mobile service, as following:
Click in CREATE A NEW WINDOWS STORE APP (we could select other target):
The Windows AppStudio give us the Menu App source code, for this reason can be more easy to create
a new project in Visual Studio, to the Azure Mobile Service, like we saw in the last topic Creating the
project in Visual Studio.
Nuget Package
The Azure Mobile Service project, for .Net backend, by default uses Entity Framework and the main
Nuget package used in this kind of project is
Installing this Nuget package will install all related Nuget, for this reason is better to install / remove
the packages using it.
If the project shows errors related to references, it's possible to remove this Nuget package
and then install it again to restore the references, in some cases it is required to close the project
and open it again, to load all references added.
When a Windows App Studio application is generated it is possible to get the source code to change it
in Visual Studio, and then run the application in the emulator or in any Windows 8.1/Windows Phone
8.1 device. But if the application is changed in the Windows App Studio website, then the source code
is changed and the new source code needs to be merged. Windows App Studio does not support the
re-upload of the source code that has been changed or
In this appendix you will show a solution to merge the different source code using a tool called Source
Tree , which provides a graphical interface for manage source repositories.
Suppose we will create an application in Windows App Studio Website, lets choose the Empty App
template and lets generate the application without make changes. To help in the process, lets set
the build version to 1.0.0.0, as following:
Download the application Source Tree (www.sourcetreeapp.com), which allow to create source
control repositories based in GIT, and install it. At the end, open it, as following:
Click in Open in Explorer and when the folder is opened, move the application generated to this
folder, as following:
The .git folder is a hidden folder that cannot be deleted, it is required for track the changes.
Which means, in Unstaged files are all files added to the folder, that can be passed to the Staged
file for then apply a commit (to save the current version). Passing all files to Staged files the
aspect will be something like in Figure 9:
Now, it is possible to save this version of the source code by doing a commit, as following:
When we click in the Commit button the application will have a look as following in Figure 12:
Creating changes
Now, lets open the source code in Visual Studio to change the source code, for example, the
Application Name and the Application Title in App.xaml, as following:
Lets define it as MyAppStudioSample in both resources and then in Source Tree, we will see the
differences, as following:
In the right, we can see the changes made, in red is the old values and in green the new values, which
we will commit like we did in the first version, and the result will be something as following:
Now, in Windows App Studio lets apply some changes, for example:
After this change, we can generate a new source code from the application, defining it as version
2.0.0.0 (for more information about set different version see the Semantic Versioning).
After the new version is generated it is needed to override the source code in the Sample folder. In
Source Tree its now possible to see the differences between the versions
In the Unstaged files the yellow circle will say that the file was change and the blue circle will say
the file is new. Selecting a file is possible to see the differences, which the green row means the new
version and the red one is the last version.
For example, the changes made in the Application Title can be find in App.xaml file, as following:
In the right is possible to accept the change or revert it, to help on it is possible to use the buttons
Stage hunk to accept and Discard hunk to discard the changes
In this way, each change can be tracked, file by file or even line by line, depending only the
requirements.
Conclusion
In conclusion, using a tool like Source Tree is possible to merge source code from Windows
App Studio in an easy way without knowledge about source controls.
Class diagrams help you understand the class structure of projects others have written (or that you
wrote a long time ago). You can use them to customize, share and present project information with
others.
In this appendix, we will see how class diagram can be used to understand the code provided or even
our own code. To help, we will use the sample Field Engineer from MSDN Samples
(bit.ly/FieldEngineerSample) and we will be focused on the model classes as an example.
After opening the Field Engineer Sample in Visual Studio, we will find a folder with the name Model.
This sample does not have so many classes that can be great because it can be easy to understand the
model. Maybe many developers will start opening all the files to see the code, but why not create a
class diagram?
Select the Model folder and then open the context menu, after it click in Add and then click in Class
Diagram, as following:
Click in OK and the class diagram file will be added to the project and will be opened.
Now we can select all the files in the Model folder and drag and drop them to the class designer area,
which the result will be something as following:
Expanding classes
If we open the context menu under the shape we can select the Class Details, as following:
This way, this user interface will allow to see more details about the classes and it is possible to
create/edit/delete/hide each property, method, event without coding.
After expanding all the shapes, we will find that some shapes show the Fields, Properties and Methods
(and can show events, nested classes and so on). Featuring the MobileServiceContext class, as
following:
We can conclude:
Each icon means something, for example the symbol * in each item means it is private. The best way
to understand the differences between each icon is to create a sample with each possible case.
To understand all icon the good way is to create a fake class for this
purpose. The class will have one field, property and method for
each modifier: private, public, internal and protected and will
have a public event.
When we select the shape and open the context menu we have options that allow showing/hiding
various details.
After expanding the shape for MyBaseClass we will see the base class MyBaseClass and the MyClass.
To show the diagram, what is the most important information that should be shown in the diagram?
It depends on what each developer likes or wants to see, but in general we can define it as a pattern.
We should show only public properties, methods and events and hide all others (in some cases it can
be useful to show everything defined as internal or protected).
Hide compartment
Selecting the shape and then the item we want to hide, we can Hide Compartment by using the
context menu, as following:
The option Show all members will revert it, but in some cases it is better to use the Class Details to
revert it, because we can have other items hidden that we want to keep hidden. When a shape hides
some item it will show the icon which means it, here is an example:
Apply Associations
Returning to the Field Engineer Sample and choosing the class JobHistory, Job and Customer we will
find that each one has a relationship with each other, let's highlight it using a red and orange rectangle,
as following:
Let's see how to show the association for properties and for collections.
Show as Association
For properties that the data type is another class we can select the property in the shape and in the
context menu we should select the option Show as Association.
For properties that are collections/lists we can choose the option Show as Collection Association, as
following:
The number of arrows will define it as a property or a collection, but using a good name can be enough
to see the differences.
Show as Property
By selecting in the arrow it is possible to revert it, using the option Show as property.
After defining all the arrows for all the associations and organizing the shapes we will have something
as in the following:
For this diagram, we can understand that the model has the five classes and
the MobileServiceContext is defined by these classes. The relationship among the classes is clear (for
example).
A job knows its job histories and each job history refers to a job
A job knows which customer is associated and a customer can have more than one job
It is possible to create arrows for the MobileServiceContext's properties but that will only make
some noise and it is not important in this case to see these associations.
Each developer should customize the class diagram and there are no fixed rules for it. With this kind
f diagram it is very simple to understand the model and in some cases find mistakes like wrong
names, wrong relationships or even missed features.
www.saramgsilva.com
typeof (saramgsilva) www.saramgsilva.com @saramgsilva
151