Tuesday, December 30, 2014

Use Oracle with ASP.net MVC

MVC is well known software architecture pattern which is widely using. Combination of .net framework and Visual studio facilitates few well defined templates to implement applications as MVC-1, MCV-2,MVC-3... MVC-6. Not only that there are several 3rd party templates and extended modules such as "Hot towel", "SPA", that are supportive to form applications using this modal.  

As usual, these templates originally defined to use MS SQL database. This is good enough when we use code first approach or modal first approach, but database approach. 

When it comes to a scenario to replace an industrial level application which handles an existing database, we need to combine the templates with existing database technology. Oracle DB has plenty of usages in industry level data management. in this case its better to know how to connect Oracle db with the MVC template. 

To start this we need to install oracle client and oracle .net provider in our computer. After successful installation of above two applications you need to configure TNS settings to connect to the Oracle DB server. 

(REF : http://kb.tableausoftware.com/articles/knowledgebase/oracle-connection
REF: http://docs.oracle.com/cd/E11882_01/network.112/e10835/tnsnames.htm#NETRF007)

After create the MVC project in visual studio we need to add reference to the Oracle.DataAccess.dll. 

To setup modals from existing database

STEP 1:
right click the project and select "add new" option form the database to get following window


as the picture select ADO.NET entity data modal and add appropriate name for the modal. 

STEP 2:

after click the add button you will end with the following window.


fro this select the "Generate form the database" option and click next 

STEP 3:


From this window you need to select "New Connection" button to setup a connection to to the DB server. This will give you the following sub window to collect information.

when you expand the "Data source name" drop down, you will be able to see a list of  data sorceress that you are defined in TNS configuration file at the very beginning.Select the source and select the "Use a specific name and password" option to add the database username and password by your self rather using windows defaults. its better to save password to avoid unnecessary log in steps in testing environments.  

Before press "Ok" button you can test the connection by using "Test Connection" button. 

After complete the connection creation you can see the parent window with filled details as follow


you can select to save or not sensitive data as your preference and give an appropriate name for the context before click next

STEP 4:
now you can select the tables views and procedures that you need to map for the modal


after finish the process you can treat the oracle database as same as the MS SQL database. 
   

Thursday, May 22, 2014

Remote Desktop application with RDP protocol

        Skype, Team viewer and Lync are some of well-known desktop sharing applications that are widely using in novel world. This kind of applications enable users to login to remote computer and use it form any where.

         Most of these application developers provide API s that can be used to integrate those facilities in to our own applications.The problem is all the feature are inflexible due to the terms and conditions. 

      RDP, which is introduced by Microsoft can be used to create windows applications which can share desktop among users. It is more flexible and easy to use rather than other APIs .

RDP stand for the term of Remote desktop protocol .Remote Desktop Protocol is a property protocol developed by Microsoft, which provides a user with a graphical interface to connect to another computer over a network connection.
In order to configure RDP with the project it should have some additional references to both rdpcomplib and Axrdpcomplib. both these dll files enable you to use RDP in your program. 

** to import rdpcomplib   you need to go the "Add references" menu by right clicking the project. rdpcomplib is categorized under com libraries. so you can select the co and tick the rdpcomplib. in addition you need to search for windows terminal services library and tick it too.

** to import Axrdpcomplib you should use "RDP viewer class" in your Form. So you need to add it to the tools box by right click on the tool box. From the popup menu, you can select "Choose Items" and search for the  "RDPviewer class" which is categorized under Com items.

Following source code shows you how to write the server side of the application.       
     
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RDPCOMAPILib;
using AxMSTSCLib;
using System.Runtime.InteropServices;

namespace TCP_to_RDP_Converter
{
    public partial class Form1 : Form
    {
        public static RDPSession currentSession = null;
        public static void createSession()
        {
            currentSession = new RDPSession();
        }

        public static void Connect(RDPSession session)
        {
            session.OnAttendeeConnected += Incoming;
            session.Open();
        }

        public static void Disconnect(RDPSession session)
        {
            session.Close();
        }

        public static string getConnectionString(RDPSession session, String authString, 
            string group, string password, int clientLimit)
        {
            IRDPSRAPIInvitation invitation =
                session.Invitations.CreateInvitation
                (authString, group, password, clientLimit);
                        return invitation.ConnectionString;
        }

        private static void Incoming(object Guest)
        {
            IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;
            MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
        }

        /// <summary>
        /// Handle the form items
        /// </summary>
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            createSession();
            Connect(currentSession);
            textConnectionString.Text = getConnectionString(currentSession,
                "Test","Group","",5);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Disconnect(currentSession);
        }


    }
}
Following source code shows the client application that is using above server.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RDPCOMAPILib;
using AxRDPCOMAPILib;

