Welcome

You have reached the blog of Keith Elder. Thank you for visiting! Feel free to click the twitter icon to the right and follow me on twitter.

.Net Developers Guide to Identity

Posted by Keith Elder | Posted in .Net, Programming | Posted on 20-07-2006

0

Have you ever wondered how windows credentials and Kerberos worked under the hood and how to leverage that as a .Net developer?  What about Smart Cards, or the new up and coming addition to Vista called “InfoCard”?  Did you know there was a tool to assist in building roles for your applications called Azman?  Or better yet what is PKI or Federated Services?

I think you get the idea, there are tons of things .Net developers should be aware of when it comes to securing our applications.  Keith Brown from PluralSight.Com has an MSDN article title .Net Developers Guide to Identity that covers all of this and more.  Extremely well written and even has code samples where applicable.

TIP: Managing BindingSource Position in Data Driven WinForms

Posted by Keith Elder | Posted in .Net, Programming, Smart Clients | Posted on 28-06-2006

12

If you are working with a Windows Form where a user can create and edit data in the same form you may run into the problem of trying to set the BindingSource to a given record in a DataSet you want to work with. 

For example let’s say you have a DataGridView in a Smart Client.  When the user double clicks a given row in the DataGridView a form opens so they can edit the data.  More times than not (no matter how many demos you watch) user’s do not edit data values in DataGridViews.  Although this is a supported feature, business objects are too complex.  Imagine having to edit a contact in a single row in Outlook for example, not fun and not very user friendly.  Why every Microsoft demo I watch shows editing in DataGridViews is beyond me.  I digress though.

When the new form is instantiated we need to pass two things:  the dataset we are working with, and the IDof the item we want to edit.  We can pass this information into the constructor of the form without any trouble as seen below. By passing in the DataSet we can add new records, delete records or whatever we need to do.  The other benefit is since the dataset is passed by reference, any changes to it will automatically appear in the row the user just double clicked on.  In order for the form fields to be auto bound to the record the user clicked on we need to set the DataBinding of the controls in the form to a BindingSource.  The BindingSource serves as the go between between the UI and data store.    Here’s a sample “CellDoubleClick” event that would happen in the DataGridView:

    1    int id = Convert.ToInt32(DataGridView.Rows[e.RowIndex].Cells[0].Value);

    2             MyForm myForm = new MyForm(dataSet, id);

    3             myForm.Show();

As the form loads the problem we face is having to tell the BindingSource in the form which record we want to set as the BindingSource.Current item.  At first glance it looks like we would just get the DataRow and then set it as the Current property.  Wrong.  The BindingSource.Current property has only a get accessor.  Instead we need to use the BindingSource.Position property.  Note:  Any change to the position property updates the current property used by the bindingsource.  The problem we face now is the BindingSource.Position property wants to know the index of the item in the underlying DataSource.  

We don’t know the index value used by the BindingSource but we do know the ID we want to use.  This is where the BindingSource.Find() method comes in.  Using the find method we can basically search the underlying datasource and retrieve the index of a given item.  Here’s an example:

contactBindingSource.Position = contactBindingSource.Find(“Id”, 2);

Once the line above runs, it is going to search the column “Id” in the DataSource associated with the BindingSource and return the index of that item. 

What if you use the same form to create a new item?  Simple, call the BindingSource.AddNew() method which will add a new item to the underlying DataSource.  Then move the index to the last item.  Here’s a sample:

      bindingSource.AddNew();
      bindingSource.MoveLast();

Since items are always added at the end of the associated data source the MoveLast() method will set the index to the last item in the underlying datasource.

I hope this makes sense because it is an easy way to have a form bound to a DataSet and use the same form to perform “CRUD” operations with.

Setting Up ClickOnce Certificate Files

Posted by Keith Elder | Posted in .Net, Smart Clients | Posted on 26-06-2006

0

Looks like Brian Noyes stole my thunder for a blog post I was going to do soon.  I get asked the same question.  “How do you sign your ClickOnce program with a valid provider like Versign?”. 

Unfortunately for myself, I had to figure this out the hard way last year during the VS2005 beta when I had to publish the new CRM app out with a Go Live license.  It’s a wonder I was able to piece all of the pieces together.  Call it a true testament to my genius.

Thanks to Brian for putting this together. If I get hit by a bus now at least someone else on my team can figure it out instead of wasting endless hours reading docs.  Why this type of content isn’t standard help on MSDN I have no idea.  I was talking to someone at Tech Ed who was responsible for the content on MSDN (sorry, can’t remember her name) and expressed my concern that they should catalog what blogger’s write about and turn them into docs.  It isn’t that hard to read the forums, newsgroups etc.  If two people have had the same problem, it should be documented and searchable on MSDN.

