Could not load file or assembly 'NHibernate, Version=2.1.0.4000

by sunil ravulapalli /16. June 2010 20:43 /.net-tools /Comments (0)

I got this error when I was trying out Linq to NHibernate.

Looks like I was using an older version of NHibernate.Linq.dll(1.0) with NHibernate.dll (2.1.2.4000).
So I downloaded NHibernate.Linq.dll version 1.1.0.1001, removed my old NHibernate.Linq.dll reference and added this to make my application work.
To get that dll, search for NHibernate.Linq-2.1.2-GA-Bin.zip and extract it using WinRar( WinZip did not work) if you are having similar problems.

NHibernate.MappingException : No persister for

by sunil ravulapalli /16. June 2010 19:57 /.net-tools /Comments (0)
I got this error when I was adding new functionality to my "Teach myself NHibernate" application.
I binged, googled for several hours....
Some of popular suggestions include, setting the xml file as an "Embedded resource", checking for typos, making the classes public, but those were not my problems. Most of them solved their problem easily by fixing one of those things. But my problem wasn't that simple or so I thought.
 
I tried everything under the sun and finally it came to me that I named my file PRODUCT.XML instead of PRODUCT.HBM.XML.
 
 

PL/SQL ROLLBACK WITHIN A LOOP GOTCHA

by sunil ravulapalli /14. June 2010 16:57 /oracle /Comments (0)
PROCEDURE DUMMY_PROC( x OUT NUMBER )
IS

CURSOR a_cursor IS
SELECT a  FROM TABLE_A;

a_record a_cursor%ROWTYPE;

BEGIN

OPEN a_cursor;
LOOP
FETCH a_cursor INTO a_record;
EXIT WHEN a_cursor%NOTFOUND;
BEGIN

update TABLE_B;
update TABLE_C; -- MAY CAUSE EXCEPTION

COMMIT;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;

END;
END LOOP;
CLOSE a_cursor;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;

END DUMMY_PROC;

The intention of this procedure is to read TABLE_A row by row and update TABLE_B and TABLE_C based on the values in TABLE_A. Line 4: Initially, TABLE_A contents are loaded into a_cursor. Line 11-14: Then we use a LOOP to iterate through it. Line 17-18: We update TABLE_B and TABLE_C. Line 20: We COMMIT to make changes permanent. Line 22-24: If we have an EXCEPTION, let's say on Line 18 while updating TABLE_C, the program jumps over the COMMIT to Line 22 and does a ROLLBACK on Line 24, restoring the contents of TABLE_B and the LOOP continues, goes back to Line 13 to read the next line in the CURSOR. At the outset, this seems ok, but the fact is that the ROLLBACK on Line 32 'kills' the cursor. So, when the program goes back to Line 13 to read the next row in the CURSOR, the program blows up, because it is trying to read something which isn't there. There are two ways to fix this. I am not sure which way is 'politically correct'. The first way is to just put COMMIT on Line 6 as show above. So, when we ROLLBACK, this COMMIT(Line 6) 'saves' the CURSOR.

PROCEDURE DUMMY_PROC( x OUT NUMBER )  
IS

CURSOR a_cursor IS
SELECT a  FROM A_TABLE;
COMMIT;--DEFENCE
a_record a_cursor%ROWTYPE;

BEGIN

OPEN a_cursor;
LOOP
FETCH a_cursor INTO a_record;
EXIT WHEN a_cursor%NOTFOUND;
BEGIN

update TABLE_B;
update TABLE_C; -- MAY CAUSE EXCEPTION

COMMIT;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;

END;
END LOOP;
CLOSE a_cursor;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;

END DUMMY_PROC;

The other way is to put a SAVEPOINT like in Line 16 and then ROLLBACK to only that point like in Line 24.

PROCEDURE DUMMY_PROC( x OUT NUMBER )  
IS

CURSOR a_cursor IS
SELECT a  FROM A_TABLE;

a_record a_cursor%ROWTYPE;

BEGIN

OPEN a_cursor;
LOOP
FETCH a_cursor INTO a_record;
EXIT WHEN a_cursor%NOTFOUND;
BEGIN
SAVEPOINT defense_point;
update TABLE_B;
update TABLE_C; -- MAY CAUSE EXCEPTION

COMMIT;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO defense_point;

END;
END LOOP;
CLOSE a_cursor;

EXCEPTION
WHEN OTHERS THEN
ROLLBACK;

END DUMMY_PROC;

NHibernate Configuration for Oracle using Microsoft Driver

by sunil ravulapalli /11. May 2010 23:11 /.net-tools /Comments (0)


NHibernate.Connection.DriverConnectionProvider

NHibernate.Dialect.Oracle9iDialect
NHibernate.Driver.OracleClientDriver

Data Source=x;User Id=xxx;Password=xxx;


NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

true



1. Take note of the "9i" in "dialect" property. 2. Add reference to System.Data.OracleClient in the .Net project.

How to use Form in Watin

by sunil ravulapalli /11. May 2010 23:08 /.net-tools /Comments (0)
Firefox fox = new Firefox("http://***********.com");
Form f = fox.Form(Find.ByName("MyForm"));
f.TextFields[0].TypeText("niko");
f.TextFields[1].TypeText("bellic");
f.Images[0].Click();

Windows Phone 7 Silverlight: How to move an image

by sunil ravulapalli /30. March 2010 04:17 /windows-phone /Comments (0)

