Dependency Injection using Unity with C#

Hello guys, Today I will introduce you to the Microsoft Unity Framework and also take you through its dependency injection feature. First of all we will see “What is Dependency Injection.?”.In simply Dependency Injection is decouples the module dependencies in your application by creating and injecting the object at runtime.

The dependency of a class can be injected at runtime using the Dependency Injection mechanism. Unity will help us to handle those things very easily.

It is a two-step process.

  • Register the dependency
  • then resolve the concrete business module class.

RegisterType and RegisterInstance methods of the UnityContainer classes can be used to perform the Register operation. And Resolve method can be used for creating the concrete business class instance.

Today i will show you guys how should we use the NamedRegistration for the handling Dependency Injection. In the real world applications there might be situations like we want to dynamically create objects according to the requirements. When using Unity, Unity knows that which class object is need to be created.

Let’s suppose example like this. According the the user input we need to change the database which is going to save the data. Here i will use SQL and Oracle.

For the explanation we will create a console application and do dependency constructor injection using Unity. Then you need to add the Unity via NuGet.  So go to the NuGet package manager and search for the unity and install it.

unioty

Continue reading

Build Real time Instagram App with ionic and Firebase

Hello guys, Today I’m going to show how we will use the Firebase Real Time Database for implement Instagram like application.In order to do that i’m using Ionic2 with Firebase.

So first we will configure the Firebase. So navigate to Firebase developer Console.  https://console.firebase.google.com. You can use your gmail account to login to the Firebase Console. Once login create a new project and you can give what ever name you want. Once you create the new project go to Database section and under “Rules” and set read and write permissions to “auth == null”. This will allow to unauthenticated clients to access to the our created database.

 

database-fire

And the other thing you want to do is need to add the  Firebase sdk to your application.

1

Continue reading

Using Factories and Web Services for Get Dynamic Data in Ionic App

In a typical Ionic mobile app has a Data Layer which uses Factories or Services to provide data to the controllers of the mobile app. Those data may come from an external web service in the form of JSON or XML. Or may be from another backend services written by your self. 🙂

In this article, I will show how to build a Data Layer for an Ionic app, wired to a web service. First of all i will clear about what are the Services and Factories in ionic application.

Services vs Factory

 app.service('YourServiceName', function () {
     this.yourFunc= function () {
         console.log('hello service');
     };
 });

Actually Service is a method on our module that takes a name and a function. This will defines the our service.. Once you defined the Services, we can inject and use that particular service in other components, like controller or directives. This is same as you inject other directives to your controller.

 app.controller('YourControllerName', function (YourServiceName) {
    YourServiceName.yourFunc();
 });

So this will give the output as “hello service” in the console. So now we will consider the factory.

app.factory('YourFactoryName', function () {
  return {
    yourFunc: function () {
      console.log('hello factory');
    }
  }
});

Well, right off the bat I’ll say they’re pretty much equivalent. Why do we have them both, then? That’s for the gods of Angular to know. They both allow us to create an object that can then be used anywhere in our app.

Most important is to realize that both are singletons in your application. Essentially, factories are functions that return the object, while services are constructor functions of the object which are instantiated with the new keyword.

Continue reading

Get the Current location Using Cordova Geolocation in ionic app

In this post i’m going to show how the cordova geolocation plugin used for iOS and Android apps that reads your phone gps location and displays it on a map. This will save you time if you are going to make location based app in ionic. Now lets see how to start a new project and use CordovaGeolocation in your mobile app.

1.ionic start myapp blank

2.cd myapp

3.ionic platform add android

Now make a new folder and name it as templates and make a new html file. In here i named it as map.html. In map.html


<ion-view>
   <ion-content>
<div id="map" data-tap-disabled="true"></div>
</ion-content>
</ion-view>

In here note that, i named id as “map” for load the map in the view.

Now in index.html

<body ng-app="starter">

   <ion-pane>
      <ion-header-bar align-title="center" class="bar-dark">
<h1 class="title">Tracker</h1>
</ion-header-bar>
      <ion-nav-view></ion-nav-view>
      <script src="http://maps.google.com/maps/api/js?key=GIVE_YOUR_API_KEY&sensor=true"></script>

   </ion-pane>
</body>

