For the past three weeks I have been busy with one of those projects where next to no days were allocated to a certain module yet it requires as many days as the length of a piece of string... I am sure everyone gets these from time to time.
Like most people I do not like doing many of the repetititive tasks and so use
CodeSmith to help me out. I had cleared its stats counter before starting this module and was shocked to find that as-of today it had already generated more than 20,000 lines of code!!
Now, we use our own code generator to handle the data layer and these lines are not included in the 20,000 lines, so you can only begin to imagine how much time code generation can save you. If you don't already use a code generator then I suggest you spend a few hours looking into it. It will save you many days in the long run!
I am a firm believer in using programming patterns. It helps to build more stable, predictable and better applications.
Microsoft have not seemed to allocate any resources to their first patterns & practices release for quite some time, but at least the guys have updated the library for VS2008. Get it at
http://smartclient.codeplex.com/.
I have been having a lot of trouble moving all my Compact Framework projects to 3.5 over the past few days.
The first problem came in the form of the "Update Web Reference" failing with the following error:
The custom tool 'MSDiscoCodeGenerator' failed. Could not retrieve the current project.
From what I can gather, there are leftover's from VS2008 beta... no matter, the only solutions out there involved reinstalling, which means lots of time wasted. The best info I found was
here.
All I can say is that I rediscovered how many hours it takes to install the tools and SDK's that I use every day (i.e. it would be nice if the installation process was much faster).
The final error I had for the day was when compiling my setup project:
An error occurred while validating. HRESULT = '80004005'
My recommendation here is to delete any references you have to other projects within your solution and recreate them.
I have been struggling to get my version of SQL Compact 3.5 SP1 to work. Version
3.5 used to work without a hitch but my next project is going to be using SQL
Server 2008 which requires the service pack (but I will still have to support
SQL2005 applications). The project will have handheld scanners operating at the docks where wireless signal will not be guaranteed and so replication is the best option.
I could not get the replication working to a SQL2005 publication no matter what I tried and the information I found when Googling did not help, so I did what seemed to be the best advice, I uninstalled all SQL Compact versions from my laptop and then only reinstalled 3.5 SP1.
It still kept failing. You can imagine the frustration because I have used replication many times on many projects and knew/thought that my setup was correct.
The error I was getting was
“SQL Server Reconciler has failed” with the following info from the log:
Hr=80045005 ERR:Initialize failed for DistributorSessionID = 0
Hr=80045005 The subscription to publication 'Pubname' could not be verified. Ensure that all Merge Agent command line parameters are specified correctly and that the subscription is correctly configured. If the Publisher no longer has information about this subscription, drop and recreate the subscription. -2147201019
Access to the IIS server extension worked fine (e.g. use a link similar to
“http://<servername>/Mobile/sqlcesa35.dll?diag”
to check connection and version information).
However I noticed that the version number of the SQLCESA35.DLL was wrong… it should have been 3.5.5692.0, but was showing 3.5.5386.0 instead. It also showed that the Reconciler Test had failed for the 8.0 database test.
I then used the SQL Compact Server Tools wizard to create a new virtual folder in IIS and when I connected to it
(e.g. “http://<servername>/SSCE351/sqlcesa35.dll?diag”)
the version information was correct and the Reconciler Tests all passed.
I tried my synchronisation again and everything worked properly.
I hope this helps somebody else out there save some time!
A good majority of my work is for mobile applications using the Compact Framework. Something really annoying I came across today was that if I used a variable for the pattern in my Regex then the IsMatch did not work, but if I used a constant then it did.
So, for example, if I used:
string val = "YELLOW";
string pattern = "(YELLOW)$";
The following statement does not give the correct result (true):
bool flg1 = Regex.IsMatch("YELLOW", pattern);
But the following does:
bool flg2 = Regex.IsMatch(val, "(YELLOW)$");
So far I have not found a workaround (e.g. creating a Regex object and trying to use IsMatch using it also does not work if the pattern is from a var), but am investigating... if anybody has a solution then please let me know...
26 March 2009 - Okay, a colleague has finally helped me out with this one. There is a workaround so instead of using the IsMatch, rather return a Match object and then use the Success property to determine if the match was successful. Thanks Rich!
Solution below:
Regex r = new Regex(this.txtPattern.Text), RegexOptions.IgnoreCase);
bool pass = r.Match(this.txtInput.Text).Success;
this.txtFeedback.Text = (pass ? "Matched" : "No match");
I found something really cool with SQL yesterday that I did not think it would do; give me the distinct count of a field.
For example, to calculate the number of payment terms being used for our customers in the UK I can use the following statement:
SELECT COUNT(DISTINCT [Payment Terms Code])
FROM [Customer]
WHERE [Country_Region Code]='GB'
Create a project template for your Windows Service applications to save loads of time.
Make developing, testing and debugging your Windows Service application easy.
REGEX is not exactly my favorite technology to have to work with, but there are times when it is definitely the right tool for the job. Recently I needed to parse a large text file that contained blocks of information within curly brackets - {}.
I found a great solution for the REGEX at:
http://blog.stevenlevithan.com/archives/balancing-groups
Note that balancing groups is only in the Microsoft REGEX classes... if you are using a different library you may have to follow an alternative, less powerful route where you know the number of levels that may be used:
http://blog.stevenlevithan.com/archives/regex-recursion
KUDOS to Steve...
My final solution by the way was:
@"\{(?>[^{}]+|\{(?
)|\}(?<-Depth>))*(?(Depth)(?!))\}"