Welcome to MSDN Blogs Sign in | Join | Help

Introducing Shelly

Say hello to the new face which is rocking my world:

Her name is Shelly.

Update:  A Shelly Santo fanclub is now up @ http://shellysanto.spaces.msn.com

 

Posted by Addys | 4 Comments

LINQ at the NYC Code Camp this Saturday

I'll be delivering my famous (ok, not really) "LINQ & C# 3.0 For Mere Mortals" presentation at the NYC Code Camp this Saturday.  For those who haven't registered yet- unfortunately the code camp registration is already full , but another one is already being planned, so don't despair :)

During the presentation I will take a simple real-world application  in C# v1.1,  port it to C# 2.0, and then to 3.0.  Along the way I'll discuss the strengths and weaknesses of the previous and current versions, and also introduce the incredible new features appearing in C# 3.0 and LINQ.   By the time the pizza arrives, we will have condensed about 300+ lines of code down into a single one, while also adding some functionality along the way.  It should be an interesting presentation!

 

Posted by Addys | 0 Comments

[OT] 0 Items!

Kirk Allen Evan inspired me to finally take action on something which has been on my to-do list for months - cleaning out my Inbox, which had (despite all my rules) grown to over 1200 items.  It is strangely empowering to look at outlook and see:

(Thanks Kirk for both the inspiration and the above image)

[OT] = Off Topic, no technical content here!

 

 

Posted by Addys | 1 Comments

[OT] Not enough music!

I haven't been listening to music much lately, which must mean that I haven't been coding enough either.  Between Scrum-meistering the team, tweaking our infrastructure and completing a few lingering architecural tasks,  I haven't had time to squeeze in any serious development work in days.  

Oh well, thats what weekends are for, right? 

Posted by Addys | 0 Comments

Anti-Agile development conference

Agile developers should get a smile (at least) from http://www.waterfall2006.com/. This anti-agile conference couldn't possibly go wrong, they already have it planned down to the smallest detail:

"Because it's possible you may want to attend all sessions, Waterfall 2006 features no concurrent sessions. All sessions are run sequentially for your enjoyment. However, since in a waterfall process we don't want testers to know anything about coding, or programmers to know anything about design, and so on, you can only attend sessions that match your job function. When you register to attend you'll be asked to select an appropriate job function. When sessions that are not relevant to you are running you will be required to sit idle in the lobby.

The conference will also feature a number of workshops. Unlike typical conferences where workshops involve participants talking with each other, all Waterfall 2006 workshops will be conducted by document. Come to a workshop, open up your favorite word processor and state your opinion on something. Email it to other workshop participants. (We'll set up mailing list aliases for this--after all, we want to keep this process efficient!) Then just sit back and wait for someone to reply with their own document. Don't miss this opportunity to participate in vigorous written discussion with your peers."

Obviously, superior minds are at work here :-)

 

 

Posted by Addys | 1 Comments

GDI + LINQ = Generate a bar graph in a single line of code

This is a simplified version of actual code from an app I'm working on.  There are a few lines of setup, and then the cool part (the last statement): Using a select statement to iterate over a List<double>, creating a RectangleF object for each value, packaging them all into an Array, and passing the array to the FillRectangles method of the Graphics object.  All in a single line of code...

// Get values to draw

private List<double> performanceHistory = ReadPerformanceValues();

 

// Get the Graphics object to draw on

Bitmap bmp = new Bitmap(dimensions.Width,dimensions.Height);

Graphics canvas =  Graphics.FromImage(bmp);

 

// Scale the Graphics object according to the # of values

canvas.ScaleTransform(this.Size.Width/ performanceHistory.Count,1 );

 

// Create an array of RectangleF objects (one for each value) and pass them to FillRectangles

canvas.FillRectangles(

    Brushes.Green,

    performanceHistory.Select( (v,index) => new RectangleF((float)index, this.Size.Height - (float)v, 1F,  this.Size.Height)).ToArray()

   );

 

Posted by Addys | 1 Comments

