Monday, November 19, 2007

14% done VS-2008

Eber told me today that the VS2008 was on MSDN.. I was pretty excited so we both logged into MSDN (which was amazingly slow today :)..
But we couldn't find it listed in the DevTools section..

We ended up finding it on the main page of MSDN(before you log in).

It's under the 'Top Downloads' section..

Sunday, October 28, 2007

Leopard

Leopard came out the other day and I started to loose anticipation for the release when it seemed more and more features were being dropped, or were just not being added as features. I was expecting that with the new Boot Camp there would better NTFS support, but the sales pitch from Apple on this is “Leopard understands the Windows FAT32 disk format”. I guess I could use NTFS-3G’s driver for this, but I guess I’ve been spoiled for too long and wanted it built right in :).

A feature that was actually on Apple’s web-site but then mysteriously disappeared was “Fast Switching” for Boot Camp. This would basically put one OS into hibernation and load up the other OS (Awesome if you don’t want to close all your programs down before switching).

BUT! There are a lot of things that I really like about the new OS. Probably one of my favorite things is the path bar in Finder (bread crumb like trail of where you are in the file system). This is one thing that always drove me nuts, when you had a file up and you had to do info or something on it to know where it was in the FS.

Spaces is probably one of my other favorite things. If you have a laptop and need a lot of stuff on the screen it’s nice to be able to place things in different spaces. I wasn’t too excited about this until after I loaded up Parallels and I could go full screen on one space and easily go back to a screen with all my Mac stuff. Parallels has Coherence but with all the Windows stuff I sometimes have loaded it’s easy for my screen to get cluttered.

I’ve never used iChat, simply because most of my contacts are using MSN. Well iChat still doesn’t support MSN BUT it does support Jabber now (as well as Google Talk, since it’s a Jabber too). So all I had to do was find a Jabber server that had MSN/AOL/Yahoo etc transports. The only bad thing was that I had to use Psi to create an account on the Jabber server I found to create my Jabber account. Once my Jabber account was created I could point iChat to it and I can now talk to all my MSN/Yahoo..... contacts. The other downside is that if you have Google Talk and a Jabber account (or more than one account of anything iChat supports) then each account gets loaded in it’s own window, instead of consolidating all your contacts into just one window. I’m still up in the air about iChat, I may still go back to using Adium since it pretty much supports anything you’d ever use, and they have announced that they are going to support video chats in the near future.

So far for the most part I like Time Machine. I don’t like the dock if it’s on the bottom (don’t like the reflective thing the icons sit on) good thing I always place it on the left (no reflectiveness if the dock is on the sides of the screen) I guess you can turn it off, I found a quick little shell command to do it but didn’t bookmark the site where I found it :). I don’t care for the little cross-walk in the dock (used for changing the dock size). Oh I forgot, I love the new Quick View feature too, much quicker to quickly grab something from a dock instead of loading up whatever to view it. Other than that I’m happy with it, they didn’t make major changes to where everything is so I didn’t feel lost like I did with Vista.

Whoa whoa! just as I finished writing this I think I just found my biggest complaint! I use Pages to do my blogging, I export it as HTML and use a Ruby script to make it Blogspot happy and get rid of the extra CSS it generates. Well just as I finished I went to export it as HTML and well.... that feature is GONE! (Right after I installed Leopard there was a Pages update so I figure that removed it). I’m not quite sure why they removed that :(.

Saturday, September 01, 2007

I love c#.. but lately.. whoa!

So lately I’ve been wanting to get into some programming on my Mac (yes I own a mac and develop .NET at work). Well I don’t really have a lot of time to devote to some new language like Objective-C. Yes I could use Java.... but I’ve really started to like c# a lot better than Java lately (maybe because it’s just what I’m used to, and I want to avoid people bashing me for taking sides :) ).
 
Anyways I’ve kept tabs on the Mono project every now and again and recently decided I’d give it a go. So I downloaded the latest (right now it’s 1.2.5) and started to tinker. I did the cheesy ‘Hello World’ console stuff just to start out. Well I’d really like to develop ‘real’ things, ‘useful’ things, but I was a little concerned about the GUI aspect (WinForms). I’d read a few places saying you need to install GTK and blah blah to get it working and that kinda turned me off of the whole thing.
 
Well I think I had been reading some slightly out-dated material. I wrote a little program to just pop-up a MessageBox and what do you know.. it worked!... and it worked on my Mac! (well you do have to run X11 first, but hey it’s a small price to pay)..
 
Then I wanted to see what new stuff was added to Mono. So I implemented a quick Lambda just for fun. Well it didn’t work right off the bat but after a couple Google searches I found the answer.
 
To use Lambdas, and some of the other c# 3.0 features, you need to use the ‘gmcs’ not the ‘mcs’ mono compiler command. (I remember reading that gmcs was newer and they plan on getting rid of mcs I think with v 2.0... don’t quote me though that’s from my wonderfully not so good memory). AND you need to provide this argument to compiler ‘-langversion:linq’. And that’s it!
 
So here’s my little program I did..
 
using System;
using System.Windows.Forms;
 
namespace Test {
   delegate string GetMessageDelegate(string name);
      public class Test {
         public static void Main(string[] args) {
            Console.WriteLine(“Hello from the console”);
            GetMessageDelegate getMsg = name => string.Format(“Hello {0}”, name);
            MessageBox.Show(getMsg(“Frank”));
      }
   }
}
 
And here’s what I did to compile and run.
 
gmcs -langversion:linq -r:System.Windows.Forms Test.cs
 
 
So basically you’ll get the message on the console and a message box that displays “Hello Frank”;
 
So I’m pretty sure I’m gonna stick with Mono/c# as my choice for development on my Mac :)

Sunday, August 19, 2007

ASP.NET color priority

This is fun :)
 
