Microsoft Pivot Blog Viewer

26. July 2010

Ok, I built something I am excited about. The one biggest gripe I’ve had with blogs is that it’s often hard to sort and filter the posts to find the posts I’m most interested in. In comes Microsoft Pivot. Microsoft Pivot allows for viewing data in an intuitive filterable manner in a completely visual context. Incredibly cool for filtering images, magazines, or even the magic the gathering card collection. Take that single column blog lists!

My idea last night is to view blogs through Pivot. I set about programming the cXML schema into a series of .Net classes, and then built an input mechanism to build a static cXML file with my blogs postings. It’s still in the early phase of just the roughest information, mainly blog title and descriptions, but given another day of polishing will have additional meta data with appropriate blog links. I also realize how terrible my categories are since the Pivot category filtering is very limited with my junk data input.

Below is a screen shot of the very rough data output I created with cXML for viewing in Microsoft Pivot. Now that I have my framework together I can expand the idea to anything with categories.

PivotBlog

I will keep the cXML path displayed in the Pivot screenshot so if you’re interested you can also view the generated blog Pivot output as it goes through the transition to getting cleaned up totally.

Programming, .Net, Third Party Controls

VB.Net inline XML loop

20. July 2010

Coming from a C# background I was a little jealous of VB literals (still hate VB.) Recently I was flung into the VB.Net world on a new project, and my only consolation was finally being able to work with VB literals first hand. The first thing I needed to do was iterate a collection of objects to custom build an XML message. I did a little Google, and Bing action to no real results on looping a collection within XML literals. Eventually I found the solution as XML literals do not directly support loops as we know it. Fortunately that is where LINQ steps up to the plate:

   1:  Dim xml = <Processes>
   2:                 <%= From process in Processes 
   3:                       Select <Process><%= process.Name %></Process>
   4:                 %>
   5:            </Processes>

In this example I’ve created an XElement variable called “xml” that contains the literal XML. Using a LINQ query within the “Processes” element the select query will iterate through the items in the processes collection object. Each item will output a process element that will be included within the processes element.

.Net, Programming

.Net Extension Methods – Extending ViewState With Generics

15. May 2010

I may be a little late to the party on mentioning how much extension methods have made my life easier. Extension methods tend to fill that gap between wanting to add an extra little tweak to an existing class without actually having to implement a customized inherited version. Previously whenever you wanted to use one extra tweak or feature you’d be responsible for making sure to replace all instances of the inherited class with your new version. That gets into supporting the new class when all you wanted to do was change or add one thing to an existing class!

In my case I just really wanted to stop having to check whether a ViewState value was null before trying to unbox the value into whatever value type or class I thought I stored in that key’s value field. In my case I really wanted to add generic typing support to the ViewState property of the page with as little work as possible. That is exactly where Extension methods come to the rescue.

For example normally one would see the following code to access a ViewState property:

   1:  private int GetGroupId()
   2:  {
   3:      int groupId = -1;
   4:   
   5:      if(ViewState["CurrentGroupId"] != null)
   6:      {
   7:          groupId = (int)ViewState["CurrentGroupId"];
   8:      }
   9:   
  10:      return groupId;
  11:  }

Ideally I would like to do the following:

   1:  private int GetGroupId()
   2:  {
   3:      return ViewState.Get<int>("CurrentGroupId", delegate { return -1; });
   4:  }

To do this I’d use a .Net extension method to extend the ViewState property through it’s StateBag class. Below you’ll find the ViewStateHelper class with all the required code to extend the StateBag class, thereby extending the ViewState property, and adding support for generic Get/Set functions. In order to use it just add the namespace where the static class is contained to the “usings” on the code-behind file of the page needing the ViewState extension support.

   1:      public static class ViewStateHelper
   2:      {
   3:          /// <summary>
   4:          /// Returns an object from view state
   5:          /// </summary>
   6:          /// <typeparam name="T">Type of object</typeparam>
   7:          /// <param name="key">View state key of object</param>
   8:          /// <param name="delegateDefault">If view state is empty, a delegate to return a value to put in view state.</param>
   9:          /// <returns></returns>
  10:          public static T Get<T>(this StateBag viewState, string key, DefaultMethod<T> delegateDefault)
  11:          {
  12:              T viewStateValue;
  13:              
  14:              if (viewState != null &&
  15:                  viewState[key] != null &&
  16:                  viewState[key].GetType() == typeof(T))
  17:              {
  18:                  viewStateValue = (T)viewState[key];
  19:              }
  20:              else
  21:              {
  22:                  viewStateValue = delegateDefault();
  23:                  viewState.Set<T>(key, viewStateValue);
  24:              }
  25:   
  26:              return viewStateValue;
  27:          }
  28:   
  29:          /// <summary>
  30:          /// Put an object in view state
  31:          /// </summary>
  32:          /// <typeparam name="T">Type of object to put in view state</typeparam>
  33:          /// <param name="key">Key of object to put in view state</param>
  34:          /// <param name="value">Object to put in view state</param>
  35:          public static void Set<T>(this StateBag viewState, string key, T value)
  36:          {
  37:              if (value != null)
  38:                  viewState[key] = value;
  39:              else
  40:                  viewState.Remove(key);
  41:          }        
  42:      }

