Tag Archives: Azure

Azure: Create Node JS App and link it from GitHub to Azure Local Git

Assume you have a project on GitHub. We first use Azure, and create a LOCAL GIT. What this means is that we have a local git repository running on Azure. We then push our project from GitHub into the Azure local git.

make sure your code is simple.

Create Node JS Website, push it to GitHub, and clone it onto your Mac

https://github.com/Azure/azure-content/blob/master/articles/app-service-web/web-sites-nodejs-develop-deploy-mac.md

add_client_ip_firewall

Select Local GIT. This means that are going to push our project from GitHub, have a remote git here in Azure. Azure will provide us a git location via a GIT URL. We just put our files into that URL, and that’s it.

local-git

Make sure we create credentials for when we push our files from our local Mac, up into Azure’s local git.

deployment_credentials

Get the GIT URL
git_url

In our Mac’s local repository, we create a remote git location called ‘azure’. This means that we are to push our files/changes to that GIT location.

Make sure you are in your Mac’s local project directory (the where the .git folder is):

rickytsao$ git remote remove azure
rickytsao$ git remote add azure https://rtsao@myazurenodedemo.scm.azurewebsites.net:443/MyAzureNodeDemo.git
rickytsao$ git push azure master
Password for ‘https://rtsao@myazurenodedemo.scm.azurewebsites.net:443’:
Counting objects: 83, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (79/79), done.
Writing objects: 100% (83/83), 13.19 MiB | 1.06 MiB/s, done.
Total 83 (delta 7), reused 0 (delta 0)
remote: Updating branch ‘master’.
remote: Updating submodules.
remote: Preparing deployment for commit id ‘fda61c8b1c’.
remote: Generating deployment script.

..you’ll also see it copying the files, then telling you the deployment is successful


remote: Copying file: ‘controllers\users\PUT_bbt~email.js’
remote: Copying file: ‘controllers\users\PUT_sign~email.js’
remote: Copying file: ‘controllers\users\PUT_~email.js’
remote: Copying file: ‘models\user.js’
remote: Looking for app.js/server.js under site root.
remote: Using start-up script server.js
remote: Generated web.config.
remote: The package.json file does not specify node.js engine version constraints.
remote: The node.js application will run with the default node.js version 4.2.3.
remote: Selected npm version 3.5.1
remote: …….
remote: npm WARN book_api@0.0.0 No repository field.
remote: Finished successfully.
remote: Running post deployment command(s)…
remote: Deployment successful.
To https://rtsao@myazurenodedemo.scm.azurewebsites.net:443/MyAzureNodeDemo.git
* [new branch] master -> master

Creating SQL Database

https://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/

Node Code

Further samples on SQL manipulation:
https://msdn.microsoft.com/library/mt715784.aspx

run “Node server.js” in a terminal

If you run your node app, you’ll see that your connection may have a problem because:

Basically, you have to go to your SQL server, and have the firewall allow access to your ip address like so:

sql_server_firewall

Import another project/framework (ADAL) into your project

ref – http://www.insert.io/frameworkios8xcode6/

Let’s say we want to get a project called ADAL from the git repository and then add it to our project as an external framework for us to use.

First, let’s get the project:

git submodule add https://github.com/AzureAD/azure-activedirectory-library-for-objc adal
cd adal
git checkout tags/2.1.0

Optionally, later don’t forget to add this framework to your git, and push it.

cd ..
git add adal
git commit -m “Use ADAL git submodule at 2.1.0”
git push

Locate the ADAL project folder

the adal folder will be downloaded into your root git directory. (the one with the .git hidden folder)
You will see the ADAL project. Inside, you’ll see several folders. Locate the main ADAL folder with the source files by looking for a .xcodeproj file, along with src folder and its header/implementation files.

source_files

Drag the project over

Make sure you drag the .xcodeproj file over to your project space. Open it and you’ll see the src folders and what not. Look in the Products folder. You will see the ADAL.framework. That is what we’ll be importing into our project.

drag_project_over

Select your Target, then Build Phases, then click on Link Binary With Libraries

Also, in Target, then Build Phases, then Target Dependencies, make sure you add the ADAL framework as well