To do this you will need a Canvas in the "ContentGrid" in the MainPage.xaml. Also make sure you have ManipulationStarted, ManipulationDelta activated on the content grid as show below.

 

In MainPage.xaml.cs,

public partial class MainPage : PhoneApplicationPage
{
    Image img;
    double startingPositionOfImageX;
    double startingPositionOfImageY;


    public MainPage()
    {
        InitializeComponent();

        SupportedOrientations = SupportedPageOrientation.Portrait | 
                SupportedPageOrientation.Landscape;

        img = new Image();

        img.Name = "myimg";
        //Size the Image
        img.Height = 80;
        img.Width = 80;

        //Place it top left
        img.HorizontalAlignment = HorizontalAlignment.Left;
        img.VerticalAlignment = VerticalAlignment.Top;

        //Point at the physical file
        Uri uri = new Uri("1.JPG", UriKind.Relative);
        ImageSource imgsource = new 
        System.Windows.Media.Imaging.BitmapImage(uri);

        //Set image property
        img.SetValue(Image.SourceProperty, imgsource);
        img.SetValue(Canvas.TopProperty, 100.0);
        img.SetValue(Canvas.LeftProperty, 100.0);

        canvas1.Children.Add(img);
    }

    private void ContentGrid_ManipulationStarted(object sender, 
                                           ManipulationStartedEventArgs e)
    {
        if (e.OriginalSource == img)
        {
            startingPositionOfImageX = 
            Convert.ToDouble(img.GetValue(Canvas.LeftProperty));
             
            startingPositionOfImageY =
            Convert.ToDouble(img.GetValue(Canvas.TopProperty));
        }
    }

    private void ContentGrid_ManipulationDelta(object sender, 
                                         ManipulationDeltaEventArgs e)
    {
        if (e.OriginalSource == img)
        {
            img.SetValue(Canvas.LeftProperty, 
            e.CumulativeManipulation.Translation.X + startingPositionOfImageX);
                
            img.SetValue(Canvas.TopProperty,
            e.CumulativeManipulation.Translation.Y + startingPositionOfImageY);
        }
    }

}

Windows Phone 7 Silverlight: How to place an image at a co-ordinate

by sunil ravulapalli /30. March 2010 03:30 /windows-phone /Comments (0)

To do this you will need a Canvas in the "ContentGrid" in the MainPage.xaml.

 

In MainPage.xaml.cs, set co-ordinates using img.SetValue(Canvas.TopProperty, 100.0) and img.SetValue(Canvas.LeftProperty, 100.0);

public MainPage()
{
       InitializeComponent();

       SupportedOrientations = SupportedPageOrientation.Portrait |
       SupportedPageOrientation.Landscape;

       Image img = new Image();

       //Size the Image
       img.Height = 80;
       img.Width = 80;

       //Point at the physical file
       Uri uri = new Uri("1.JPG", UriKind.Relative);
       ImageSource imgsource = new
       System.Windows.Media.Imaging.BitmapImage(uri);

       //Set image property
       img.SetValue(Image.SourceProperty, imgsource);

       //Set co-ordinates
       img.SetValue(Canvas.TopProperty, 100.0);
       img.SetValue(Canvas.LeftProperty, 100.0);

       canvas1.Children.Add(img);
}

Windows Phone 7 Silverlight: How to Load an Image using C#

by sunil ravulapalli /18. March 2010 03:39 /windows-phone /Comments (0)
public MainPage()
       {
           InitializeComponent();

           SupportedOrientations = SupportedPageOrientation.Portrait |
               SupportedPageOrientation.Landscape;

           Image img = new Image();

           //Size the Image
           img.Height = 80;
           img.Width = 80;

           //Place it top left
           img.HorizontalAlignment = HorizontalAlignment.Left;
           img.VerticalAlignment = VerticalAlignment.Top;

           //Point at the physical file
           Uri uri = new Uri("1.JPG", UriKind.Relative);
           ImageSource imgsource = new System.Windows.Media.Imaging.BitmapImage(uri);
          
           //Set image property
           img.SetValue(Image.SourceProperty, imgsource);
          
           //Add it to the main grid
           ContentGrid.Children.Add(img);

       }

Find the MainPage() function in the MainPage.xaml.cs and paste the code. Make sure there is image file in the project folder. When the windows emulator loads the image stretches to the entire screen. That is why you need to specify the Height and Width. We also need to specify the Horizontal and Vertical alignments, otherwise the image will appear in the center of the screen.

Never Ending Blast

by sunil ravulapalli /1. February 2010 19:35 /other /Comments (0)

Here's some Game play video of the game I created.



I owe a lot to Riemers.net. This where I learnt and ripped off some of the game functions and the
Explosion Image.
The small spaceship image is from this Alien Game

You can download:
Setup Download

(If you want to play unzip and double click setup.exe )
Code Download
(You will need Visual studio 2008 with XNA installed.)

jQuery - Prevent default hyperlink behaviour when the click event calls user defined function

by sunil ravulapalli /30. January 2009 17:19 /jquery /Comments (0)

This may be obvious to many, but I am stupid, so it took me a while to figure this out.

When we bind a click behavior like this:
$("#temp").click( function(){ onClick("hello"); } );
and you want to prevent default behaviour of the click using preventDefault() you have to do:
$("#temp").click( function(e){ onClick("hello"); e.preventDefault(); } );