?? Operator Scott's most recent post on LINQ, showed me that I still have alot to learn about C#. The ?? operator was casually thrown into the mix as if it were as common as +, =, or a semi-colon (;). It took a couple of searches on Google to find what I wanted, but I finally found a page on MSDN that lists all of the C# operators in 2.0, and the one I was looking for. The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand. int? x = null; //This will assign the value of -1 to y int y = x ?? -1; //Change x to an integer, and it will be assigned to y x = 5; y = x ?? -1; //y now = 5 Extension Methods in .Net 3.5 Another tidbit I ran across, was the introduction of extension methods in C# 3.5. Basically, extension methods allow you to create a method that is associated with a type, such that you can call it (and have intelli-sense support), as if it was defined as a method if the type's definition. For example, the Subtract() method of the DateTime type, is defined in the type. With extensions, you can add some code to define a method foo(), such that you can do something like DateTime.foo(); Extension methods are most closely compared to similar functionality in Ruby. I found an example on Phil Haack's blog which I tried out myself, and reproduced below (note to self, learn how to format code examples nicely). namespace ExtensionMethods { public static class Extenders { public static DateTime Ago(this TimeSpan value) { return DateTime.Now.Subtract(value); }
public static TimeSpan Minutes(this int value) { return new TimeSpan(0, value, 0); } }
class Program { static void Main(string[] args) { Console.WriteLine(20.Minutes().Ago()); //With Extensions Console.WriteLine(DateTime.Now.Subtract(new TimeSpan(0, 20, 0))); //Without Extensions Console.ReadLine(); } }
}
I got intelli-sense on after typing Minutes(), but no intelli-sense on 20. I was also curious to scope, and where extension methods will need to be placed, and how to access them. Moving the Extenders class outside of the main namespace, I got compile a compile time error stating that int doesn't have a Minutes method (standard 2.0 error), as well as text indicating that there were no extension methods (new for 3.5 obviously). Adding a using statement allows the code to compile. I then tried duplicating my extension namespace and adding a 2nd using statement, and got the expected compile error about ambiguous methods. To me, I can see trouble in the future with conflicting Extension Methods in different namespaces. It doesn't look like you can use a fully qualified name either.
This MSDN article gives some technical info on Extension Methods (it's an article containing info on several new language features). Here is some of what I got:
- Extension methods are declared by specifying the keyword this as a modifier on the first parameter of the methods.
- Extension methods can only be declared in static classes.
- Instance methods take precedence over extension methods, and extension methods imported in inner namespace declarations take precedence over extension methods imported in outer namespace declarations.
There is some debate going on in the comments section of the blog post where I got the example from. Some people seem to think that while easier to read (debatable itself), it makes for harder to maintain code. Others claim it breaks OO principles.
See Also: ScottGu's post on Extension Methods
The latest version of Google Earth (4.2), which adds a feature to look at the sky, has a hidden feature as well. Marco's Blog reports that a flight simulator is now included in Google Earth. To enter the flight simulator, press Ctrl+Alt+A. Here is a list of commands. There is supposed to be joystick support, and possibly force feed back, you can also use the mouse to control Aileron and elevators. I tried it out for a few minutes, and I could see where it could get addictive. It's not MS Flight Simulator, but it is free, and doesn't take up gigabytes of storage space on your HD. Also, it's a little easier to hide on your work computer ;) Download Google Earth Here (Just click agree to the ToS).
A friend of mine recently inquired about how he could gain access to an old Windows server he had running, for forgot the admin password. I pointed him towards this software, which I have successfully used in the past. There is a new version since the last I checked that now supports Vista, and more disk controllers. I was starting to run into some newer laptops from HP with SATA controllers, which did not have drivers included on the password reset disk. Hopefully this new version will have those drivers.
I recently came across an article on UTC to store date/time values. A decision made on a current project I am working on was to use UTC for client applications. However, the dates stored in SQL currently not in UTC. I guess I've just gotten used to the GetDate() function in SQL. A more appropriate function for our application would be the GetUtcDate(), which will return the current date/time in UTC format. From the article: The primary advantage of storing date/time values in UTC is that it makes the data transportable. To see what I mean, imagine that following scenario: you have an eCommerce website that is being hosted in a web server located in the Pacific time zone (UTC -8) and this application stores the date and time orders were placed in server time. Say a user, Bob, makes an order on August 1, 2007 at 9:00 AM UTC -8. After many months of phenomenal growth, you decide to switch to a larger web hosting company, one on the east coast where the time zone is UTC -5. Since the date/time is stored in server time, Bob's previous order still shows that it was made on August 1 2007 at 9:00 AM. But since we are now in UTC -5, it is as if Bob's order was made three hours earlier than it really was (since when it was 9:00 AM on August 1, 2007 in the west coast it was really 12:00 noon on the east coast). The author then goes into explain how you can fix the above issue by doing an update on the data to correct the time, which he refers to as "Ick", and I will have to agree with that. You don't want to, nor should you have to ever update a time stamp type property. The next example uses various time zones to illustrate the problem of converting from one time zone to another (not to mention DST and SDT). Since we plan on eventually offering localized versions of our Web Application, displaying all times in CST/CDT is not idea. Not to mention the change from daylight savings time to stand time makes the way we display data currently, very confusing. Things seem out of order at best. Well, I'm off to update my use of GetDate to GetUTCDate. Be sure to read the full article. Note: I found this article originally from ScottGu's RSS feed. However, the actual blog doesn't have the UTC article listed under Asp.Net, or listed at all.
All I wanted to do was make an ISO of a CD so that I could keep it on my server for use with VMware Server. I didn't think it should be that hard, I have Nero 7 ultra edition, surely that can create a prefect ISO copy. Nope, no go, couldn't find the option to create anything other then a Nero image file. Onto ISO buster, which I had installed a long time ago. I'm pretty sure I used it to create an ISO before, but it just wasn't working out. I was able to create an iso, but it wasn't bootable like the original. /sigh Off to Google to search. 4th hit on a search for free iso tool led me to DoISO whish is a GPL ISO Creation utility. A quick download and install, and I was off and running. Creation process was a success, selected it as my image for my VM CD-ROM drive, and, didn't boot. Back to Google, and found ISO Recorder. Lists support for XP and Vista, and it is free. So far so good, however, looking at the user guide, it struck me, that I already had this installed, I had just forgot about it. Trial #3 for making an ISO was then underway. Success, created the ISO, and it was bootable. Summary: ISO Recorder created a perfect ISO copy from a CD. Note to self, check to see what you already have installed before going off in search of something else.
This is my first post for my new blog, and it will be short, as I've just spent most of the night getting everything setup. So far I am very happy with dasBlog. I just need to get email submission working, and move all my old posts over. Hopefully this post I'm writing in Live Writer will work, so I can cross that (test with Live Writer) off my to do list. Speaking of Live Writer. After using it for less then 5 minutes, I like what I see. I can't wait to install it at work as well and begin contributing en-mass to the blog sphere! Blog To-Do List: - Move old blogs from personal site
- Move new blogs from work site
- Setup some type of nightly backup of this blogs content to my local computer
- Get email submission working
- Define Categories (Check to see if it's easy to rename a category)
- Define additional Macros
Update: Just tested updating a previous entry using Live Writer. If you see this, it worked.
Scott posted another edition of his "Weekly Source Code" where he lists open source projects that he finds interesting. The idea is to examine the source to find ways to improve your own coding, by finding examples of what to do, and what not to do. One of the projects listed was Fog Creek's Co-Pilot software, which is a remote help desk software that works across firewalls. The client code, based on VNC, is available under the GPL. Reading thru their tech page, they talk about implementing a version of the STUNT protocol. The STUNT protocol, put simply, is a way to do direct Internet connections across NAT, bypassing the need for a proxy or reflector (Co-Pilot's term) piece of server software. The main advantage to the STUNT approach is that it is much faster since you are not going thru an intermediary. STUNT reminds me of one of the methods used by Skype to establish connections. While they didn't use the term STUNT, it was very similar in concept. This is particularly interesting for me due to my current project, and some of the communication requirements we have for our products. The idea of a direct connection, possibly to a VNC type application listening on the other end would make trouble shooting a whole lot easier....assuming we were not trouble shooting network connectivity.
After being informed of VS2008 multi-targeting capabilities, I went to download and install Beta 2. The install was quite easy and allot faster then VS 2005. I had to reboot once after installing the framework 3.5, and then once after the install was completed. My first 2 issues that I encountered were, no support for rptproj files, and it wanted to do an upgrade on the solution and project files. For the upgrade, if it just updates the solution, I'm not that concerned, as we don't keep solutions in source control. However, if the project files are updated, then that is a problem, and will prevent me from using Beta2 until the entire team is ready to upgrade. To test, I copied a project to a separate folder and ran an inplace upgrade. Since I don't have TFS client installed (issue #3, need to either install the 2005 TFS client or download and install the TFS Beta 2 client, or rather the entire ISO), I had to remove the source control bindings (good for this test). The project file converted successfully with no errors. I opened up VS2005 and selected the project, and was prompted with a warning about invalid tags in the csporj file, and I could either open for browsing, or open normally. I chose to open normally, and it did successfully. There was a hint that installing a registry key will allow you to specify to ignore the new tag that VS2008 inserts. I think that this will be a suitable work around. Next step is to try upgrading on the live projects, rebuild and make sure everything works. Then create a registry file that the team users can execute. Upon closer examination of the converted csproj file, it replaces an Import statement, with a new one. Old: <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" /> New: <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" Condition="" /> I added the old line manually to the converted csproj file, and it still built. However on a machine that doesn't have Vs2008 installed, that new import path doesn't exist, and the project can not load. Doing some more searching has yielded no suitable work around except coping the new build targets to each workstation. This seems to work. One other upgrade issue is VS2008 will replace what version of the UnitTesting assembly you use (8 to 9). Changing the reference to use specific version to false seems to be a suitable workaround. I just need to remember to set it back to true once everyone else is up and running.
I found a new blog that had a ton of information that I just happen to be looking for. http://blogs.technet.com/daven All of the following was taken from the above blog. - Microsoft.com is running on IIS7/Win2k8 Beta 3
- http://blogs.iis.net/bills/archive/2007/06/15/www-microsoft-com-is-live-on-iis7-beta-3-are-you.aspx
- The web server role is now included in the core
- Speaking of core, below is a list of command line commands that can be used to get your core install off to a good start.
When the Core installation is finished, you have a server with an unknown name, with a blank administrator's password in a workgroup. To get it configured you'll need these commands: net user administrator * hostname netdom renamecomputer <ComputerName> /NewName:<NewComputerName> netsh interface ipv4 show interfaces netsh interface ipv4 set address name="<ID>" source=static address=<StaticIP> mask=<SubnetMask> gateway=<DefaultGateway> netsh interface ipv4 add dnsserver name="<ID>" address=<DNSIP>index=1 netdom join <ComputerName> /domain:<DomainName> /userd:<UserName> /passwordd:* And a few optional ones: Cscript C:\Windows\System32\Scregedit.wsf /ar 0 WinRM quickconfigcontrol timedate.cpl control intl.cpl Slmgr.vbs -ato start /w ocsetup /?
So Automatic updates installed some stuff and rebooted my computer. I thought I had it set to download and let me choose to install, but I guess not. Upon getting to work this morning, I couldn't log on. I kept on getting an error about something could not be initialized. Turns out, this was HP Credential Manager. Messing around with the logon options, I finally found the checkbox to bypass credential manager for logon (at least HP was smart enough to put that in there). One weird thing I noticed, was that the finder print reader, which had stopped working after installing those 2 Vista reliability patches, was working again. Upon logging into Windows, I started to notice things were broken. Folder Share failed to start, I could not login to outlook, MSN IM said it was down, and VS said that I had a licensing error. Needless to say I was quite concerned. After messing around for awhile, I got around to uninstalling HP credential manager, and most of my login issues were resolved. I could login normally, outlook worked, MSN, and foldershare, and I'm sure a bunch more stuff that I hadn't tried worked now as well. Unfortunately, VS was still hosed. A Google search revealed that I need to uninstall delete some registry keys and reinstall. Well the first time thru, that failed, and I was left with a partially installed VS. Next up, I started following the instructions from this KB article. http://support.microsoft.com/kb/907965 Thankfully I had already downloading the windows SDK to get SvcTraceViewer for WCF, so I had the MsiZap utility. After I was done with the KB article, I deleted the registry keys specified here as well: http://blogs.msdn.com/astebner/archive/2005/11/14/492765.aspx UPDATE: It's been a little over a week since this all went down. I'm happy to report that everything is pretty much back to normal. Some of the VS addins needed to be reinstalled, like TestDriven.Net and the Business intelligence stuff for SQL 2005. I found a posting on how to re-install the sql BI: go to the location for SQL Server setup and run .\Tools\Setup\vs_setup.exe. This will install the VS Shell. After this is installed repair the BI Studio installation by running the following from the command line from the .\Tools directory: start /wait setup.exe /qb REINSTALL=SQL_WarehouseDevWorkbench REINSTALLMODE=OMUS Unfortunately, it still didn't give me BI support in VS 2008.
Today I came across 2 articles relating to SQL server. The first, talks about determining events that take place during a time slice. I can see possible uses for this in scheduling, and definite use in reporting. The second article, discusses some new features and functionality in SQL 2008. Below are some quick notes that were important to me. - Transparent DB encryption - I'm more in interested in transparent table encryption, including indexes (in case the index contains sensitive data). Further research is needed. I know SQL 2005 has some encryption functionality, so I'm interested in what has exactly changed.
- Built in support for auditing data. Configured thru T-SQL.
- Data Compression.
- MS says slight processor performance hit on compression, but made up due to less I/O.
- It will be an interesting exercise to see how this will work on VMWare.
- Resource Governor
- Prevent users or groups from consuming high levels of resources.
- Since everyone is going to be coming in as Network Service (a rather large assumption), be interesting to see if we can still take advantage of this
- HotPlug CPU
- Don't know if we can take advantage of this. Probably only if we were using blades.
- Performance Data
- Sql Dashboard to display
- Suggestions for improving performance
- Current and historical data
- Installation sounds allot easier
- Configuration data separate from engine, so you should be able to setup once, deploy multiple servers and then configure.
- Should help with cloning.
|