Instant Eyedropper Rocks!

by dotnetpete 19. November 2008 17:13

I was working with a website the other day and I needed to know the background color of a TH row that was coming from an image. I tried unsuccessfully to use Paint and Paint.NET to get the RBG without success. 

Then I came across Instant Eyedropper. Awesome little tool that when activated allows you to move a cursor around the screen and it tells you the colour underneath the cursor. 

There probably was a way in either Paint or Paint.NET so I'd be interested to find out if there was.

Be the first to rate this post

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

Tags:

Strongly typed LINQ to XML with LINQ to XSD

by dotnetpete 7. November 2008 11:49

Got stuck into LINQ to XML the other week and I thought wouldn't it be great if this could be strongly typed somehow. Of course the MS XML Team were WAY ahead of me. You can find the article at their blog here.

It's only in preview Alpha 0.2 Refresh at this stage (here) so I'm a little hesitatent to install on my regular machine. What the heck, if you're not living on the edge, you're taking up too much room. Right?

Scott Hanselman also has some interesting thoughts on LINQ to Everything.

Be the first to rate this post

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

Tags:

LINQ

LINQPad a great tool for learning and trying out LINQ (to SQL)

by dotnetpete 6. November 2008 09:12

LINQ for us was a huge productivity improvement as we didn't have to generate stored procedures anymore for our CRUD database operations. Because we had a rule that ALL data access was via stored procedures, everytime we had a new processing operation or new search situation, we either had to adapt an exisitng stored procedure or create a new one. Then we had to create a method in our data layer to make the call to the stored procedure.

Now with LINQ we can create a new method in our data layer. Saves time and the generated SQL is not too bad. One thing going against LINQ is that it's very easy to start putting LINQ queries in your UI (aka inline SQL from the old days).

Learning LINQ is a challenge. More specifically doing things that come naturally in TSQL are challenging. I have found it quicker to create a few stored procedures to do some complex queries and call them through the data context.

Never fear LINQPad is here. Very similar to management studio you can connect to servers, run queries against databases. I have found it to be a great tool for learning LINQ.

Happy LINQing.

Be the first to rate this post

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

Tags:

LINQ

"Every .NET developer knows about the Hessian Project", claims Flex developer!

by dotnetpete 17. October 2008 17:03

We're working on a project now where there is a .NET WinForms client (for power users) communicating with a Java middle tier. For occasional and public users there is a Flex client. Because .NET clients cannot directly communicate with the Java middle tier (Spring Beans), the middle tier guys have created web services for our team to use.

When the Flex team came onboard and saw the web services, they said they could talk directly with Spring Beans via OpenAMF or Hessian project so there was no need for the web services layer. They also said that the .NET client could also use the Hessian project and that EVERY .NET developer knew about the Hessian project!

Anyone used the Hessian project? At this point I'm just interested hearing from people who've heard of it!

Interestingly I was at Bunnings looking at paint over the weekend and I saw a colour called Hessian. I wonder if all painters know about this colour! :) 

Be the first to rate this post

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

Tags:

Localised resource files in VS2008

by dotnetpete 10. October 2008 14:12

I'm looking into internationalisation for a project we're about to start. There are a few articles on how to localise label text etc on windows forms. But what about error messages that are displayed to the user.

I created a new resource file calles Messages.resx and this created a "code behind" CS file that allowed me to access each of the string resouces in the file. Cool so far. Once I had a few message texts in the resource file I copied it a few times to Messages.fr-FR.resx for France French, Mesages.fr.resx for default French, Messages.nb-NO.resx for Norwegian etc. Each of these resource files also had "code behind" CS files but they were empty. 

I set my UI culture before loading my form in my static void Main method like so:

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR"); 

And to my surprise when I called Messages.M001 (M001 was name of the message in the resource file), it would attempt to get the text for message M001 in my Mesages.fr-FR.resx file. How cool is that?

Also interesting if I set my UI culture to fr-BE it would try to receive the text from the Messages.fr.resx file as I didn't have a Belgium specific resource file.

Any advice or tips on how to handle internationalisation would be most appreciated too. 

Be the first to rate this post

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

Tags:

Internationalisation | Culture

SQL Management Studio 2008 - Connecting to a server where you are not sysadmin

by dotnetpete 8. October 2008 09:20

I came across a very annoying problem recently where I was using management studio to connect to a hosted SQL Server (2005) and I wasn't connecting as a  sysadmin as I didn't have access to all DBs on the server.

Under SQL Management Studio 2005 I could connect to the server and expand the databases node to see all databases. But under Studio 2008 when I tried to expand the databases node I got the following error:

After a bit of searching I found a fix for it here. The fix was to press F7 to view the object explorer and only have the name, date created, policy health and owner columns displayed. This fixed the issue but didn't tell me which column was initially causing the error.

After some trial and error, it turns out that the collation column causes the issue.
 
Glad to get that fixed as I was having to use Management Studio 2005 whenever I needed to connect to the hosted server. 

Be the first to rate this post

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

Tags:

SQL2008

Google maps and surrounding suburbs search

by dotnetpete 7. October 2008 09:09

Recently I found a wrapper around the google geocode API here. Which got me thinking about map coordinates of Australian suburbs and being able to do distance from or surrounding suburbs searches for starters.

