Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mobile: many new and updated tutorials

  • Loading branch information...
commit 4faf0d95e939288efa96b4e41729f853aa4ab1ea 1 parent 06ba5b6
@ggailey777 ggailey777 authored
Showing with 447 additions and 212 deletions.
  1. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-data-browse.png
  2. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-data-tab.png
  3. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-eclipse-quickstart.png
  4. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-portal-quickstart-android.png
  5. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-completed-android.png
  6. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-startup-android.png
  7. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-steps-vs.png
  8. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-services-import-android-project.png
  9. BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-services-import-android-workspace.png
  10. BIN  articles/media/mobile-services-dotnet-backend-ios-get-started/mobile-quickstart-steps-ios.png
  11. BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/add-linq2twitter-nuget-package.png
  12. BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/create-new-job.png
  13. BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/manage-sql-azure-database.png
  14. BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/mobile-schedule-new-job-cli.png
  15. BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/mobile-services-selection.png
  16. BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/sample-job-run-once.png
  17. BIN  ...cles/media/mobile-services-how-to-register-twitter-authentication/mobile-services-twitter-register-app1.png
  18. +2 −2 articles/mobile-services-android-get-started.md
  19. +148 −0 articles/mobile-services-dotnet-backend-android-get-started.md
  20. +54 −0 articles/mobile-services-dotnet-backend-how-to-use-code-first-migrations.md
  21. +167 −144 articles/mobile-services-dotnet-backend-schedule-recurring-tasks.md
  22. +2 −2 articles/mobile-services-dotnet-backend-windows-phone-get-started-users.md
  23. +3 −56 articles/mobile-services-windows-phone-get-started-users.md
  24. +13 −1 includes/mobile-services-dotnet-backend-create-custom-api.md
  25. +2 −0  includes/mobile-services-filter-user-results-dotnet-backend.md
  26. +3 −7 includes/mobile-services-restrict-permissions-dotnet-backend.md
  27. +53 −0 includes/mobile-services-windows-phone-authenticate-app.md
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-data-browse.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-data-tab.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-eclipse-quickstart.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-portal-quickstart-android.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-completed-android.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-startup-android.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-steps-vs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  ...cles/media/mobile-services-dotnet-backend-android-get-started/mobile-services-import-android-project.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  ...es/media/mobile-services-dotnet-backend-android-get-started/mobile-services-import-android-workspace.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-ios-get-started/mobile-quickstart-steps-ios.png
Deleted file not rendered
View
BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/add-linq2twitter-nuget-package.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/create-new-job.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/manage-sql-azure-database.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/mobile-schedule-new-job-cli.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/mobile-services-selection.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  articles/media/mobile-services-dotnet-backend-schedule-recurring-tasks/sample-job-run-once.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  ...s/media/mobile-services-how-to-register-twitter-authentication/mobile-services-twitter-register-app1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
4 articles/mobile-services-android-get-started.md
@@ -14,10 +14,10 @@
<a href="/en-us/documentation/articles/mobile-services-javascript-backend-phonegap-get-started/" title="PhoneGap">PhoneGap</a>
</div>
-<!--<div class="dev-center-tutorial-subselector">
+<div class="dev-center-tutorial-subselector">
<a href="/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started/" title=".NET backend">.NET backend</a> |
<a href="/en-us/documentation/articles/mobile-services-android-get-started/" title="JavaScript backend" class="current">JavaScript backend</a>
-</div>-->
+</div>
<div class="dev-onpage-video-clear clearfix">
<div class="dev-onpage-left-content">
View
148 articles/mobile-services-dotnet-backend-android-get-started.md
@@ -0,0 +1,148 @@
+<properties pageTitle="Get Started with Azure Mobile Services for Android apps" metaKeywords="Azure android application, mobile service android, getting started Azure android, azure droid, getting started droid windows" description="Follow this tutorial to get started using Azure Mobile Services for Android development." metaCanonical="" services="" documentationCenter="Mobile" title="Get started with Mobile Services" authors="glenga" solutions="" manager="" editor="" />
+
+# <a name="getting-started"> </a>Get started with Mobile Services
+
+<div class="dev-center-tutorial-selector sublanding">
+ <a href="/en-us/documentation/articles/mobile-services-dotnet-backend-windows-store-get-started" title="Windows Store">Windows Store</a>
+ <a href="/en-us/documentation/articles/mobile-services-dotnet-backend-windows-phone-get-started" title="Windows Phone">Windows Phone</a>
+ <a href="/en-us/documentation/articles/mobile-services-dotnet-backend-ios-get-started" title="iOS">iOS</a>
+ <a href="/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started" title="Android" class="current">Android</a>
+</div>
+
+<div class="dev-center-tutorial-subselector">
+ <a href="/en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started/" title=".NET backend" class="current">.NET backend</a> |
+ <a href="/en-us/documentation/articles/mobile-services-android-get-started/" title="JavaScript backend">JavaScript backend</a>
+</div>
+
+This tutorial shows you how to add a cloud-based backend service to an Android app using Azure Mobile Services. In this tutorial, you will create both a new mobile service and a simple _To do list_ app that stores app data in the new mobile service. The mobile service that you will create uses the supported .NET languages using Visual Studio for server-side business logic and to manage the mobile service. To create a mobile service that lets you write your server-side business logic in JavaScript, see the [JavaScript backend version](/en-us/documentation/articles/mobile-services-android-get-started/) of this topic.
+
+A screenshot from the completed app is below:
+
+![][0]
+
+Completing this tutorial requires the [Android Developer Tools][Android SDK], which includes the Eclipse integrated development environment (IDE), Android Developer Tools (ADT) plugin, and the latest Android platform. Android 4.2 or a later version is required.
+
+The downloaded quickstart project contains the Mobile Services SDK for Android. While this project requires Android 4.2 or a later version, the Mobile Services SDK requires only Android 2.2 or a later version.
+
+<div class="dev-callout"><strong>Note</strong> <p>To complete this tutorial, you need an Azure account. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see <a href="http://www.windowsazure.com/en-us/pricing/free-trial/?WT.mc_id=AE564AB28" target="_blank">Azure Free Trial</a>.</p></div>
+
+## <a name="create-new-service"> </a>Create a new mobile service
+
+[WACOM.INCLUDE [mobile-services-create-new-service](../includes/mobile-services-create-new-service.md)]
+
+## Download the mobile service to your local computer
+
+Now that you have created the mobile service, download your personalized mobile service project that you can run on your local computer or virtual machine.
+
+1. Click the mobile service that you just created, then in the quickstart tab, click **Android** under **Choose platform** and expand **Create a new Android app**.
+
+2. If you haven't already done so, download and install [Visual Studio Professional 2013](https://go.microsoft.com/fwLink/p/?LinkID=391934), or a later version.
+
+3. Click **Download** under **Download and publish your service to the cloud**.
+
+ This downloads the Visual Studio project that implements your mobile service. Save the compressed project file to your local computer, and make a note of where you saved it.
+
+4. Also, download your publish profile, save the downloaded file to your local computer, and make a note of where you save it.
+
+## Test the mobile service
+
+[WACOM.INCLUDE [mobile-services-dotnet-backend-test-local-service](../includes/mobile-services-dotnet-backend-test-local-service.md)]
+
+## Publish your mobile service
+
+[WACOM.INCLUDE [mobile-services-dotnet-backend-publish-service](../includes/mobile-services-dotnet-backend-publish-service.md)]
+
+## Create a new Android app
+
+In this section you will create a new Android app that is connected to your mobile service.
+
+1. In the [Management Portal], click **Mobile Services**, and then click the mobile service that you just created.
+
+2. In the quickstart tab, click **Android** under **Choose platform** and expand **Create a new Android app**.
+
+3. If you haven't already done so, download and install the [Android Developer Tools][Android SDK] on your local computer or virtual machine.
+
+4. Click **Create TodoItem table** to create a table to store app data.
+
+5. Under **Download and run your app**, click **Download**.
+
+ This downloads the project for the sample _To do list_ application that is connected to your mobile service. Save the compressed project file to your local computer, and make a note of where you save it.
+
+## Run your Android app
+
+The final stage of this tutorial is to build and run your new app.
+
+1. Browse to the location where you saved the compressed project files and expand the files on your computer.
+
+2. In Eclipse, click **File** then **Import**, expand **Android**, click **Existing Android Code into Workspace**, and then click **Next.**
+
+ ![][14]
+
+3. Click **Browse**, browse to the location of the expanded project files, click **OK**, make sure that the TodoActivity project is checked, then click **Finish**.
+
+ ![][15]
+
+ This imports the project files into the current workspace.
+
+ ![][8]
+
+4. From the **Run** menu, click **Run** to start the project in the Android emulator.
+
+ <div class="dev-callout"><strong>Note</strong> <p>To be able to run the project in the Android emulator, you must define a least one Android Virtual Device (AVD). Use the AVD Manager to create and manage these devices.</p></div>
+
+5. In the app, type meaningful text, such as _Complete the tutorial_, and then click **Add**.
+
+ ![][10]
+
+ This sends a POST request to the new mobile service hosted in Azure. Data from the request is inserted into the TodoItem table. Items stored in the table are returned by the mobile service, and the data is displayed in the list.
+
+ <div class="dev-callout"><strong>Note</strong>
+ <p>You can review the code that accesses your mobile service to query and insert data, which is found in the ToDoActivity.java file.</p>
+ </div>
+
+<!--This shows how to run your new client app against the mobile service running in Azure. Before you can test the Android app with the mobile service running on a local computer, you must configure the Web server and firewall to allow access from your Android development computer. For more information, see [Configure the local web server to allow connections to a local mobile service](/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-configure-iis-express).-->
+
+## <a name="next-steps"> </a>Next Steps
+Now that you have completed the quickstart, learn how to perform additional important tasks in Mobile Services:
+
+* [Get started with data]
+ <br/>Learn more about storing and querying data using Mobile Services.
+
+* [Get started with authentication]
+ <br/>Learn how to authenticate users of your app with an identity provider.
+
+* [Get started with push notifications]
+ <br/>Learn how to send a very basic push notification to your app.
+
+<!-- Anchors. -->
+[Getting started with Mobile Services]:#getting-started
+[Create a new mobile service]:#create-new-service
+[Define the mobile service instance]:#define-mobile-service-instance
+[Next Steps]:#next-steps
+
+<!-- Images. -->
+[0]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-completed-android.png
+[1]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-steps-vs.png
+
+
+
+
+[6]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-portal-quickstart-android.png
+[7]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-steps-android.png
+[8]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-eclipse-quickstart.png
+
+[10]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-quickstart-startup-android.png
+[11]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-data-tab.png
+[12]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-data-browse.png
+
+[14]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-services-import-android-workspace.png
+[15]: ./media/mobile-services-dotnet-backend-android-get-started/mobile-services-import-android-project.png
+
+<!-- URLs. -->
+[Get started with data]: /en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-data
+[Get started with authentication]: /en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-users
+[Get started with push notifications]: /en-us/documentation/articles/mobile-services-dotnet-backend-android-get-started-push
+[Android SDK]: https://go.microsoft.com/fwLink/p/?LinkID=280125
+[Mobile Services Android SDK]: https://go.microsoft.com/fwLink/p/?LinkID=266533
+
+[Management Portal]: https://manage.windowsazure.com/
View
54 articles/mobile-services-dotnet-backend-how-to-use-code-first-migrations.md
@@ -0,0 +1,54 @@
+<properties pageTitle="How to use Code First Migrations .NET backend (Mobile Services)" metaKeywords="" description="" metaCanonical="" services="" documentationCenter="" title="Considerations for supporting multiple clients from a single mobile service" authors="glenga" solutions="" writer="glenga" manager="dwrede" editor="" />
+
+# How to use Code First Migrations with Mobile Services .NET backend
+
+In a .NET backend project, the default Entity Framework database initializer derives from the [DropCreateDatabaseIfModelChanges] class. Because of this, Entity Framework drops and recreates the database whenever it detects a data model change in the Code First model definition. The .NET backend tutorials continue to use this initializer because you don't need to maintain the TodoItem data you generate during the tutorials. However, for situations where you want to make data model changes and maintain existing data in the database, you must use Code First Migrations.
+
+>[WACOM.NOTE]When developing and testing your mobile service project against live Azure services, you should always use a mobile service instance that is dedicated for testing. You should never develop or test against a mobile service that is currently in production or being used by client apps.
+
+This topic shows how to use Code First Migrations to make data model changes without losing existing data. This procedure assumes that you have already published your mobile service project to Azure, that there is existing data in your database, and that the remote and local data models are still in sync.
+
+1. In Visual Studio in the Solution Explorer, expand the App_Start folder, open the WebApiConfig.cs project, and comment-out the call to the **Database.SetInitializer** method, which looks like this:
+
+ Database.SetInitializer(new todolistInitializer());
+
+ This disables the default Code First database initializer that drops and recreates the database. At this point, any data model changes will result in an InvalidOperationException when the data is accessed. Going forward, your service must use Code First Migrations to migrate data model changes to the database.
+
+2. Right-click the mobile service project and click **Set as startup project**.
+
+3. From the **Tools** menu, expand **NuGet Package Manager**, then click **Package Manager Console**.
+
+ This displays the Package Manager Console, which you will use to manage your Code First Migrations.
+
+4. In the Package Manager Console, run the following command:
+
+ PM> Enable-Migrations
+
+ This turns on Code First Migrations for your project and generates a migration for the existing database.
+
+5. In the console, run the following command:
+
+ Add-Migration -Name MySchemaChange -IgnoreChanges
+
+ This creates a new migration, with the specified name. If you have have already made a pending data model change, use the -IgnoreChanges parameter.
+
+6. In the console, run the following command:
+
+ Update-Database
+
+ This generates the code for a migration that will make the data model change in your database.
+
+9. Rerun the app locally, and verify that the we can still read data without getting the “out of sync” errors.
+10. Now make a model change, like adding a “Foot” property.
+11. Rebuild.
+12. IN the PM console:
+a. Add-Migration Foot
+ i. Note: if you look at the code generated for the “Foot” migration, you’ll see that it has the correct schema (when using the latest bits):
+AddColumn("jcooketestNet031301.TodoItems", "Foot", c => c.String());
+b. Update-Database
+13. Rerun app locally, and verify that the new property is returned when querying the table.
+
+
+<!-- URLs -->
+
+[DropCreateDatabaseIfModelChanges]: http://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&l=EN-US&k=k("System.Data.Entity.DropCreateDatabaseIfModelChanges`1");k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-csharp)&rd=true
View
311 articles/mobile-services-dotnet-backend-schedule-recurring-tasks.md
@@ -4,7 +4,7 @@
# Schedule recurring jobs in Mobile Services
<div class="dev-center-tutorial-subselector">
- <a href="/en-us/documentation/articles/articles/mobile-services-dotnet-backend-schedule-recurring-tasks/" title=".NET backend" class="current">.NET backend</a> | <a href="/en-us/documentation/articles/articles/mobile-services-schedule-recurring-tasks/" title="JavaScript backend" >JavaScript backend</a>
+ <a href="/en-us/documentation/articles/mobile-services-dotnet-backend-schedule-recurring-tasks/" title=".NET backend" class="current">.NET backend</a> | <a href="/en-us/documentation/articles/mobile-services-schedule-recurring-tasks/" title="JavaScript backend" >JavaScript backend</a>
</div>
This topic shows you how to use the job scheduler functionality in the Management Portal to define server script code that is executed based on a schedule that you define. In this case, the script periodically check with a remote service, in this case Twitter, and stores the results in a new table. Some other periodic tasks that can be scheduled include:
@@ -13,213 +13,236 @@ This topic shows you how to use the job scheduler functionality in the Managemen
+ Requesting and storing external data, such as tweets, RSS entries, and location information.
+ Processing or resizing stored images.
-<!-- // Removed because this shortcode b/c it's old and doesn't use the new Twitter v1.1. APIs
->[WACOM.VIDEO Windows-Store-app-Getting-Started-with-the-Windows-Azure-Mobile-Services-Scheduler]
--->
-
-<!-- // Original video HTML code for reference.
-<div class="dev-onpage-video-clear clearfix">
-<div class="dev-onpage-left-content">
-<p>
-</div>
-<div class="dev-onpage-video-wrapper"><a href="http://channel9.msdn.com/Series/Windows-Azure-Mobile-Services/Windows-Store-app-Getting-Started-with-the-Windows-Azure-Mobile-Services-Scheduler" target="_blank" class="label">watch the tutorial</a> <a style="background-image: url('/media/devcenter/mobile/videos/get-started-with-scheduler-180x120.png') !important;" href="http://channel9.msdn.com/Series/Windows-Azure-Mobile-Services/Windows-Store-app-Getting-Started-with-the-Windows-Azure-Mobile-Services-Scheduler" target="_blank" class="dev-onpage-video"><span class="icon">Play Video</span></a> <span class="time">5:22</span></div>
-</div>-->
-
This tutorial walks you through the following steps of how to use the job scheduler to create a scheduled job that requests tweet data from Twitter and stores the tweets in a new Updates table:
+ [Register for Twitter access and store credentials]
++ [Download and install the LINQ to Twitter library]
+ [Create the new Updates table]
+ [Create a new scheduled job]
+>[WACOM.NOTE]This tutorial uses the third-party LINQ to Twitter library to simplify OAuth 2.0 access to Twitter v1.1. APIs. You must download and install the LINQ to Twitter NuGet package to complete this tutorial. For more information, see the [LINQ to Twitter CodePlex project].
+
##<a name="get-oauth-credentials"></a>Register for access to Twitter v1.1 APIs and store credentials
[WACOM.INCLUDE [mobile-services-register-twitter-access](../includes/mobile-services-register-twitter-access.md)]
-##<a name="create-table"></a>Create the new Updates table
+##<a name="install-linq2twitter"></a>Download and install the LINQ to Twitter library
+
+1. In **Solution Explorer** in Visual Studio, right-click the project name, and then select **Manage NuGet Packages**.
+
+2. In the left pane, select the **Online** category, search for `linq2twitter`, click **Install** on the **linqtotwitter** package, then read and accept the license agreements.
+
+ ![][1]
+
+ This adds the Linq to Twitter library to your mobile service project.
Next, you need to create a new table in which to store tweets.
-1. In the Solution Explorer in Visual Studio, right-click the DataObjects folder add new **Updates** class.
+##<a name="create-table"></a>Create the new Updates table
+
+1. In the Solution Explorer in Visual Studio, right-click the DataObjects folder, expand **Add**, click **Class**, type `Updates` for **Name**, then click **Add**.
-2. In this new class, add the following **using** statement:
+ This creates a new project file for the Updates class.
+
+2. In this new class, add the following **using** statements:
using Microsoft.WindowsAzure.Mobile.Service;
+ using System.ComponentModel.DataAnnotations;
-3. Add the following properties to the new **Update** class:
+3. Replace the **Updates** class definition with the following code:
- public class Updates
+ public class Updates
{
- public int TwitterId { get; set; }
+ [Key]
+ public int UpdateId { get; set; }
+ public long TweetId { get; set; }
public string Text { get; set; }
public string Author { get; set; }
public DateTime Date { get; set; }
- }
+ }
4. Expand the Models folder, open the data model context file (named <em>service_name</em>Context.cs) and add the following property that returns a typed **DbSet**:
public DbSet<Updates> Updates { get; set; }
- This lets you access the Updates table, which is created when the DbSet is first accessed.
-
- <!--[WACOM.NOTE]The Updates table is only accessed from the mobile service backend.-->
-
-
+ The Updates table, which is created in the database when the DbSet is first accessed, is used by the service to store tweet data.
+ >[WACOM.NOTE] When using the default database initializer, Entity Framework will drop and recreate the database whenever it detects a data model change in the Code First model definition. To make this data model change and maintain existing data in the database, you must use Code First Migrations. For more information, see [How to Use Code First Migrations to Update the Data Model](/en-us/documentation/articles/mobile-services-dotnet-backend-use-code-first-migrations).
+Next, you create the scheduled job that accesses Twitter and stores tweet data in the new Updates table.
##<a name="add-job"></a>Create a new scheduled job
-Now, you can create the scheduled job that accesses Twitter and stores tweet data in the new Updates table.
-
1. Expand the ScheduledJobs folder and open the SampleJob.cs project file.
- This class represents a job that can be scheduled to run on a fixed schedule or on demand.
-
-2.
-
-2. Click the **Scheduler** tab, then click **+Create**.
-
- ![][4]
-
- >[WACOM.NOTE]When you run your mobile service in <em>Free</em> tier, you are only able to run one scheduled job at a time. In paid tiers, you can run up to ten scheduled jobs at a time.
-
-3. In the scheduler dialog, enter _getUpdates_ for the **Job Name**, set the schedule interval and units, then click the check button.
-
- ![][5]
-
- This creates a new job named **getUpdates**.
-
-4. Click the new job you just created, then click the **Script** tab.
+ This class, which inherits from **ScheduledJob**, represents a job that can be scheduled, in the Azure Management Portal, to run on a fixed schedule or on demand.
- ![][6]
-
-5. Replace the placeholder function **getUpdates** with the following code:
-
- var updatesTable = tables.getTable('Updates');
- var request = require('request');
- var twitterUrl = "https://api.twitter.com/1.1/search/tweets.json?q=%23mobileservices&result_type=recent";
-
- // Get the service configuration module.
- var config = require('mobileservice-config');
+2. Replace the contents of SampleJob.cs with the following code:
+
+ using System;
+ using System.Linq;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using System.Web.Http;
+ using Microsoft.WindowsAzure.Mobile.Service;
+ using Microsoft.WindowsAzure.Mobile.Service.ScheduledJobs;
+ using LinqToTwitter;
+ using todolistService.Models;
+ using todolistService.DataObjects;
- // Get the stored Twitter consumer key and secret.
- var consumerKey = config.twitterConsumerKey,
- consumerSecret = config.twitterConsumerSecret
- // Get the Twitter access token from app settings.
- var accessToken= config.appSettings.TWITTER_ACCESS_TOKEN,
- accessTokenSecret = config.appSettings.TWITTER_ACCESS_TOKEN_SECRET;
+ namespace todolistService
+ {
+ // A simple scheduled job which can be invoked manually by submitting an HTTP
+ // POST request to the path "/jobs/sample".
+ public class SampleJob : ScheduledJob
+ {
+ private todolistContext context;
+ private string accessToken;
+ private string accessTokenSecret;
- function getUpdates() {
- // Check what is the last tweet we stored when the job last ran
- // and ask Twitter to only give us more recent tweets
- appendLastTweetId(
- twitterUrl,
- function twitterUrlReady(url){
- // Create a new request with OAuth credentials.
- request.get({
- url: url,
- oauth: {
- consumer_key: consumerKey,
- consumer_secret: consumerSecret,
- token: accessToken,
- token_secret: accessTokenSecret
- }},
- function (error, response, body) {
- if (!error && response.statusCode == 200) {
- var results = JSON.parse(body).statuses;
- if(results){
- console.log('Fetched ' + results.length + ' new results from Twitter');
- results.forEach(function (tweet){
- if(!filterOutTweet(tweet)){
- var update = {
- twitterId: tweet.id,
- text: tweet.text,
- author: tweet.user.screen_name,
- date: tweet.created_at
- };
- updatesTable.insert(update);
- }
- });
- }
- } else {
- console.error('Could not contact Twitter');
- }
- });
+ protected override void Initialize(ScheduledJobDescriptor scheduledJobDescriptor, CancellationToken cancellationToken)
+ {
+ base.Initialize(scheduledJobDescriptor, cancellationToken);
- });
- }
- // Find the largest (most recent) tweet ID we have already stored
- // (if we have stored any) and ask Twitter to only return more
- // recent ones
- function appendLastTweetId(url, callback){
- updatesTable
- .orderByDescending('twitterId')
- .read({success: function readUpdates(updates){
- if(updates.length){
- callback(url + '&since_id=' + (updates[0].twitterId + 1));
- } else {
- callback(url);
+ // Create a new context with the supplied schema name.
+ context = new todolistContext(Services.Settings.Name);
}
- }});
- }
- function filterOutTweet(tweet){
- // Remove retweets and replies
- return (tweet.text.indexOf('RT') === 0 || tweet.to_user_id);
+ public async override Task ExecuteAsync()
+ {
+ // Try to get the stored Twitter access token from app settings.
+ if (Services.Settings.TryGetValue("TWITTER_ACCESS_TOKEN", out accessToken) |
+ Services.Settings.TryGetValue("TWITTER_ACCESS_TOKEN_SECRET", out accessTokenSecret))
+ {
+ Services.Log.Error("Could not retrieve Twitter access credentials.");
+ }
+
+ // Create a new authorizer to access Twitter v1.1 APIs
+ // using single-user OAUth 2.0 credentials.
+ MvcAuthorizer auth = new MvcAuthorizer();
+ SingleUserInMemoryCredentialStore store =
+ new SingleUserInMemoryCredentialStore()
+ {
+ ConsumerKey = Services.Settings.TwitterConsumerKey,
+ ConsumerSecret = Services.Settings.TwitterConsumerSecret,
+ OAuthToken = accessToken,
+ OAuthTokenSecret = accessTokenSecret
+ };
+
+ // Set the credentials for the authorizer.
+ auth.CredentialStore = store;
+
+ // Create a new LINQ to Twitter context.
+ TwitterContext twitter = new TwitterContext(auth);
+
+ // Get the ID of the most recent stored tweet.
+ long lastTweetId = 0;
+ if (context.Updates.Count() > 0)
+ {
+ lastTweetId = (from u in context.Updates
+ orderby u.TweetId descending
+ select u).Take(1).SingleOrDefault()
+ .TweetId;
+ }
+
+ // Execute a search that returns a filtered result.
+ var response = await (from s in twitter.Search
+ where s.Type == SearchType.Search
+ && s.Query == "%23mobileservices"
+ && s.SinceID == Convert.ToUInt64(lastTweetId + 1)
+ && s.ResultType == ResultType.Recent
+ select s).SingleOrDefaultAsync();
+
+ // Remove retweets and replies and log the number of tweets.
+ var filteredTweets = response.Statuses
+ .Where(t => !t.Text.StartsWith("RT") && t.InReplyToUserID == 0);
+ Services.Log.Info("Fetched " + filteredTweets.Count()
+ + " new tweets from Twitter.");
+
+ // Store new tweets in the Updates table.
+ foreach (Status tweet in filteredTweets)
+ {
+ Updates newTweet =
+ new Updates
+ {
+ TweetId = Convert.ToInt64(tweet.StatusID),
+ Text = tweet.Text,
+ Author = tweet.User.Name,
+ Date = tweet.CreatedAt
+ };
+
+ context.Updates.Add(newTweet);
+ }
+
+ await context.SaveChangesAsync();
+ }
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ if (disposing)
+ {
+ context.Dispose();
+ }
+ }
+ }
}
+ In the above code, you must replace the strings _todolistService_ and _todolistContext_ with the namespace and DbContext of your downloaded project, which are <em>mobile&#95;service&#95;name</em>Service and <em>mobile&#95;service&#95;name</em>Context, respective.
+
+ In the above code, the **ExecuteAsync** override method calls the Twitter query API using stored credentials to request recent tweets that contain the hashtag `#mobileservices`. Duplicate tweets and replies are removed from the results before they are stored in the table.
- This script calls the Twitter query API using stored credentials to request recent tweets that contain the hashtag `#mobileservices`. Duplicate tweets and replies are removed from the results before they are stored in the table.
+3. Republish the mobile service project to Azure.
- >[WACOM.NOTE]This sample assumes that only a few rows are inserted into the table during each scheduled run. In cases where many rows are inserted in a loop you may run out of connections when running on the Free tier. In this case, you should perform inserts in batches. For more information, see <a href="/en-us/develop/mobile/how-to-guides/work-with-server-scripts/#bulk-inserts">How to: Perform bulk inserts</a>.
+4. In the [Azure Management Portal], click Mobile Services, and then click your app.
+
+ ![][2]
-6. Click **Run Once** to test the script.
+2. Click the **Scheduler** tab, then click **+Create**.
- ![][7]
+ ![][3]
- This saves and executes the job while it remains disabled in the scheduler.
+ >[WACOM.NOTE]When you run your mobile service in <em>Free</em> tier, you are only able to run one scheduled job at a time. In paid tiers, you can run up to ten scheduled jobs at a time.
-7. Click the back button, click **Data**, click the **Updates** table, click **Browse**, and verify that Twitter data has been inserted into the table.
+3. In the scheduler dialog, enter _SampleJob_ for the **Job Name**, set the schedule interval and units, then click the check button.
+
+ ![][4]
- ![][8]
+ This creates a new job named **SampleJob**.
-8. Click the back button, click **Scheduler**, select **getUpdates**, then click **Enable**.
+4. Click the new job you just created, then click **Run Once** to test the script.
- ![][9]
+ ![][5]
- This enables the job to run on the specified schedule, in this case every hour.
+ This executes the job while it remains disabled in the scheduler. From this page, you can enable the job and change its schedule at any time.
-Congratulations, you have successfully created a new scheduled job in your mobile service. This job will be executed as scheduled until you disable or modify it.
+4. (Optional) In the [Azure Management Portal], click manage for the database associated with your mobile service.
-## <a name="nextsteps"> </a>Next Steps
+ ![][6]
-* [Mobile Services server script reference]
- <br/>Learn more about registering and using server scripts.
+5. In the Management portal execute a query to view the changes made by the app. Your query will be similar to the following query but use your mobile service name as schema name instead of `todolist`.
+
+ SELECT * FROM [todolist].[Updates]
+
+Congratulations, you have successfully created a new scheduled job in your mobile service. This job will be executed as scheduled until you disable or modify it.
<!-- Anchors. -->
[Register for Twitter access and store credentials]: #get-oauth-credentials
+[Download and install the LINQ to Twitter library]: #install-linq2twitter
[Create the new Updates table]: #create-table
[Create a new scheduled job]: #add-job
[Next steps]: #next-steps
<!-- Images. -->
-[0]: ./media/mobile-services-schedule-recurring-tasks/mobile-twitter-my-apps.png
-[1]: ./media/mobile-services-schedule-recurring-tasks/mobile-twitter-app-secrets.png
-[2]: ./media/mobile-services-schedule-recurring-tasks/mobile-data-tab-empty-cli.png
-[3]: ./media/mobile-services-schedule-recurring-tasks/mobile-create-updates-table.png
-[4]: ./media/mobile-services-schedule-recurring-tasks/mobile-schedule-new-job-cli.png
-[5]: ./media/mobile-services-schedule-recurring-tasks/mobile-create-job-dialog.png
-[6]: ./media/mobile-services-schedule-recurring-tasks/mobile-schedule-job-script-new.png
-[7]: ./media/mobile-services-schedule-recurring-tasks/mobile-schedule-job-script.png
-[8]: ./media/mobile-services-schedule-recurring-tasks/mobile-browse-updates-table.png
-[9]: ./media/mobile-services-schedule-recurring-tasks/mobile-schedule-job-enabled.png
-[10]: ./media/mobile-services-schedule-recurring-tasks/mobile-schedule-job-app-settings.png
-[11]: ./media/mobile-services-schedule-recurring-tasks/mobile-identity-tab-twitter-only.png
+[1]: ./media/mobile-services-dotnet-backend-schedule-recurring-tasks/add-linq2twitter-nuget-package.png
+[2]: ./media/mobile-services-dotnet-backend-schedule-recurring-tasks/mobile-services-selection.png
+[3]: ./media/mobile-services-dotnet-backend-schedule-recurring-tasks/mobile-schedule-new-job-cli.png
+[4]: ./media/mobile-services-dotnet-backend-schedule-recurring-tasks/create-new-job.png
+[5]: ./media/mobile-services-dotnet-backend-schedule-recurring-tasks/sample-job-run-once.png
+[6]: ./media/mobile-services-dotnet-backend-schedule-recurring-tasks/manage-sql-azure-database.png
<!-- URLs. -->
-[Mobile Services server script reference]: http://go.microsoft.com/fwlink/?LinkId=262293
-[WindowsAzure.com]: http://www.windowsazure.com/
-[Windows Azure Management Portal]: https://manage.windowsazure.com/
-[Register your apps for Twitter login with Mobile Services]: /en-us/develop/mobile/how-to-guides/register-for-twitter-authentication
+[Azure Management Portal]: https://manage.windowsazure.com/
+[Register your apps for Twitter login with Mobile Services]: /en-us/documentation/articles/mobile-services-how-to-register-twitter-authentication
[Twitter Developers]: http://go.microsoft.com/fwlink/p/?LinkId=268300
[App settings]: http://msdn.microsoft.com/en-us/library/windowsazure/b6bb7d2d-35ae-47eb-a03f-6ee393e170f7
+[LINQ to Twitter CodePlex project]: http://linqtotwitter.codeplex.com/
View
4 articles/mobile-services-dotnet-backend-windows-phone-get-started-users.md
@@ -36,9 +36,9 @@ This tutorial is based on the Mobile Services quickstart. You must also first co
Next, you will update the app to authenticate users before requesting resources from the mobile service.
-##<a name="add-authentication"></a> Add authentication to the app
+##<a name="add-authentication"></a>Add authentication to the app
-[WACOM.INCLUDE [mobile-services-windows-dotnet-authenticate-app](../includes/mobile-services-windows-dotnet-authenticate-app.md)]
+[WACOM.INCLUDE [mobile-services-windows-phone-authenticate-app](../includes/mobile-services-windows-phone-authenticate-app.md)]
## <a name="next-steps"> </a>Next steps
View
59 articles/mobile-services-windows-phone-get-started-users.md
@@ -55,7 +55,7 @@ To be able to authenticate users, you must register your app with an identity pr
Both your mobile service and your app are now configured to work with your chosen authentication provider.
-<h2><a name="permissions"></a><span class="short-header">Restrict permissions</span>Restrict permissions to authenticated users</h2>
+##<a name="permissions"></a>Restrict permissions to authenticated users
1. In the Management Portal, click the **Data** tab, and then click the **TodoItem** table.
@@ -73,62 +73,9 @@ Both your mobile service and your app are now configured to work with your chose
Next, you will update the app to authenticate users before requesting resources from the mobile service.
-<h2><a name="add-authentication"></a><span class="short-header">Add authentication</span>Add authentication to the app</h2>
-
-5. Open the project file mainpage.xaml.cs and add the following code snippet to the MainPage class:
-
- private MobileServiceUser user;
- private async System.Threading.Tasks.Task Authenticate()
- {
- while (user == null)
- {
- string message;
- try
- {
- user = await App.MobileService
- .LoginAsync(MobileServiceAuthenticationProvider.Facebook);
- message =
- string.Format("You are now logged in - {0}", user.UserId);
- }
- catch (InvalidOperationException)
- {
- message = "You must log in. Login Required";
- }
-
- MessageBox.Show(message);
- }
- }
-
- This creates a member variable for storing the current user and a method to handle the authentication process. The user is authenticated by using a Facebook login.
-
- <div class="dev-callout"><b>Note</b>
- <p>If you are using an identity provider other than Facebook, change the value of <strong>MobileServiceAuthenticationProvider</strong> above to the value for your provider.</p>
- </div>
-
-8. Delete or comment-out the existing **OnNavigatedTo** method override and replace it with the following method that handles the **Loaded** event for the page.
-
- async void MainPage_Loaded(object sender, RoutedEventArgs e)
- {
- await Authenticate();
- RefreshTodoItems();
- }
-
- This method calls the new **Authenticate** method.
-
-9. Replace the MainPage constructor with the following code:
-
- // Constructor
- public MainPage()
- {
- InitializeComponent();
- this.Loaded += MainPage_Loaded;
- }
-
- This constructor also registers the handler for the Loaded event.
-
-10. Press the F5 key to run the app and sign into the app with your chosen identity provider.
+##<a name="add-authentication"></a>Add authentication to the app
- When you are successfully logged-in, the app should run without errors, and you should be able to query Mobile Services and make updates to data.
+[WACOM.INCLUDE [mobile-services-windows-phone-authenticate-app](../includes/mobile-services-windows-phone-authenticate-app.md)]
## <a name="next-steps"> </a>Next steps
View
14 includes/mobile-services-dotnet-backend-create-custom-api.md
@@ -17,17 +17,29 @@
In the above code, replace `todolistService` with the namespace of your mobile service project, which should be the mobile service name appended with `Service`.
-4. Add the following POST method to the new controller:
+4. Add the following code to the new controller:
+
+ // Provides access to Mobile Services functionality.
+ public ApiServices Services { get; set; }
// POST api/completeall
public Task<int> Post()
{
using (todolistContext context = new todolistContext())
{
+ // Get the database from the context.
var database = context.Database;
+
+ // Create a SQL statement that sets all uncompleted items
+ // to complete and execute the statement asynchronously.
var sql = @"UPDATE TodoItems SET Complete = 1 " +
@"WHERE Complete = 0; SELECT @@ROWCOUNT as count";
var result = database.ExecuteSqlCommandAsync(sql);
+
+ // Log the result.
+ Services.Log.Info(string.Format("{0} items set to 'complete'.",
+ result.ToString()));
+
return result;
}
}
View
2  includes/mobile-services-filter-user-results-dotnet-backend.md
@@ -12,6 +12,8 @@ Now that authentication is required to access data in the TodoItem table, you ca
public string UserId { get; set; }
+ >[WACOM.NOTE]The default Entity Framework Code First initializer for this project
+
3. In Solution Explorer, expand the Controllers folder, open the TodoItemController.cs project file, and add the following **using** statement:
using Microsoft.WindowsAzure.Mobile.Service.Security;
View
10 includes/mobile-services-restrict-permissions-dotnet-backend.md
@@ -12,17 +12,13 @@ By default, all requests to mobile service resources are restricted to clients t
using Microsoft.WindowsAzure.Mobile.Service.Security;
-4. To each method in the **TodoItemController** class, apply the following RequiresAuthorization attribute:
+4. Apply the following AuthorizeLevel attribute to the **TodoItemController** class:
- [RequiresAuthorization(AuthorizationLevel.User)]
+ [AuthorizeLevel(AuthorizationLevel.User)]
This will ensure that all operations against the **TodoItem** table require an authenticated user.
-5. (Optional) Open the web.config file for the mobile service project, locate the Mobile Services keys in appSettings, and set the crendentials that you obtained from your identity provider earlier in the tutorial.
-
- You only need to do this when you plan to test authentication on your local computer.
-
- >[WACOM.NOTE]These credentials are only used when your service runs locally. The settings are overwritten with the values that you set in the Management Portal.
+ >[WACOM.NOTE]Apply the AuthorizeLevel attribute to individual methods to set specific authorization levels on the methods exposed by the controller.
6. Republish your service project.
View
53 includes/mobile-services-windows-phone-authenticate-app.md
@@ -0,0 +1,53 @@
+1. Open the project file mainpage.xaml.cs and add the following code snippet to the MainPage class:
+
+ private MobileServiceUser user;
+ private async System.Threading.Tasks.Task Authenticate()
+ {
+ while (user == null)
+ {
+ string message;
+ try
+ {
+ user = await App.MobileService
+ .LoginAsync(MobileServiceAuthenticationProvider.Facebook);
+ message =
+ string.Format("You are now logged in - {0}", user.UserId);
+ }
+ catch (InvalidOperationException)
+ {
+ message = "You must log in. Login Required";
+ }
+
+ MessageBox.Show(message);
+ }
+ }
+
+ This creates a member variable for storing the current user and a method to handle the authentication process. The user is authenticated by using a Facebook login.
+
+ >[WACOM.NOTE]If you are using an identity provider other than Facebook, change the value of <strong>MobileServiceAuthenticationProvider</strong> above to the value for your provider.</p>
+ </div>
+
+2. Delete or comment-out the existing **OnNavigatedTo** method override and replace it with the following method that handles the **Loaded** event for the page.
+
+ async void MainPage_Loaded(object sender, RoutedEventArgs e)
+ {
+ await Authenticate();
+ RefreshTodoItems();
+ }
+
+ This method calls the new **Authenticate** method.
+
+3. Replace the MainPage constructor with the following code:
+
+ // Constructor
+ public MainPage()
+ {
+ InitializeComponent();
+ this.Loaded += MainPage_Loaded;
+ }
+
+ This constructor also registers the handler for the Loaded event.
+
+4. Press the F5 key to run the app and sign into the app with your chosen identity provider.
+
+ When you are successfully logged-in, the app should run without errors, and you should be able to query Mobile Services and make updates to data.
Please sign in to comment.
Something went wrong with that request. Please try again.