Friday, July 29, 2011

How to Iterate Through all Enums from a Class in C#

This took me a good while to figure out. This is specifically for looping through multiple enumerations declared inside of a class. This code would have to be modified slightly in order to loop through all enumerations inside of a namespace. I searched for this code everywhere on the net and I couldn't find it so I wrote it myself.

Enjoy.

public void GetAllEnums()
{
 object enumValue;
 string[] arrEnumNames;

 Type enumType;
 FieldInfo field;
 MemberInfo member;
 
 //Get all of the members of this class, this includes everything
 MemberInfo[] members = typeof(AllEnumsToTable).GetMembers();

 //Loop through the members.
 //Hard coded to 7 because I can't figure out how to filter just for enums
 //System.RuntimeType isn't allowed to be used for what ever reason
 for (int i = 0; i < members.Length; i++ )
 {
  member = members[i];

  if (member.MemberType == MemberTypes.NestedType)
  {
   enumType = Type.GetType(member.DeclaringType.FullName + "+" + member.Name);

   if (enumType.IsEnum)
   {
    Console.WriteLine(member.Name);

    arrEnumNames = enumType.GetEnumNames();

    foreach (string name in arrEnumNames)
    {
     field = enumType.GetField(name);

     enumValue = field.GetRawConstantValue();

     Console.WriteLine("Key {0} Value {1}", name, Convert.ToString(enumValue));
    }
   }

   Console.WriteLine();
  }
 }
}

Wednesday, July 20, 2011

Tuesday, July 19, 2011

Cisco IP Communicator Virtual IP Phone Hijacks Port 80 When You Aren't Looking

I have reproduced this problem so it isn't a bunch of hooey or heresy. If you are using the "Cisco IP Communicator" Virtual IP Phone and you work with IIS on the same machine you could mistakenly run into a scenario where the Virtual IP Phone hijacks port 80. This is especially a big problem if this machine is hosting an application that people are trying to hit externally (as opposed to locally IE: http://localhost/)

How does this happen?
Follow these steps to recreate the problem (or just read through them):
  1. IIS Must be running first
  2. Hit your IIS Server externally (from another computer) via IP or Computer name to verify that IIS is functioning properly. IE: http://1.2.3.4/ or http://ComputerName/
  3. Start Cisco IP Communicator
  4. Reset IIS - (cmd: iisreset /restart)
  5. Hit your IIS Server externally again, notice this time you are looking at a Cisco Page running off of Java?
What is most interesting about this is there is no Preference or option to turn this shit off (easily), it just happens. THANKS CISCO I APPRECIATE IT

OMG How do I make it stop!
The good news is you can make it stop and here are the steps on how to do that:
  1. Exit out of "Cisco IP Communicator" and I don't mean minimize, I mean close the program completely.
  2. Reset IIS
  3. Hit IIS externally again, you should see what ever it is you are hosting in IIS, congrats.
  4. Alternatively: You can just restart your computer, that should work too.
I hope Cisco has a way to avert this issue in the future. I think you have to edit the registry, but I am honestly not sure. I don't like the idea of this program hijacking my port 80, especially in the middle of development. I work with two machines because of our setup at work; otherwise I don't think I would have figured this out.

Either way, SHAME ON YOU CISCO!

My setup, just for reference:
Windows 7
IIS7
Visual Studio 2010

Friday, July 8, 2011

Windows 7: How to locate a task you created in the Task Scheduler

I created a task recently in the windows 7 task scheduler and I couldn't find my task after I created it. I saw other people were having problems with this too so I just wanted to point out one way to find your task again.

Open up the Task Scheduler (windows orb, search for task scheduler) and assuming your task is running look at the bottom of the window in the section named Active Tasks. Look through those tasks until you find the task you created.


If you need to edit your task
After locating your task double click on it. You can review it in the window show, but in order to actually edit it you need to click on the properties option located on the right hand side.


And there you have it, you have successfully located your task and you can modify it now.

If your task isn't running I am not sure now to locate it. I will try to figure that out later.