.Net, ASP.Net, Programming

Visual Studio 2010 Beta 2 Needs Work

16. January 2010

I’ve been trying to use nothing but Visual Studio 2010 for my at-home development uses. For the most part it works decently until it decides to be not be so cordial. I’ve seen things from group boxes all of a sudden only half the text on any contained controls displays. Restarting Visual Studio does nothing to redisplay the text even though it’s clearly in the Text property window. The only solution to that seems to be to add or change one character on any of the contained controls and auto-magically the rest of the text in all the controls displays properly again within the group box. That one has happened several times already.

There has also been the fancy quirks of leaving Visual Studio 2010 running and using it through a remote desktop connection. That one causes some strange behavior from getting stuck in a frozen state, not releasing locks to referenced assemblies, which that assembly part sucks when said assemblies solution is open in another Visual Studio instance you want to compile. That may have just been something weird between Visual Studio 2010 as the main windows form project and Visual Studio 2005 as the assembly project. The worst being when switching between code pages where the code-behind looses the cursor. Just stops showing up, don’t know where you are, but it can still move and select text using the mouse or keyboard. Just the funny thing is the text doesn’t show itself being selected either, but you can definitely ctrl-c it and it copies find to the clipboard.

Who knows, but the oddities are adding up quickly. I just had Visual Studio 2010 crash for the third time for unknown reasons as a result of adding an About Form to the project and modifying the About Form’s form wide text. Open the project, close all code behind, open the About Form, right-click to view code, and then it prompts to restart itself. I think that means go to bed and shut down for the night.

Programming, .Net

DataGridView Drag and Drop with Multiple Files

13. January 2010

I was working on a project tonight and I noticed something kind of odd. There are a ton of references out there for how to handle the DragDrop event with a single file, but I wasn’t able to find really anything about handling multiple files. Needless to say I figured I’d make a post to remedy this problem.

First thing to note is to select the DataGridView in the designer and from the properties window set “Allow Drop” to “True" to enable the events. Second is to add an event handler to the DataGridView DragEnter event. Within the event simply set e.Effect to one of the desired DragDropEffects enumeration values as such:

private void dgvImageFiles_DragEnter(object sender, DragEventArgs e)
{
     e.Effect = DragDropEffects.Copy;
}

The next step is to simply add an event handler for the DragDrop event and use e.Data.GetData(“FileDrop”) to get a string array containing the full file paths to each file dropped into the DataGridView control. That was at least my desire when building this code, but you could just as easily handle any of the other data format values available from e.Data.GetFormats() function. Below is the DragDrop event I’ve used to get the files dropped into the DataGridView control:

        private void dgvImageFiles_DragDrop(object sender, DragEventArgs e)
        {            
            if (e.Data.GetDataPresent("FileDrop"))
            {
                string[] files = (e.Data.GetData("FileDrop") as string[]);
 
                foreach (string file in files)
                {
                    . . . 
                }
            }
        }

That is how to handle drag and drop with the DataGridView with multiple files. Easy enough eh? Well then back to programming I go.

.Net, Programming

Blog Engine Spam Cleanup Utility

9. January 2010

While this is totally a reactive approach to dealing with the spam bots posting comments I thought I’d share the clean-up project. In the end I have to give the bots credit for being so kind in nature of appreciative comments. It’s easy to get a big head reading the comments even though they are clearly bots with scripted content.

Attached is the project along with the XML block list. The block list is not complete with equal email, author, IP, and website listing for all the comment postings I received. It was sufficient enough for my needs to clean the comments up. The list may vary depending on the different bots that have visited the blog site, but should allow anyone in the same situation to clean up the mess. The code is roughly written and meant for a one-off cleanup, but below is the code along with the full project that includes the XML block list.

Blog Comment Cleaner Utility

Please note the project was created with Visual Studio 2010 beta 2 in case of difficulty opening the solution file.

Example Command Line:

BlogCommentCleaner.exe “c:\blog\App_Data\posts” “c:\blog\App_Data\block.xml”

Programming, Programs & Utilities, .Net

.Net 4.0 and IIS 7 Application Pool Problem

28. September 2009

Ok, I admit it. I am one of those people who likes new technologies. I also am ‘that guy’ who installs a beta framework on a production web server just so I can host a new website using the bleeding edge technology/framework. They don’t call it bleeding edge for nothing because sometimes it can just plain hurt after you install said new technology and the new technology takes down the existing system.

