/// <summary>
        /// Delete a Module definition
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> instance containing the event data.
        /// </param>
        protected override void OnDelete(EventArgs e)
        {
            try
            {
                if (!this.btnUseInstaller.Visible)
                {
                    ModuleInstall.UninstallGroup(
                        this.Server.MapPath(string.Format("{0}/{1}", Path.ApplicationRoot, this.InstallerFileName.Text)));
                }
                else
                {
                    ModuleInstall.Uninstall(this.DesktopSrc.Text, this.MobileSrc.Text);
                }

                // Redirect back to the portal admin page
                this.RedirectBackToReferringPage();
            }
            catch (ThreadAbortException)
            {
                // normal with redirect
            }
            catch (Exception ex)
            {
                this.lblErrorDetail.Text = General.GetString(
                    "MODULE_DEFINITIONS_DELETE_ERROR", "An error occurred deleting module.", this);
                this.lblErrorDetail.Visible = true;
                ErrorHandler.Publish(LogLevel.Error, this.lblErrorDetail.Text, ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// OnUpdate installs or refresh module definiton on db
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected override void OnUpdate(EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    if (!btnUseInstaller.Visible)
                    {
                        ModuleInstall.InstallGroup(Server.MapPath(Path.ApplicationRoot + "/" + InstallerFileName.Text),
                                                   lblGUID.Text == string.Empty);
                    }
                    else
                    {
                        ModuleInstall.Install(FriendlyName.Text, DesktopSrc.Text, MobileSrc.Text,
                                              lblGUID.Text == string.Empty);
                    }

                    ModulesDB modules = new ModulesDB();

                    // Update the module definition
                    for (int i = 0; i < PortalsName.Items.Count; i++)
                    {
                        modules.UpdateModuleDefinitions(defID, Convert.ToInt32(PortalsName.Items[i].Value),
                                                        PortalsName.Items[i].Selected);
                    }

                    // Redirect back to the portal admin page
                    RedirectBackToReferringPage();
                }
                catch (ThreadAbortException)
                {
                    //normal with redirect
                }
                catch (Exception ex)
                {
                    lblErrorDetail.Text =
                        General.GetString("MODULE_DEFINITIONS_INSTALLING", "An error occurred installing.", this) +
                        "<br>";
                    lblErrorDetail.Text += ex.Message + "<br>";
                    if (!btnUseInstaller.Visible)
                    {
                        lblErrorDetail.Text += " Installer: " +
                                               Server.MapPath(Path.ApplicationRoot + "/" + InstallerFileName.Text);
                    }
                    else
                    {
                        lblErrorDetail.Text += " Module: '" + FriendlyName.Text + "' - Source: '" + DesktopSrc.Text +
                                               "' - Mobile: '" + MobileSrc.Text + "'";
                    }
                    lblErrorDetail.Visible = true;

                    ErrorHandler.Publish(LogLevel.Error, lblErrorDetail.Text, ex);
                }
            }
        }
        /// <summary>
        /// OnUpdate installs or refresh module definition on db
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"/> instance containing the event data.
        /// </param>
        protected override void OnUpdate(EventArgs e)
        {
            if (this.Page.IsValid)
            {
                try
                {
                    // Removed MVC Action and Portable Area installation code
                    //if (this.chbMVCAction.Visible || this.chbPortableAreas.Visible)
                    {
                        // Es un módulo clásico
                        if (!this.btnUseInstaller.Visible)
                        {
                            ModuleInstall.InstallGroup(
                                this.Server.MapPath(Path.ApplicationRoot + "/" + this.InstallerFileName.Text),
                                this.lblGUID.Text == string.Empty, true);
                        }
                        else
                        {
                            ModuleInstall.Install(
                                this.FriendlyName.Text,
                                this.DesktopSrc.Text,
                                this.MobileSrc.Text,
                                this.lblGUID.Text == string.Empty);
                        }

                        // Update the module definition
                    }

                    // Removed MVC Action and Portable Area installation code
                    //else
                    //{
                    //    // Es una acción MVC
                    //    var path = this.ddlAction.SelectedValue;

                    //    path = path.Substring(path.IndexOf("Areas"));
                    //    path = path.Replace("\\", "/");
                    //    path = path.Replace(".aspx", string.Empty);
                    //    path = path.Replace(".ascx", string.Empty);

                    //    var name = this.FriendlyNameMVC.Text;

                    //    this.defId = ModelServices.AddMVCActionModule(name, path);
                    //}

                    var modules = new ModulesDB();

                    for (var i = 0; i < this.PortalsName.Items.Count; i++)
                    {
                        modules.UpdateModuleDefinitions(
                            this.defId,
                            Convert.ToInt32(this.PortalsName.Items[i].Value),
                            this.PortalsName.Items[i].Selected);
                    }

                    // Redirect back to the portal admin page
                    this.RedirectBackToReferringPage();
                }
                catch (ThreadAbortException)
                {
                    // normal with redirect
                }
                catch (Exception ex)
                {
                    this.lblErrorDetail.Text =
                        string.Format("{0}<br />", General.GetString("MODULE_DEFINITIONS_INSTALLING", "An error occurred installing.", this));
                    this.lblErrorDetail.Text += ex.Message + "<br />";
                    if (!this.btnUseInstaller.Visible)
                    {
                        this.lblErrorDetail.Text += string.Format(
                            " Installer: {0}",
                            this.Server.MapPath(
                                string.Format("{0}/{1}", Path.ApplicationRoot, this.InstallerFileName.Text)));
                    }
                    else
                    {
                        this.lblErrorDetail.Text += string.Format(
                            " Module: '{0}' - Source: '{1}' - Mobile: '{2}'",
                            this.FriendlyName.Text,
                            this.DesktopSrc.Text,
                            this.MobileSrc.Text);
                    }

                    this.lblErrorDetail.Visible = true;

                    ErrorHandler.Publish(LogLevel.Error, this.lblErrorDetail.Text, ex);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Handles the Click event of the UpdateDatabaseCommand control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void UpdateDatabaseCommand_Click(object sender, EventArgs e)
        {
            ArrayList errors   = new ArrayList();
            ArrayList messages = new ArrayList();

            foreach (UpdateEntry myUpdate in scriptsList)
            {
                //Version check (a script may update more than one version at once)
                if (myUpdate.Apply && DatabaseVersion < myUpdate.VersionNumber && DatabaseVersion < Portal.CodeVersion)
                {
                    foreach (string scriptName in myUpdate.scriptNames)
                    {
                        //It may be a module update only
                        if (scriptName.Length > 0)
                        {
                            string currentScriptName =
                                Server.MapPath(System.IO.Path.Combine(Path.ApplicationRoot + "/Setup/Scripts/", scriptName));
                            ErrorHandler.Publish(LogLevel.Info,
                                                 "CODE: " + Portal.CodeVersion + " - DB: " + DatabaseVersion + " - CURR: " +
                                                 myUpdate.VersionNumber + " - Applying: " + currentScriptName);
                            ArrayList myErrors = Rainbow.Framework.Data.DBHelper.ExecuteScript(currentScriptName, true);
                            errors.AddRange(myErrors);                      //Display errors if any

                            if (myErrors.Count > 0)
                            {
                                errors.Insert(0, "<P>" + scriptName + "</P>");
                                ErrorHandler.Publish(LogLevel.Error,
                                                     "Version " + myUpdate.Version + " completed with errors.  - " +
                                                     scriptName);
                                break;
                            }
                        }
                    }

                    //Installing modules
                    foreach (string moduleInstaller in myUpdate.Modules)
                    {
                        string currentModuleInstaller =
                            Server.MapPath(System.IO.Path.Combine(Path.ApplicationRoot + "/", moduleInstaller));

                        try {
                            ModuleInstall.InstallGroup(currentModuleInstaller, true);
                        }
                        catch (Exception ex) {
                            ErrorHandler.Publish(LogLevel.Fatal,
                                                 "Exception in UpdateDatabaseCommand installing module: " +
                                                 currentModuleInstaller, ex);
                            if (ex.InnerException != null)
                            {
                                // Display more meaningful error message if InnerException is defined
                                ErrorHandler.Publish(LogLevel.Warn,
                                                     "Exception in UpdateDatabaseCommand installing module: " +
                                                     currentModuleInstaller, ex.InnerException);
                                errors.Add("Exception in UpdateDatabaseCommand installing module: " +
                                           currentModuleInstaller + "<br/>" + ex.InnerException.Message + "<br/>" +
                                           ex.InnerException.StackTrace);
                            }
                            else
                            {
                                ErrorHandler.Publish(LogLevel.Warn,
                                                     "Exception in UpdateDatabaseCommand installing module: " +
                                                     currentModuleInstaller, ex);
                                errors.Add(ex.Message);
                            }
                        }
                    }

                    if (Equals(errors.Count, 0))
                    {
                        //Update db with version
                        string versionUpdater;
                        versionUpdater = "INSERT INTO [rb_Versions] ([Release],[Version],[ReleaseDate]) VALUES('" +
                                         myUpdate.VersionNumber + "','" + myUpdate.Version + "', CONVERT(datetime, '" +
                                         myUpdate.Date.Month + "/" + myUpdate.Date.Day + "/" + myUpdate.Date.Year + "', 101))";
                        Rainbow.Framework.Data.DBHelper.ExeSQL(versionUpdater);
                        ErrorHandler.Publish(LogLevel.Info,
                                             "Version number: " + myUpdate.Version + " applied successfully.");

                        //Mark this update as done
                        ErrorHandler.Publish(LogLevel.Info, "Sucessfully applied version: " + myUpdate.Version);
                    }
                }
                else
                {
                    //Skipped
                    //string skippedMessage = "Skipping: " + myUpdate.Version
                    //	+ " DbVersion (" + DatabaseVersion
                    //	+ ") "
                    //	+ " Codeversion (" + Portal.CodeVersion
                    //	+ ")";
                    // messages.Add(skippedMessage);
                    ErrorHandler.Publish(LogLevel.Info,
                                         "CODE: " + Portal.CodeVersion + " - DB: " + DatabaseVersion + " - CURR: " +
                                         myUpdate.VersionNumber + " - Skipping: " + myUpdate.Version);
                }
            }

            dbUpdateResult.Visible = false;
            dbNeedsUpdate.Visible  = false;
            Status.Visible         = true;

            if (messages.Count > 0)
            {
                dlErrors.DataSource = messages;
                dlErrors.DataBind();
                dlErrors.Visible       = true;
                dlErrors.ForeColor     = Color.Green;
                dbUpdateResult.Visible = true;

                dbUpdateResult.Visible = true;
                dbNeedsUpdate.Visible  = false;
            }

            if (errors.Count > 0)
            {
                dlErrors.DataSource = errors;
                dlErrors.DataBind();
                dlErrors.Visible   = true;
                dlErrors.ForeColor = Color.Red;

                dbUpdateResult.Visible = true;
                dbNeedsUpdate.Visible  = false;
                Status.Visible         = false;
            }
        }
Exemple #5
0
        /// <summary>
        /// The run db update.
        /// </summary>
        /// <param name="connectionString">
        /// The connection string.
        /// </param>
        /// <returns>
        /// The run db update.
        /// </returns>
        /// <remarks>
        /// </remarks>
        public bool RunDBUpdate(string connectionString)
        {
            CurrentCache.Insert(Portal.UniqueID + "_ConnectionString", connectionString);

            var databaseVersion = DatabaseVersion;

            var xmlDocument     = new XmlDocument();
            var tempScriptsList = new List <UpdateEntry>();

            try
            {
                if (databaseVersion < Portal.CodeVersion)
                {
                    ErrorHandler.Publish(
                        LogLevel.Debug, string.Format("db:{0} Code:{1}", databaseVersion, Portal.CodeVersion));

                    // load the history file
                    var docPath =
                        HttpContext.Current.Server.MapPath("~/Setup/Scripts/History.xml");

                    xmlDocument.Load(docPath);

                    // get a list of <Release> nodes
                    if (xmlDocument.DocumentElement != null)
                    {
                        var releases = xmlDocument.DocumentElement.SelectNodes("Release");
                        if (releases != null)
                        {
                            // iterate over the <Release> nodes
                            // (we can do this because XmlNodeList implements IEnumerable)
                            foreach (XmlNode release in releases)
                            {
                                var updateEntry = new UpdateEntry();

                                // get the header information
                                // we check for null to avoid exception if any of these nodes are not present
                                if (release.SelectSingleNode("ID") != null)
                                {
                                    updateEntry.VersionNumber = Int32.Parse(release.SelectSingleNode("ID/text()").Value);
                                }

                                if (release.SelectSingleNode("Version") != null)
                                {
                                    updateEntry.Version = release.SelectSingleNode("Version/text()").Value;
                                }

                                if (release.SelectSingleNode("Script") != null)
                                {
                                    updateEntry.ScriptNames.Add(release.SelectSingleNode("Script/text()").Value);
                                }

                                if (release.SelectSingleNode("Date") != null)
                                {
                                    updateEntry.Date = DateTime.Parse(release.SelectSingleNode("Date/text()").Value);
                                }

                                // We should apply this patch
                                if (databaseVersion < updateEntry.VersionNumber)
                                {
                                    // Appleseed.Framework.Helpers.LogHelper.Logger.Log(Appleseed.Framework.Site.Configuration.LogLevel.Debug, "Detected version to apply: " + myUpdate.Version);
                                    updateEntry.Apply = true;

                                    // get a list of <Installer> nodes
                                    var installers = release.SelectNodes("Modules/Installer/text()");

                                    // iterate over the <Installer> Nodes (in original document order)
                                    // (we can do this because XmlNodeList implements IEnumerable)
                                    foreach (XmlNode installer in installers)
                                    {
                                        // and build an ArrayList of the scripts...
                                        updateEntry.Modules.Add(installer.Value);

                                        // Appleseed.Framework.Helpers.LogHelper.Logger.Log(Appleseed.Framework.Site.Configuration.LogLevel.Debug, "Detected module to install: " + installer.Value);
                                    }

                                    // get a <Script> node, if any
                                    var sqlScripts = release.SelectNodes("Scripts/Script/text()");

                                    // iterate over the <Installer> Nodes (in original document order)
                                    // (we can do this because XmlNodeList implements IEnumerable)
                                    foreach (XmlNode sqlScript in sqlScripts)
                                    {
                                        // and build an ArrayList of the scripts...
                                        updateEntry.ScriptNames.Add(sqlScript.Value);

                                        // Appleseed.Framework.Helpers.LogHelper.Logger.Log(Appleseed.Framework.Site.Configuration.LogLevel.Debug, "Detected script to run: " + sqlScript.Value);
                                    }

                                    tempScriptsList.Add(updateEntry);
                                }
                            }
                        }
                    }

                    // If we have some version to apply...
                    if (tempScriptsList.Count <= 0)
                    {
                        // No update is needed
                    }
                    else
                    {
                        this.scriptsList = tempScriptsList.ToArray();

                        // by Manu. Versions are sorted by version number
                        Array.Sort(this.scriptsList);

                        // Create a flat version for binding
                        var currentVersion = 0;
                        var databindList   = new List <string>();
                        foreach (var updateEntry in this.scriptsList.Where(updateEntry => updateEntry.Apply))
                        {
                            if (currentVersion != updateEntry.VersionNumber)
                            {
                                databindList.Add(string.Format("Version: {0}", updateEntry.VersionNumber));
                                currentVersion = updateEntry.VersionNumber;
                            }

                            databindList.AddRange(
                                updateEntry.ScriptNames.Where(scriptName => scriptName.Length > 0).Select(
                                    scriptName => string.Format("-- Script: {0}", scriptName)));
                            databindList.AddRange(
                                updateEntry.Modules.Where(moduleInstaller => moduleInstaller.Length > 0).Select(
                                    moduleInstaller => string.Format("-- Module: {0}", moduleInstaller)));
                        }

                        var errors = new List <object>();

                        // var messages = new List<object>();
                        foreach (var updateEntry in this.scriptsList)
                        {
                            if (updateEntry.Apply && DatabaseVersion < updateEntry.VersionNumber &&
                                DatabaseVersion < Portal.CodeVersion)
                            {
                                // Version check (a script may update more than one version at once)
                                foreach (var scriptName in updateEntry.ScriptNames)
                                {
                                    if (scriptName.Length <= 0)
                                    {
                                        continue;
                                    }

                                    // It may be a module update only
                                    var currentScriptName =
                                        HttpContext.Current.Server.MapPath(
                                            System.IO.Path.Combine("~/Setup/Scripts/", scriptName));
                                    ErrorHandler.Publish(
                                        LogLevel.Info,
                                        string.Format(
                                            "CODE: {0} - DB: {1} - CURR: {2} - Applying: {3}",
                                            Portal.CodeVersion,
                                            DatabaseVersion,
                                            updateEntry.VersionNumber,
                                            currentScriptName));
                                    var myerrors = DBHelper.ExecuteScript(currentScriptName, true);
                                    errors.AddRange(myerrors); // Display errors if any

                                    if (myerrors.Count <= 0)
                                    {
                                        continue;
                                    }

                                    errors.Insert(0, string.Format("<p>{0}</p>", scriptName));
                                    ErrorHandler.Publish(
                                        LogLevel.Error,
                                        string.Format(
                                            "Version {0} completed with errors.  - {1}", updateEntry.Version, scriptName));
                                    break;
                                }

                                // Installing modules
                                foreach (var currentModuleInstaller in from string moduleInstaller in updateEntry.Modules
                                         select HttpContext.Current.Server.MapPath(System.IO.Path.Combine("~/", moduleInstaller)))
                                {
                                    try
                                    {
                                        ModuleInstall.InstallGroup(currentModuleInstaller, true);
                                    }
                                    catch (Exception ex)
                                    {
                                        ErrorHandler.Publish(
                                            LogLevel.Fatal,
                                            string.Format(
                                                "Exception in UpdateDatabaseCommand installing module: {0}",
                                                currentModuleInstaller),
                                            ex);
                                        if (ex.InnerException != null)
                                        {
                                            // Display more meaningful error message if InnerException is defined
                                            ErrorHandler.Publish(
                                                LogLevel.Warn,
                                                string.Format(
                                                    "Exception in UpdateDatabaseCommand installing module: {0}",
                                                    currentModuleInstaller),
                                                ex.InnerException);
                                            errors.Add(
                                                string.Format(
                                                    "Exception in UpdateDatabaseCommand installing module: {0}<br />{1}<br />{2}",
                                                    currentModuleInstaller,
                                                    ex.InnerException.Message,
                                                    ex.InnerException.StackTrace));
                                        }
                                        else
                                        {
                                            ErrorHandler.Publish(
                                                LogLevel.Warn,
                                                string.Format(
                                                    "Exception in UpdateDatabaseCommand installing module: {0}",
                                                    currentModuleInstaller),
                                                ex);
                                            errors.Add(ex.Message);
                                        }
                                    }
                                }

                                if (Equals(errors.Count, 0))
                                {
                                    // Update db with version
                                    var versionUpdater =
                                        string.Format(
                                            "INSERT INTO [rb_Versions] ([Release],[Version],[ReleaseDate]) VALUES('{0}','{1}', CONVERT(datetime, '{2}/{3}/{4}', 101))",
                                            updateEntry.VersionNumber,
                                            updateEntry.Version,
                                            updateEntry.Date.Month,
                                            updateEntry.Date.Day,
                                            updateEntry.Date.Year);
                                    DBHelper.ExeSQL(versionUpdater);
                                    ErrorHandler.Publish(
                                        LogLevel.Info,
                                        string.Format("Version number: {0} applied successfully.", updateEntry.Version));

                                    // Mark this update as done
                                    ErrorHandler.Publish(
                                        LogLevel.Info,
                                        string.Format("Successfully applied version: {0}", updateEntry.Version));
                                }
                            }
                            else
                            {
                                ErrorHandler.Publish(
                                    LogLevel.Info,
                                    string.Format(
                                        "CODE: {0} - DB: {1} - CURR: {2} - Skipping: {3}",
                                        Portal.CodeVersion,
                                        DatabaseVersion,
                                        updateEntry.VersionNumber,
                                        updateEntry.Version));
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorHandler.Publish(LogLevel.Error, "An error occurred during the installation process.", exception);
                throw;
            }
            return(true);
        }