target_link_library

Click on the ADAL framework and import it.

select_it

Make sure you’ve imported the framework. The run the project.

framework_should_appear

Inserting some code

Finally, in your ViewControllelr.m, import the header file and you should get no errors.

add some define strings for the table names in our azure cloud

Let’s create a service so the view controller can communicate with the cloud tables

Set up the service with the table name and query

dyld: Library not loaded

http://stackoverflow.com/questions/24993752/os-x-framework-library-not-loaded-image-not-found

After you’d made sure there are no errors, if you run into an image not found error, it just means that in your Target, General, Embedded Binaries, click the ‘+’ button and add the ADAL ios framework from its original directory. (NOT the one you dragged into your project)

add_embedded_binaries

Converting existing Project to read from Azure Backend

Import Data Model

File >> New >> File >> Data Model. Name it “Activities”.

Ctrl + click >> Show in Finder. Then drag that file onto a text editor such as sublime. You will see basic xml file.

Drag and drop an existing data model file onto the text editor. Copy and paste all the content into your Activities file. Save and close. Your data model should be now updated. Your iOS data model is ready.

Basic Core Stack Class

Create a basic core data stack class with a context, MOC, and PSC.
Make sure the your sql file name, and the data model name are specified.

core data demo

#define DATA_MODEL_FILENAME @”Activities”
#define SQL_FILENAME @”Activities.sqlite”

QSTodoService

Azure should generate a QSTodoService object that does all the reading and writing of data for you.

Unfortunately, it also generates core data code that sits in your AppDelegate. Pull all the core data code out onto your own CoreDataStack class so that AppDelegate is clean.

Then, make these modifications to your QSTodoService:

Use your core stack and its context in QSTodoService’s init method. Commented out code is the original.

ViewController

conform to NSFetchedResultsControllerDelegate protocol

specify what/how you want to fetch for the fetchedResultsController

In the viewDidLoad, make sure you create your QSTodoService because we are going to implement a refresh method that uses it to sync all the data between your app the backend service.

use the fetchedResultsController to get the objects

Add data attribute to table and app

Let’s say we want to add an attribute event_date, so that the iOS app takes in that date, and can send and store it in an Easy Table on Azure backend.

Azure backend side

Click on the designated table, you add the column attribute. Save it.

add_column

iOS side

Note: For ever new attribute you add, make sure you delete the old app that’s installed on your device. This is so that the existing app’s Core Data mode does not conflict with your new addition.

After you have finished your Easy Table, you use Quick Start to generate an iOS project that connects its Core Data to the Easy Table in Azure backend.

What you pull from the Easy Table depends on your NSFetchController:

  • entity
  • predicate
  • sortDescriptors

of the NSFetchController get method like so:

So we want to match the event_title attribute we added on the Azure backend.

We do so by manipulating our .xcdatamodelId file. In core data, each entity matches that of a table. Look for the TodoItem (or whatever table name you have created in Azure) entity. Click on it, and click the plus button to add it.

add_attribute_to_entity

In your iOS code, we pass the data dictionary to the Azure backend to fill in on the attribute. Thus, just make sure you put the key for “event_date”, and the value that you want to send, which in our case is NSDate.

Then, run your app. Add an entry. Go to your dashboard, and refresh the table rows. You will see your results there.

column_reflected

Logging in Azure

In order to log in Azure

Settings >> Diagnostic Logs >> Logs

diagnostic_logs

Make sure the Application Logging is turned on

azure_logs2

Create FTP credential accounts

In order to view your logs, you must create a FTP account so you can log in.

credentials

After creating a new FTP user, you’ll see your user name, and the FTP URLs. You will be using these FTP urls and credentials to view your logs.

azure_logs

Use the user name and password you just created to log into FTP client like Filezilla

filezilla_url

Once you log in, go to /LogFiles/Application and you’ll see all your logs with timestamps

filezilla_url2

You can copy the files onto your desktop and view it. However that is not efficient because you don’t want to do a copy every time a log is updated.

Web browser to view your logs

Hence, just put the FTP url into your browser, insert your credentials and update the browser whenever you make a change.

http_log_view