Exemple #1
0
        protected void Application_Start()
        {
            if (App.Settings.AutomaticMigrationsEnabled)
            {
                Database.SetInitializer(new MigrateDatabaseToLatestVersion <CoreDbContext, DNA.Web.Data.Entity.Migrations.Configuration>());
            }
            else
            {
                Database.SetInitializer(new CreateDatabaseIfNotExists <CoreDbContext>());
            }

            System.Web.Mvc.ViewEngines.Engines.Clear();
            System.Web.Mvc.ViewEngines.Engines.Add(new RazorViewEngine());

            ModuleRegistration.RegisterModules(RouteTable.Routes, new TypeContainer());

            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            Bootstrapper.RegisterTypes();
            RegisterGlobalFilters(GlobalFilters.Filters);
            Bootstrapper.RegisterGlobalFilters(GlobalFilters.Filters);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var tasks = new TaskCollection();

            ModuleRegistration.RegisterTasks(tasks);
            Scheduler.AddTasks(tasks);

            if (App.Settings.AutoStartScheduler)
            {
                Scheduler.Start();
            }

            Bootstrapper.RegisterWidgets();

            //var embeddedViewResolver =System.Web.Mvc.DependencyResolver.Current.GetService<IEmbeddedViewResolver>();
            var embeddedProvider = new EmbeddedViewPathProvider(new EmbeddedViewResolver().GetEmbeddedViews());

            HostingEnvironment.RegisterVirtualPathProvider(embeddedProvider);

            //Bootstrapper.Init();
            ModuleRegistration.AppStart(this);
            //Logger.Info("Application start.");
        }
Exemple #2
0
        /// <summary>
        /// Register widgets in modules.
        /// </summary>
        public static void RegisterWidgets()
        {
            var widgets = new WidgetCollection();

            ModuleRegistration.RegisterWidgets(widgets);
            var widgetMgr       = App.Get().Widgets;
            var pendingRegister = new List <string>();

            foreach (var w in widgets)
            {
                var installedPath = w.Category + "\\" + w.Name;
                var widgetID      = DNA.Utility.TextUtility.Slug(w.ModuleType.FullName + "." + w.Name);
                var viewName      = string.Format("~/Widgets/{0}/{1}", w.Name, w.ViewName);

                if (widgetMgr.Find(widgetID) == null)
                {
                    XNamespace ns        = "http://www.w3.org/ns/widgets";
                    var        widgetEle = new XElement(ns + "widget",
                                                        new XAttribute("id", widgetID),
                                                        new XAttribute("version", w.ModuleType.Assembly.GetName().Version.ToString()),
                                                        new XElement(ns + "name", new XAttribute("short", w.Name), w.Title),
                                                        new XElement(ns + "description", w.Description)
                                                        );

                    var contentEle = new XElement(ns + "content", new XAttribute("type", "application/x-ms-aspnet"), new XAttribute("src", viewName));
                    widgetEle.Add(contentEle);

                    var fullPath = Path.Combine(HostingEnvironment.MapPath("~/content/widgets/"), installedPath);
                    if (!Directory.Exists(fullPath))
                    {
                        Directory.CreateDirectory(fullPath);
                    }

                    if (w.Preferences != null && w.Preferences.Count > 0)
                    {
                        foreach (var key in w.Preferences.Keys)
                        {
                            var val = w.Preferences[key];
                            widgetEle.Add(new XElement(ns + "preference", new XAttribute("name", key), new XAttribute("value", FormPreferenceValue(val))));
                        }
                    }

                    var configXmlFile = Path.Combine(fullPath, "config.xml");
                    widgetEle.Save(configXmlFile);

                    //XmlSerializerUtility.SerializeToXmlFile(configXmlFile, widgetEle);
                    pendingRegister.Add(w.Category + "," + w.Name);
                }
                else
                {
                    // widgetMgr.Update(w);
                }
            }

            if (pendingRegister.Count > 0)
            {
                App.Get().Widgets.Reload();

                for (int i = 0; i < pendingRegister.Count; i++)
                {
                    try
                    {
                        var args = pendingRegister[i].Split(',');
                        App.Get().Widgets.Register(args[0], args[1]);
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e);
                        continue;
                    }
                }
            }
        }