New FCKEditorProvider for DotNetNuke#
A newer (beta) version of the FCKEditorProvider for DotNetNuke has been made available: http://www.dotnetnuke.com/Community/Forums/tabid/795/forumid/127/threadid/247501/scope/posts/Default.aspx

It finally integrates the newest version of FCKeditor, giving you much better styling support and various other features. So far, my tests have been quite positive with the new version.

One thing to note is the bothering "Red title" style, that is configured by default. If you wish to remove it, you can edit the fckconfig.js files located in the provider's "FCKeditor" and "Custom" folders. Just comment out the line that add the style to FCKeditor's custom styles, and you'll be rid of it.

Regards to Mauricio Márquez for his great work on the integration!

Monday, August 11, 2008 4:18:22 PM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

News concerning TransactionScope and Timeouts#

We finally got a useful response concerning the TransactionScope Timeout problem. Someone else had a similar issue and started a new thread in the Microsoft forums: http://forums.microsoft.com/forums/ShowPost.aspx?PostID=3069149&SiteID=1. The issue has been resolved, but only as of the .NET Framework 3.5. There is a new connection string parameter named "Transaction binding". This is set to "Implicit unbind", which by default causes the described (mis-)behavior. Instead, you must set it to "explicit unbind", so that queries issued after the transaction times out are still considered to be INSIDE the transaction and not in auto-commit mode. You can read the details in the forum post.

Alas, this only solves the problem when using the SqlClient ADO.NET provider. For all other transactive repositories, the issue still exists.

Friday, March 28, 2008 12:43:27 PM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

PersistenceMode.InnerDefaultProperty#

While I was building an ASP.NET user control, I ran across the problem, how to serialize a property as the inner text of the Control in the ASPX-Code. I found a nice attribute named PersistenceModeAttribute, that allows you to specify, how a property is supposed to be persisted. Setting it to InnerDefaultProperty or EncodedInnerDefaultProperty should do the trick, I thought.

But, as I had to find out, this is only part of what needs to be done. There are two more Attributes, that control the parsing of a control: ParseChildrenAttribute and PersistChildrenAttribute. When you use InnerDefaultProperty to persist a property, you must add [ParseChildren(true, "<YourPropertyName>")] and [PersistChildren(false)] to your control's class declaration. Otherwise things won't persist.

It took me a while to find this solution, and I found a nice explanation of things here: http://alvinzc.blogspot.com/2006/10/aspnet-basic-of-custom-server-control_25.html.

Alvin did a really nice job of explaining, what the attributes do. So if you want the details, just visit his blog.

 |  |  | 
Thursday, December 21, 2006 11:33:40 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

TransactionHelper#

For the time being, I have built myself a helper class, that tries to fix the "timeout-bug" when using TransactionScope. And since I'm such a nice guy, I decided to let everyone have it ;-)

So here goes, completely commented including a usage example:

using System;
using System.Threading;
using System.Transactions;

namespace Succell.Framework.Utils
{
    /// <summary>
    /// This class is used to abort transactions when the timeout occurs.
    /// </summary>
    /// <remarks>
    /// <para>This class is required, because TransactionScopes do not abort processing, when they expire. Instead
    /// all actions done after the timeout occurs are not included in the transaction, but instead carried out
    /// normally. This can lead to inconsistencies in your data, when processing large amounts.</para>
    ///
    /// <para>This class can be used nestedly, i.e. methods called in the supplied working delegate can safely
    /// create instances of this class.</para>
    /// </remarks>
    /// <example><code>
    /// try
    /// {
    ///     using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 2)))
    ///     {
    ///         new TransactionHelper(ts, delegate() {
    ///                 // do transactive work here
    ///             });
    ///         ts.Complete();
    ///     }
    /// }
    /// catch (TransactionAbortedException tae)
    /// {
    ///     // handle aborted transaction
    /// }
    /// </code>
    /// </example>
    public sealed class TransactionHelper
    {
        /// <summary>
        /// A tagging object to determine, whether the thread is aborted due to a transaction timeout
        /// </summary>
        private object _abortObject;

        /// <summary>
        /// The current thread executing the transactive work
        /// </summary>
        private Thread _currentThread;