Code Snippet: Setting NTFS permissions

My previous post shows how to use Windows32.Security to read and set permissions to the registry.  Doing the same for a NTFS is even simpler:

public bool TestNTFSPermissions(string path, string userName)

{

      SecurityDescriptor secDesc = SecurityDescriptor.GetFileSecurity(path, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);

      Dacl dacl = secDesc.Dacl;

      return TestAcl(dacl, userName);

}

 

 

public void SetNTFSPermissions(string path, string userName)

{

      SecurityDescriptor secDesc = SecurityDescriptor.GetFileSecurity(path, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);

      Dacl dacl = secDesc.Dacl;

      Sid sidUser = new Sid (userName);

 

      // allow: folder, subfolder and files

      dacl.AddAce (new AceAccessAllowed (sidUser, AccessType.GENERIC_ALL, AceFlags.OBJECT_INHERIT_ACE | AceFlags.CONTAINER_INHERIT_ACE));

 

      secDesc.SetDacl(dacl);

      secDesc.SetFileSecurity(path, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);                 

}

There is one caviat - I couldn't find a way to automagically apply a setting to a folder and recursively to all the subfolders & files. The following snippet takes care of that:

public void SetRecursiveNTFSPermissions(string path, string userName)

{

      SetNTFSPermissions(path,userName);

 

      foreach(string file in Directory.GetFiles(path))

            SetNTFSPermissions(file,userName);

 

      foreach(string dir in Directory.GetDirectories(path))

            SetRecursiveNTFSPermissions(dir,userName);

}

 

Posted by Addys | 0 Comments

Code Snippet: Working with Permissions (ACLs/ACEs) in C# under .Net 1.1

I've been working lately on adding "self-healing" capabilities to a certain application.  The idea is to create a set of utility functions which will validate (and fix if needed) various environmental settings such as NTFS permissions, registry permissions, IIS metabase settings, etc.  None if this is rocket science but there still was some work involved in bringing it all together, so I'll list it here in case I (or you) ever need to do it in the future.

Note: For anything related to security in 1.1, the Windows32.Security library  (written by Renaud Paquay) is an indispensable resource.

Snippet #1:   Check for permissions on a registry key (using Windows32.Security)

public bool TestRegistryKeyPermissions(string keyName, string userName)

{

      // get a handle to the key

      IntPtr hKey;

      if (Microsoft.Win32.Security.Win32.RegOpenKey(Win32Consts.HKEY_LOCAL_MACHINE, keyName, out hKey) != Microsoft.Win32.Security.Win32.SUCCESS)

      {

            return false;

      }

      try

      {

            // get the security descriptor

            using (SecurityDescriptor sd = SecurityDescriptor.GetRegistryKeySecurity (hKey, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION))

            {

                  // check whether the specified user has an ACE in the ACL

                  Dacl acl = sd.Dacl;

                  return TestAcl(acl,userName);

            }    

      }    

      catch

      {

            return false;

      }

}

 

public static bool TestAcl(Dacl acl, string userName)

{

      for(int i=0; i<acl.AceCount;i++)

      {

            Ace ace= acl.GetAce(i);

            if (ace.Sid.AccountName == userName)

            {

                  return true;

            }

      }

      return false;

}

 

Snippet #2:   Set permissions on a registry key (using Windows32.Security)

 

public static void SetRegistryKeyPermissions(string keyName, string userName)

