Search This Blog

Tuesday, April 27, 2010

Get Outlook contacts using Javascript

function getOutLookContacts(){
//id contact in outlook Active X is 10
                            var Const_olFolderContacts = 10;
                            var objApp = new ActiveXObject('Outlook.Application');
                            var objNS = objApp.GetNamespace('MAPI');
                            var colContacts = objNS.GetDefaultFolder(Const_olFolderContacts).Items
                            var currentContact='';
                            var contacts='

';
                            contacts+='';
                            contacts+='';
                            for(var i=1;i<=colContacts.count;i++){
                                var v = colContacts.item(i);
                                contacts+='';
                                contacts+='
';
                                contacts+='';
                                contacts+='';
                            }
                            contacts+='
NameE-mailtd>
>'+v["FullName"]+''+v["Email1Address"]+'
';
                        
                            return contacts;
                        }


Feel free to ask Questions 

Sunday, April 11, 2010

PHPUnit and Selenium in NetBeans





Using PHPUnit


  1. phpunit –skeleton-test [class name] [yourfilename.php] (This will create a layout for test case with a class name you have given as a file named your filename suffixed “Test”)
  2. You can the file to check for results how may passed and how many failed
  3. We can add any number of cases for each function in the class as in the example below

Using Selenium IDE


  1. In tools we can find Selenium IDE item clicking that one open IDE in which we can find the button to record (Red color right corner button)
  2. Click record button minimize the popup
  3. Perform the action which you want to test
  4. After completion of actions we can see the test case filled with the script for testing on table tab
  5. We can run the full test case once to check for the output at the bottom log or even we can store the source for future use (don’t forget to change the format to PHP from options menu)
  6. Whenever you want to test just load the test case file from the folder and click the test icon (Green play button with stack )
  7. We can see the results in the log window
  8. We can also edit the test case in Selenium IDE or the code generated from it

Install Selenium


  1. pear install Testing_Selenium-0.4.3 (This will create a Testing folder in your pear directory which will have a php file for selenium)
  2. For Selenium we can use firefox Selenium IDE for creating test case (if we use this we can port test case in different languages which included php,html,java,c#, perl etc)
  3. http://release.seleniumhq.org/selenium-ide/1.0.6/selenium-ide-1.0.6.xpi
     (click this link from firefox and allow to install)

Install PhpUnit



  1. pear config-show (Check the configuration parameters are correct if not fix it by editing pear.ini file from your php folder)
  2. pear channel-discover pear.phpunit.de
  3. pear install phpunit/PHPUnit (it will ask for optional packages if we want we can use install pdo_sqlite ,image_graphviz etc)
  4. if everything goes file you will see a PHPUnit folder on your pear directory if not check for the errors in log file

Wednesday, April 7, 2010

Get Twitter updates using php

To get Twitter tweets using php 
syntax

curl_init(http://twitter.com/statuses/user_timeline/[user_name].xml)

    eg: http://twitter.com/statuses/user_timeline/gmsundar.xml
or
curl_init(http://twitter.com/statuses/user_timeline/[user_id].rss)
    eg: http://twitter.com/statuses/user_timeline/5794542.rss

Parse the xml and get the data

we can use the same method in any language

Using PHP and C to read data from client and send to server

Once i faced a problem like we have to connect the device(RS232 or serial port) to the client machine and we have to get the data from the client machine to the server when user performs an action like click of a button or blur from a control etc


As if we are using PHP,Apache on linux platform on server and windows for client machine and also the application in which i was trying to add this feature runs on browser 



So what i did is created a 'C' Program complied on different platforms, Program in the RS232 will send the data from the client to the server in particular time interval and the program on the Server will store the incoming data in a text file on the server when user performs action on the client then client request to the server for data and the server gives the data to the client (this is achieved using Ajax) then the data is shown in the desired field after user confirms that it is taken further (stored to database ) 

Data integrity is achieved using the time stamp comparison of data generated from the client and the request given time (time when user performs action)

One thing i want to clarify is while we run applications through browser its not allowed to access the system resources directly 

C program code hints 

Server Code:
sd = socket(AF_INET, SOCK_STREAM, 0);


   /* bind server port */
   servAddr.sin_family = AF_INET;
   servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
   servAddr.sin_port = htons(SERVER_PORT);


   if(bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr))<0) {
   }


   listen(sd,5);
.
.
.
cliLen = sizeof(cliAddr);
newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen); 
.
.
.



strftime(time_data,100," %d-%m-%Y %H:%M:%S ",timeinfo);
        fp=fopen("data4.txt","a");
         fputs(time_data,fp);
fputs(line,fp);
fclose(fp);

Client Code :



h = gethostbyname(HOST);
if(h!=NULL)
{
servAddr.sin_family = h->h_addrtype;
memcpy((char *) &servAddr.sin_addr.s_addr,
h->h_addr_list[0],h->h_length);
servAddr.sin_port = htons(SERVER_PORT);
sd = socket(AF_INET, SOCK_STREAM, 0);


/* bind any port number */
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
localAddr.sin_port = htons(0);


rc = bind(sd, (struct sockaddr *) &localAddr,
sizeof(localAddr));
rc = connect(sd, (struct sockaddr *) &servAddr,
sizeof(servAddr));
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
.
.

res = read(fd,buf,255);   
buf[res]=0;



rc = send(sd, buf, strlen(buf) + 1, 0);


.
.
close(sd);



Thursday, April 1, 2010

Installing ANT (Windows)

1. Download ANT
2. Unzip the zip file ( C:/ant)
3. Set ANT_HOME environment variable to the Ant location
(MyComputer -->Properties --> Advanced Tab --> Environment Variables --> Add --> Set New Variable Name as "ANT_HOME" and set New Variable Value as C:/ant)
4. Now set Path variable to point to your ANT bin directory
(User Variables for Administrator --> Click on Path variable --> Append the ANT bin location ,  %ANT_HOME%\bin)
5. Open a command prompt and type "ant" , In case of any failure try the below command and see the value for ANT_HOME
c:\echo %ANT_HOME%