Tuesday, December 20, 2011

Getting Combinations in c++

we had programming exercise and I needed to put a function to return K combinations from N numbers starting from 1
So for example of N = 10, K = 3
I would have combinations starting from
1,2,3 - 1,2,4 – 1,2,5 – 1,2,6 – … and so on  till 8,9,10
I found some function to do this in c# here
http://stackoverflow.com/questions/548402/list-all-possible-combinations-of-k-integers-between-1-n-n-choose-k
I took the same algorithm and wrote it in c++ using vectors
below is the 2 functions I used, getCombinations will return the combinations vector
vector<vector<int> > getCombinations(int n, int k)
{
    // define variales
    vector<vector<int> > combincations;
    vector<int> row;
    for(int i=0;i<k; i++)
    {
        row.push_back(0);
    }
    row[0] = 1;
    // call the iterate function
    iterate(0,combincations,row,n,k);
    return combincations;
}
void iterate(int i, vector<vector<int> > &c, vector<int> &row, int n, int k )
{
    /// i represents the current index in the row vector that is used to fill the c matrix with combinations
    // set the i term to previous term +1
    if(i>0)
    {
        row[i] = row[i-1] +1;
    }
    //for loop to increment the current cell in the row till it reachs n-k+i+1
    // we are using n-k+i because we want to reach different values depending on the index
    // for example in N = 10, k = 3, first cell will increase till 8, second till 9, third till 10
    // so the last combination is 8,9,10
    for(;row[i] <= (n - k + i + 1);row[i]++)
    {
        // if this is not the last index, call iterate with next index
        // else fill in the combinations matrix
        if (i < k - 1)
        {
            iterate(i + 1, c, row, n, k);
        }
        else
        {
            vector<int> combination = row; //copying the row content
            c.push_back(combination); // adding the row to combinations vector
        }
    }
}

Wednesday, December 7, 2011

testlink: setting up MySQL Daily backup job

We wanted to keep our data safe, so we started taking backups using phpmyadmin, and because of forgetting sometimes, we thought of automating the backup

After doing some search, using the information from this page http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

I created a batch file, called DailyBackup.bat for example

and wrote the below in the batch file

@ECHO OFF
for /f "tokens=1-4 delims=/ " %%a in ('date/t') do (
set dw=%%a
set mm=%%b
set dd=%%c
set yy=%%d
)

SET bkupdir="path to backup folder"
SET mysqldir="C:\Program Files (x86)\EasyPHP5.3.0\mysql"
SET dbname=testlink

SET dbuser=username

SET password=password

set zip="C:\Program Files (x86)\GnuWin32\bin\gzip.exe"
@ECHO Beginning backup of %dbname%...

%mysqldir%\bin\mysqldump -B %dbname% -u %dbuser% –p%password% | %zip% > %bkupdir%\dbBkup_%dbname%_%dd%%mm%%dw%.sql.gzip

The above batch file needs gzip to be installed

Then I created a scheduled task that runs daily and executes the above batch file

Monday, November 21, 2011

Upgrading testlink, changed test case formatting in exported document when exporting test cases

We had testlink 1.8.4 and we upgraded to 1.9.3, one of the differences we noted is that 1.9.3 test cases now have steps and when doing export for test cases, the test cases in the exported document looked different that we had exported before. we already exported one document with all test cases from 1.8.4 and did lots of changes. and we wanted to have 1.9.3 exported test cases looks the same