        /// <summary>
        /// Creates a new TransactionHelper that executes transactive statements and aborts the process
        /// if a timeout occurs.
        /// </summary>
        /// <param name="toExecute">The delegate to call for processing</param>
        public TransactionHelper(ThreadStart toExecute)
        {
            if (null == toExecute)
                throw new ArgumentNullException("toExecute");

            // get current transaction
            Transaction tx = Transaction.Current;

            if (null == tx)
                throw new InvalidOperationException("You must create an ambient transaction before using the TransactionHelper");

            // Don't execute, if the transaction is already aborted
            if (tx.TransactionInformation.Status != TransactionStatus.Aborted)
            {
                // keep handle to current thread for aborting
                _currentThread = Thread.CurrentThread;

                // register completion handler
                tx.TransactionCompleted += new TransactionCompletedEventHandler(Current_TransactionCompleted);

                // execute transactive code
                try
                {
                    toExecute();
                }
                catch (ThreadAbortException tae)
                {
                    // was the thread aborted by our TransactionCompleted handler?
                    if (null != _abortObject && tae.ExceptionState == _abortObject)
                    {
                        Thread.ResetAbort();
                    }
                }
                // unregister completion handler (required when using multiple TxHelpers in one transaction,
                // otherwise multiple ThreadAbortExceptions are thrown on timeout)
                tx.TransactionCompleted -= new TransactionCompletedEventHandler(Current_TransactionCompleted);
            }
        }

        /// <summary>
        /// Transaction completion event handler, that checks, whether a timeout occured
        /// and, if so, causes the registered executing thread to abort
        /// </summary>
        /// <param name="sender">The originating transaction</param>
        /// <param name="e">The event args for this event</param>
        void Current_TransactionCompleted(object sender, TransactionEventArgs e)
        {
            // Is the transaction aborted (possibly due to timeout)?
            if (e.Transaction.TransactionInformation.Status == TransactionStatus.Aborted)
            {
                // Is the executing thread registered?
                if (null != _currentThread)
                {
                    // generate a new abortion tagging object
                    _abortObject = new object();

                    // abort the executing thread
                    _currentThread.Abort(_abortObject);
                }
            }
        }
    }
}

I hope, this helps some of you. Of course, I'll be updating my blog, as soon as some notice of how TransactionScope is supposed to be used reaches me. I know, that ThreadAbortExceptions aren't something to use lightly, but currently I see no other way.

Monday, November 27, 2006 11:28:20 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

TransactionScope, ADO.NET, and Timeouts#

Someone has finally found a dirty, yet working solution to the TransactionScope problem. You can register an event on the transaction, that fires, when the transaction finishes, which also happens on a timeout. You can then abort the main thread, to keep further commands from executing.

And this is also the dirty part: ThreadAbortExceptions are a little dangerous and can cause unexpected behavior. But for now it works for me, and as long as Microsoft does not come up with a better solution, I'll have to use this.

You can find more details here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876150&SiteID=1

Saturday, November 18, 2006 11:10:16 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

TransactionScope, ADO.NET, and Timeouts#

Happy Halloween everyone!

Today I'll tell you about some problems I've been having with the TransactionScope class. Namely, I've had timeouts running out, but the application still running the nested queries until they were finished. Amazingly, the data seemed to be in the tables, although the TimeoutException was thrown.