WebControl.Style[HtmlTextWriterStyle.BackgroundColor] = Color.White.Name;
OVERRIDES
WebControl.BackColor = ColorWhite;

Saturday, August 18, 2007

Setting up SVN to authenticate against a domain

At work we’ve been developing our latest and greatest project and when we first started we inherited a version control application from a previous team. It has worked okay so far, but we’ve hit the point now where we want to start doing releases for different clients keep specific features with certain versions etc. Our inherited version control software didn’t do the whole versioning thing very nicely so we began looking into different options.
 
SVN ended up being the final choice. A few reasons went into the decision factor. For one it’s free, it’s also widely used, tried and true, and it does versioning much less painfully than our current solution. One thing we wanted to get rid of was having a different set of credentials for our version control. We wanted to just use our domain authentication so we don’t have different passwords for everything. SVN makes this pretty easy to accomplish, so for this article I’m going to give some quick steps on how to achieve this.
 
First you’ll need SVN
 
Second you’ll also need to download Apache. Why do you need Apache for version control?? Well you don’t HAVE to have it, but if you want to authenticate against a domain controller then just download it :)
 
Third you’ll want to download mod_auth_sspi for domain authentication with Apache.
 
Awright now we’re ready to go. Install Apache, this is pretty straightforward, once you’ve got this installed you should be able to view the default root page from a web browser, if not check out the Apache docs :( (Apache should install without a hitch though)
 
Next copy over the files mod_authz_svn.so and mod_dav_svn.so from the bin folder of SVN into Apache’s module folder. And while were copying files we might as well copy the mod_auth_sspi.so file there as well.
 
Now lets go ahead and install subversion. This should be pretty straightforward as well. Once you’ve downloaded it just make sure to add the bin folder to the path. After you’ve done this create your initial repository using something like this
 
    svndmin create c:/some/path/your/want/to/use
 
Now open up the httpd.conf file and add these lines into the modules section
 
    LoadModule dav_module modules/mod_dav.so
    LoadModule dav_svn_module modules/mod_dav_svn.so
    LoadModule sspi_auth_module modules/mod_auth_sspi.so
    LoadModule authz_svn_module modules/mod_authz_svn.so
 
Also at the bottom somewhere add this line
 
    Include c:/some/path/to/your/repository/subversion.conf
 
Don’t worry that file doesn’t exist yet but we’ll get to that right now!
 
So in your repository path (the one we created just a bit ago) go ahead and create a text file called subversion.conf. Edit the file and add something like this.
 
<Location /some/url/for/apache/to/use/>        #make sure to add the last ‘/’ in the url
    DAV svn
    SVNParentPath c:/svn/project/path
    SVNListParentPath on  #this just allows you to view the contents from a web browser
    AuthName “put whatever you want here”
    AuthType SSPI
    SSPIOmitDomain on #allows you to not supply your domain with your user name every time
    SSPIAuthoritative On
    SSPIDomain yourDomainThatYouLogInto.com
    SSPIOfferBasic On
    Require valid-user
    AuthZSVNAccessFile “c:/the/path/to/your/repository/svnaccess.conf”
</Location>
 
You can also add support to authenticate against multiple domains, or one domain and username/password pairs in a text file etc. All you need to do is just add those after one another in the Location tag.
 
And finally edit the svnaccess.conf file for the repository we created earlier. Here is a sampler
 
[groups]
svnadmins = DOMAIN\joe.williams, Joe.Williams, joe.williams
developers = DOMAIN\bob.williams, Bob.Williams, bob.williams
 
 
[/]
@svnadmins = rw
[yourSVNProjectName:/]
@svnadmins = rw
@developers = r
[yourSVNProjectName:/trunk]
@developers = rw
 
You’ll notice we have three entries for each user. This is because different apps may use one of the three variations so to avoid some headaches just add all three for each user. You only have to do it once anyway.
 
So that’s pretty much the quick run-through for setting it up.. Below is a list of links that I found useful when setting this up :) enjoy
 
 
 

Tuesday, June 12, 2007

ASP.NET Html Encoding

So have you ever had an ASP.NET application where you placed a couple of TextBox’s on but soon realized that when you entered in something like ‘1 is < 2’ or even more blunt and to the point “<div> hello </div><script type=’text/javascript’>alert(‘something bad’)</script>” and when you performed a post back you would get a nice little error from the server? Well if you haven’t had this happen you may experience this some time in the future so hopefully you’ll remember this bit of info and you wont be left scratching you head.

So this is actually a feature. I mean if you mistakenly forgot to verify some user input you might end up with some nice html injections on your site, and no-one wants those right. So this will display an error (not just a little ‘hello here I am now you can move on’ error, but an error that you probably don’t want people seeing either). So if you want to handle on your own you can disable the error that gets displayed by adding this little bit of text to your page directive (you can also add a setting to the web.config to make a system wide change, but I don’t think it’s recommended since you may overlook a place where they’re not being handled)

ValidateRequest=”false”

Now you’ll no longer get the errors. But now what? How are you going to handle these potential pests? Another little built in feature is the HTML encode/decode functions of the HttpServerUtility class. You might quickly find out though that this is a sealed class with no available constructors so there’s no making your own instance of this class. This class is however available to your Pages through the Server object (Server.HtmlEncode / Server.HtmlDecode). So now when someone sends in ‘<div>hello’ you can handle this by passing the text into the HtmlEncode(string) method and you’ll get back the encoded text ‘&ltdiv&gthello’ and if you want to update your text-box with the newly added info you can simply make a call to HtmlDecode(string) and get back ‘<div>hello’.

Sunday, June 10, 2007

Fun data retrieval

So I have a cousin who just bought his girlfriend a laptop. Well I guess he had the laptop for a couple weeks when someone gave him a.. well... not so legal copy of Windows and told him that it had everything he needed on it (Office etc). He figured it'd be pretty simple to get it installed and everything..

