Ejemplo n.º 1
0
        /// <summary>
        /// Installs module
        /// </summary>
        /// <param name="friendlyName">Name of the friendly.</param>
        /// <param name="desktopSource">The desktop source.</param>
        /// <param name="mobileSource">The mobile source.</param>
        /// <param name="install">if set to <c>true</c> [install].</param>
        public static void Install(string friendlyName, string desktopSource, string mobileSource, bool install)
        {
            ErrorHandler.Publish(LogLevel.Info,
                                 "Installing DesktopModule '" + friendlyName + "' from '" + desktopSource + "'");
            if (mobileSource != null && mobileSource.Length > 0)
            {
                ErrorHandler.Publish(LogLevel.Info,
                                     "Installing MobileModule '" + friendlyName + "' from '" + mobileSource + "'");
            }

            string controlFullPath = Path.ApplicationRoot + "/" + desktopSource;

            // Instantiate the module
            Page page = new Page();
            //http://sourceforge.net/tracker/index.php?func=detail&aid=738670&group_id=66837&atid=515929
            //Rainbow.Framework.Web.UI.Page page = new Rainbow.Framework.Web.UI.Page();

            Control myControl = page.LoadControl(controlFullPath);

            if (!(myControl is PortalModuleControl))
            {
                throw new Exception("Module '" + myControl.GetType().FullName + "' is not a PortalModule Control");
            }

            PortalModuleControl portalModule = (PortalModuleControl)myControl;

            // Check mobile module
            if (mobileSource != null && mobileSource.Length != 0 && mobileSource.ToLower().EndsWith(".ascx"))
            {
                //TODO: Check mobile module
                //TODO: MobilePortalModuleControl mobileModule = (MobilePortalModuleControl) page.LoadControl(Rainbow.Framework.Settings.Path.ApplicationRoot + "/" + mobileSource);
                if (!File.Exists(HttpContext.Current.Server.MapPath(Path.ApplicationRoot + "/" + mobileSource)))
                {
                    throw new FileNotFoundException("Mobile Control not found");
                }
            }

            // Get Module ID
            Guid defID = portalModule.GuidID;

            //Get Assembly name
            string assemblyName = portalModule.GetType().BaseType.Assembly.CodeBase;

            assemblyName = assemblyName.Substring(assemblyName.LastIndexOf('/') + 1); //Get name only

            // Get Module Class name
            string className = portalModule.GetType().BaseType.FullName;

            // Now we add the definition to module list
            ModulesDB modules = new ModulesDB();

            if (install)
            {
                //Install as new module

                //Call Install
                try
                {
                    ErrorHandler.Publish(LogLevel.Debug, "Installing '" + friendlyName + "' as new module.");
                    portalModule.Install(null);
                }
                catch (Exception ex)
                {
                    //Error occurred
                    portalModule.Rollback(null);
                    //Rethrow exception
                    throw new Exception("Exception occurred installing '" + portalModule.GuidID.ToString() + "'!", ex);
                }

                try
                {
                    // Add a new module definition to the database
                    modules.AddGeneralModuleDefinitions(defID, friendlyName, desktopSource, mobileSource, assemblyName,
                                                        className, portalModule.AdminModule, portalModule.Searchable);
                }
                catch (Exception ex)
                {
                    //Rethrow exception
                    throw new Exception(
                              "AddGeneralModuleDefinitions Exception '" + portalModule.GuidID.ToString() + "'!", ex);
                }

                // All is fine: we can call Commit
                portalModule.Commit(null);
            }
            else
            {
                // Update the general module definition
                try
                {
                    ErrorHandler.Publish(LogLevel.Debug, "Updating '" + friendlyName + "' as new module.");
                    modules.UpdateGeneralModuleDefinitions(defID, friendlyName, desktopSource, mobileSource,
                                                           assemblyName, className, portalModule.AdminModule,
                                                           portalModule.Searchable);
                }
                catch (Exception ex)
                {
                    //Rethrow exception
                    throw new Exception(
                              "UpdateGeneralModuleDefinitions Exception '" + portalModule.GuidID.ToString() + "'!", ex);
                }
            }

            // Update the module definition - install for portal 0
            modules.UpdateModuleDefinitions(defID, 0, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Installs module
        /// </summary>
        /// <param name="friendlyName">
        /// Name of the friendly.
        /// </param>
        /// <param name="desktopSource">
        /// The desktop source.
        /// </param>
        /// <param name="mobileSource">
        /// The mobile source.
        /// </param>
        /// <param name="install">
        /// if set to <c>true</c> [install].
        /// </param>
        public static void Install(string friendlyName, string desktopSource, string mobileSource, bool install)
        {
            ErrorHandler.Publish(
                LogLevel.Info, string.Format("Installing DesktopModule '{0}' from '{1}'", friendlyName, desktopSource));
            if (!string.IsNullOrEmpty(mobileSource))
            {
                ErrorHandler.Publish(
                    LogLevel.Info, string.Format("Installing MobileModule '{0}' from '{1}'", friendlyName, mobileSource));
            }

            var controlFullPath = Path.ApplicationRoot + "/" + desktopSource;

            // if ascx User Control based Module-> Instantiate the module
            if (controlFullPath.ToLowerInvariant().Trim().EndsWith(".ascx"))
            {
                var page = new Page();

                var control = page.LoadControl(controlFullPath);
                if (!(control is PortalModuleControl))
                {
                    throw new Exception(string.Format("Module '{0}' is not a PortalModule Control", control.GetType().FullName));
                }

                var portalModule = (PortalModuleControl)control;

                // Check mobile module
                if (!string.IsNullOrEmpty(mobileSource) && mobileSource.ToLower().EndsWith(".ascx"))
                {
                    // TODO: Check mobile module
                    // TODO: MobilePortalModuleControl mobileModule = (MobilePortalModuleControl) page.LoadControl(Appleseed.Framework.Settings.Path.ApplicationRoot + "/" + mobileSource);
                    if (!File.Exists(HttpContext.Current.Server.MapPath(Path.ApplicationRoot + "/" + mobileSource)))
                    {
                        throw new FileNotFoundException("Mobile Control not found");
                    }
                }

                // Get Module ID
                var defId = portalModule.GuidID;

                var baseType = portalModule.GetType().BaseType;

                // Get Assembly name
                if (baseType != null)
                {
                    var assemblyName = baseType.Assembly.CodeBase;
                    assemblyName = assemblyName.Substring(assemblyName.LastIndexOf('/') + 1); // Get name only

                    // Get Module Class name
                    var className = baseType.FullName;

                    // Now we add the definition to module list
                    var modules = new ModulesDB();

                    if (install)
                    {
                        // Install as new module

                        // Call Install
                        try
                        {
                            ErrorHandler.Publish(LogLevel.Debug, string.Format("Installing '{0}' as new module.", friendlyName));
                            portalModule.Install(null);
                        }
                        catch (Exception ex)
                        {
                            // Error occurred
                            portalModule.Rollback(null);

                            // Re-throw exception
                            throw new Exception(string.Format("Exception occurred installing '{0}'!", portalModule.GuidID), ex);
                        }

                        try
                        {
                            // Add a new module definition to the database
                            modules.AddGeneralModuleDefinitions(
                                defId,
                                friendlyName,
                                desktopSource,
                                mobileSource,
                                assemblyName,
                                className,
                                portalModule.AdminModule,
                                portalModule.Searchable);
                        }
                        catch (Exception ex)
                        {
                            // Re-throw exception
                            throw new Exception(string.Format("AddGeneralModuleDefinitions Exception '{0}'!", portalModule.GuidID), ex);
                        }

                        // All is fine: we can call Commit
                        portalModule.Commit(null);
                    }
                    else
                    {
                        // Update the general module definition
                        try
                        {
                            ErrorHandler.Publish(LogLevel.Debug, string.Format("Updating '{0}' as new module.", friendlyName));
                            modules.UpdateGeneralModuleDefinitions(
                                defId,
                                friendlyName,
                                desktopSource,
                                mobileSource,
                                assemblyName,
                                className,
                                portalModule.AdminModule,
                                portalModule.Searchable);
                        }
                        catch (Exception ex)
                        {
                            // Re-throw exception
                            throw new Exception(
                                      string.Format("UpdateGeneralModuleDefinitions Exception '{0}'!", portalModule.GuidID), ex);
                        }
                    }

                    // Update the module definition - install for portal 0
                    modules.UpdateModuleDefinitions(defId, 0, true);
                }
            }
        }