Archive - Historical Articles
You are viewing records from 03/24/2007 10:06:14 to 03/16/2008 13:35:16. I'll be adding support for selecting a date range in future.
I wanted to run a bunch of methods simultaneously on as many threads as possible to get the job done, but still wait at the end. I know MS have something coming to solve this, but wanted a lightweight solution, so here it is:
To use this, you simply call it with a list of delegates you want to execute, and define the return type:
The result is now valid for 100 executions but took a lot less time than 100 seconds to calculate. You could of course just be running four things at the same time, all different using this.
PermalinkThis is really simple but annoyed me for a few minutes until I got .NET Reflector up, so hopefully this will help someone else.
The render method on ASP.NET WebControl based server controls seems to be adding a span tag around the HTML output for some reason, to fix this simply override the Render method:
protected override void Render(HtmlTextWriter writer)
{
RenderContents(writer);
}
Well Microsoft have just released Windows Server 2008 and Visa service pack 1 to manufacturing. Still waiting for SQL Server 2008, but the stack is almost complete :)
Excellent features I'm looking forward to are:
- IIS 7 on a server OS!
- IPv6 file and print sharing (and oh my goodness is file and print sharing faster)
- IPv6 over VPN!!
- RDP over IPv6! (Can you tell I'm an IPv6 fan)
- Application level terminal services (like Citrix has)
- Fail back router support! If you bring one down and then back up, it doesn't keep using the failover!
- IPv6 enabled by default and not uninstallable (disabling will have to do for people who don't want to use it which should result in a lot more IPv6 compatible servers).
- Read only domain controllers - good for if the domain controller is sighted somewhere insecure.
- ADAM is now a first class citizen if you need an LDAP server but not active directory. Active directory is also no longer completely intrinsyc to the server once promoted too!
The only unfortunate thing I can see is the removal of the basic firewall and OSPF from routing and remote access, but the basic firewall has been replaced by windows firewall - I just hope you can still define rules for the other hosts in the network.
Permalink 3 CommentsThere's an article on MSDN about how to host the Windows Workflow Foundation design surface (which is a redistributable).
The example code is really complete and worth a look at, it's almost an out-of-the-box copy of just the workflow designer from Visual Studio.
If your end user requires more flexibility than most you can offer them drag-and-drop customisation of particular processes in your system (like creating a new customer could be made to go off and send details to a webservice without you, the developer; needing to get involved).
PermalinkJust a single snippet of code to work from, I included explanations in the comments. This is really a very easy to use feature in C# 3. Unfortunately you can’t create extension properties yet, but that will likely be coming soon.
namespace ExtensionMethods
{
//Note that this class is static, it must be to contain extension methods and
//it also can't reside inside another class.
public static class ExampleExtensionMethod
{
//This is the extension method
public static bool HasLetterAInIt(this string s)
{
//Just return if it contains the capital letter A as this is just an
//example
return s.Contains("A");
}
}
class Program
{
static void Main(string[] args)
{
//This will print false
Console.WriteLine("TEST".HasLetterAInIt().ToString());
//whilst this will print true
Console.WriteLine("AAHH!!".HasLetterAInIt().ToString());
}
}
}
Create a .NET 3.5 Console, Windows Forms or WPF project, add an SQL Compact Edition local database, I left the default name of Database1.sdf for the example. Just right click and open it from solution explorer and add some tables. I added two tables: Person and Pet, with a relationship between the two (right click the child table, choose properties to get the add relationship option).
Command: C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\SqlMetal.exe
Arguments: $(ItemPath) /dbml:$(ItemFileName).dbml
Initial Directory: $(ItemDir)
This is really easy and quick, but something that is handy. Getting speech synthesis to work under .NET 3.0 is really a breeze.
synth.SelectVoiceByHints(System.Speech.Synthesis.VoiceGender.Female, System.Speech.Synthesis.VoiceAge.Teen, 0);
If you’re getting the Windows Forms designer instead of the Compact Framework 3.5 designer then you likely have a problem in your registry. When you try to compile the build succeeds, but then you get the following warning:
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets : warning : An internal error occurred in PlatformVerificationTask. System.Exception: Could not locate an IAsmmetaBindingService for platform PocketPC. Check your registry settings for the platform.
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets : warning : at Microsoft.CompactFramework.Build.AsmmetaContext..ctor(String ndpversion, String platformFamily, String platformID, ICollection references)
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets : warning : at Microsoft.CompactFramework.Build.Tasks.PlatformVerificationTask.Execute()
This also manifests itself in the GetDeviceFrameworkPath entry not accepted by the schema in the “C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets” file.
Well, there’s an easy enough solution to these problems, the AsmmetaBinder entries are missing from the registry in each of the sub-types under:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0
So here’s the entries you need to copy into notepad, save as fix.reg or similar and then double click:-
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\PocketPC\AsmmetaBinder]
"TypeName"="Microsoft.CompactFramework.Build.PocketPC.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\PocketPC\AsmmetaBinder\4118C335-430C-497f-BE48-11C3316B135E]
"TypeName"="Microsoft.CompactFramework.Build.WM50PocketPC.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\Smartphone\AsmmetaBinder]
"TypeName"="Microsoft.CompactFramework.Build.SmartPhone.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\Smartphone\AsmmetaBinder\BD0CC567-F6FD-4ca3-99D2-063EFDFC0A39]
"TypeName"="Microsoft.CompactFramework.Build.WM50SmartPhone.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\v3.5.0.0\WindowsCE\AsmmetaBinder]
"TypeName"="Microsoft.CompactFramework.Build.WindowsCE.BindingService, Microsoft.CompactFramework.Build.Tasks, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, Custom=null"
This one has been annoying me for a while now, as I do a bit of compact framework development. I simply compared two exactly similar XP machines entire compact framework installs – files, registry settings, etc till I found the differences between a working and non-working system.
There's a limit on the data sent and recieved in WCF, resulting in errors like this when the webservice sends back larger messages:
"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."
The fix for this is to create a new binding with much larger limits:
System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
binding.MaxBufferSize = 1024 * 1024 * 2; //bit bigger than default
binding.MaxReceivedMessageSize = 1024 * 1024 * 2;
binding.ReaderQuotas.MaxStringContentLength = 1024 * 1024 * 2;
ServiceReference1.MyServicesSoapClient client = new ServiceReference1.MyServicesSoapClient(binding, new System.ServiceModel.EndpointAddress("http://myservice/service.asmx"));
Just a reminder to myself, to let a user run an application pool without granting silly rights, you just need to run:
aspnet_regiis -ga <machine>\<user>
Which grants rights to the metabase and the temporary files folder.
PermalinkI just noticed that Visual Studio 2008 is now out to MSDN subscribers!
Unsurprisingly MSDN is struggling to work :)
PermalinkWell the subject says it all - I am indeed still around.
Trying to develop Windows Presentation Foundation applications with VS2K5 is more an exercise in suffering than getting any work done, even with Expression Blend to help.
Since it is coming out this month I should have plenty more to post at some point soon :)
Permalink
Just a quick note so I can look it up easier later :) - Simply call EnableGlass(); in the Form load event and it'll change the form to support glass.
You also need to implement support for changing the colour scheme of Vista and it needs to invalidate the form after running EnableGlass - a call to this.Invalidate();
private void EnableGlass()
{
if (Environment.OSVersion.Version.Major >= 6) //check for vista
{
DwmEnableComposition(true);
DWM_BLURBEHIND d = new DWM_BLURBEHIND();
d.dwFlags = DWM_BLURBEHIND.DWM_BB_BLURREGION | DWM_BLURBEHIND.DWM_BB_ENABLE;
d.fEnable = true;
d.hRegionBlur = IntPtr.Zero;
DwmEnableBlurBehindWindow(this.Handle, d);
Paint += new PaintEventHandler(Glass_Paint);
}
}
[StructLayout(LayoutKind.Sequential)]
public class DWM_BLURBEHIND
{
public uint dwFlags;
[MarshalAs(UnmanagedType.Bool)]
public bool fEnable;
public IntPtr hRegionBlur;
[MarshalAs(UnmanagedType.Bool)]
public bool fTransitionOnMaximized;
public const uint DWM_BB_ENABLE = 0x00000001;
public const uint DWM_BB_BLURREGION = 0x00000002;
public const uint DWM_BB_TRANSITIONONMAXIMIZED = 0x00000004;
}
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableComposition(bool bEnable);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmEnableBlurBehindWindow(IntPtr hWnd, DWM_BLURBEHIND pBlurBehind);
private void Glass_Paint(object sender, PaintEventArgs e)
{
if (Environment.OSVersion.Version.Major >= 6)
{
if (DwmIsCompositionEnabled()) //check Aero is enabled
{
e.Graphics.FillRectangle(Brushes.Black, this.ClientRectangle);
}
}
}
PermalinkMSDN subscriber downloads now works in Opera, I just happened to use the wrong browser to go there and it worked great. They even suggested manually installing the file transfer manager if not running IE.
I'm impressed, congratulations to whoever at Microsoft instigated making it cross browser (or at least, not moan and stop you outright).
PermalinkMicrosoft has released Visual Studio 2008 Beta 2 for your enjoyment and testing, which is excellent news.
Hopefully there has been some significant improvement in the tools for WPF built into it!
PermalinkMicrosoft UK have a blog about MS tech in UK schools (which is indirectly related to my current job as we do a lot of work for the education sector).
Some of their examples are actually heavily related to what I actually implement (although the products I've built for my employer are here right now rather than theorhetical!!) - particularly the cashless and registration systems one presentation shows off.
PermalinkMicrosoft have just released beta 1 of Orcas, let the testing begin!
Permalink(Warning: Boring legal bit of news!)
A limited precedent has been set by the European court of human rights which just found in favour of the complainant in a case against the UK government regarding the unlawful monitoring of private communications at work. (Covered by numerous news outlets)
Effectively this overrides UK law and any contracts implicitly in respect to human rights cases - statute law automatically trumps contract law; and means that employers and the government will have to respect article 8 of the human rights act.
What does that mean? The specifics are available on the this UK government site http://www.opsi.gov.uk/acts/acts1998/80042--d.htm - just scroll down to article 8.
It will be interesting to see if this precendent is able to be called upon in UK courts themselves, where there is a law that permits employers to monitor employees communications for the purposes of detecting things like viruses and seeing how employees interact with customers however that law itself could breach the data protection act in several situations.
With such a contradictory situation a precedent is actually needed to decide how to interpret the 'grey area' - and this could well be the one used in that situation.
Permalinkusing System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
A self hosting service example mostly so I don't forget how. Remember to add references to System.ServiceModel and System.Runtime.Serialisation!
Permalink 3 CommentsIf you are getting the following error on its own in a message box:
Exception from HRESULT: 0x80041001
Whilst trying to update your WCF service reference then it can't access either the .map file or the C# source file. I happened to have them open in visual studio whilst trying to update the reference!!
Oddly if you open them after running the program then it doesn't moan... For some reason I think it may be to do with clickonce locking the files.
PermalinkI very rarely write about anything to do with work, usually I intentionally avoid topics that would relate to it but I feel that it is my moral duty to provide information should people look for it. I’d also like to defend the system I wrote which doesn’t seem to be happening in the media.
Firstly I feel people should know a little about the background before they read the actual article:
1) I disagree with ID cards and biometrics as a requirement for things, there should be no reason you need to constantly prove who you are and you should always have a choice to avoid needing to prove your identity. Maybe you will loose some benefits that you would have gained, but there should never be an infringement of your rights or make something more difficult than it is now.
2) I’m the programmer of a cashless catering system that allows fingerprinting students and using their finger instead of carrying the equivalent of a debit card. I’m responsible from a technical standpoint for how it works technically underneath (although we do buy in the algorithm to analyse the image of a fingerprint that comes from the reader and work out what bits we’re interested in). Yes, I write one of those systems that is being both criticised and is massively in demand right now for various reasons.
Okay now that’s out of the way I see a lot of publicity about the fingerprint systems in use today and I will leave the other companies and people involved to defend their own systems, but more than likely they are using a similar technique to what I have used simply because it’s easier.
I’ll start by explaining why I believe the system I wrote isn’t a threat to privacy, then I’ll add what we’re going to provide shortly to ENSURE it isn’t a threat to privacy where the customer (the student usually) wants and we’ll cover why I think our system benefits from having support for fingerprints.
How the System Works, and How it Protects the Fingerprint
The system I developed does not store a fingerprint. We really don’t want to store one - we don’t want to have to comply with police requests for a forensically valid database of fingerprints. It shouldn’t be our responsibility and the student didn’t give us their fingerprint for that reason. What is needed for criminal forensics is a picture of the fingerprint otherwise there’s doubt, and our system deliberately introduces doubt in favour of:
- Speed
- Lower storage requirements
- Lower memory requirements
- Accuracy of detecting the closest fingerprint (note: not the exact person, but just the most similar)
- A degree of privacy.
To achieve this we store relative points on the fingerprint and discard data that applies specifically to the persons fingerprint. Techie bit: We also cryptographically hash the details where possible so there’s no way to get back to the original ones to allow generating a fingerprint that would pass as the original from the data, but you can read up on irreversible encryption at wikipedia or somewhere else. Basically if you don’t have the data the hash is made from it makes the data useless (that being the person’s real fingerprint).
So what we have is a map that says something like this: “left one unit and up one unit there’s an interesting point that goes up, right two of those distances there’s an interesting point that goes down” – that’s two points but you get the picture. It’s like street directions only we add in that the directions are actually stored in a one way method. The unit of distance is actually not specified in any way other than the relative distance either, so what you end up with is a set of street directions that is like “Turn left, then turn right then right again. Turn right, turn left, turn right.” Could you work out what city those directions are for? I hope not. But if you were given a bunch of maps and tried them all, it would only be possible on a few.
So it is my belief that our system stores sufficiently little of the fingerprints they can’t be used anywhere else. In reality it causes us business problems as schools would like to have a single fingerprinting session for all their students but that’s a trade-off we willingly make.
I won’t go into the protection we apply to the database, if someone wants that just e-mail me and I’ll cover it. Needless to say if you turned up on site you shouldn’t be able to just stick a USB key in and copy it without physically getting to the server and entering valid usernames and passwords. Which in most circumstances we as a company don’t have and only the school have.
And finally, the last step is that (as far as I’m aware) we require both the students and parental permission prior to fingerprinting. In many cases our projects department has helped draft the consent letters the schools send out, and we will provide assistance should anyone not wish to be fingerprinted – or indeed change their mind and want their fingerprints removed from the system!!
Measures Being Taken and Who Benefits
To buy a meal you would either pay cash (we provide full support for cash by an account, or cash from anyone without an account in our system) or swipe a card/place your finger on the reader and the till operator sees your picture on screen and selects the food you have on your tray. They then press confirm sale and you walk off having paid for the meal. If the person is on free school meals (low income family) then there’s nothing said, the money is just there as if it were loaded on by the student earlier in the day.
Kids love it! Bullying gets reduced a little! Till staff love it as it’s quick and easy! Catering companies love seeing how much of something they are selling easily, how much it changed during the year (who would guess that sandwiches get more popular in the summer?). The schools love the fact they don’t handle as much cash – it all goes through an ATM like machine that eats the money and counts it up for them, or an online service that the parent uses. Parents love it as they can ask for what their son/daughter has been eating and see their balance online!
Privacy advocates hate it! Kids that steal dinner money really do hate it (they pass a card over to the till operator and a different picture appears and it’s known they stole the card), and anyone that was stealing from the tills must hate it.
Occasionally the two ends up as the same thing, so in this case we can offer a few options:
- The tills accept cards (proximity and magnetic stripe) as well as biometrics, so we can give the students cards if that satisfies their discomfort with using their fingerprint.
- The person can always opt out of the entire system and pay cash, as long as they aren’t free school meal. If they are free school meal they need to pay cash and use a voucher (we support the idea of a voucher sale in our software).
But we just had a request from a parent to not store data about a student. And the school don’t want them to just use cash; they want the system to still behave as it does now. But the government need us to be able to back up our financial transactions!!
Talk about contradictory requirements. How do we do this? I’ve not finished the work to do it yet, but I fully intend to find a solution that makes the transaction of the individual totally anonymous:
- We will not store who the sale was made to.
- Or by, because we don’t want the human operator being asked.
- Or on what till.
- We still need to store their name and balance, and financial transactions. So we’ll flatten the financial transactions and have just one transaction for how much they loaded and one for how much they bought.
- If the person is free school meals they will need to use a voucher and say they are free school meals at the till. We can give them some paper vouchers they can give to the till operator then. If the person that is marked uses a voucher, we’ll make two separate entries, one for the voucher purchase and one for the items they were sold. We won’t store the time on the voucher purchase.
If anyone can think of anything else I need to do, please e-mail me. Also if you have any questions about biometrics or indeed anything to do with the system I write (or want contact details of our sales people to buy it!!) please feel free to e-mail me. My contact details are on the right.
I would rather not have my name posted on sites like http://www.leavethemkidsalone.com/ and my employer already is, so please respect my privacy as much as I do others.
This article is being posted publicly though so anyone can feel free to link to this. If you have any criticism, please feel free to comment (sign up with fake details if you wish) or e-mail me!
Permalink