I started looking into the code, and found it in file \lib\functions\print.inc.php

    if ($tcInfo[$key] != '')
    {
        $code .= '<tr>' .
                 '<td><span class="label">' . $labels['step_number'] .':</span></td>' .
                 '<td><span class="label">' . $labels['step_actions'] .':</span></td>' .
                 '<td><span class="label">' . $labels['expected_results'] .':</span></td></tr>';
       
        $loop2do = count($tcInfo[$key]);
        for($ydx=0 ; $ydx < $loop2do; $ydx++)
        {
            $code .= '<tr>' .
                     '<td width="5">' .  $tcInfo[$key][$ydx]['step_number'] . '</td>' .
                     '<td>' .  $tcInfo[$key][$ydx]['actions'] . '</td>' .
                     '<td>' .  $tcInfo[$key][$ydx]['expected_results'] . '</td>' .
                     '</tr>';
        }

 

The above code created a table with a column for step number, column for step actions, column for step results, then there is a loop to create rows for each step. We wanted to get ride of step number column and have just one row for with one cell for step details, and another row for expected results, I have changed the code to be like below

    if ($tcInfo[$key] != '')
    {
        $loop2do = count($tcInfo[$key]);
        for($ydx=0 ; $ydx < $loop2do; $ydx++)
        {
            $code .= '<tr><td colspan="' .  $cfg['tableColspan'] . '"><span class="label">' . $labels['step_actions'] . ':</span><br />' .   $tcInfo[$key][$ydx]['actions'] . '</td></tr>' .
                     '<tr><td colspan="' .  $cfg['tableColspan'] . '"><span class="label">' . $labels['expected_results'] . ':</span><br />' .  $tcInfo[$key][$ydx]['expected_results'] . '</td></tr>';
        }

    }

This worked out great, now it looks exactly like test cases we had before

Testlink: Timeout Exception in reports after setting up integration with Bug tracking system

We are using testlink and already did setup for integration with bug tracking system that we are using, trac. While doing testing after this step we found out that some reports are not working and it is giving timeout exception

after digging into the code looking for why this is happening, I found out that there is some loop that is calling the bug tracking system for each bug attached to test case.

The function that is called to get the bug is called get_bugs_for_exec, found in exec.inc.php file

This function is not causing any problem when opening the test cases, it is listing the bugs and getting the bug data from bug tracking system without any problems

To workaround the error I am getting in the reports, I have created another function called get_bugs_for_exec_reports with the same implementation but instead of calling the bug interface to get bug details, I just commented this part and only displayed the bug number, this will be enough for the reports, then in reports files, I changed instead of calling get_bugs_for_exec, I am calling get_bugs_for_exec_reports

files where I have done this change

\lib\functions\results.class.php

\lib\results\resultsByStatus.php

\lib\results\resultsBugs.php

Function:

function get_bugs_for_exec_report(&$db,&$bug_interface,$execution_id)
{
    $tables['execution_bugs'] = DB_TABLE_PREFIX . 'execution_bugs';
    $tables['executions'] = DB_TABLE_PREFIX . 'executions';
    $tables['builds'] = DB_TABLE_PREFIX . 'builds';
   
    $bug_list=array();
    $sql = "SELECT execution_id,bug_id,builds.name AS build_name " .
        "FROM {$tables['execution_bugs']}, {$tables['executions']} executions, " .
        " {$tables['builds']} builds ".
        "WHERE execution_id={$execution_id} " .
        "AND   execution_id=executions.id " .
        "AND   executions.build_id=builds.id " .
        "ORDER BY builds.name,bug_id";
    $map = $db->get_recordset($sql);
   
    // BUGID 3440 - added is_object() check
    if( !is_null($map) && is_object($bug_interface))
    {     
        foreach($map as $elem)
        {
            $bug_list[$elem['bug_id']]['link_to_bts'] = $elem['bug_id'];#$bug_interface->buildViewBugLink($elem['bug_id'],GET_BUG_SUMMARY);
            $bug_list[$elem['bug_id']]['build_name'] = $elem['build_name'];
        }
    }   
    return($bug_list);
}

Wednesday, November 16, 2011

Disabling Symantec endpoint protection, Fixing copying to external drives problem

lately Symantec endpoint protection was installed in our company, it worked fine for my colleagues, but for me I wasn’t able to copy anything to external devices
so I started looking on how to disable it
I have tried lots of solutions and all didn't work
I tried normal uninstall, it required admin credentials, and the IT admin was on vacation ;)
I have tried Clean Whip tool, it didn’t uninstall endoint
I have tried disabling the services, I remember the services names, EAFRCliManager, Removel Storage Mgmt Service, Removal storage service
all methods didn’t work
Finally I started looking into the registry trying to find anything related
I was looking for hidden start up services and I found 2 services, named GeFilter, Geprotection
I have tried to change the startup type for these services, I wasn’t able to. I wasn’t able to do any changes for these services, I have tried lots of tricks to have full control over this keys to change them, none has worked.
I have noticed there is a key inside of them that is named VolumeInformation{SomeGuid}, I started looking with this Guid, and appeared that this guid is for my C drive
I wasn’t able to rename any of the keys before, but after my changes to have full control, I was able to, so I have renamed this key, removing the Guid part. then I restarted my PC
After restart still I wasn’t able to change values inside these services keys, also unable to delete. since I was able to rename, I tried renaming the services name, I was able to. after renaming, I tried deleting, I was able to
Finally I deleted both services, I look for other locations for the 2 words, GeFilter, GeProtection, deleted them all
Then I restarted my PC one more time, and voila, I was able to copy to external hard drives
To have full control over registry keys you can find more details here
http://www.mydigitallife.info/grant-read-write-full-control-permissions-on-registry-keys-fix-cannot-import-and-access-denied-error-in-regedit/

