The boards given away at WinHEC and PDC for Windows 7 sensor development are now available for sale from Freescale:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=JMBADGE&tab=Buy_Parametric_Tab&fromSearch=false
These are a great way to experiment with the new sensors such as light, gyroscope, and accelerometer. The price is pretty fair, and it’s a nice compact board. Even better, the Windows API Code Pack support it nicely in managed code.
Have fun!
So how do you query in the text-based Where clause of an LINQ to Entity query? This question drove me up the wall! I’m used to the CONVERT function, or just passing a string, or with a full-on LINQ query, using a DateTime object. With an EntityDataSource, though, you specify the where clause using the Where property which is a string.
First, I couldn’t even figure out how to refer to a column. “IsCancelled” (my column name) didn’t work. The Visual Studio expression editor did not help one bit. Finally, I came across some samples. You need to prefix your columns/properties with “it”. Iterator, I guess. So my clause can say “it.IsCancelled == false” and it works.
The next part was trying to deal with a DateTime. I couldn’t include a date in quotes, surrounded by hash marks, or in any ToString representation. The trick, it turns out, is the CAST function. This isn’t a T-SQL function. This is specific to the framework. You don’t use it like convert, changing to datetime. You actually cast it to System.DateTime. The syntax is: CAST(date_string as System.DateTime). For example: CAST(DateTime.Today as System.DateTime). Not what I expected!
My final Where clause ended up as:
DSEvents.Where = "it.IsCancelled == false and it.startTime > CAST('" + DateTime.Today + "' as System.DateTime)";
So far, my volunteer registration system for non-profits has been coming along well, but I’d love some help! I’m hosting the project at CodePlex. You need to be able to view upcoming volunteer events, register as a member, and then volunteer for specific events. Administrators can create events, manage the list of volunteers in an event, and define related entities (neighborhoods and organizations). Most of this is working, but there’s very little error-checking, the design is very ugly, and some of the smaller features aren’t in place (filtering for active, future events for instance). Anyone interested in working on an ASP.NET project with Entity Framework please get in touch with me! Use the comments though, as my Contact form hasn’t been working for some reason. Another thing to take up with GoDaddy…
Well, upper level support has confirmed that they are indeed running .NET 3.5 SP1 on their shared hosting servers. This seems unlikely since the Entity assemblies are missing. I’ve replied yet again so we’ll see what happens this time. I hope it ends up being a simple fix.
Aargh! Very frustrating. I tried setting up a site on Godaddy. The site uses Entity Framework. Site failed. Even though they claim .NET 2.0/3.0/3.5 it’s missing all the Entity classes. Even when I copied them to my bin folder it fails since the System.Runtime.Reflection assembly is missing some attributes, The compilation error tells me that it’s the 2.0 compiler. Maybe that’s right, I don’t know. They tell me EF is not supported though which is really strange. After looking closer I noticed that EF is part of 3.5 SP1 (release last November). Perhaps though don’t do service packs. I’m not happy.
I should have blogged on this beforehand… but on Saturday I gave a talk about Windows 7 for developers at the Iowa Code Camp, and last night I gave another similar talk to the Cedar Rapids INETA group. There are lots of neat new features to take advantage of. The taskbar alone offers peeks and previews, custom buttons on preview, alerts/progress, even icon overlays (something that would have really come in handy with Notification Icons!). The intent is to move away from the notification area now and they’ve really provided some good tools for it.
I always have fun showing the Sensors and Location API’s. The are user-mode driver-based so it’s much easier to create your own implementations. The API’s are pretty easy to use. Enumerate a type of sensor, register for events, and read your reports as they come in. Much better than dealing with data formats and wire protocols. Unfortunately, not much to look at with the Location API yet. I have a feeling we’ll be seeing some open-source implementations for various GPS devices and other concepts.
The RC is well-worth downloading. It’s been rock solid for me and really performs well. Time to start developing for it!
I spent more hours than I’d like figuring out why data caching didn’t work for me in a Word-based VSTO solution. I did what I needed to implement a cached property:
- Public property
- Marked with Cached attribute
- Type to be cached marked as Serializable
I saved the document on closing (after writing to the cached field), yet no luck. After messing around for some time, I finally decided to test out serializing the type. Since it’s specifically XML serialization that must succeed I used the XmlSerializer object, wrote to a MemoryStream, then displayed the result in a message box.
Ah ha! As soon as I tried to explicitly serialize it, it failed and gave me the exception. It turned out that one of my serializable classes was marked fine and used public properties where needed, but had a private get declared. Of course this makes sense that it’s a problem since the framework can’t deserialize a property that it can’t set! I just changed it to a public get and set and now it works! Apparently the VSTO framework swallowed the exception so I just couldn’t tell before. Word to the wise!
The reason I had a private setter was the property was a collection. I wanted consumers of the object to be able to get and work with the collection, but there’s no reason for the collection to be replaced. I changed it in the setter to throw an exception if
set is invoked when the value is already non-null. Simple solution!
In a recent project I decided to use variable arguments to a function – the first time I’ve needed to. If you haven’t worked with them before, you probably don’t know the point of them. They’re easy to use though.
Every so often you may need to pass a number of arguments to a function, but it may be hard to predict how many. An example is the String.Format() method:
String.Format("{0:d} - {1} ({2})", DateTime.Now, msg, severity);
You could pass more or less arguments depending on what you are formatting. If you’ve ever given it a thought, though, you’d realize it’s not obvious how to do it. You could overload the method:
String.Format(string, string);
String.Format(string, string, string);
String.Format(string, string, string, string);
I’m sure you can see that this would get out of hand quickly! Fortunately there’s a better way though: Variable Arguments. Instead of creating overloads with more and more parameters, you can just use the params keyword. How it works is simple. Just use the params keyword, specify the datatype and variable name, and you’ll actually get an array of values passed to the method. From our Format example, we would just declare it as:
String.Format(string formatString, params string[] args);
In the method itself then, you could reference the required argument formatString as any other argument, then the args array would have zero of more elements depending on how many were passed in. Just in case it’s at all confusing, it’s the params keyword that creates the magic. Any parameters before that one are completely normal. You could just as easily have something like this:
MyClass.MyMethod(string source, int code, params object[] values);
Important points:
- You can only have one params arguments (all others will be normal arguments)
- The argument with variable arguments must be the last (too confusing otherwise)
- You can use any datatype, but it must be declared as an array (and therefore, all variable arguments are the same type)
- In the method itself, just access the last argument as any other array (foreach works nicely)
This is not a new feature by a long shot. Just mentioning it in case people haven’t seen it yet. Also, VB has a similar feature using the
ParamsArray keyword. VB also has support for optional parameters which C# lacks.