{

      // get a handle to the key

      IntPtr hKey;

      if (Microsoft.Win32.Security.Win32.RegOpenKey(Win32Consts.HKEY_LOCAL_MACHINE, keyName, out hKey) != Microsoft.Win32.Security.Win32.SUCCESS)

      {

            throw new Exception ("failed to access registry key " + keyName);

      }

 

      try

      {

            // get the security descriptor

            using (SecurityDescriptor sd = SecurityDescriptor.GetRegistryKeySecurity (hKey, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION))

            {

                  // give the service user standard read access.

                  Dacl acl = sd.Dacl;

                  Sid serviceUserSID = new Sid(userName);

                  acl.RemoveAces (serviceUserSID);

                 

                  AccessType aclAccessType =  AccessType.GENERIC_ALL ;

                  acl.AddAce (new AceAccessAllowed (serviceUserSID, aclAccessType , AceFlags.OBJECT_INHERIT_ACE | AceFlags.CONTAINER_INHERIT_ACE));

                       

                  // set the values

                  sd.SetDacl(acl);

                  sd.SetRegistryKeySecurity (hKey, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);

            }

      }

      finally

      {

            Microsoft.Win32.Security.Win32.RegCloseKey (hKey);

      }

}

 

 

Posted by Addys | 0 Comments
Filed under:

[OT] Coolest 360 upgrade yet (might be a bit pricey though)

http://www.microsoft.com/presspass/press/2005/dec05/12-27URGE360PR.mspx

"Conceived by Nissan Design America Inc. (NDA) and equipped with the Xbox 360™ next-generation video game and entertainment system from Microsoft, the Nissan URGE concept car allows drivers (while parked) to play “Project Gotham Racing® 3” using the car’s own steering wheel, gas pedal and brake pedal while viewing the game on a flip-down seven-inch LCD screen. “PGR® 3” is developed exclusively for Xbox 360 by Bizarre Creations Ltd. for Microsoft Game Studios."

 

Posted by Addys | 0 Comments

Something really was wrong with Google's original PageRank...

... and this guy put his finger on it:  

Something is Wrong with Google's Mathematical Model 

(Math alert: Eigenvalue problems and general hilary ensue).





Posted by Addys | 0 Comments

So are we cool again now?

It will be interesting to see how the "Web 2.0" crowds reacts to the new "Windows Live" and "Office Live" offerings...  Sometimes I think that many of them are too young to remember how Microsoft turned on a dime and conquered the previous internet platform space back in the late '90s.  The new services are a clear statement that we don't plan to go silently into the night this time either.  The Google vs. Microsoft arms race will be an interesting one to watch [ guess who I'm rooting for ;-) ] but its already clear that the real winners will be the developers and end-users who will have access to tools and platforms which were in the realm of science fiction less than a decade ago...   so let the games begin.

Posted by Addys | 1 Comments

LINQ presentation slides

The PPT deck from my "LINQ For Mere Mortals" is available on NJ Code Camp, or here (direct link).
Posted by Addys | 1 Comments

XOR in C#

Random factoid:

Use  ^  for bitwise XOR in C#, for example:

  a = a ^ c;   (or simply:   a ^= c;)

 

Posted by Addys | 1 Comments

LINQ for mere mortals @ NJ Code Camp, this Saturday (Oct. 15th)

If the LINQ materials currently available on the web make your head spin (Lambda Expressions?  Query Comprehensions /w Extension Methods and Inline Initialization of Anonymously Typed objects? huh?) then you are invited to the the NJ Code Camp this Saturday. 

I'll be trying out a new & novel approach to explaining LINQ - We will begin with a simple .Net 1.1 application, then port it to 2.0, and finally over to LINQ under C# 3.0, while highlighting the differences and related language improvements in each step.  All this in 60 minutes! This will turn out to be either a totally awesome session or a total train wreck, but whatever happens- it will surely be entertaining to watch :)   

There are a total of 24 sessions (6 timeslots * 4 rooms) on a variety of topics so check out the agenda.

 

 

 

 

Posted by Addys | 0 Comments

VS.NET Bug? Easter Egg?

After "Collapsing to Definitions" (Cntl-M,Cntl-O), Visual Studio decided to color the collapsed code section in black, white and red:

Can anyone clue me in on what/why that is?  It happened consistently while VS.NET was open, but only for that specific method.  After rebooting VS.NET I can't recreate this, so its a good thing I took a screenshot. 

This is VS.NET 2005 RC1.

Posted by Addys | 1 Comments
Filed under:
More Posts Next page »