Calender
<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Posted by: jason | Created on: 23/02/2010, 17:15

 

I recently wrote some RSS feed logic into a site.  I used an HttpHandler to do this, so it will return to the browser xml instead of html in the Response.OutputStream.  I did what I’m guessing every person new to this area does and tried to write a function that returns the xml data into the Response.OutputStream property and got the following error:

Property or indexer 'System.Web.HttpResponse.OutputStream' cannot be assigned to -- it is read only

Oh.  Ok, well that’s pretty clear … but how do I put my data into the OutputStream?  Looks like you dump it all into a MemoryStream and then call the OutputStream.Write method to shove it all in.  Not bad!  Here is some psuedocode to illustrate.

MemoryStream stream = new MemoryStream();
stream = bl.GetMemoryStreamOfXML();
context.Response.OutputStream.Write(stream.ToArray(), 0, stream.ToArray().Length);

Posted by: Jason | Created on: 23/02/2010, 00:42

I found myself in a situation where I had to get from a string forced upon me by a 3rd party web service into an property that is an enumeration on our side. 

That led me to look into how to loop through a enumeration in order to match on the string, but assign the value.

Basically i was getting “FAX” but I had to set a property = 2 because the enumeration was:

public enum ContactType : int

{

HOME = 0,

BUSINESS = 1,

FAX = 2,

}

 

For future reference here is how I accomplished this:

foreach (var contact in System.Enum.GetValues(typeof(ContactType)))
{
    if (contact.ToString() == phone.phoneType) //phone.PhoneType is a string, in this case it = “FAX”
    {
        phoneDTO.ContactType = (ContactType)System.Convert.ToInt16(contact);
    }

Posted by: jason | Created on: 16/02/2010, 00:14

This is one of those things where you say to yourself, “there must be an easy way to do this” but all the searching in the world isn’t netting you an example.  I finally found this tidbit which gave me exactly what I wanted, although it’s disappointing to me that it requires a direct windows API call.

My issue was that I need to know when someone right-clicked on a tab that is NOT the currently selected tab in a tab control. 

I finally gave up and just implemented it this way, (fortunately it was for a one-off project that didn’t require a lot of scrutiny.)

<Flags()> _
Private Enum TCHITTESTFLAGS
    TCHT_NOWHERE = 1
    TCHT_ONITEMICON = 2
    TCHT_ONITEMLABEL = 4
    TCHT_ONITEM = TCHT_ONITEMICON Or TCHT_ONITEMLABEL
End Enum

Private Const TCM_HITTEST As Int32 = &H130D

<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)> _
Private Structure TCHITTESTINFO
    Public pt As Point
    Public flags As TCHITTESTFLAGS
    Public Sub New(ByVal x As Int32, ByVal y As Int32)
        pt = New Point(x, y)
    End Sub
End Structure

<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal msg As Int32, ByVal wParam As IntPtr, ByRef lParam As TCHITTESTINFO) As Int32
End Function

Private Sub TabControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseDown
    If e.Button = MouseButtons.Right Then
        Dim HTI As New TCHITTESTINFO(e.X, e.Y)
        Dim hotTab As TabPage = TabControl1.TabPages(SendMessage(TabControl1.Handle, TCM_HITTEST, IntPtr.Zero, HTI))
        TabControl1.ContextMenu = hotTab.ContextMenu
    End If
End Sub

Private Sub TabControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseUp
    TabControl1.ContextMenu = Nothing
End Sub

I recently set out to generate documentation for a very large project I’ve been writing over the last several months.  Asking the business to spend $500 on a single license to some popular documentation generation software was not an option so I went looking for the open source options.  It was a tedious maze to determine how to accomplish this to my liking, but I finally made my way through the gauntlet.  If you are hoping to avoid the painful discovery process then try the following steps.  I’d like to make a video of this install process eventually but if your careful and follow these steps exactly it should work out pretty well for you.  Of course this may not work forever as changes to the free tools occur, so bare in mind this configuration should work with Visual Studio 2008 on 64bit Vista and the May 2008 release of SandCastle.

This is meant to be a “how-to-get-it-working-without-really-knowing-what-I’m-doing-I-just-want-to-generate-documentation-why-is-it-so-hard” explanation.  It’s very oversimplified.  if you want more info, then look to the many sites written by experts in the subject.

How and What do I install and in what order?

(Install these into the default locations unless you want to spend a bunch of time messing with configuration and pathing variables.)

  1. Download and install HTML Workshop - http://www.microsoft.com/downloads/details.aspx?FamilyID=00535334-c8a6-452f-9aa0-d597d16580cc&displaylang=en
  2. Download and install SandCastle (May 2008 release) - http://sandcastle.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=13873
  3. Download and install SandCastle Help File Builder - http://www.codeplex.com/SHFB

What’s the Deal with these packages?

  • Html Workshop is a command line utility that sandcastle uses to turn the html it generates into a CHM. 
  • SandCastle is a command line utility (there is a GUI but don’t use it) that reflects through your assemblies, merges your code comments (the xml files that visual studio generates as long as you have the "Generate comment XML” option turned on in each of your project files, and generates the html files that will get subsequently compiled into the CHM.
  • SandCastle Help File Builder (SHFB) (it took me a while to realize this was different than the SandCastle product sheesh) is a very cool front end GUI to sandcastle that will rock your world if you’ve already spent countless hours trying to figure out sandcastle on it’s own.

So essentially, install those 3 things in the order I’ve listed them.  The first 2 will not have any links in your start|program files so just think of them as being utilities you never have to mess with (SandCastle might put an icon on your desktop, just delete it.) What you WILL have is links to run “SandCastle Help File Builder” so run THAT.

I found the interface to be extremely intuitive, so I’m not going to go into too much detail.  This is the page that made it all click for me so read this:  http://www.ewoodruff.us/shfbdocs/html/d5dbf017-25f1-48cb-86db-90f76ee8f4d7.htm

2 final hints that might save you some time:

  • When adding assemblies to be documented to the SHFB project, I found browsing to and adding the actual project files to give me the best experience. (versus the assemblies or the solution file)
  • Following these steps will let you generate HtmlHelp1x files (chm files).  If you want HtmlHelp2x files there is a lot more you have to do and it’s beyond the scope of this walkthrough.

This worked for me, but if you encounter an issue, ping me and I’ll see if I can help. Good luck!