Oct
15

Broken project reference

by Dan Gershony

We had a very severe problem recently on our BizTalk environments when building the solution some of the projects lose the reference to other projects in the solution.

We are using BizTalk 2009 Visual studio 2008 SP1 on Windows Server 2008 (SQL Server 2008  though i don't think this has anything to do with the problem)

The references are lost randomly, one moment the solution compiles, or for that mater even when just building a single project, and after a small change (that does not generate an error) the next build VS looses references and can not recognise external components and thus build will fail.

We worked around using file reference and not project reference which seems to respond better but still generates build errors on occasion because of reference loss. 

Another detail which is probably worth mentioning is all BizTalk environments are on VPC’s, don't think this should matter.

 

Searching around we found that this problem was recently raised to Microsoft.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

BizTalk

Oct
15

Raise an error in a Stored procedure

by Dan Gershony

How to raise an error on an SP and catch the exception in code

Some times, especially when working in a transactional environment,  we wound need to raise an exception from our SQL server Stored Procedure deliberately and catch this exception, for example, in a c# application within a try catch block in order to Roll Back the changes.

This is common behaviour when having the .NET code manage the transaction logic, when the code will call several Stored Procedures and the Roll Back is coordinated in code.

so our call to the DB will look something like this:

using (SqlDB db = new SqlDB(BusinessLogic.Constants.ConnectString))
{
     try
     {
    SqlParameter p;
    SqlCommand cmd;
         using (cmd = new SqlCommand("usp_MyUsp", db.Connection, db.Transaction))
         {
              p = new SqlParameter("@id", SqlDbType.NVarChar, 50); p.Value = data.id; cmd.Parameters.Add(p);
              p = new SqlParameter("@data1", SqlDbType.NVarChar, 40); p.Value = data.data1; cmd.Parameters.Add(p);
              p = new SqlParameter("@data1", SqlDbType.Int); p.Value = data.data1; cmd.Parameters.Add(p);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.ExecuteReader()
         }
    db.Commit();
     }
     catch (Exception ex)
     {
         db.Rollback();
     }
}

To raise an error in the SP that will be caught in the catch block we need to call the SQL server method RAISERROR() and immediately return a value. the Stored Procedure to raise the error would look something like this:

 
  DECLARE @DocID int;
  --find the id
  SELECT @DocID = id FROM table WHERE id = @id
    
  --if not exist send back an error       
  IF @DocID is null  
  BEGIN
      RAISERROR('ID not Found', 16, 1)
      RETURN -1
  END
 

note: concatenating the error message might create an error.

This example is very general, the two numbered parameters passed in to the method in this case (16 ,1) represent the severity and status of the raised error.

for more detailed information you can read it on the MSDN pages. http://msdn.microsoft.com/en-us/library/ms178592.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL Server

Oct
15

Debug XSLT Error

by Dan Gershony

Lately I came across an annoying bug when debugging a map in the BizTalk map editor.

I used the Database Lookup Functoid testing the map, using the test map option worked fine.

Taking advantage of this new cool feature provided with BizTalk 2009 to debug the map, when the execution point reached the Database Lookup Functoid the debug step in produced this un unclear error.

Cannot find the script or external object that implements prefix 'http://schemas.microsoft.com/BizTalk/2003/ScriptNS0'.

in the debug trace output the following error showed:

 

XslTransformException
---------------------
Cannot find the script or external object that implements prefix 'http://schemas.microsoft.com/BizTalk/2003/ScriptNS0'.

Not sure about why or how this exception happened.

I started to debug the map (rather then test it first) only to find out some several long hours later that the map was in fact valid, hope this post will save some frustrated BT developer precious time.

Currently rated 2.0 by 2 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

BizTalk

Mar
12

set the Tab Key in Infragistics UltraTabWorkspace

by Dan Gershony

In the Infragistics.Practices.CompositeUI.WinForms.UltraTabWorkspace workspace.
one of the projects i worked on we needed to have the Tab item key property set with a unique key, unfortunately the key property is not set when the tab is created(actually it was never set and always resolved to be null).

first of all create a custom SmartPartInfo that will hold an extra property TabKey.

public class CustomTabSmartPartInfo : Infragistics.Practices.CompositeUI.WinForms.UltraTabSmartPartInfo
{
    private string _TabKey;
    public string TabKey
    {
        get { return _TabKey; }
        set { _TabKey = value; }
    }
}

next inherit from the UltraTabWorkspace control and override two methods that will help set the key “manually”.

/// <summary>
/// inherited UltraTabWorkspace object in order to get access to the override methods
/// </summary>
/// <remarks>the reason is to set the TabKey property when the a workItem is created</remarks>
public class CustomUltraTabWorkspace : Infragistics.Practices.CompositeUI.WinForms.UltraTabWorkspace
{
    private string addTabKey;

    protected override void OnShow(System.Windows.Forms.Control smartPart, Infragistics.Practices.CompositeUI.WinForms.UltraTabSmartPartInfo smartPartInfo)
    {
        if ((smartPartInfo) is CustomTabSmartPartInfo)
        {
            if (Strings.Len(((CustomTabSmartPartInfo)smartPartInfo).TabKey) > 0)
            {
                addTabKey = ((CustomTabSmartPartInfo)smartPartInfo).TabKey;
            }
        }
        base.OnShow(smartPart, smartPartInfo);
        addTabKey = string.Empty;
    }

    protected override void OnControlAdded(System.Windows.Forms.ControlEventArgs e)
    {
        base.OnControlAdded(e);
        if (Strings.Len(addTabKey) > 0)
        {
            if ((e.Control) is Infragistics.Win.UltraWinTabControl.UltraTabPageControl)
            {
                ((Infragistics.Win.UltraWinTabControl.UltraTabPageControl)e.Control).Tab.Key = addTabKey;
            }
        }
    }
}

when OnShow() is called for the first time OnControlAdded() will be called as well, this is the point to set the Tab Key which is extracted from the Custom smartPartInfo created earlier.

CustomTabSmartPartInfo spi = new CustomTabSmartPartInfo();

spi.Title = tabText;
spi.TabKey = mSessionId + mName + ":" + viewId; ;
spi.ActivateTab = activateTab;

MyWorkspace.Show(thisView, spi);

 

All set the Tab’s Key property is populated and we have control over the content of the key, in my case it had to reflect the active session and the view id.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Win Forms | C# and .NET

Mar
06

balls bouncing and colliding on the screen

by Dan Gershony

Just a small graphical application i made in my free time.
The program has a ball form which is called in a loop from the void main method.

We catch the paint event which is where the ball is drawn:

private void BallForm_Paint(object sender, PaintEventArgs e)
{
    Width = Convert.ToInt32(radios * 2); //24;
    Height = Convert.ToInt32(radios * 2); //24;
    
    Graphics g = e.Graphics;
    g.Clear(Color.Cyan);
    g.FillPie(new SolidBrush(col), 0, 0, Width - 1, Height - 1, 0, 360);
    g.DrawArc(new Pen(Color.Black,2), 0, 0, Width - 1, Height - 1, 0, 360);
}

Gravity:
the balls are under the force of gravity there for always pulled down, to get this effect every tick  the Y vector decreased in just a bit which simulated gravity and can be modified to have a stronger gravitational pull if increased

double gravity = 0.1;
moveY += gravity;

also the X vector is changed to simulate fraction
moveX *= 0.75;

Collision:
balls that collide with one each other are calculated to bounce away in the opposite direction of the impact, in this case some physics is needed to calculate the direction of 2 collisions using the radios of the circles equation to find if one ball entered another balls radios space  

double distIn = Math.Sqrt(Math.Pow((int)x1 - (int)x2, 2) + Math.Pow((int)y1 - (int)y2, 2));
m = (y2 - y1) / (x2 - x1);
double b = y1 - (m * x1);

and the velocity of the ball which absorbs the velocity from the ball it collided with
double difX = Math.Abs(oBall.moveX - moveX);
double difY = Math.Abs(oBall.moveY - moveY);

if right clicking on a ball a small menu will open and allow some functionality like make it bounce again(which will any way happen when the ball stops movement) the tricky part is to catch the right click event exactly when the pointer is over the ball good luck :)

here is the source code:

Visual studio 2005: BouncingBall-SRC.zip

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Gaming

Powered by BlogEngine.NET 1.4.5.0
Dan Gershony Tsabar Blog