I got a call from him basically saying that the laptop would no longer boot, and he had installed Windows 3 times and now he just gets a blue screen. He asked if I could take a look at it for him. Well he bought it from HP so it had an XP Home edition license sticker on the bottom so I don't ask me why he was installing this other copy of XP. I figured it'd be pretty easy. I have a little USB adapter that I can plug into laptop hard drives that have the standard pin setup. We'll he brought it over and I took the drive out and it was some other different configuration (go go standards) so my little USB conversion wouldn't work. I needed to get the data he had on there off (didn't want to loose their files etc). I coulda installed Windows on an external drive and then booted from that to get to the files on the drive, but that'd take too long. Then I remembered my good ol' days of tinker-ing with BSD's and Linux and downloaded a Linux 'Live' distro (you know.. the ones that boot completely off of a cd). I decided upon using Ubunto because it's been getting a lot of rave lately. So I popped it in, booted up, and the only thing I had to do was get Nautilus running with super user rights to access the NTFS file system. The rest was down hill. I copied everything over and formatted the drive. Then I installed his original copy of Windows using the license that was issued to the laptop and he was on his way. So the next time I need to get data off of a non-bootable computer that I can't easily just take the HD out and plug it into a functioning computer I'll remember the little trick I did this time.


Need an SSL cert to test your site?

Sometimes when you're developing a website that you know will be served on 'https' it's nice to be able to test using 'https' to make sure things work as expected. You could go the route of creating your own certificate using something like

makecert -r -pe -n "CN="%computername% -b 01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12

but then you have to deal with the pesky messages that let you know that it's NOT a valid certificate, and/or adjust your browsers settings for your site etc. There is an easier approach to this. Many certificate authorities are now offering trial certificates. All you have to do is just give them a little bit of info about yourself (I guess you could use someone elses though) and you're good to go for a period of time.

I recently received a certificate from Thawte that will last me 90 days. This is plenty long enough for dev/testing of our site on SSL and I have a valid certificate that wont cause my browser to yell at me. Thawte was just the one that I happened to go through you can also get a trial from VeriSign although the trial isn't as long.

Saturday, June 02, 2007

Source Code Formatting... ugh

So I started a new blog and do most of the work for that blog on a Mac. I mainly use windows for this blog (since I post mainly about .NET) and have been fairly happy with Windows Live Writer and a code formatting plugin. Well I was looking for a good blogging tool for my Mac to use for my new blog. I looked into Ecto, Qumana, ScribeFire and I wasn't extremely thrilled about any of them. They would screw up my formatting mainly when doing code snippets. Why does it have to be such a pain to simply just post some source code in a blog as it appears in your code editor? Well after an hour of playing around with some of the mentioned blogging tools I finally remembered "Hey you're making this harder than you need to, remember you have a Mac and things are easier". After that little thought it took me a few seconds to get some source code into nice HTML form.

First I just did a simple copy of the source code straight from Eclipse.

Then I loaded up Pages and pasted what I copied.

Then I exported it to HTML and voila! Magic!

Thursday, May 24, 2007

asp:FileUpload not posting back?

This is fun.

Didn't really find a whole lot out there on this so I figured I'd post it just in case I ever forget :)
We had a little upload pop-up in an ASP.NET application. We are just using the 'asp:FileUpload' control for this. We have another regular ASP button that has a server-side click event that will perform some validation and then save the file into a database and a few other things. Well someone reported a bug stating that if you just typed in anything (ie 'asdf') then it wouldn't let you know that it was an invalid file. No validation would be performed. We'll I started looking into this and noticed that the button click event wouldn't even post back? It would only post back if you had something that was somewhat valid entered in. (ie. 'c:\bob.txt').
Well here's the reason. This happens only when using IE. This is an IE specific issue. If you try this same thing in FireFox or Opera you'll notice that the post back will be fire off just as expected. IE trys to validate this before calling back. So if you enter something in that is just invalid IE wont even bother posting back, thus you'll never see your lovely button click event ever being called.

Don't believe me. Try it for yourself. Here's a link to a site that already has a sample 'asp:FileUpload' control loaded. Try it in IE and then in some other browser both with valid files and some junk like 'asdf'. You'll notice you only get the postback with the junk data on non-IE browsers.

Tuesday, May 22, 2007

Silverlight Airlines

I stumbled across this today and had to link it here. It's just a cool Silverlight demo application from Microsoft that shows a few of the new really cool things you can accomplish with the new Silverlight (previously WPF/E) project.

If you don't already have the Silverlight 1.1 installed you'll need it before the demo will work. You can download it here.

Monday, May 21, 2007

.NET ActiveX Example. Javascript event wireup. SSL

Okay if you read my last post and are wanting some answers (visual ones that is) then here ya go! :)