This has now happened to me in multiple applications. But today I read an article on the System.Transactions namespace (http://msdn.microsoft.com/msdnmag/issues/06/11/DataPoints/default.aspx).    There the author states, that you should open the database connection INSIDE the TransactionScope. This becomes logical, when you know that there is also a parameter you can add to the connection string named "auto-enlist" defaulting to true, that tells ADO.NET to look for an ambient transaction when connecting. So, if you open the database connection and then open a TransactionScope, the database does not seem to care about the ambient transaction.

I haven't tried yet, if this solves my problems. But since this is quite an important matter, I wonder why Microsoft does not point this out clearly. The TransactionScope may be a really great invention, but if you don't know how to use it, it causes damage instead of making things safer.

[Update]: This did not fix the problem. Instead, I built a test-app containing both a method, which first opens the database, then the TransactionScope, and a method doing it the other way around. Both methods have the same result. And that is VERY disappointing: The changes to the database made during the Transaction's non-timeout-ed period are rolled back, all changes AFTER the transaction times out are committed. I've written a post in the MSDN-Forum concerning Transactions Programming (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876150&SiteID=1). Let's see what they come up with.

Tuesday, October 31, 2006 10:58:24 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

Service Factory with WCF#

The Microsoft Patterns and Practices team published a Service Factory Add-On recently, that enables the Service Factory to also create WCF services. Sorrily, just after the release of the Add-On, the .NET Team released .NET 3.0 RC1, which is not supported by the Add-On.

If you still wish to install it, you can install the Orca tool located in the bin/ directory of the Windows Vista SDK, open the Service Factory WCF installer package, and change the value of the LaunchCondition variable FRAMEWORK30 to the Version of RC1 (3.0.04324.17). Save it and then you can install it.

You can find more information at http://www.gotdotnet.com/codegallery/messageBoard/Thread.aspx?id=6fde9247-53a8-4879-853d-500cd2d97a83&mbid=fc07ebfb-4369-48e1-ab74-d6098ed220fe&threadid=99894479-0335-4a1b-bf91-bf771237cdfb.

 |  | 
Sunday, September 24, 2006 9:52:42 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

ToolStripContainer and MDI#

Today I was wondering, how you are supposed to use the ToolStripContainer when you want to build an MDI application. I found some solutions in forums speaking about enumerating all controls and finding the MDIClient control, bringing it to the front, and resizing it to match the size of the content panel. But I thought, this is quite a workaround and can't be the way Microsoft meant for things to be done.

A quick search actually ended with the explanation of how you should do it right. There is an article in the msdn library containing a summary of the ToolStrip technology. And in one paragraph, they actually tell you, that there is also a ToolStripPanel component you can use on your form. This component is not present in the toolbox, but you can activate it.

So then you can simply drop as many ToolStripPanels onto your form, dock them accordingly, and leave the content area free for the MDIClient.

For reference: http://msdn2.microsoft.com/en-us/library/a5swc13h.aspx

Wednesday, August 30, 2006 9:49:49 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

Disabling Double-Click maximizing of windows#

Sometimes, the developers of the .NET framework seem not to have thought things through. This is also the case with the windows.forms namespace concerning the maximizing of windows. When you have a fixed size dialog, you will probably also disable resizing using the SizeGripStyle property. Furthermore, you'll want to disable the maximize button, either by setting the MaximizeBox property to false, or by hiding the titlebar controls altogether using the ControlBox property.

This is all well, but I've noticed, that disabling all of these things doesn't disable maximizing of windows completely. When you double-click the titlebar of the window, you'll still be able to maximize it, probably making the contents of the form quite ugly. If you REALLY want to disable maximizing, you'll have to handle some window messages.

This is actually not that difficult. All you have to do is override the WndProc method and search for some constants in the windows API. What you'll need here are WM_SYSCOMMAND and SC_MAXIMIZE, both found in winuser.h. Then all there's left to do is implement the method as follows:

    private const int WM_SYSCOMMAND = 0x0112;
    private const int SC_MAXIMIZE = 0xF030;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_SYSCOMMAND)
        {
            if (((int)m.WParam & 0xFFF0) == SC_MAXIMIZE)
            {
                if (this.WindowState != FormWindowState.Normal)
                {
                    this.WindowState = FormWindowState.Normal;
                }
                m.Result = new IntPtr(0);
                return;
            }
        }
        base.WndProc(ref m);
    }

That's it! You've now got a window, that WON'T MAXIMIZE.

If you want a window, that can ONLY be maximized or minimized (as in there's no WindowState.Normal), you will follow the same approach. But you'll find that in an article I wrote on codeproject.com a while ago. If you want all the details, just read them here: http://www.codeproject.com/useritems/DisableNormalWindowState.asp

Thursday, March 30, 2006 9:43:02 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

On using SQL Express membership providers#

When using ASP.NET membership, you should always be sure to specify the applicationName attribute on all providers. If you omit it, and deploy your database to the web server, you will find, that all your users have vanished (or at least cannot be found). So make sure your web.config looks similar to this:

<membership>
    <providers>
        <remove name="AspNetSqlMembershipProvider" />
        <add name="AspNetSqlMembershipProvider" applicationName="/" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" />
    </providers>
</membership>

After setting the application name, you can start adding users. If you added users before specifying it, they will probably no longer be available.

 |  |  | 
Monday, March 27, 2006 9:35:22 AM (W. Europe Standard Time, UTC+01:00)
Comments [0]  | 

 

All content © 2008 , Christoph Herold