Windows Azure Mobile Services (WAMS) has come a long way in a few short months. At the 2013 Build conference in San Francisco, Microsoft announced more than the service’s General Availability date – it also showed that the service had been integrated into the Visual Studio 2013 Preview in several key places. These included a “Connected Services Manager” that will augment an existing project to connect with a new or preexisting WAMS instance, an entry for WAMS in the Server Explorer panel that allows viewing and editing the server-side data table business logic scripts (with access to the other WAMS script elements expected to be added over time), and a Push Notification Wizard that facilitates connecting an existing Windows Store app to a WAMS instance. These features are detailed in this post on the Visual Studio Blog. The expectation is that these integration points are expected to be enhanced as Visual Studio 2013 is updated to its RTM version.
One of the more recent features added to WAMS itself has been the integration of Git-based source control for the server scripts (as of this writing, this feature is currently in Preview.) This integration provides several advantages for managing a WAMS service’s scripts. First, it allows for scripts to be edited locally /offline using desktop file editing tools, including Visual Studio. Changes can be managed through the local Git repository until they are ready to be synchronized to the server. What’s more, this arrangement also allows access to some of the WAMS script-related content that is not (presently) available through the WAMS management portal (though access to these files can also be obtained from the command-line management tools.)
To mostly round out the collection of the tools will be discussed here, the Team Foundation Server Power Tools team at Microsoft has released the Visual Studio Tools for Git, which is an extension that allows Visual Studio’s Team Explorer to integrate with Git. This integration includes using the Team Explorer GUI to manage and connect to local repositories, as well as to track changed elements in a selected repo, and managing branches, commits, and syncs in that repo. As of this writing, the extension is at version 0.9.5.
This post will explore how the new integrated Visual Studio tools for Git can be used to provide GUI-based source-controlled management for client-side editing of the scripts belonging to a Windows Azure Mobile Services instance.
Enabling Source Control in a WAMS Instance
The first step in the process is to enable Git Source Control for the account which owns the WAMS instance, if it has not already been set up for that account. This process is documented here. Basically, the steps entail:
- – If this is the first time a Mobile Service Git repository is being set up for the current Azure subscription:
- – From the WAMS Management Portal “Dashboard” page for the desired service, select “Set up source control”
- – Provide a username and password to be used for access to mobile service Git repositories within the subscription. These credentials can be changed later by selecting the “Reset your source control credentials” link on a WAMS Dashboard page for any Mobile Service attached to the same subscription.
- – Copy the Git URL from the service instance’s Configure tab.
Connect to the Git Repository from Visual Studio
The next step is to connect to the server-side repository that was just created and clone it to the local machine. This (and many of the remaining steps) can be accomplished via several Git tools, including the command line, but the focus here is on using Visual Studio (for the most part, I prefer to leave the command line to build scripts and for hacking into the Matrix.) Once the Visual Studio Tools for Git extension has been downloaded and installed, open Visual Studio 2013 and select the Team Explorer pane (if necessary, it can be found in the View menu.)
Select Connect (the icon looks like a the male end of a 2-prong extension cord)
In the ensuing Connect dialog, select Clone to do the initial setup of the local repo as a clone of the server repository. This will show a couple of text boxes – the top one is used to provide the URL to the remote repository – paste the URL that was copied earlier from the WAMS Management Portal. In the second one, type in or browse to the local directory path into which the repository should be cloned.
When you press the Clone button, you will be prompted for your server-side Git repository credentials.
…and after entering these credentials, you will have a local clone of the WAMS repository.
Examining the WAMS File Structure and Script Files
If you right-click on the new repository entry in the Team Explorer Connection Panel, you will see context menu options which include one for opening the repository in File Explorer.
The folder you open will contain a file and single subfolder titled “service”. Within the service folder are the folders that contain the WAMS script content. These folders and their purpose are listed below:
- shared: contains scripts and/or Node.js modules that can be reused by other scripts in the service instance. Note that there is no browser in the portal (at present) for files in this folder.
Note #1: Each folder also includes a text md file that describes the intended contents of the folder and any layout constraints for each file.
Note #2: For the most part, with the exception of the “shared” folder, the files should be “seeded” by creating the desired named item server-side and then syncing the repository. WAMS often has to spin up other infrastructure elements in addition to just the scripts, such as database tables and entries for the scheduler.
For Table scripts, the table can be created in the Visual Studio Server Explorer, but the individual table operation script files won’t be brought down by a Sync operation until the corresponding scripts is modified in some way – the change can be as simple as adding a comment. Once the file has been altered and saved to the server, using Sync will fetch the file to the local repository. The WAMS instance context menu (with the Create Table option) in the Server Explorer is shown below, along with a script that has been modified with nothing but a comment.
The screenshot below shows after the file above has been saved to the server from within the Server explorer, after doing a Sync of the Git repositories, the local folder has been updated with the table’s corresponding read script file.
Note that generating files this way is probably best left only for initially “seeding” the files, thus leaving day-to-day editing to an operation that is covered by source control and includes change tracking, etc.
Working with the Visual Studio Git Tools
From the Connections panel, opening one of the repositories (double-click or right-click and select Open) displays the Home panel for the selected repository.
Note that there’s also an entry for “demosharedcontent.js” in the Untracked Files listing. To include the file, simply drag it (or its containing folder) up and drop it in the “Included Changes” section:
Once the collection of changed files that is to be committed to the local repository is ready, a commit message (comment) can be entered and the Commit button can be pressed. Pressing the Commits link from this panel, returning to the home panel and selecting the Commits button, or selecting the Commits pulldown at the top of the TFS explorer will show the current set of outgoing and incoming Commits available for Syncing with the Server.
Pressing the Sync button once again synchronizes the script changes with the WAMS service. Examining the table script in the WAMS Management Portal shows that the change in fact has been uploaded to the server:
If the Sync results in conflicts that Git cannot resolve, (the same word was changed both in the client and the server, for example) the Sync will indicate so, and a list of conflicts will be displayed:
The conflicts can be examined in detail and adjusted using the 3-way merge tool that comes with Visual Studio (with apologies for my typos):
Once the Merge is committed, it can be synced to the server.
The final working panel that hasn’t been shown yet is the Branches panel, which allows management of branches in the selected local repository.
While Windows Azure Mobile Services currently benefits from several points of integration into the Visual Studio 2013 IDE, the addition of the Visual Studio Tools for Git offers an additional tool to help with the management of server-side scripts. For what it’s worth, the Visual Studio Tools for Git also works with Visual Studio 2012, and supports the same kinds of source control management as was shown here in Visual Studio 2013 Preview, except that Visual Studio 2012 lacks the additional WAMS integration points such as the entry in the Server Explorer. Nonetheless, look for the integration of these tools to become even richer as WAMS, Visual Studio 2013 , and even the Visual Studio Tools for Git are enhanced over the next few months.
Pingback: Adding Intelligence to the IntelliSense for Windows Azure Mobile Services | DotNet Gator
Pingback: Windows Azure Community News Roundup (Edition #72) - Windows Azure - Site Home - MSDN Blogs
Pingback: Windows Azure Community News Roundup (Edition #72) - Windows Azure Blog