Skipping along to step#2
Here's an example of an interface used for events that you wanna hook up with in JS

    [Guid("00000000-0000-0000-0000-000000000000")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface IExposedEvents{
[DispId(0x60050000)]
void DoSomething(string someString);
[DispId(0x60050001)]
void DoItAgain(int someInt);
}

Obviously you're gonna wanna put a valid GUID in there. So basically the second attribute, after the GUID, just says that this is a dispatch interface that will be exposed to COM. The second line is just re-iterating that this will be visible to COM. The [DispID]'s are used to uniquely identify the events to COM. These id's can be simple ints '[DispID(0)]' if you'd like, just make sure they're unique. You don't wanna have 2 events with the same dispId.

Next is the interfaces used to expose properties/methods...

    [Guid("00000000-0000-0000-0000-000000000000")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
public interface IExposedMethods{
void SetSomeVariable(string newVar);
string GetSomeVariable();
}

Again you want a unique GUID. This interface is nearly identical to the Events interface. The only difference is that you don't need the dispId's for the properties/methods that will be exposed.

Now here is the UserControl class

    [Guid("00000000-0000-0000-0000-000000000000")]
[ProgId("WindowsFormsUserControl.UserControl")]
[ClassInterface(ClassInterfaceType.None), ComSourceInterfaces(typeof(IExposedEvents))]
[ComVisible(true)]
public partial class MyControl: UserControl, IExposedMethods { //your code }

Okay so this one is a little different now. You still need the GUID (Well you don't HAVE to, read my last post. But if you wanna expose events in JS and use SSL then you need it). The ProgID is used to simply return the programmatic identifier for the specified COMAddin object. The next line starts off by saying what kind of interface is going to be generated for the exposed COM object. Here we are saying we don't want to generate one 'ClassInterfaceType.None'. The other 2 options are AutoDispatch and AutoDual which will auto generate an interface to expose for you (If you don't have any events to expose you could just write the user control with no interfaces and select one of these 2 options). The last part of this line is saying we want to use a specific type to expose this attributed class's events to COM.

So once you've got your control ready to go (created strong name, regasm'd it, etc) then you're ready to write the Javascript code in your .asmx file.

<object id="Bob" classid="clsid:00000000-0000-0000-0000-000000000000"></object>

This will place the custom control onto your form (if it's within the right tags, ie <div> <body> etc.). Next all you need to do is hook the event

<script for="Bob" event="DoSomething(someString)">
//Some code here... whatever you want to do :)
</script>

Like I said in my previous post you could also do it this way

<script>
function Bob::DoSomething(someString) {
//some code
}
</script>
I've had more success with the first approach, but it's silent so if you have a problem you wont know until you fire your event and it simply doesn't work.
Now you should be able to write some Custom Controls that you can hook up to JS events AND work with over SSL (Just make sure you register the assembly on the machine you want to see the controls on)
And again this is for SSL/event controls. If you just want to make a control for a public site over non-ssl without registering the controls on the clients then you don't have to take this exact approach. There is another way! Hopefully I can get some time and I'll do another post or two on this topic..

.NET and ActiveX

Wow, what a lot of trouble it can be to just get some ActiveX going in ASP.NET. Some may ask why you would want to even incorporate this technology which is only supported in Internet Explorer and which opens up a can of security worms. Well sometimes you gotta do what you gotta do and this is the best thing to use for some situations. The project I'm currently working on is a web based customer service type application and one request from one of our customers is that they would like our application to respond to their phone IVR. So that when employees receive calls, our web app will automatically respond by loading the customers info before the agent answers the phone. Hey it's nice to be greeted by 'Good morning Mr. Wilson what can I help you with". This is a situation where we kinda needed to use ActiveX. Well the good news is is that you can do this in .NET, the bad news is is that it can be very picky sometimes and it seems there isn't a whole lot of info out there about this topic (There is on Win32, but not .NET).

 

Okay, so here's the good stuff you came here for :)
First - you're gonna want to create a custom control that you can drop somewhere on your ASP page. We kept ours out of our existing solution and made a new solution just for our ActiveX stuff. (new class library solution -> new user control)
Second - If you're gonna want to be able to call methods / set variables etc AND respond to events (like mouse click, or custom events like the IVR is sending you a call) you MUST create two interfaces. One for events only and the other for methods/properties etc. These interfaces will be exposed to COM and will be the things your web page / other applications will communicate with. (example of all this will be on the next post)
Third - You will need to give all of your events [DispId(some unique int)] attributes
Fourth- You need GUIDs for your interfaces and custom control class/object. If you're using VS2005 it's easy just do 'Tools -> Create GUID'. (You don't HAVE to have GUIDs if you're making a plain jane control.. But if you want to use it over SSL and hook up events in JavaScript then you're gonna need to use them for sure)
Fifth - Right click on your the project your custom control is within and select 'Properties', go the the 'Build' settings and check the 'Register for COM interop' box. If you wanna be able to respond to COM you gotta set it.
Sixth - Register your new dll created when you compiled your new custom control. The old way, Win32 way, to do this was with 'regsvr32.exe'. The way you do it in .NET is to open up the VS Command Prompt, navigate to your .dll and type 'regasm /codebase customControl.dll'. Regasm is short for 'RegisterAssembly'. The '/codebase' will set the codebase in the registry. (Now you don't HAVE to do this step either... But again, if you wanna use it over SSL and respond to events and things your gonna need to register. Otherwise you don't have to)
Seventh - Add your new custom control to your ASP page. '<object id="Bob" classid="clsid:00000000-0000-0000-0000-000000000000"></object>'. Replace the 000... GUID with the one you used for your custom control. If all went well you should be able to see your custom control on your page. There is another approach to this, you could use 'classid="customControl.dll#namespace.classname' but then the dll has to reside in your ASP site, AND the KICKER is that this will NOT work if you plan on using SSL. So it's just easier to use the GUID :)... (But you don't HAVE to do it this way, you can use the second way 'dll#namespace.class' but.. it just wont work with SSL :)
Eigth - To wire up your events there are also two approaches. The first '<script for="Bob" event="yourEvent(args)"> some script </script>' is the the approach that seems to work the best. This will also not throw JS exceptions if it doesn't hook/sink correclty. The second approach which may let you know there are problems is '<script> function Bob::yourEvent(args) { } </script>'. I would recommend the first since it seems to work a little more often.
Ninth - Okay the last step is to strong name your assembly. This is pretty easy. Just right click on your project -> properties. Go to the bottom tab 'Signing' and check the box 'Sign the assembly'. Then in the drop down select 'New'. This will bring up a pop-up. Type in a name for your key file (this can be anything you'd like) and you can supply a password or uncheck the 'Protect my key file with password' if you don't want a password. Click 'okay' and you're done!
So there are the basics. Now we'll do some code examples in the next post, if you're a visual kinda person like me :)

Also check out Eber's blog to. We both worked on many of the ActiveX problems so we'll both be posting about some of the issues. So if I don't answer you question he may have it in his blog :)

Tuesday, May 08, 2007

Ignoring SSL Certificate Problems

Have you ever run across these problems when trying to connect to a secure web service?

"The remote certificate is invalid according to the validation procedure",
"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

Usually this is caused by a bad certificate on the server side, but what if you want to connect anyway, maybe you trust the remote system and just don't care. How do you get around this? How do you get your code to ignore these warnings and continue? We'll if you're using .NET 2.0 it's really easy (still pretty easy in .NET 1 but it takes a little more work). You'll need to use the ServicePointManager class, and add this using statement (if you don't want to use the fully qualified names anyway).

using System.Security.Cryptography.X509Certificates;
Now all you need to do is add this bit of code somewhere before you make the call to the web service.
ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors) {
return true;
};
The 'ServerCertificateValidationCallback' is used to custom validate server certificates. By default it is null, and since the above code just returns 'true' all certificates will be valid now. You could add some more custom code to this if you wanted to do your own validation, say you only want it to be valid if the cert comes from a specific place etc.
You can also check out this MS link as well that has the same code as above

Tuesday, May 01, 2007

F#... Hot or Not?

Eber and I recently decided we wanted to play around with a new language. We looked into a few of the current popular ones like Ruby or Python (Since we can use them in VS, IronRuby / IronPython), but they are all 'fairly' similar. (I put in IronRuby instead of Ruby in Steel because one is $199 and the other is not, and hey... free is good ;)  ) So we decided to go somewhere new, a language that is quite a bit different, F#. F# is an experimental language from Microsoft that shares the same syntax style as OCAML (Object CAML). It's a functional language which made it different enough for us.

So if you wanna play along here's what you're gonna need:

1-Visual Studio 2005 (does not currently work on Orcas)
2-F# (download the newest version (1.9.1) here, the F# home page currently doesn't have the newest release listed)
3-Some patience since there is not a whole lot of stuff out there about F#. But there is quite a bit of stuff out there for OCAML (Which is where I've been getting most of my info since most of it will work in F#)
One other things that led us to F# was the amount of influence it has had on C#. What you say? Well yes there are many things from F# that have made their way into C# from this experimental language. One of the newest things are Lambdas, as of C# 3.0, which make the new LINQ possible (where they are used everywhere!). So if all of this hasn't gotten you the least bit excited it's also a type safe language, you can do scripting, or objects, and since it's a .NET supported language you can access your F# DLL's from your C# projects, and vice-versa. Since it is a .NET supported language and it isn't widely used you will find lots of examples out there that use quite a bit of the .NET librarys.

ex. You may see quite of bit of this

Console.WriteLine("Hello");; // Looks familiar if you use C#

instead of this

print_string("Hello");; // This is the F# stuff (which is also the same in OCAML)

print_newling();;

So one thing you may notice right of the bat is the double ';' at the end of the lines. This is one of the first things that had stumped me, and I was hard pressed to find anything on the F# website. So I started looking around the OCAML pages and found this nice explanation of when to use no ';' when to use a single ';' and when to use double ';' (scroll down a little over half way down the page until you find 'Using and omitting ;; and ;')

So far I give F# a potential 'HOT' vote, since I haven't done a lot with it as of yet. It's a different way of thinking, since it is a functional language, and it's also a pretty flexible language. Eber and I plan on doing more with F# so expect more blogs from the both of us in the future, if you're interested in F# if not keep checking our blogs for other fun stuff :)

Monday, April 30, 2007

Visual Studio Acting Up

Has Visual Studio ever started 'acting up' on you? Every once in a while I notice that VS just acts plain weird for me. For example, it will quit compiling certain projects for me, or sometimes project A, that has a ref to project B, quits seeing updates to project B. Just little nuances like these every once in a while can be a pain to figure out, and are just plain frustrating. Eber had a strange issue last week where if he compiled the projects within a solution individually they would work fine, but If he compiled the entire solution certain projects dll's would revert back to a previous build in referencing projects??

This was just plain weird! He would changed the version number of one of the projects, build the solution and in the referencing project the dll would revert back to the old version. Tried deleting all the dll's and rebuilding, tried removing and re-adding the reference, tried deleting cache. None of these worked, and we were both kinda stumped on this one. I remembered a while back I was having some issue after getting a bunch of files from our current projects repository, and I had deleted the .suo file just for fun :) and after I re-opened the project everything started working again for me. So we figured we'd give that a try and see if it would some how fix the issue he was having. Voila! and what do you know... it fixed this strange problem.

 

Weird..

Saturday, April 28, 2007

Vista - Security and Usability

I recently installed Vista on my wife's computer (I figured maybe it would be a little harder for her to break). I had installed it before, but wasn't happy with VS2005 support and a few other things, but I thought it would be great for her. One thing I had been meaning to do for a while was setup some sort of back-up for all of her stuff (She keeps all videos, pictures etc on her computer and if a hard drive crashed she would loose 8+ years of photos). I set up a striping array for a general safety net, which when doing this on XP you have to add a floppy drive to install drivers so that you can even use any type of RAID setup. Basically with XP it's a pain, especially if you don't have a floppy drive in the computer. I was happy to see that I didn't have to do a thing to get the RAID recognized in Vista. The installer came up and just asked where I wanted to install and right there was the RAID array all ready to go. This is one improvement that I've been waiting for :)

Here's the downside though. Have you seen some of the new Apple commercials? The one where the 'Windows' guy has the security guy behind him asking him to 'deny' or 'accept' everything? Well... that can get kinda irritating, but what about when stuff just doesn't work? My wife has an iPaq, and pretty much all we needed to do on XP was just plug it in and tell ActiveSync what should be synchronized. Well once I was done with the Vista install I figured 'Hey the RAID was sooo easy to get going that the iPaq should be a sinch'. Man, I was wrong. I plugged it in and it installed a 'generic' driver and that was it. One thing with Vista is that there is no more ActiveSync, it's being replaced with Windows Mobile Device Center. So I loaded the device center up thinking the iPaq would be there... Nope.

Basically after a little searching I stumbled across this link. Wow what a lot of setup just to get Vista to work with the iPaq. I don't think someone with decent knowledge of Windows, like my wife, would have found this easily. I also don't think the basic user, like my grandmother, would have ever been able to figure this out without help. So is forcing the user to have more knowledge of the underlying system the 'Best' approach to solving some of Windows security issues??

Friday, April 13, 2007

Calling static class A's static methods from a singleton class C where C does not reference A?

Whoa.. I ran across this little scenario the other day.

In the application I'm currently working on we have a static class with static methods that are used for some logging purposes throughout the rest of the app. (The static methods link to a back-end singleton class). This logging class lives within our objects. We also have a bunch of interfaces for these objects that are passed around in the rest of the app. Our objects hold a reference to the interfaces but the interfaces do not hold a ref to our objects. We have another Singleton class in a plugins project that only gets passed interfaces (the plugins also hold a ref to the interfaces, but not the objects). We needed to be able to do some logging (preferably using the already implemented object) from this singleton but ran into this fun little scenario.

So basically (If you didn't want to read the above paragraph)

Class A(singleton) has a reference to Class B(interfaces)

Class C(objects) has a reference to B

A does not ref C and C does not ref A

How does A call a static class' static methods of C?

Well, here goes.. Our singleton (class A) gets started up and no one ever calls methods against it.. It just runs and periodically does some checking. We need to log though using class B..

When we do our startup and begin the singleton of A we pass in the methods needed from C. We added an Init method that is called at startup that takes local delegate types with matching signatures of class C's methods. Then we keep local copies of these an can call them whenever we need to, thus calling into class C's methods that we don't really have access to...

Some sample code:

public static class C {
public static LogA(string s) {}
public static LogB(string s, int i) {}
...
}
public class A {
//Some singleton stuff here//
public delegate void LogADelegate(string s);
public delegate void LogBDelegate(string s, int i);

LogADelegate _logA;
LogBDelegate _logB;

public void Init(LogADelegate a, LogBDelegate b) {
_logA = a;
_logB = b;
//more init code//
}
}
//Code from a startup class
A.Init(C.LogA, C.LogB);

The neat thing is that your passing a static method and storing it and using it as though it where an instance method.
One other quick neat thing is if you have multiple overrides of LogA

public static LogA(string s) {}
public static LogA(string a, string b) {}
public static LogA(string s, int i) {}

The compiler automatically infers which one to pass when calling the Init() function based on the delegate's signature.


I thought it was pretty neat anyways ;)

Friday, April 06, 2007

Crystal Reports Revisited

I setup Google's Analytics yesterday after I noticed that I actually had some visits to my blog, Woo Hoo ;) I noticed that I was getting some hits about a post I did on the 'grouping' feature of formulas in Crystal Reports. I guess I shouldn't be too surprised, the documentation for CR is not good at best.

I'm going to do some more research into this, since it has been a little while, and do another post that will, hopefully, explain the formula/grouping a little better.

So hang tight! it'll be posted here in a little while ;)

Monday, April 02, 2007

< > Abstraction

I was refactoring some code last week and ran across a little section I thought was kinda neat. We had a method in some object that basically would try and get the next lowest item from a collection. Not the lowest, but the next lowest. There was also a method that did the exact same thing for the next highest item as well.

So basically if we had this collection { 2, 4, 5, 7, 9 } we would pass in one of those values to the method which would return the next lowest/highest. So if we called the next lowest function passing in '9' we would get '7' in return.

Here's the basics of the next lowest function

public Item GetNextLowest(Item item) {
Item result = null;
//Some other checking here
foreach (Item i in Values) {
if(i < item) {
//Set the result
if (result == null) result = i;
//There is a lower item, but make sure it's the next lower
else if (result > i) result = i;
}
}
return result;
}

Reversing the '< >' in the next higher function made the two methods identical so I needed a way to abstract this out. One way would be to pass some delegate in that did the comparison for you, but that would add a bunch of code elsewhere, and we're trying to shorten the amount of code. Another way would be to pass in a boolean and then do some if/else statements to determine if we want '<' or '>', but this adds unecessary logic that occurs quite often. So the solution that I finally implemented was this.

public Item GetNextLower(Item item) {
return GetNextItem(item, false);
}
public Item GetNextHigher(Item item) {
return GetNextItem(item, true);
}
public Item GetNextItem(Item item, bool higher) {
//Use this to figure out if we want < or >
int compare = (higher) ? 1 : -1;
Item result = null;
//Some other checking here
foreach (Item i in Values) {
if(i.CompareTo(item) == compare) {
//Set the result
if (result == null) result = i;
//There is a lower item, but make sure it's the next lower
else if (i.CompareTo(result) == compare) result = i;
}
}
return result;
}

So basically all that was added was the abstracted method and the 'compare' int that is used to determine if we wanted the next lower or higher Item.

Thursday, March 01, 2007

Javascript is cool?

So I was gonna blog about this yesterday... but It was late and 'The Greatest Thing Ever' was a tad bit higher on my priority list.
Well here goes another blog.
The project I'm currntly working on has sooooo much AJAX madness. (It's like way after my bed-time so bear with me), and I'm not an 'Expert' on JavaScript... yet. So I started looking for some cool tools that might benefit me a lil' bit. I found ActiveState's and IntelliJ's solutions but I didn't want to pay alot of money. I finally stumbled acrossed this plugin for Eclipse that looked promising. It's from Adobe (previously Interak). So I downloaded it, installed it..... And EXCEPTIONS!... Wow!