namespace Simple_RDP_Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static void Connect(string invitation, AxRDPViewer display, string userName, string password)
        {
            display.Connect(invitation, userName, password);
        }

        public static void disconnect(AxRDPViewer display)
        {
            display.Disconnect();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Connect(textConnectionString.Text, this.axRDPViewer, "", "");
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to connect to the Server");
            }
        }
    }
}

Source of the project can be downloaded from here

Tuesday, April 8, 2014

Internet of things

         About a decade ago there are very few devices that can be connected to the internet, such as early adopters smart mobile phones, Some special kinds of expensive cameras and PC s. Most of these connections were wired connection and worn't very flexible for the data sharing. Actually this we can define this era as"Era of human connected to the internet" . Even though beginning of the decade appear as like above, there was very aggressive growth of internet connected devices at the end of the decade. you can see that by referring to the image . 

         This makes the world more connected and more sensitive than previous mean while upgrade the "era of human connected to the internet" to "Things connected to the internet". The word "Things" literally refer for every thing and all (Ex. Animal,Person,Equipment,document,soil,place etc.). The thing that needs to be have to actualize this concept is universal ID that can be used to refer the object uniquely. According to the flow of things, all the objects around us will have virtual representation on internet same as the humans. This makes hard to differentiate devices from live wares because even those things can be hanged with other devices same as live wares. We call this concept as "Internet of Things".This Situation has both pros and cons same as any other technologies and related concepts.

        When we talking about the pros simply we can say, we can connect things with things . So this will be grate advantage. imagine about a refrigerator that propose what you can make from the existing foods instead tell what are the things remaining. Also it is easy to monitor things even in remotely. For example you can monitor your heart beat using your mobile phone mean while your doctors mobile device ready for a react when it has a hard situation. Also there will be a grate searching plat for the users even can be searched for their car key or the favourite shirt. Controlling things and automation will be easy because every device became intelligent due to the connectivity. Simply you can put your dirty cloths in to the washing machine without informing it to when to start the washing task. this will be a grate advantage for the efficient use of energy.

         When we talking about the cons of the technology, due to the high availability of personal details it will be a grate risk for the privacy. Simply NSA can come to your house and do a full search regarding your works and behaviour. Next thing is malware. One of the main concept behind the malware is spread all over the devices as much as possible. so this is grate play ground for the malware. Influence of the malware can be upgraded due to the wide access of the devices.Intrusion is the next main problem regarding this concept.Consider about the previous example that says about the medical report send to the doctor. Web mining is major field to grab details of the web users. so any one can get the contact details and access to the relevant person up to a level of limitation. So any unethical advertiser can use your medical problems to sell their products meanwhile providing the facility to connect with the doctor.

Actually this concept is not 100% of future concept. Just now even when you  are reading this article new devices are connecting with the internet , thousands of experiments are doing related to the well bean of this concept. So we are entering that future even this time.

Be ready for search everything mean while connect with everything                     

Monday, February 24, 2014

Strategy Design pattern with simple example

        "In computer programming, the strategy pattern (also known as the policy pattern) is a software design pattern, whereby an algorithm's behavior can be selected at run time. Formally speaking, the strategy pattern defines a family of algorithm, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it."this is how Wikipedia defines the strategy pattern, which is not clear for the beginners.



But using following example, anyone can get an idea about what is going on here. look at the following class diagram 





                This is a company that makes toy vehicles for the children. Every toy has its own power source to use which are often using battery and solar power to recharge it self. In some special cases such as introducing new version of an existing toy there is a possibility to change the power option between Solar and battery power. Strategy pattern helps programmer to change the power option within the run time without re-implementing the class. 

Following code shows how we can use strategy pattern for this kind of situation.  

Interface "PowerOption" and Class "BatteryPower" and Class "SolarPower" thet implements the interface

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public interface PowerOption {
	public String power();
}

// Class of the toys which are using battery
class BatteryPower implements PowerOption {
	public String power() {

		return "Is using battery power";
	}

}

//Class of the toys which are using solar power
class SolarPower implements PowerOption{
	public String power() {

		return "Is using solar power";
	}
	
}