Note: If you dont know how to get the API key for your project then refer my post  “Using              google map API for web development

Now open your Terminal (In windows Command Prompt) and change the directory to your app.For add the cordova geolocation plugin :

cordova plugin add cordova-plugin-geolocation

Now all you have to do is , add folowing to your app.js


.config(function($stateProvider, $urlRouterProvider) {

$stateProvider
  .state('map', {
     url: '/',
     templateUrl: 'templates/map.html',
     controller: 'MapCtrl'
  });

   $urlRouterProvider.otherwise("/");

})

To get the current location then you have to create a controller for your map, i named it as MapCtrl. Dont forget to inject $cordovaGeolocation in the function


.controller('MapCtrl', function($scope, $state, $cordovaGeolocation) {
    var options = {timeout: 10000, enableHighAccuracy: true};

    $cordovaGeolocation.getCurrentPosition(options).then(function(position){

        var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

        var mapOptions = {
            center: latLng,
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);

        google.maps.event.addListenerOnce($scope.map, 'idle', function(){

            var marker = new google.maps.Marker({
                 map: $scope.map,
                 animation: google.maps.Animation.DROP,
                 position: latLng,
                 icon:'http://i.imgur.com/fDUI8bZ.png'
            });

            var infoWindow = new google.maps.InfoWindow({
                content: "Here You Are.!"
            });

            google.maps.event.addListener(marker, 'click', function () {
                infoWindow.open($scope.map, marker);
            });
       });
    }, function(error){
         console.log("Could not get location");
  });
});

 

aaa

 

 

 

 

 

 

Encrypt and Decrypt photos in Ubuntu Terminal

 

Simple file encryption is probably better done using OpenSSL. All you want to have to remember is a password. It can nearly be that simple. Linux has plenty of powerful encryption software, but what can you use if you just want to secure a couple files quickly? The openSSL toolkit works well for this. It comes installed with Ubuntu and can provide stronger encryption than you would ever need.

OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) network protocols and related cryptography standards required by them.

The openssl program is a command line tool for using the various cryptography functions of OpenSSL’s crypto library from the shell. It can be used for

  • Creation and management of private keys, public keys and parameters
  • Public key cryptographic operations
  • Creation of X.509 certificates, CSRs and CRLs
  • Calculation of Message Digests
  • Encryption and Decryption with Ciphers
  • SSL/TLS Client and Server Tests
  • Handling of S/MIME signed or encrypted mail
  • Time Stamp requests, generation and verification

Encypt Code:

note: make sure to change the directory

 openssl enc -des-cbc -salt -in my.jpg -out sumi.enc

After type this code in terminal then it will asked you to give a  enter des-cbc encryption password.  Remember your password. because it will need when comes to decypt the file.

Decrypt Code: Continue reading

Use SQLite in ionic framework

Hello guys, today lets see how to use SQLite database in an ionic app. When thinking about native development local storage it might be tough for someone who starting use ionic framework. Dont worry. !!! This is not much harder you guys thinking. There is a plugin called Cordova SQLite for this.  Now lets see how to start a new project and use SQLite with simple form data submition.

Note- if you guys want to build a ios app using ionic then you have to use a mac. Otherwise it won’t work.

1.ionic start myapp blank

2.cd myapp

3.ionic platform add android

Its recommend to through the official ionic site and have a better idea about this technology and how its work.

Now open your project in whatever text editor you using. go to the www folder then you can see index.html and js folder, css folder and lib folder.

Now we need to add cordova plugin to working with SQLite. For that simply u can use cordova plugin add cordova-sqlite-storage. Instead of that you can use:

cordova plugin add https://github.com/litehelpers/Cordova-sqlite-storage.git

Then you need to add the latest version of the ng-cordova.min.js file to www/js directory. Now we need to add it on the index.html file. Make sure to include it before the cordova.js

Continue reading

load MySql database Latitude and Longitude markers on google map using PHP

  • Today we are going to see how to load the database Latitude and Longitude in  the google map using PHP.
  • My previous article shows that how to use google map API in our projects. Follow that article and you can get the basic idea for use Google Map API in a web project.
  • You can get a API Key from Here.

