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.