WT? #1

This last year, we have uncovered numerous websites with some severe flaws. And sometimes there are fairly _large_ websites where you’d think they’d have more professional skill available to avoid the kind of things we end up seeing…

And i don’t think ca$h (lack of) is the issue- in fact, i supect that sometimes there is more than sufficient being invested. The resultant product and runtime errors that crop up are, well… for the reader to discern. The names have been hidden to protect the embarassed.

First up: TheBrowserBackButton
This is a large university’s website. I was browsing through the Maths and Computer Science areas when i clicked on my browser’s back button:

Back Button

Maybe this was intentional? It sure does help getting a call from the help desk and they can tell you exactly which line of code is causing the problem 🙂

Delegate Gotcha

A while back i was trying to find a solution to the delegate gotcha and stumbled upon, even more recently, some answers to a lot of my questions… they trackback and link with each other at some point, but my entry point to this discussion was mostly through, in no specific order:
Observable property pattern, memory leaks and weak delegates for .Net. – Alexey A. Popov
Simulating “Weak Delegates” in the CLR – Greg Schechter
.Net 2.0 Generics, Anonymous Methods, and Delegate inference bug – Udi Dahan

After reviewing a lot of the different solutions, i’m currently experimenting with an idea. Given your usual suspect:

public class EventSource
{
    public event EventHandler FireEvent;
    public void OnFireEvent( )
    {
      if(null != FireEvent)
          FireEvent( this, EventArgs.Empty );
    }
}

I’ve reworked some ideas and using WeakReference, rewritten the EventSource above as follows:

public class EventSource
{
    private Dictionary<EventHandler, WeakReference> origDelgs =
            new Dictionary<EventHandler, WeakReference>();   
    public event EventHandler FireEvent
    {
        add
        {
            if( !origDelgs.ContainsKey( value ) )
                origDelgs.Add( value, new WeakReference( value ) );
        }
        remove
        {
            if( origDelgs.ContainsKey( value ) )
                origDelgs.Remove( value );
        }
    }
    public void OnFireEvent( )
    {
        foreach( WeakReference aref in origDelgs.Values )
        {
            if( null != aref.Target )
            {
                EventHandler hdl = (EventHandler)aref.Target;
                hdl.Invoke( this, EventArgs.Empty );
            }
        }
    }
}

Now, at least, if my sink goes out of scope, it won’t get resurrected 🙂
Will continue experimenting with this idea and see how it performs….

.NET Migration v1.1 – v2.0

So the code migration was fairly straightforward. There’s enough documentation and learned lessons available to get you through that relatively pain-free. Also, striving to keep the code base as straightforward as possible helps tremendously. The deploy was not *as* obvious.

Dev boxes and staging environments deployed without fuss, but as it will be, the LIVE production box will always have something different about it 🙂

If you’re suddenly getting “404 Not Found” errors, check that v2 has actually been allowed to run. Verify with the “Web Service Extensions” section in managing IIS6.

These two urls were particularly useful:
“HTTP Error 404 – File or Directory not found” error message when you request dynamic content with IIS 6.0
IIS 6.0: ASP.NET Is Not Automatically Installed on Windows Server 2003

as part of a response to the question:
ASP.NET doesn’t work Error Code 404 2 1260

hopefully this saves you 30minutes somewhere 🙂

FtpWebRequest Part II

.. following on from the first one, the project has now been updated to include some work with the new BackgroundWorker component available in Net 2.0… 😀

Creating responsive UI’s on lengthy processes has never been so easy!

including source code

FtpWebRequest

After looking for a trim Ftp client library for .Net 1.1, .Net 2.0 releases with FtpWebRequest. I completely missed this one in the search to find *something*.

After hacking around with it for a very short while, it proved to be by far the easist “library” to integrate with… the fruits of that freely available here .

There’s not much to the code itself as most of it is just a straightforward copy-paste out of MSDN but it ends up being the very light file dumper i was looking for.

Owning Your Continous Integration

The ideas here is to “own” your continous integration process and make it work for you. Afterall, you spent some time setting up CruiseControl.Net and it’s ticking along nicely. At some stage, you need to make it “yours” and let it reflect your needs in terms of your process and record build data that you use [need] to make decisions.