Now lets see the hard works for load the markers in the google map using stored data in MySql database.

  • First you need to download the   jquery-min.js and jquery-ui.min.js files.
  • You can download my database file for this article from here.
  • Now lets see how to do this stuff.

 /*Connect to the MySQL database that is holding the data will handle in here, replace the relevent data with your data
 with database name username and password*/
 mysql_connect("localhost", "root", "") or
 die("Could not connect: " . mysql_error());
 mysql_select_db("googleMap");

 //Initialize your first couple variables
 $encodedString = ""; //This is the string that will hold all your location data
 $x = 0; //This is a trigger to keep the string tidy

 //Now we do a simple query to the database
 $result = mysql_query("SELECT * FROM `locations`");

 //Multiple rows are returned {
 //This is to keep an empty first or last line from forming, when the string is split
 if ( $x == 0 ){
     $separator = "";
 } else{
     //Each row in the database is separated in the string by four *'s
     $separator = "****";
 }

 //Saving to the String, each variable is separated by three &amp;amp;'s
 //this is for the shows the details in the map
   $encodedString = $encodedString.$separator.
"
<p class='content'><b>Lat:</b> ".$row[1].
"
<b>Long:</b> ".$row[2].
"
<b>Name: </b>".$row[3].
"
<b>Address: </b>".$row[4].
"
<b>Division: </b>".$row[5].
"

&&&".$row[1]."&&&".$row[2];
$x = $x + 1;
 }

 

 

  • Here is the main html file. i have include two jquery files in folder named as js.

 


<html>
<head>
<script type='text/javascript' src='js/jquery-1.6.2.min.js'></script>
    <script type='text/javascript' src='js/jquery-ui.min.js'></script>
<style>

BODY {font-family : Verdana,Arial,Helvetica,sans-serif; color: #000000; font-size : 13px ; }

#map { width:100%; height: 100%; z-index: 0; }
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY" /></script>

    <script type='text/javascript'>
 
       <!--java script code comes here-->
    </script>

</head>
<body>
<div id='input'>

<!--php code will come here-->

<input type="hidden" id="encodedString" name="encodedString" value="<?php echo $encodedString; ?>" />
</div>
<div id="map"></div>
</body>

 

  • Here is the javascript file

 jQuery(document).ready( function($){

     //Initialize the Google Maps
     var geocoder;
     var map;
     var markersArray = [];
     var infos = [];

     geocoder = new google.maps.Geocoder();
     var myOptions = {
         zoom: 9,
         mapTypeId: google.maps.MapTypeId.ROADMAP
     }
     //Load the Map into the map div
     var map = new google.maps.Map(document.getElementById("map"), myOptions);
     map = new google.maps.Map(document.getElementById("map"), myOptions);

     //Initialize a variable that the auto-size the map to whatever you are plotting
     var bounds = new google.maps.LatLngBounds();
     //Initialize the encoded string
     var encodedString;
     //Initialize the array that will hold the contents of the split string
     var stringArray = [];
     //Get the value of the encoded string from the hidden input
     encodedString = document.getElementById("encodedString").value;
     //Split the encoded string into an array the separates each location
     stringArray = encodedString.split("****");

     var x;
     for (x = 0; x &amp;lt; stringArray.length; x = x + 1){
          var addressDetails = [];
          var marker;
          //Separate each field
         addressDetails = stringArray[x].split("&&&");
        //Load the lat, long data
       var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]);
       //Create a new marker and info window
        marker = new google.maps.Marker({
            map: map,
            position: lat,
            //Content is what will show up in the info window
            content: addressDetails[0]
        });
 //Pushing the markers into an array so that it's easier to manage them
 markersArray.push(marker);
 google.maps.event.addListener( marker, 'click', function () {
      closeInfos();
      var info = new google.maps.InfoWindow({content: this.content});
      //On click the map will load the info window
      info.open(map,this);
      infos[0]=info;
 });
    //Extends the boundaries of the map to include this new location
    bounds.extend(lat);
 }
 //Takes all the lat, longs in the bounds variable and autosizes the map
 map.fitBounds(bounds);

 //Manages the info windows
 function closeInfos(){
      if(infos.length > 0){
          infos[0].set("marker",null);
          infos[0].close();
          infos.length = 0;
      }
 }

 });