Archive for June, 2010

Unit testing with web services

June 17, 2010

I’m currently using visual studio 2008 unit testing to develop a class library, and into the library I put one of my classes that calls a web service. So I added a service reference to the class library.

But when I tried to test something that intantated the web service client, I kept getting weird errors as I ran the unit test.

It turns out that when I copied the app.config from the class library that included the web service definitions into the app.config of the unit testing project, the error went away. I’m not sure why the debugging project needs to have the service definitions.

WPF databinding

June 16, 2010

ok, so I never got the databinding to work quite right between my listbox and the various add,update,delete operations I was doing with Linq to SQL.

However, I did get it all to look good, with the listbox getting updated, and this is how I did it.

The magic function was: GetNewBindingList called from my linq table object.

Somehow it feels like the linq to sql class should inform the listbox that it needs to refresh and there should be some magic setting, but for the time being:
XAML extract:

set the datasource in the window:
<Window x:Class="HomerV3_Queries.Window_Queries"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
bind to it at the listbox. "Queries" is the table I'm binding to.:
ItemsSource="{Binding Path=Queries,UpdateSourceTrigger=PropertyChanged}"

C# code called after every database change – note the commented out stuff that does not work:

void PageRefresh()
{
//_context.SubmitChanges();

//_context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, _context.Queries);
//lbQueries.UpdateLayout();
//lbQueries.ItemsSource = null;
//lbQueries.Items.Clear();
lbQueries.ItemsSource = _context.Queries.GetNewBindingList();
//lbQueries.Refresh();
lbQueries.SelectedIndex = -1;
txtQuery.Text = "";
txtTitle.Text = "";
}

sharepoint 2010 just installed

June 9, 2010

why should I feel such a sense of triumph at finally getting this to work on my windows 7 laptop? Probably I had made some mistakes along the way – notably when I installed sql server enterprise on top of developer, and then applied the wrong file for the service pack 1 for about a week.

I think it was a little weird that installing the identity framework did not work, but installing Geneva did (I had never previously installed Geneva, so perhaps the identity service pack wasn’t doing anything for me).

The best resource (in addition to the msdn doc on how to install 2010) is probably the Rehman Gul blog post titled “Sharepoint 2010 Configuration Wizard Errors on Windows 7”.

change page url

June 4, 2010

ok, what I learned was that you can’t change the page url using the httpcontext.current.request.rewritePath function. But, to achieve that effect, I did the following:

Protected Sub ddlListRecentErrorSessions_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlListRecentErrorSessions.SelectedIndexChanged
Dim sSession As String = Me.ddlListRecentErrorSessions.SelectedValue
set_url_for_session(sSession)
'handle_load_gridview_for_session(Me.gvResult, sSession)
End Sub

'http://forums.asp.net/p/1315610/2601836.aspx
'Using Context.RewritePath is not for changing how the URL is displayed
'in the browser. Let's be very, very clear.
'You cannot change what is displayed in the browser address bar.
Sub set_url_for_session(ByVal sSession As String)
' change the url to use our session
Dim sPath As String = HttpContext.Current.Request.Path
Dim sQuery As String = "?session=" + sSession
Diagnostics.Debug.Print("set_url SESSION=" + sSession)
Dim sFullPath As String = sPath + sQuery
Response.Redirect(sFullPath, True)
Response.End()
'HttpContext.Current.RewritePath(sPath, True, sQuery)
End Sub

top scroll bar

June 4, 2010

take a look at this guy’s site:

// http://www.autofusion.com/development/jwsinv/v0.3/compare_divs.html

wow – I had a bunch of logging data in a datagrid and since it was larger than my page, I had to scroll to the bottom and scroll to the right continuously. Finally my co-worker wondered if we couldn’t put a scroll bar at the top.

Here’s how it works:

1) suppose you have a div with a horizontal scroll bar at the bottom

2) add another div above it with auto scroll on. (make it not too tall so you don’t see the vertical scroll bar) Put another div inside this one – this div will represent the content and will cause the overflow to fire.

3) the javascript function that wires all this up connects the “scroll” events from each scroll bar so that when one is scrolled, the other’s scroll event also gets fired

Here’s the javascript I’m using:

// http://www.autofusion.com/development/jwsinv/v0.3/compare_divs.html
(function() {

var initDualScrollBar = function() {
var oScrollGrid = document.getElementById("ScrollGrid");
var otop_ScrollGrid = document.getElementById("top_ScrollGrid");

var gvWidth = $("#gvResult").width();
if (gvWidth == null) gvWidth = 100;
var divWidth = $("#ScrollGrid").width();
if (divWidth > gvWidth) gvWidth = divWidth;
$("#fakeInteriorGrid").width(gvWidth); // keep the widths the same in two scroll bars

// parallel the scroll events
addEvent(oScrollGrid, "scroll", function(e) {
otop_ScrollGrid.scrollLeft = oScrollGrid.scrollLeft;
});
addEvent(otop_ScrollGrid, "scroll", function(e) {
oScrollGrid.scrollLeft = otop_ScrollGrid.scrollLeft;
});
}

initDualScrollBar();

})();

// *************************************************************************************
// http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
// addEventListener not supported by IE
// these functions used in tstDataInspector to achieve the dual-scrollbar effect
function addEvent( obj, type, fn )
{
if (obj.addEventListener)
obj.addEventListener( type, fn, false );
else if (obj.attachEvent)
{
obj["e"+type+fn] = fn;
obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
obj.attachEvent( "on"+type, obj[type+fn] );
}
}

function removeEvent( obj, type, fn )
{
if (obj.removeEventListener)
obj.removeEventListener( type, fn, false );
else if (obj.detachEvent)
{
obj.detachEvent( "on"+type, obj[type+fn] );
obj[type+fn] = null;
obj["e"+type+fn] = null;
}
}
// *************************************************************************************