Well I started looking into this a bit... and apparently this is something that just happened to make its way into the release. I found some info on Adobe's website, but none of it was promising. Basically everyone was saying "Just upgrade to Java 5", well my OS X pc has 5.0 ready-to-go. I kept getting this error "The selected wizard could not be started", "Plugin-in com.interakonline.jseclipse was unable to load class com.interaktonline.jseclipse.ui.newwizard.JSClass".

The solution is basically to just ignore this error!?!? I mean don't worry about, Adobe hasn't done any upgrades for this product in a while, and there's not a whole lot of info out there for this fix. So to use this plugin all you need to do is just add a new 'File' to your project and give it a '.js' extension. This will bypass the previous error and let you get down to business. Code completion works good, and best of all it's not $200 + to use it. So if you're not using Orcas (or can't) then this is a good solution if you want to develop some JS code but don't want to fork out a lotta cash!

Wednesday, February 28, 2007

The Greatest Thing Ever!

This picture pretty much sums it up :)

Have you ever wanted to be able to do everything you ever wanted on just one computer, without the need for reboots, special setups, or very hindered performance? Well now you can!

In my professional life I'm a windows kinda guy, I go to work, I log into a windows domain, I develop in c# and Visual Studio. In my personal life I'm an Apple kind of a guy, I love the stability and easy to use applications, the BSD core, etc.

