CASK - Auto update module fires on error

On May 19th Alex57 wrote the following in this CASK discussion thread

Table - Community_NamedPages

ASPNET.StarterKit.Communities.Login - ASPNET.StarterKit.Communities.Users.Login
ASPNET.StarterKit.Communities.Logout
....
Now that I'm blowing the dust off of the CASK source code I see the problem.

In the first release of CASK there was an annoying coding issue that made things real difficult to find - everything had the same namespace ASPNET.StarterKit.Communities.   It was a MAJOR undertaking to refactor namespaces so that it reflected the folder the class code was located in; almost every code file and user control was touched in the process.  When all was done and said another problem remained - there are tables that store namespaces.
 
This problem was resolved with an "auto update on error" process.   One forgotten about until I ran the following Click-Once application to install a new CASKDB database on my system: http://www.global-webnet.net/CSK/CSKInstall.htm;  when the following error occurs the factory processes it and runs the applicable code to fix the error:

The following process is executed:

public class CASKV2_2_0_0 : ICommand, IHandlesException

{

    private List<NamedPageStruct> namedPage = new List<NamedPageStruct>();

    private string connectionString = string.Empty;

 

    /// <summary>

    /// Flags this class as an Exception handler - if an exception occurs

    /// while loading the page the CommunityDefault.aspx.cs will instantiate

    /// the UpgradeModuleClass and execute this process

    /// </summary>

    public bool IsHandlingException  { get { return true; }  }

 

    /// <summary>

    /// Executed by the UpgradeController class.

    /// </summary>

    /// <param name="sender">Process that initiated the event</param>

    /// <param name="e"></param>

    public void Execute(object sender, EventArgs e)

    {

        // Cast back to ModuleUtilEventArgs

        ModuleUtilEventArgs muea = e as ModuleUtilEventArgs;

 

        if (sender is Exception)

        {

            Exception ex = sender as Exception;

            if (!ex.Message.ToLower().Contains("could not load type"))

                return;

 

            muea.Message = ex.Message;   

        }

 

 

        // Store the connection string for class use

        connectionString = muea.ConnectionString;

 

        // Instantiate our sql connection

        SQLUtil sql = new SQLUtil(connectionString);

        sql.OnExecuteReader += new

            EventHandler<DataEventArgs>(ReaderHandler);

 

        // Pull all current named pages

        sql.SqlExec("Select * from Community_NamedPages");

 

        // ReadHandler will have processed the data and all records

        // will be loaded into the "namedPage" collection.  We

        // Need to find each record and update its

        NameFieldWithContents("Login", "ASPNET.StarterKit.Communities.Users.Login", muea);

        NameFieldWithContents("Logout", "ASPNET.StarterKit.Communities.Users.Logout", muea);

        NameFieldWithContents("Register", "ASPNET.StarterKit.Communities.Users.Register", muea);

        NameFieldWithContents("ShowProfile", "ASPNET.StarterKit.Communities.Users.ShowProfile", muea);

        NameFieldWithContents("EditProfile", "ASPNET.StarterKit.Communities.Users.EditProfile", muea);

        NameFieldWithContents("Password Reminder", "ASPNET.StarterKit.Communities.Users.PasswordReminder", muea);

        NameFieldWithContents("Search", "ASPNET.StarterKit.Communities.Search.Search", muea);

        NameFieldWithContents("Delete Content Page", "ASPNET.StarterKit.Communities.ContentPages.DeleteContentPage", muea);

        NameFieldWithContents("Move Content Page", "ASPNET.StarterKit.Communities.ContentPages.MoveContentPage", muea);

        NameFieldWithContents("Add Comment", "ASPNET.StarterKit.Communities.Comments.AddComment", muea);

        NameFieldWithContents("Topic", "ASPNET.StarterKit.Communities.Topics.Topic", muea);

        NameFieldWithContents("Message", "ASPNET.StarterKit.Communities.Message.Message", muea);

 

        muea.Message = "<b>UPDATED - try process again</b>";

 

    }

Which results in the following output

The tables are updated with the proper namespaces and the program no longer crashes.

So this error will happen if you installed the original release and have downloaded the latest source code and attempt to run the application (since the latest source code expects the namespaces to be correct).  

If you are not running the release version of CASK, i.e., it has been modified, it is possible the error signature will not be the same and the code update won't fire - you'll know this has happened because you won't see the above results.   In this case I need to be contacted so we can support the error signature being provided so that your process will update correctly.

 


Tags:
Categories:


Actions: E-mail | Permalink |  Grammar/Typo/Better way? Please let me know