Thursday, November 3, 2011

trac - installing XMLRPC plugin required for testlink integration

In order for testlink to work with trac, we must install the xmrpc plugin for testlink
To install this plugin

1- Follow the download instructions download the plugin from http://trac-hacks.org/wiki/XmlRpcPlugin
2- Open the command line, go to python directory\scripts
3- Run the command

$ easy_install -Z -U /path/to/unpacked/download/version 

I used the path to the trunc folder inside the downloaded plugin

4- Search for trac.ini files and update with the below

[components] 
tracrpc.* = enabled 

5- Test the install by visiting http://server-name/trac/project-name/xmlrpc, you should see a wiki page with the protocol usage with trac

Thursday, October 27, 2011

Testlink–trac integration

We are using testlink for test case management, and using trac for bug tracking, we were looking for integration between the 2 tools.
I found out there is built in support for different bug tracking tool in testlink, all we need to do is just to enable this integration
The integration work like the following, you can link any execution of test case to one or more bugs, and when viewing these tese cases it will show the bug id, bug status, bug summary. Also when displaying reports, same bug information is displayed
To enable the integration:
1- Go to testlink directory, open the file
2- Look for the line:  $g_interface_bugs = 'NO';
3- Change to $g_interface_bugs = 'TRAC';
4- Save and close
To setup the integration with trac
1- Go to cfg folder
2- open the file trac.cfg.php
3- Update the setting with your trac url
define('BUG_TRACK_DB_HOST', 'http://hostURL/trac/');
4- update the mapping between testlink project and trac project
$g_interface_bugs_project_name_mapping = array(
    'testlink project name' => 'trac project name'
5- Save and close

Wednesday, June 1, 2011

CRM4: inserting data field from custom field in related entity depending on the contact language

We faced a situation where we had some data fields in a phone call template, but we wanted to use custom field for this data field depending on the language of the contact, also we had some picklist that is always coming in the user context language, and we wanted it to depend on the contact language
To solve this, I have updated the template with some text pattern for each field, for the picklist and the custom fields, then I have created a plugin for the phone call, with the below steps
1- Get the contact language
2- Get the custom field depending on the language
3- Get the localized picklist label for the language
4- Search the phone call description for patterns, and replace with the localized value
5- Update the phone call with the new description
To get the localized lookup label I used the metadata service to get all pick list values, then compared each picklist option with the value and the language
                        Option[] deptOptions = RetrieveEntityPicklistValues(metaService, EntityName.incident.ToString(), _attCaseInternalStatus);
                        foreach (Option option in deptOptions)
                        {
                            if (option.Value.Value == (int)internalStatus)
                            {
                                foreach (LocLabel label in option.Label.LocLabels)
                                {
                                    if (label.LanguageCode.Value == languageCode)
                                    {
                                        newCaseInternalStatus = label.Label;
                                        break;
                                    }
                                }
                                break;

                            }
                        }


        public Option[] RetrieveEntityPicklistValues(IMetadataService metaService, string strEntityType, string pickListName)
        {
            try
            {
                RetrieveAttributeRequest request = new RetrieveAttributeRequest();
                request.EntityLogicalName = strEntityType;
                request.RetrieveAsIfPublished = true;
                request.LogicalName = pickListName;

                RetrieveAttributeResponse response = (RetrieveAttributeResponse)metaService.Execute(request);
                AttributeMetadata retreivedAttributeMetadata = response.AttributeMetadata;
                if (retreivedAttributeMetadata is PicklistAttributeMetadata)
                {
                    return ((PicklistAttributeMetadata)retreivedAttributeMetadata).Options;
                }
            }
            catch (Exception eGlobalException)
            {
                throw;
            }
            return null;
        }


Same concept can be applied with any template, a more generic solution could be developed by creating a plugin on template retrieval that replaces the values for any retrieved template

Monday, May 23, 2011

Viewstate is not maintained in iframe inside MS CRM form

We had a page that is hosted inside CRM form, the page contains list with a checkboxes beside each each row. When clicking apply, certain action should be performed on the selected items. things are working fine on the development machine, but when hosting inside the CRM form, when clicking “apply”, the action wasn’t applied on the selected items, we discovered later that the code that loops over the checked items, doesn’t run as if there is no records checked.

Doing some search I found that CRM web.config by default has the following line

enableViewState="false" i.e. by default Viewstate is not enabled in CRM.

Changing this to enableViewState="true" and restarting IIS, every thing worked fine and actions were applied successfully.

There is another option which is to enable this in the page directives like the following

<%@ Page Language="C#" ... EnableViewState="true" %>

Viewstate is not maintained in iframe inside MS CRM form

We had a page that is hosted inside CRM form, the page contains list with a checkboxes beside each each row. When clicking apply, certain action should be performed on the selected items. things are working fine on the development machine, but when hosting inside the CRM form, when clicking “apply”, the action wasn’t applied on the selected items, we discovered later that the code that loops over the checked items, doesn’t run as if there is no records checked.
Doing some search I found that CRM web.config by default has the following line
enableViewState="false" i.e. by default Viewstate is not enabled in CRM.
Changing this to enableViewState="true" and restarting IIS, every thing worked fine and actions were applied successfully.
There is another option which is to enable this in the page directives like the following
<%@ Page Language="C#" ... EnableViewState="true" %>

Allowing concurrent user terminal sessions on windows 2008

We had a server running windows 2008, we were several persons working on the same machine at the same time, we all were using one user credentials. Each time one of us was connecting remotely to the server, it was disconnecting the other person who was working at that time, so only 1 session was allowed per user on the server

I was looking for the option to enable multiple sessions per user, doing some search, finally i found it

Click on start
Type "Remote desktop session host configuration" and hit enter
You will find an option on the screen that says "Restrict each user to a single session"

Double click that option, and uncheck this option and click OK



Then you will be able to connect several users remotely to windows 2008 using the same user credentials

Thursday, April 28, 2011

Modifying non customizable entities in CRM 4.0

We wanted to add extra columns for the Queues view, while the Queue item is not customizable entity we found a way posted in several blogs, by modifying the "isCustomizable" setting from the DB directly with the below statement

UPDATE Entity
SET ISCUSTOMIZABLE = 1
WHERE NAME = 'queueitem'

After doing this, we were able to open the Queue Item entity and modify the View, we added more columns, then with javascript we modified the values for this columns.

It is very important to change back the settings as it was after finishing the modification by running the same script again and setting it back to 0


UPDATE Entity
SET ISCUSTOMIZABLE = 0
WHERE NAME = 'queueitem'




Monday, March 7, 2011

Escaping single quote in server side script in asp page

We had a javascript function that was using server side property like the following,

<a href="#" onclick="MyFunction('<%=SomeProperty %>')">Link</a>

When "SomeProperty" contains single quote "'" this was causing script errors in the page.




To solve this error, just add the following after SomeProperty

.ToString().Replace("'","\\'").Replace("\"","&quot;")

so that it will look like this at the end

<a href="#" onclick="MyFunction('<%=SomeProperty.ToString().Replace("'","\\'").Replace("\"","&quot;") %>')">Link</a>

This will solve the problem


Note: when i tried to do this from the code behind, replacing the quote, it didn't working