+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom module not installing

Custom module not installing

6 posts, 0 answered
  1. Chad
    Chad avatar
    9 posts
    Registered:
    23 Aug 2012
    19 Sep 2012
    Link to this post
    GOAL:
    To create a redistributable module that contains multiple front-end widgets that is compiled into a .dll for easy installation across multiple sites. Below is my code for the module and is not installing when I copy the dll into the bin folder for my Sitefinity site. Any help would be great.

    using System;
    using System.Linq;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Fluent.Modules;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Modules.Pages.Configuration;
    using Telerik.Sitefinity.Modules.Pages;
    using Telerik.Sitefinity.Web;
    using System.Web.Security;
    using AvianisModule.Widgets;
     
    namespace AvianisModule
    {
        public class AvianisModule : ModuleBase
        {
            #region Properties
                             
            /// <summary>
            /// Gets the landing page id for each module inherit from <see cref="T:Telerik.Sitefinity.Services.SecuredModuleBase" /> class.
            /// </summary>
            /// <value>The landing page id.</value>
            public override Guid LandingPageId
            {
                get { return SiteInitializer.DashboardPageNodeId; }
            }
     
            /// <summary>
            /// Gets the CLR types of all data managers provided by this module.
            /// </summary>
            /// <value>An array of <see cref="T:System.Type" /> objects.</value>
            public override Type[] Managers
            {
                get { return null; }
            }
     
            #endregion
     
            #region "Methods"
     
            public static void InstallModule()
            {
                var configManger = ConfigManager.GetManager();
                var appConfig = configManger.GetSection<SystemConfig>();
     
                var appModuleConfig = appConfig.ApplicationModules;
                if (!appModuleConfig.ContainsKey(AvianisModule.ModuleName))
                    appModuleConfig.Add(new AppModuleSettings(appModuleConfig)
                    {
                        Name = AvianisModule.ModuleName,
                        Title = "Avianis Module",
                        Type = typeof(AvianisModule).FullName,
                        StartupType = StartupType.OnApplicationStart
                    });
                configManger.SaveSection(appConfig);
     
                Config.RegisterSection<AvianisModuleConfig>();
            }
     
            public static void UninstallModule()
            {                                   
                var configMgr = ConfigManager.GetManager();
                var config = configMgr.GetSection<ToolboxesConfig>();
                var pageControls = config.Toolboxes["PageControls"];
                             
                var section = pageControls
                    .Sections
                    .Where<ToolboxSection>(e => e.Name == SectionName)
                    .FirstOrDefault();
     
                if (section != null)
                {
                    UnInstallWidget(section, "AccountProfile");
                    UnInstallWidget(section, "ChangePassword");               
                    UnInstallWidget(section, "ContactProfile");
                    UnInstallWidget(section, "EmptyLegList");
                    UnInstallWidget(section, "EmptyLegTable");
                    UnInstallWidget(section, "FleetListing");
                    UnInstallWidget(section, "InvoiceList");
                    UnInstallWidget(section, "LeadCapture");
                    UnInstallWidget(section, "ListQuotes");
                    UnInstallWidget(section, "Login");
                    UnInstallWidget(section, "LoginForm");
                    UnInstallWidget(section, "Registration");
                    UnInstallWidget(section, "Request");
                    UnInstallWidget(section, "SearchInvoices");
                    UnInstallWidget(section, "SearchQuotes");
                    UnInstallWidget(section, "SearchTrips");
                    UnInstallWidget(section, "TripList");
                    UnInstallWidget(section, "TripManager");
                }
                configMgr.SaveSection(config);
     
                var appConfig = configMgr.GetSection<SystemConfig>();
     
                var appModuleConfig = appConfig.ApplicationModules;
                if (appModuleConfig.ContainsKey(AvianisModule.ModuleName))
                    appModuleConfig.Remove(AvianisModule.ModuleName);
     
                configMgr.SaveSection(appConfig);
            }
     
            /// <summary>
            /// UnInstalls widget
            /// </summary>
            /// <param name="section"></param>
            /// <param name="name"></param>
            public static void UnInstallWidget(ToolboxSection section, string name)
            {
                var widget = section.Tools.FirstOrDefault<ToolboxItem>(e => e.Name == name);
                if (widget != null)
                    section.Tools.Remove(widget);
            }
     
            /// <summary>
            /// Installs this module in Sitefinity system for the first time.
            /// </summary>
            /// <param name="initializer">The Site Initializer. A helper class for installing Sitefinity modules.</param>
            public override void Install(SiteInitializer initializer)
            {
                 
                // get section from toolbox
                var config = initializer.Context.GetConfig<ToolboxesConfig>();
                var pageControls = config.Toolboxes["PageControls"];
                var section = pageControls.Sections
                    .Where<ToolboxSection>(e => e.Name == SectionName)
                    .FirstOrDefault();
     
                if (section == null)
                {
                    section = new ToolboxSection(pageControls.Sections)
                    {
                        Name = SectionName,
                        Title = SectionName,
                        Description = SectionName
                    };
                }
     
                // add widget to section if it doesn't exist
                InstallWidget(section, "AccountProfile", "Account Profile", "Displays the Account profile for the logged in User", typeof(AccountProfile));
     
                InstallWidget(section, "ChangePassword", "Change Password", "Allows logged in user to change their password", typeof(ChangePassword));
     
                InstallWidget(section, "ContactProfile", "Contact Profile", "Displays the profile for the logged in User", typeof(ContactProfile));
     
                InstallWidget(section, "EmptyLegList", "Empty Legs", "Gets and displays all empty legs from Avianis", typeof(EmptyLegList));
     
                InstallWidget(section, "EmptyLegTable", "Empty Legs Table", "Gets and displays all empty legs from Avianis in table format", typeof(EmptyLegTable));
     
                InstallWidget(section, "FleetListing", "Fleet Listing", "Gets a list of all fleet for company", typeof(FleetListing));
     
                InstallWidget(section, "InvoiceList", "Invoice List", "Gets a list of all invoices for the logged in User's account", typeof(InvoiceList));
     
                InstallWidget(section, "LeadCapture", "Lead Capture", "Allows users to send a quote request", typeof(LeadCapture));
     
                InstallWidget(section, "ListQuotes", "Quote List", "Gets a list of all quotes for the logged in User's account", typeof(ListQuotes));
     
                InstallWidget(section, "Login", "Login", "Control for top of page. Shows if logged in or not", typeof(Login));
     
                InstallWidget(section, "LoginForm", "Login Form", "Form used by user to login", typeof(LoginForm));
     
                InstallWidget(section, "Registration", "Registration", "Registration form", typeof(Registration));
     
                InstallWidget(section, "Request", "Request Quote", "Allows users to request quotes", typeof(Request));
     
                InstallWidget(section, "SearchInvoices", "Search Invoices", "Allows users to search for invoices", typeof(SearchInvoices));
     
                InstallWidget(section, "SearchQuotes", "Search Quotes", "Allows users to search for quotes", typeof(SearchQuotes));
     
                InstallWidget(section, "SearchTrips", "Search Trips", "Allows users to search for trips", typeof(SearchTrips));
     
                InstallWidget(section, "TripList", "Trip List", "Gets a list of active trips for the logged in User's Account", typeof(TripList));
     
                InstallWidget(section, "TripManager", "Trip Manager", "Allows the user to manager a trip", typeof(TripManager));
            }
     
            /// <summary>
            /// Installs the widget to the section specified
            /// </summary>
            /// <param name="section"></param>
            /// <param name="name"></param>
            /// <param name="title"></param>
            /// <param name="description"></param>
            /// <param name="controltype"></param>
            public void InstallWidget(ToolboxSection section, string name, string title, string description, Type controltype)
            {
                // add widget to section if it doesn't exist
                if (!section.Tools.Any<ToolboxItem>(e => e.Name == name))
                {
                    var tool = new ToolboxItem(section.Tools)
                    {
                        Name = name,
                        Title = title,
                        Description = description,
                        ControlType = controltype.AssemblyQualifiedName,
                        ModuleName = ModuleName,
                    };
                    section.Tools.Add(tool);
                }
            }
     
            /// <summary>
            /// Initializes the service with specified settings.
            /// </summary>
            /// <param name="settings">The settings.</param>
            public override void Initialize(ModuleSettings settings)
            {
                base.Initialize(settings);
     
                App.WorkWith().
                    Module(AvianisModule.ModuleName).Initialize().
                    Configuration<AvianisModuleConfig>();
                             
                var configManger = ConfigManager.GetManager();
                var appConfig = configManger.GetSection<SystemConfig>();
     
                var appModuleConfig = appConfig.ApplicationModules;
                if (!appModuleConfig.ContainsKey(AvianisModule.ModuleName))
                    appModuleConfig.Add(new AppModuleSettings(appModuleConfig)
                    {
                        Name = AvianisModule.ModuleName,
                        Title = "Avianis Module",
                        Type = typeof(AvianisModule).FullName,
                        StartupType = StartupType.OnApplicationStart
                    });
                configManger.SaveSection(appConfig);
     
                Config.RegisterSection<AvianisModuleConfig>();           
            }
     
            /// <summary>
            /// Upgrades this module from the specified version.
            /// </summary>
            /// <param name="initializer">The Site Initializer. A helper class for installing
            /// Sitefinity modules.</param>
            /// <param name="upgradeFrom">The version this module us upgrading from.</param>
            public override void Upgrade(SiteInitializer initializer, Version upgradeFrom)
            {
            }
     
            /// <summary>
            /// Gets the module configuration.
            /// </summary>
            /// <returns></returns>
            protected override ConfigSection GetModuleConfig()
            {
                return Config.Get<AvianisModuleConfig>();
            }
            #endregion
     
            #region Private members & constants
            /// <summary>
            /// Name of the module.
            /// </summary>
            public const string ModuleName = "AvianisModule";
            public const string SectionName = "Avianis";
     
            #endregion
        }
    }
    Any help would be greatly appreciated. thx.
  2. Brett Whittington
    Brett Whittington avatar
    89 posts
    Registered:
    10 Aug 2012
    20 Sep 2012
    Link to this post
    Are you registering the module in Sitefinity's backend administration section? I've included a screenshot where this can be found if you are not aware of it.  The other possibility is the code you are providing is throwing an exception. I've noticed that these exceptions are not logged anywhere. 

    It is possible to debug your module code if it is getting hit.  Restart IIIS, hit your local machine but not your sitefinity instance, then attach your debug process to your Network Service process.  Finally, hit your site,  If you module is getting hit at all you should be able to walk through the code to find out where it is getting an exception.
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    20 Sep 2012
    Link to this post
    oop Brett beat me to it! was about to ask the same thing :)

    But I will add that the latest versions of Sitefinity also have a Module section under Administration > Modules which allows you to more easily install, disable, uninstall, and delete modules.

    Also be sure you have the full type and namespace for the module, you have to put the fully qualified name for Type for it to work.

    If it is throwing an exception on load, it shouyld show you the error on this modules page as well as the error.log file (though you have to restart your site for it to release the lock on the file!)

    hope this is helpful!
  4. Chad
    Chad avatar
    9 posts
    Registered:
    23 Aug 2012
    20 Sep 2012
    Link to this post
    Thanks for the input guys. So I used the Administration > Modules and when it installed my module it says Failed (Object set to a instance of an object). I can see my Configuration area in the Settings > Administration but I can't see the widgets that were supposed to be installed. Any ideas?
  5. Pavel Donchev
    Pavel Donchev avatar
    28 posts
    Registered:
    06 Dec 2012
    21 Oct 2013 in reply to Chad
    Link to this post
    Have you tried the FluentApi to register the widgets with your module?
    It has LoadOrCreateSection and will probably make your life checking if widgets are already there or not. You should probably be OK to remove the code that checks if the Widget is already installed in the section if you use the FluentApi (your InstallWidget method).
  6. Kedar Periyapatna
    Kedar Periyapatna avatar
    3 posts
    Registered:
    31 Dec 2009
    29 Oct 2013 in reply to Chad
    Link to this post
    Did you hook up handler to PreApplicationStartMethod method?
    Add this to your AssemblyInfo [assembly: PreApplicationStartMethod(typeof(UserModuleInstaller), "PreApplicationStart")]

    and this inside your installer
    public static void PreApplicationStart()
            {
                Bootstrapper.Initialized += UserModuleInstaller.OnBootstrapperInitialized;
            }



    That should be the starting point i guess.
6 posts, 0 answered