Well sometimes when I'm at home I want to be able to do some c# coding. Yes I could use Mono, but the IDE options are sparse, or require a lot of setup, and I can't use a lot of the new features in .NET 3. I originally used Parallels but hated being limited to one screen, hard to use USB devices etc. I eventually switched to Boot Camp and Vista, but Vista has a whole slew of issues with VS2005 and little support for WPF in Orcas, AND I also had to reboot. I had my iTunes and stuff in OS X and didn't want to duplicate stuff so I wasn't 100% happy.... yet. Well last night I noticed that Parallels had posted a new release. WOW! They have made some huge improvements. First off my favorite new thing, Coherence. To enable this just load up Parallels and select 'View' - 'Coherence' and BAM! done. Your desktop now has both the Windows task bar AND the Apple app launcher! How hot is that! Well like I had said before I really didn't like being limited to one monitor with Parallels. Well it just got better. If you go back to Parallels and select 'View' - 'Customize' you'll notice my other favorite new feature, a little option that says 'Use multiple desktops'. No I can drag applications (Both Windows and OS X) back and forth between my monitors.

So now I'm very happy! When I'm at home I can have my Visual Studio up on one monitor along with iTunes, and my browsers (Safari, Firefox, IE) on my other monitor. AND If I really wanted to I can boot up my Boot Camp OS using Parallels, so there is absolutely no need to reboot anymore!