That is exactly what happened when I installed .Net 4 on my web server. The next thing i know after the installation and planned restart all of my websites were redirecting to the 404 website not found page. Fantastic, it’s 1am, I've just installed a beta framework, and all of my websites are effectively offline. Well that’s what i get, but at least it’s my personal server instead of a corporate server I work on. I know better than that by now, and if didn’t I wouldn’t have a job. Not saying I’ve not been guilty of taking down a web server before.

Anyway, the first thing that happened as I said was the 404 pages. From the ten website impacted only one gave the yellow-screen of death. Thankfully I was able to just simply set the custom error configuration to off so I could read the error. Sure enough it’s an error related to running a website in an application pool using a framework not supported by the configuration settings. After checking the application pools every single last one of them were set to .Net 4.0 integrated instead of the respective .Net 2.0 integrated/classic set on the individual sites. A few drop-down lists later my websites were all back up and functioning, but I was left with the “what else is impacted” feeling after the installation. You’d think after four framework releases the installer and framework configuration installation would have been set better than to default all my application pools to use .Net 4.0. It’s not like it’s the only option available.

Again to recap the .Net 4.0 Beta installer will change your IIS 7 (i assume IIS 5/6) website applications pools to use .Net 4.0 instead of your predefined settings. Just change them back and everything starts functioning again. Hopefully this will be the last “oh what have I done!” I run into after installing the beta framework. Fingers crossed!

.Net

cXML and ASP.NET

12. March 2009

What is cXML? Commerce XML referred to as cXML is actually a protocol created by Ariba to carry out interactions between procurement companies to supply something of an updated EDI process to better support e-commerce systems of suppliers. That of course was the idea in 1999 when it was created and (un)fortunately it has been used up until the present to conduct business to business interactions through a PunchOut request/response process.

I have been (un)fortunate enough to be tapped to lead the integration of a cXML based PunchOut system for a client I've been working with in order to integrate into something called ACES. ACES is a e-commerce solution by a company called American Solutions for Business. While during the initial conversations were centered about a messaging mechanism to request and respond with messages I was not initially familiar with the cXML standard. I was at least with its older competitor EDI. So this began my quest to better understand, design, and develop an support system on the client system for implementing the protocol.

I began initially with scouring the forums, Google, Live.com, and other assorted search engines for exactly what others were doing to integrate cXML into ASP.Net systems. That is when I discovered that aside from www.cXML.org there is actually very little material on the subject at all let alone regarding using it with ASP.NET in any fashion. Besides bizTalk and a few forums about validating a received cXML document against the cXML DTD available from cXML.org the protocol is a ghost.

To top the fact that the protocol is essentially never mentioned except in a few out of publishing books available on Amazon.com on B2B based messaging architectures even the Ariba website lacks any samples available for ASP.NET developers. I was excited on further searching to find a link to the classic ASP example project available on the site but my enthusiasm was shortly lived. All links to the contents were to a page that informs the user that the content has been expired from the site permanently.

So now what. Well thankfully after digging through umpteen number of websites I managed to scarf up a few PDF files of cXML solutions guides, and the cXML version 1.2 that the procurement company current users. After reading through the documents one can see quickly how reliant cXML is to the protocol standard enforcing company Ariba. The protocol relies heavily on a Ariba supplier ID and (Dun & Bradstreet) DUN numbers available from www.dnb.com.

Within the solution guide I also managed to round up the only ASP related material showing snippets of messaging decoding performed with classic ASP. It was at least enough to get me started building out my cXML support framework which essentially consists of multiple synchronous XML GET/POST to continue the interaction. By doing so an outside site can direct users from the outside customers site to display your supplier site inline the users browser experience to configure the product/service as the user would like. The request of course is posted to your domain, handled by the request object to receive the XML input stream, cXML request is parsed, and then a response posted back to the calling page from a URL identified via the response cXML document. Based on identifying whether a shared key is correct the cXML request can be processed, and the user redirected to begin product configuration seamlessly believing they’re interacting with the external site never realizing they’re working on a external supplier site.

I guess on the plus side I could qualify myself as a cXML knowledgeable company capable of being sourced to integrate the standard in other company e-commerce solutions. I don’t think I'll throw my hat in that ring just yet it’s been a big pain to integrate this standard into a modern ASP.NET based e-commerce system considering that the only documentation of the protocol was updated on classic ASP I assume that this standard was meant to be let alone for modern systems. Of course compared to EDI it’s night and day more robust.

When my project is complete I'll take the time to post a good how-to on implementing the request response mechanism in a modern web language. Heaven knows I'd have appreciated finding one myself when i started to learn this system!

ASP.Net, Programming, .Net