Enterprise Library Feedback – Integrate GAT and Workflow

Posted by Keith Elder | Posted in .Net, Programming | Posted on 22-06-2006

0

Tom Hollander, who is on the Enterprise Library team, posted to his blog the Enterprise Library team want everyone’s feedback for the .Net 3.0 framework release.  As I sat and thought about this in relation to .Net 3.0, the more I thought about it and started to write about it, it just all became crystal clear.  Here’s my wishlist for EntLib 3.0:

  1. $20 – Add the EntLib console configuration tool into Visual Studio IDE.  Lot’s of people mentioned this in comments, so it looks like this should definitely be on their list.
  2. $20 – Integrate GAT to assist setting up EntLib based on the best “patterns” and “practice”. 
  3. $60 – Workflow Block

Integrating GAT with EntLib
Number one above is is self-explanatory so let me first start with number two.  If you think about abstracting and best practices and patterns you think of EntLib, however, there is one missing piece of the puzzle.  That missing piece is there is a best practice and pattern for how to setup and use EntLib.  If you are starting out using EntLib you are more than likely not going to use an “established best practice or pattern” as to how you should use EntLib.  I’ve seen this over and over when you want to create a new application to use EntLib you wind up holding onto one configuration file that you are familar with and copying and pasting.  Wouldn’t it be nice to simply install EntLib and using the GAT (guidance automation toolkit) you could create an “Enterprise Library Web Service”.  The GAT would then guide you through a configuration wizard of best practices and patterns on the recommended configuration and setup for EntLib based on the chosen application.  At least this would provide a baseline, and I think, a higher adoption rate of Enterprise Library in the enterprise.  It would also make it easy for anyone to start using thereby eliminating lots of training overhead to get up and running.

Workflow Application Block
Let me explain my reasoning for the Workflow block and why I invested so much into it. First and foremost Tom asked what we would want in regards to the 3.0 framework.  One of the new features of the 3.0 framework will be Windows Workflow Foundation.  For developers, this simply means you have a new set of APIs namespaced as System.Workflow. 

If you look at the existing blocks of Enterprise Library ( data, logging, exceptions, etc) these are all derived from currently existing Namespaces within the framework. The goal of these blocks are to abstract, simplify and tie each block together so it can be used with one another.  This is where the power of Enterprise Library comes in.  Since this would be a 3.0 release of Enterprise Library, Workflow is a major new namespace that will be available to us in the .Net 3.0 framework.  Having an easy way to re-configure workflow through an application config file and/or manage workflows via an application block to me makes perfect sense. If you’ve played with Windows Workflow Foundation you realize a lot of things could be abstracted.  Really this abstraction is no different than how EntLib provides the data block today.

Here are a couple of scenarios how I would want to use the Workflow block.  For example, imagine being able to configure EntLib when an exception is raised to be processed through the Workflow block instead of how we do it today via Categories. So based on the exception type, time of day, user that created the error, what phase the moon is in and how the stars align at that given time, the error could be routed via the Workflow block to the appropiate place.  With place being an email, log to database, notify pager, create a support ticket in an internal helpdesk system, notify your helpdesk, whatever.   Essentially what we *try* to do with EntLib today a lot of the time is make our logging blocks do workflow by creating tons of different categories based on different rules.  We wind up with a HUGE config file that becomes, well, HUGE.  Instead of doing things the way were are today, just simply have a workflow that you can define to handle all logging, exceptions or whatever.   

That’s my $.02.  I’ll be here all week. Smile

Video Cast: Building Three Tiered Solutions in Visual Studio and Team Foundation Server

Posted by Keith Elder | Posted in .Net, Asp.Net, Programming, Smart Clients | Posted on 21-06-2006

0

One of the biggest challenges I see team members at work struggling with when trying to learn .Net is “how to get started”.  If you are a developer with lots of experience, coming into VS and .Net things are very different let’s face it.  For example, what’s the right way to setup a project?  What’s the difference between a solution and project?  Everyone knows about n-tiered architecture, but how do you pull it off in Visual Studio?  If you are using TFS how do you setup projects so they can be easily versioned?  How do you organize the name spaces of projects?

I put together this video cast which is about 30 minutes long which I hope addresses some of these questions.  It should serve as a good starting point as how to setup a project when starting out, things to think about like namespaces and how to name your projects.  I’ve built a lot of production apps over my time and what is in the video is all based on experience so if you know of an “easier / better” way please drop me a line.  In the future things like GAT (guidance automation toolkit) will provide an easier way to accomplish what I’ve outlined in the video.  If you haven’t looked at GAT, you should definitely do so. 

Watch The Video Cast

(this is a repost of a post that was lost due to data loss)