1782171924 by Unknown

1782171924 by Unknown

Author:Unknown
Language: rus
Format: mobi, epub
Published: 2014-01-09T09:24:08+00:00


Service Customization with Scripts

The script makes use of the standard JavaScript Math object to randomize board size and time allowance, and then uses the API-specific tables object to insert the level into the table.

Working locally with Git

We can work on scripts in the portal if we like; however, we can also pull a copy if we want to work locally or for a backup using Git version control. I personally use the Git GUI; however, I don't want to waste pages with screenshots of this, so we'll talk about using Git Bash (the console)!

Pulling the repository

First, we need to get a copy of the repository onto our local machine. To do this, follow this procedure:

1. We need to set up the service's repository Git credentials. On the dashboard, click on the Set up source control button and enter some credentials for Git authentication.

2. Create a folder somewhere for the repository (I put mine in one of the Visual Studio projects, so I can work on the scripts easily in Visual Studio). Next, launch Git Bash by right-clicking on the folder and selecting Git Bash or launching Bash and setting the path to the directory you want.

3. Type the following command into Bash (You can copy the URL from the GIT

URL setting under the CONFIGURE tab):

$ git clone https://your_service.scm.azure-mobile.net/Your_

Service.git

Enter the user name and password when prompted.

4. We should now have a full copy of the service's scripts in our directory: 5. If you've pulled them under one of your projects, you can add the directory into your solution and even check them in to TFS if you're using it.

[ 56 ]

Chapter 4

Updating our repository

When we add or change tables or other scripted items in our service through the portal, we can call a pull to update our local repository:

$ git pull origin master

Enter the username and password when prompted. If there are any conflicts, edit the conflicting files and call commit.

Adding scripts manually

I manually added a script named LeaderBoard.insert.js to modify the insert behavior of the LeaderBoard table:

function insert(item, user, request) {

request.execute();

console.log(item);

}

This will asynchronously insert the item into the table and log the JSON item object to a log file, which we can view in the portal.

We need to add this to the repository by calling an add to add the file to the repository: $ git add service/table/LeaderBoard.insert.js

Or we can use the following:

$ git add *

Once added, we can commit the change and add a comment:

$ git commit -m "Added LeaderBoard insert script"

Pushing back changes

Once we've done some work and committed everything, we can go and push the changes back to the service by calling a push:

$ git push origin master

Enter the username and password when prompted. We can now see that any changes made are reflected in the portal.

[ 57 ]



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.