<soapbox>
In fact, i’d encourage you to really push into making it your own. Not just the look ‘n feel- but the real nitty gritty. Define and extend and experiment with your continuous integration process to make it add value…
</soapbox>

the Scenario
Our automated build process runs a series of tests against a database. Before we start the tests, we need to record some information about the database; this being gathered by means of a stored procedure. We also need to persist the results as part of the build so we can monitor trends.

the Tools
* Nant build script
* Nant custom user task
* stored procedure
* xslt template
* cc.net config files

The Nant build script is included as part of the build process kickstarted by the bootstrap.build configured in cc. For more information on setting up cc.net, review the documentation that comes as part of the distribution. The ccnet.config file should include a nant <node> under tasks, similar to this…


<nant>
<executable>C:\nant-0.85\bin\nant.exe</executable>
<buildArgs>-D:debug=false</buildArgs>
<buildFile>bootstrap.build</buildFile>
<targetList>
<target>go</target>
</targetList>
</nant>

The Nant build script then calls a Nant custom user task which has the responsibility of executing the stored procedure and formatting the results into an xml file. To execute the custom task, somewhere along your build path, you will include something like…


<project name="ccnetLaunch" default="go">
<target name="go">
<loadtasks assembly="${nant::get-base-directory()}/mytask.dll" />
<myTask ConnectionString="MY_CONNECTION_STRING" SqlStatement="sp_myTask"
LogFile="myTask.xml" />
</target>
</project>

<loadtasks/> helps define <myTask/> which is built into an assembly and in this case, placed into the nant/bin directory. The nant custom user task is straightforward and the nant distribution includes a basic template sample which you can follow easily enough. another sample here

The xml output file itself is then merged into the cc build report. Again, your ccnet.config file handles this easily with…

<publishers>
<merge>
<files>
<file>myTask.xml</file>
</files>
</merge>
<xmllogger />
</publishers>

Finally, you need to add the xslt which transforms the xml output into the cc.net dashboard. Add the xslt file to the webdashboard xslt folder and append to the dashboard.config file, something similar to this…


<xslReportBuildPlugin description="My Results" actionName="MyDataReport" xslFileName="xsl\mytask.xsl" />

Now each build successfully calls your custom user task, saves the result of the stored procedure to an xml file which is merged into the build output and accessible from the dashboard for as long as you got build logs 🙂

Following this concept should give you an idea of how to start owning your process and not just going with the stock standard install. Set it up, take some risks and call it your own.

Categories
Technology

An Assumption Makes…

Assumptions are wonderful. They allow you to fly ahead without needing to fuss over any time-consuming details… until, at least, the assumption fails you. Like the “ref” keyword, for example.

A data type is a value type if it holds the data within its own memory allocation [Eg. numeric types, bool, any struct types]. A reference type contains a pointer to another memory location that holds the data [Eg. String, any class types].

So, when it comes to argument passing in .Net, by default, all value types are passed by, well, value 🙂 and reference types too are also passed by value. But value in the case of the reference type, is the value of the reference. This little nuance [nuisance, at first] popped up quite late in my project simply because the implemented design didn’t call for any dynamic re-allocating, until one particular test started failing during what was supposed to be routine “refactoring”. I say “supposed to be” because the refactor ended up changing the behaviour hence no longer a refactor… anyhoooo…

My assumption [reference types = raw pointer, ala C++] allowed me to gloss over an entire section of the C# specification. Had i paid any real thought to this little abstraction way back then, i would probably still have forgotten about it when i had to call upon that knowledge for the first time, months later. Or not. At least now i know i won’t *ever* forget about it 🙂

Any which way, i still think assumptions are good. Even better though if you can change them. And best if you can constantly challenge them or have them challenged. And yes, an assumption can lead you off into the wrong direction, but hey! At least it’s a direction. Could have indulged the specification in depth before hand and told my employer to wait n months while i read all about C#… don’t think that would have worked too well either.

As always, some tempering between the extremes is a refreshing welcome…