One thing I found with using this wrapper is that I had to go to google and register for access to use the API (and I was issued a key to use with the wrapper). To register for the key I had to enter the URL that would be making calls to the Google API but I found that the calls worked either from a win forms app or an ASP.NET website both running locally (and in debug mode).

I then found a site that publish a CSV file (amoungst others) with all Australia post codes and their lats and longs here.

The only thing left was to find a routine that calculated the distance between 2 lat and longs. I have attached the SQL CLR user defined function source file to the bottom of this article. 

The only thing left was to create a SQL function that returned the results. Simply pass in the postode you are starting from and the distance you want to search from the postode. I group by postcode and get the max distance because in most instances there postcodes that cover multiple suburbs. This function retrieves the "distinct" list of souurounding suburbs.

I'm sure there can be improvements in my implementation.

CREATE FUNCTION [dbo].[SurroundingSuburbs]
(
@Postcode int,
@Distance float
)
RETURNS TABLE 
AS
RETURN 
(
SELECT
P2.Postcode,
MAX(dbo.GeoDistance(P1.Latitude,P1.Longitude,P2.Latitude,P2.Longitude, 'K')) AS 'Distance'
FROM 
Postcode P1, Postcode P2
WHERE 
P1.Postcode = @Postcode
AND P1.Latitude IS NOT NULL 
AND P2.Latitude IS NOT NULL
AND dbo.GeoDistance(P1.Latitude,P1.Longitude,P2.Latitude,P2.Longitude, 'K') < @Distance
GROUP BY
P2.Postcode

GeoDistance.cs (1.17 kb)

Be the first to rate this post

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

Tags:

SQL

Passing a parameter to the autocomplete extender service method

by dotnetpete 24. September 2008 17:26

This is something that I've been meaning to delve into for a while now. I've used the AjaxControlToolkit AutoCompleteExtender a bit but until now I have never had to pass a runtime parameter through to the service method.

I found a post saying that the signature of the method must be the following: 

[WebMethod] public string[] GetCountryOrStatesInfo(string prefixText, int count, string contextKey)

For some reason I took the signature part to mean parameters string, int, and string in that order. As it turns out the parameters must be named exactly prefixText, count and contextKey. You will also need UseContextKey="true" on the AutoCompleteExtender in your aspx as well.

In the example I was doing, the context key was state and on the selected index changed of a combo I was setting the context like this:

AutoCompleteExtender1.ContextKey = ddlState.SelectedValue; 

One other point of note, the web service class itself must be decorated with [System.Web.Script.Services.ScriptService].

Be the first to rate this post

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

Tags: ,

The lost art of testing and debugging

by dotnetpete 19. September 2008 22:19

I wonder if future archaeologists will look back on us and find traces of software developers actually doing testing and debugging. As small software house, we don't have the luxury of having dedicated testers but that shouldn't mean that testing or debugging thoroughly should be any less important that wirting code.

My (brief) set of rules for testing and debugging are:

  1. You can't test what you can't reproduce.
  2. You can't test if you do not know the expected result.
  3. During testing, put yourself in the shoes of your audience.
  4. Debugging a piece of code, you have to be smarter that the person who wrote it.
Let me explain.
 
A manager of mine early in my career once said to me, "You can fix what you can't reproduce". I used to think nonsense, I know exactly where the error is. I can fix the error, test the code (which by the way I know will work) and viola problem solved. Of course my manager was right. I was just proving (to myself) that I could write code that would compile and pass my limited set of tests. 
 
If you're testing an application that outputs a file to be consumed by another system, how can you test the output if you don't know what the expected result is. All you're really doing is testing that the application can output a file without generating an error. 
 
It's all too easy as developers to perform technical testing. The application I have just tested allows me to enter data and output a file for processing wonderfully and without error. What about the user experience? Are the steps required to get the output file the most logical and the easist for non technical people. Is it intuitive and clear enough for a user with limited training?

Saying that you have to be smarter to debug code that the person who wrote it sounds plain arrogant. But to fully understand what a piece of code is doing and most (if not all) the potential side effects of the code or external factors that could affect execution of the code is no walk in the park. You have to be top of your game. 

I'd be interested in hearing other thoughts that people have.

Be the first to rate this post

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

Tags: ,

General

Response.Write within an update panel

by dotnetpete 18. September 2008 16:18

Update panels are great. Once you use them once you will use them everywhere. Until you realise that they can be slower (or seem slower) than a regular full postback. I use popup panels quite a bit and I think you get more flow in your web apps because you don't have to change pages quite as much.

One thing that's been bugging me with update panels though is the fact that I couldn't do a response.write from a button that was in an update panel e.g. send a pdf report to the browsers response to allow the user to view or save. If you tried to do this you would get an error like the following:

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

After a bit of searching today I found one solution. Add the button into the update panels triggers section as a PostBackTrigger (as opposed to an AsyncPostBackTrigger you use when ChildrenAsTriggers is false).

Works a treat and allows me to keep the benfits of update panels.

Be the first to rate this post

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

Tags: ,

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

dotnetpete

Hi I'm dotnetpete. I'm an owner and software developer at Advantech Software in Brisbane, Australia. My passions are writing great software and coffee.