Tuesday, February 13, 2007

It made me giggle a little

Maybe I was tired, or my brain was a little wrecked, but I was doing a little surfing last night and this blog made me smile a bit. I just love all the "sucks" in there HA!

Sunday, February 11, 2007

WPF/E - getting started

WPF/E is one of Microsofts latest "Hot" things. It's used to create very rich, cross-platfrom, interactive web applications.

It's fairly easy to get this working. Here's some things you'll need

Windows XP / Vista with .NET 3.0

Visual Studio 2005 (Orcas 'JAN CTP' does not work with WPF)

WPF/E SDK

Once you have these you're pretty much ready to go. The WPF/E SDK will install the template for VS2005. Now there are two ways to start playing around with this. The first is to open up VS and create a new project. ***Make sure you don't select New Web Site unless you follow the article mentioned below, just click the new project. Under the 'My Templates' section you see "WPF/E Javascript Application". This creates a web site with no aspx files, just straight up html,javascript, and XAML.

I could go into how to setup a web site with good old aspx files, but the information is already out there.. You can find it in this good article.

Hopefully I can get some better posts up about WPF in the near future (I'm just green on this technology right now :) )

Stay Tuned!

Crystal Reports Madness (Setter Exception)

Ran accross this fun little issue with a report that sets a Group condition...

We had some code like this:

Group group = report.DataDefinition.Groups[4];
group.GroupOptions.Condition = condition;

We used this to set a DateTimeCondition property of one of our reports. But everytime it hit this code an exception was thrown :(.


After spending a fair amount of time trying to track down a solution to this problem we found it to be an issue with the Setter for this object.


We changed our code to this and all is well again.

Group group = report.DataDefinition.Groups[4];
try {
group.GroupOptions.Condition = condition;
}
catch { }
group.GroupOptions.Condition = condition;

Basically we let it exception once, and don't handle it, and then set the property again. For some reason it always exceptions on the first attempt, but then sets the property fine the second time.


We found this solution by changing this value at runtime using the VS debugger. It would change the value fine at runtime if we modified the value in the watch window, but if we let it just try and pass through without manually changing the value then it would exception. If we manually changed the value and then stepped over the code, then it would work??



This is a strange one.

Crystal Reports Madness (Formulas / Datasets)

"There must be a group that matches this field."

I recently was given the task at work to get a bunch of crystal reports working from a win32 application, that we inherited, to our new web app version. I had never done anything with Crystal Reports before so I wasn't sure what I was getting myself into.

Crystal Reports ended up being pretty straightforward and easy to figure out, but that wasn't the hard part. The current reports we had connected directly with the database to get the information they needed. We didn't really like this 'pull' model for a couple reasons.

1 - The current application only connected to Oracle. The new web application was not DB specific.

2 - Didn't really like the idea of having the credentials stored within each report file.

3 - Changing DataSets was a pain, and had caused problems with the report files themselves in the past.

So we decided to implement the 'push' modal.

(Push / Pull explained here...)

This seemed pretty straight forward. We created XSD's for each report, and then changed the datasource location in the report file using VS2005.

Well... This ended up not working It wasn't until I stumbled accross some very sparse information on the web explaining that it's best to disconnect the report from the DB and THEN change the DS location. This finally ended up working for us (Task 1 DONE!)

The next issue was that we changed some of the report paramater names to make more sense. I figured this wouldn't be much of a problem, but boy was I wrong. When I saved the report I received multiple complaints from the report. Most of which were due to some of the report formulas. I loaded up a few of these formulas and received this error when I tried to save them

"There must be a group that matches this field."

I searched the web trying to figure out what it wanted, but I mostly stumbled accross web sites only offering training, actual documentation was kinda sparse, or not really that great.

Basically the solution boils down to this.

Our formulas group options were being set dynamically in code behind, so this condition wasn't in the original formulas which caused the error. The weird thing is that they had worked before we changed the dataSets, now we had to set it (we set it to 'for each month') but it would then be changed when the report was run dynamically. hmmm

The 'Average' function follows these signatures

Average(field), or Average(field, condFld), or Average(field, condFld, cond), or Average(x).

The third param 'cond' had to be set to match it's corresponding groups grouping. Now if you go to the group on the report, right click, and go to 'group expert' you can view/change the grouping (Monthly, Annually, etc) but in the formula it's not so clear as what to use. I looked in the actual CR documentation and they actually refer to the wrong thing to use for this (Many peoples posts, blogs etc had complained about CR's documentation) I stumbled accross the correct value to use and the reports save fine now, and also work, even though it's just dummy data that is changed at run time >(

Oh well... I hope this may help some poor sould out there

Crystal Reports Madness (Orcas)

I sat down today to write a blog on some information about Crystal Reports. Little did I know this would turn into 2 blogs.

I downloaded Vista Ultimate from good old MSDN a few months back and everything was working great with it. I had installed Visual Studio 2005 and was able to do some development for work, which HAD worked great. Up until a few weeks ago I hadn't had to many issues with Vista (Except for the Cisco VPN client, which doesn't work with the released version of Vista). Now some of the issues are starting to bleed through. VS2005 crashes, OFTEN, which led me to install the new Orcas (Jan CTP). This worked much better than 2005 so far, minues the WPF support :(

So leading back into the topic of this blog, I loaded up Orcas and opened my work project. I went in and double clicked a report file to refresh me on what I was going to blog about AND..... I got a straight up HEX view of the report! Apparantly that too doesn't work with Orcas... So back to 2005 I go hoping I don't make it mad enought to crash :)

Thursday, February 08, 2007

Protected Internal??

So I was writing some code today that I thought was great! I went to show my Buddy and he pointed one thing out to me. I had a few methods in a base class marked as protected internal. He told me "I don't think that's doing what you think it's doing". I was thinking that these methods would only be accessible to inherited members AND members within the same assembly. I guess I just made the assumption since public static marks the member as both available to all AND a non instance member.

Anyways I decided to take a look at the good old msdn site to see exactly what it says. Basically this says it all "only derived types or types within the same assembly can access that member". Notice the keyword "OR" in there. So my members were either available to inherited members OR members within the same assembly....

But this is not what I wanted.. I wanted what it sounded like! a member that was available ONLY to inherited AND same assembly members! So the quick solution to this was to just mark my class as Internal and it's members Protected.

ex.

internal class SameAssemblyClass {
protected void InheritedMethod() { }
}

Monday, February 05, 2007

Orcas, Vista, Linq, WPF, XNA ????

So a buddy and I have been wanting to play around with some of the very new and exciting upcoming technologies from Microsoft, well I guess Vista is officially out now. We didn't do a whole lot of research when we began this endeavor, I guess we were just a little excited. So here is the lowdown :)

Vista comes with the new .net 3.5 framework so this was good since Linq and WPF use it. Orcas is the new Visual Studio that will be used to take advantage of all of these new features, so this should be good. Well...... maybe :(

Orcas (Jan CTP) installed without a hitch, and seemed to work pretty good. The first thing we tried to do was play around with Linq. We found the '101 samples' website for Linq and started writing some queries. This was a 'no-go', VS didn't seem to like the syntax. We started to think 'What gives!' so we began our Google searches. Apparently you need to reference the 'System.Core.dll' which is found 'Windows\Microsoft.NET\Framework\v3.5\'.. Whoa.. you think this would be a little more straight-forward since this is a new feature that showcases the new .NET 3 and Orcas. Anyways after some looking around we got it working. It's pretty neat to say the least!

Next was WPF. Orcas didn't come pre-loaded with a WPF template? hmmm. 'Okay there must be a plugin' we thought. The only plugin we could find was for VS2005! This was no good, we wanted to use the new Orcas and the new WPF to write some new applications! Oh well, guess we'll be waiting on that one AND using 2005 for development, bummer.

Last but not least was XNA, surely this must work I mean it's a release version now and VS2005 kinda works with Vista(keep reading for this). Well you still have to have VS2005 Express to use XNA Game Studio Express. So we got this installed and then XNA. Went to load up a pacman style game we've been working on and...... NOTHING! Come to find out, after some more Googling, XNA does NOT work with Vista, double bummer.

Oh and the VS2005 kinda working with Vista well... Even with the SP1 for VS2005, it still has issues. It consistantly crashes at random times, among other small issues. So I guess if you want to play around with WPF, XNA Linq and many of the other new features coming out I would stick with XP and VS2005 for a while, atleast until they get some of this worked out... So I guess we'll revisit this in a couple months ;)

Friday, February 02, 2007

Google Math. How high can you go¿?

Sitting around the office the other day me and 2 of my buddies were talking about regular geek stuff. I brought up the whole 'Can you fold a piece of paper in half more than 7 times' debate. I watched the Mythbusters episode about it the night before. This eventually led to a discussion about Fibonacci. Which then led to a further debate on what the highest number you could achieve using Google.

 

Can you beat this number??