Erik Porter's Blog

Life and Development at Microsoft and Other Technology Discussions

News

    March 2004 - Posts

    .NET Compact Framework "Gotchyas" for the Beginner

    I started an article of things I've found along the way as I start working on smart device apps.

    Hopefully it will help others who are just getting started save some time.

    Quick and Dirty Navigation State in ASP.NET

    There are cleaner ways to do this, but thought this was handy so I'd throw it out...

    Just add the following code to your Base Page Class (if you have one that your pages inherit from) or add them as Shared (static) to any Class.

    Public Sub RedirectFrom(ByVal DefaultPage As String)
        
    Dim Context As HttpContext = HttpContext.Current
        
    If Context.Request.QueryString("from") <> "" Then
             
    Context.Response.Redirect(Common.BasePath & Context.Server.UrlDecode(Context.Request.QueryString("from")))
        
    Else
             
    Context.Response.Redirect(DefaultPage)
        
    End If
    End Sub

    Public Function GetUrlFrom() As String
        
    Dim Context As HttpContext = HttpContext.Current
        
    Dim Temp As String = Context.Request.RawUrl
        
    Return Context.Server.UrlEncode(Temp.Substring(Context.Request.ApplicationPath.Length, Temp.Length - Context.Request.ApplicationPath.Length))
    End Function

    On any links you have on your page that need to be redirected back to this page when finished, such as an edit page, add “&from=” & GetUrlFrom() on the end of the link.  Then on each page you want to return back to it's previous page, just do something like RedirectFrom(”Default.aspx”) where that string is the page it will go back to in case it doesn't find a from path in the querystring.  This should help smooth things out and make it more like a modal dialog in WindowsForms almost, but in the same browser window.

    Posted: Mar 29 2004, 02:27 PM by HumanCompiler | with 4 comment(s)
    Filed under:
    Safety First

    This isn't .NET related, but it's too cool to pass up...

    http://www.sawstop.com/video.htm

    Posted: Mar 26 2004, 02:34 PM by HumanCompiler | with 1 comment(s)
    Filed under:
    FrameworkUtilities

    Recently, I chatted through e-mail with a long time friend's (Joe Heller, who is now engaged [Congratulations!]) co-worker, Brian Wortman of RDS about some programming concepts and workarounds for a few things lacking in the framework.  We chatted, swapped opinions, etc.  Very smart and cool guy.  One of the things we talked about was how he had been working on a project that contained custom attributes to use as parameter method validators to ensure the data coming in fits the bill, saving developers having to write code themselves to check it.  I thought it was such a fantastic idea that I went ahead and made my own.  Another thing he had mentioned was the problem of Value Types not being able to be Empty (big problem across the board for sure), so I went ahead and wrote an Empty Class to have a standard way to “recognize” empty value type variables.

    These two things were related and one uses the other, but also could be used seperately, so I got to thinkin', “Why not create a utilities project with bunches of 'stuff' that could be used throughout all my projects?”.  Kind of like the new My Classes in VB.NET Whidbey.  So I did...I started a new GDN Workspace called Framework Utilities and also added a couple other (hopefully) useful classes for people to use.

    I know I'm usually a VB.NET guy, but this time I decided to do the project in C#.  Periodically I do that to keep my skills fresh.  Especially for when those “my language is better” arguments come up, I can actually know what I'm talking about because I use both languages.

    Current Features

    • Method Parameter Validation Attributes
      • Attribute for all Value Types and includes range validation and required validation
      • Required Attribute to make sure a value is passed in another than null for Reference Types
      • If Value Type Attributes are attached to a string, they will make sure the incoming value is Valid
    • TryParse Class
      • Contains Methods to see if a string value is valid for the particular value type
      • Returns the Type requested from a string
    • Empty Class
      • Standard Methods for Value Types for checking for empty and getting empty values
      • Has Database Methods to check for Empty as well
    • File Class
      • Contains Methods for Retrieving and Writing to files easily (string and byte array)

    Method Parameter Validation Attribute Usage

    Private Sub CallMethod(<StringParameterValidation(2, 5, True)> ByVal Param1 As String, <RequiredParameterValidation()> ByVal Param2 As XmlDocument, <DateTimeParameterValidation(True)> ByVal Param3 As String)
        
    Try
             
    ParameterValidation.Validate(Param1, Param2, Param3)

             
    'TODO: Code here

             
    MessageBox.Show("Method Called")
        
    Catch Ex As Exception
             
    MessageBox.Show(Ex.Message)
        
    End
    Try
    End Sub

    CallMethod("a", Nothing, "3/26/2004")

    I did this in the evenings over the last couple days, so it's still rough and the performance needs a lot of work on the Validation Classes.  If you have ideas for new features you'd like to see, please post them in the messageboard on the Workspace.  Also, I'd love to get some more people in to work on this, tweak what's already there (please oh please any Regex experts...it needs help), test it (I haven't done much testing yet), etc.

    Framework Utilities GDN Workspace
    Intial Source Code Release v 0.1.0.0

    UPDATE: I also wanted to thank Jason Bock for helping me get my head around some stuff with Attributes!

    Internet Explorer Problems

    Lately, I have been unable to open new windows in IE.  It wouldn't even work if I clicked on a linked that opened to a new window or even clicked on a link in an e-mail.  Today, was the ultimate pisser when I opened the find window and typed in what I was looking for and clicked Find and got an error.  Luckily, the MS KB came to the rescue and it was a very easy fix.

    If you ever have problems like this, check out KB Article 180176

    Posted: Mar 23 2004, 05:33 PM by HumanCompiler | with 8 comment(s)
    Filed under: ,
    Keeping a Database in sync

    I was thinking about developing a little (or maybe not so little, haven't thought it all through yet) app to show you the differences between two databases and allow you to then sync those differences.  The reason being, is that we usually have a Development Database and a Production Database.  Currently, we just keep track of the changes we make to the development db and once we upload the new version of the app using it, we change the database on production manually to match the development db.  It's a pain and easy to screw up or forget something, so I was thinking about writing a DBDiff or something like that.

    Before doing that however, I want to make sure there's nothing out there already that rocks and would be ready to go for us for cheap.  One of our main problems is that our development server sits internally on our network and our production server sits somewhere else on the internet and we can't run an app that can look at them both simultaneously.

    Has anyone seen anything out there that would help with synchronizing databases across networks (i.e. build a schema file, then compare another db to the schema file, etc)?  If not, maybe I could write an initial version, then stick it up on GDN Workspaces and have it expanded by myself and others.

    Just curious!  :)

    Template in Action
    Red Raven RPG has used my ASP.NET Templating and Skinning system on their site and seems to like it.  I'm really excited to see something I made being used...great!
    Off to DevDays...
    Adam and I are leaving for DevDays 2004 in Chicago right after work today and will be there early to mid evening.  This should be a fun and interesting trip and as long as there's wireless access, I'll be blogging about anything cool I see.  If anyone is going to be in the area this evening, send me an e-mail to exchange cell phone numbers or something.
    Posted: Mar 09 2004, 09:22 AM by HumanCompiler | with no comments
    Filed under:
    Speaker Job Feed?

    Cory Smith sent me a link to his user group's newly redesigned website.  I clicked on Jobs, because I was curious about what that might mean.  It turns out it's a list of jobs, go figure, but it got me thinking...(for some strange reason)...why don't user groups post a list of upcoming meetings that currently don't have speakers yet.

    Not that I have the time myself or anything, but I think it would be really cool if user groups started all having these sections and exposed them as RSS.  Then maybe INETA or someone could create a combined feed that people could subscribe to by city or region or whatever.

    Which reminds me...if you need a speaker for your .NET user group here in the midwest and you're not too far away (I'm in the north east region of Indiana), look me up!

    Posted: Mar 07 2004, 11:26 AM by HumanCompiler | with 8 comment(s)
    Filed under:
    More Posts