Parent class "ToyWehical"

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class ToyWehicle {
	// Private variables
	private String name;
	private String suitableFor;
	public PowerOption poweroption;

	// Getters and Setters
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSuitableFor() {
		return suitableFor;
	}

	public void setSuitableFor(String suitableFor) {
		this.suitableFor = suitableFor;
	}
	
	//Method to get power option of the toy
	public String PowerSource()
	{
		return poweroption.power();
	}
	
	//Method to change the power option on runtime
	public void setPowerOption(PowerOption newOption)
	{
		poweroption = newOption;
	}

}

Child Class "ToyCar"

1
2
3
4
5
6
7
8
public class ToyCar extends ToyWehicle {
	public ToyCar() {// Constructor
		super();
		setName("Car");
		setSuitableFor("Boys");
		poweroption = new SolarPower();// set default power option
	}
}

Child Class "ToyCopter"

1
2
3
4
5
6
7
8
public class ToyCopter extends ToyWehicle {
	public ToyCopter() {
		super();
		setName("Helicopter");
		setSuitableFor("boys");
		poweroption = new BatteryPower();
	}
}

Class "Main" which contain main method

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ToyWehicle toyota = new ToyCar();
		ToyWehicle mingo = new ToyCopter();

		System.out.println("toyota is a Toy " + toyota.getName() + " which "
				+ toyota.PowerSource());
		System.out.println("mingo is a Toy " + mingo.getName() + " which "
				+ mingo.PowerSource());

		// Change the power option of toyota to battery power
		System.out.println("****new toyota changing its power option***");
		toyota.setPowerOption(new BatteryPower());
		// Check the power option
		System.out.println("new toyota is a Toy " + toyota.getName()
				+ " which " + toyota.PowerSource());
	}

}

Test it and understand the concept behind the codes...

Friday, February 7, 2014

Java Python Binding

Java is a simple and powerful OOP language that is good for GUI programming rather than scientific programming. Python has its core features lays toward the scientific and logical programming rather than GUI application programming.Since python has minimized code complexities programmer don't need to spent time to map codes instead think about the logic. 

But, combination of these two languages can be very much useful. That's why most of the people looking for a better combination of these two languages.(Projects did for combining python and java) .

According to my opinion any programming language achieve its maximum performance when it has its own style rather than combining another to it. So i intended to use that as a principle when i'm doing this experiment (I didn't do any research about the others projects and architect that they used.)   

I mainly target this for the Windows platform.But with a very simple modification this can be used in either Linux or MAC  platforms. 

I used following abstract algorithm to combine the two parts of the application. 

Java part of the application, made request to CMD to run a special python file and get the output of the python application in to the CMD. CMD execute the command and take the output that given by the python script. then Java application takes that output in to it self.

Full project file of the experiment can be downloaded from here

Monday, January 20, 2014

Simple mouse event simulator with python

This is a simple python script that simulates mouse clicks. This script can do click,double click and multi-click operations of both right and left mouse buttons. I used python win32api (which can download from here) for develop this script.


import win32api, win32con, time 

def left_click(x,y):
 win32api.SetCursorPos((x,y))#set position to given 
 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)#push the left mouse button
 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)#relese the left mouse button


def right_click(x,y):
 win32api.SetCursorPos((x,y))#set position
 win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)#push the right mouse button
 win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)#relese the right mouse button

def multiple_click(x,y,times,left):#run the clicks
 if(left):#if left mouse button need to be clicked
  for _ in range(times):#clicke n timese where n =times
   left_click(x,y)#call function left_click
   time.sleep(0.1)#delay between each click
 elif(not left):#if right mouse button need to be clicked
  for _ in range(times):#click n times where n =times
   right_click(x,y)#call right_click event
   time.sleep(0.1)#delay between each click

#call functions for double click left mouse button where x= 10 and y = 10
multiple_click(10,10,2,True)
#call function for right click where x = 10 and y = 10
#multiple_click(10,10,1,False)

Sunday, January 5, 2014

Python 2.7 module Triangle appraiser version 1.0


“Triangle Appraiser”  module helps programmers to  manipulate triangles  by  illustrate  the  mathematical values with minimum effort meanwhile enhance those  values  with approximations and assumptions generating using fuzzy logic.

Since this is a big project i suppose to publish this project as several parts. This is the first part of it . You can download the relevant module (1st part) from the following link.

 

Download Triangle appraiser version 1.0 (Part 01- calculation helper)

Documentation related to above part is shown bellow 

Download PDF