private void LoadWidgetsData(AdminWidgetsModel m, AppService appSvc) { //TODO: move into service var targets = new List<Target>(); var container = (IContainer)HttpContext.Application["container"]; var instances = container.Model.AllInstances.Where(i => i.PluginType.Equals(typeof(IWidget))); var widgets = instances.Select(i => i.Get<IWidget>()).ToList(); //var widgets = container.GetAllInstances<IWidget>(); var pages = container.GetAllInstances<IPage>(); //load data based on scope if (Scope.IsWorkspace || Scope.IsCollection) { var w = appSvc.GetWorkspace(Scope.Workspace); if (Scope.IsCollection) { var c = w.GetCollection(Scope.Collection); var cTargets = c.Pages.Cast<TargetBase>().Concat(c.Widgets.Cast<TargetBase>()); targets.AddRange(cTargets.Select(p => GetTarget(p, !Scope.IsCollection, pages, widgets, m))); } var wTargets = w.Pages.Cast<TargetBase>().Concat(w.Widgets.Cast<TargetBase>()) .Select(p => GetTarget(p, !Scope.IsWorkspace, pages, widgets, m)); MergeTargets(wTargets, targets); } var sTargets = appSvc.Pages.Cast<TargetBase>().Concat(appSvc.Widgets.Cast<TargetBase>()) .Select(p => GetTarget(p, !Scope.IsEntireSite, pages, widgets, m)); MergeTargets(sTargets, targets); // select first target if (string.IsNullOrEmpty(m.TargetName) && targets.Count > 0) { m.TargetName = targets[0].Name; m.TargetType = targets[0].IsPage ? "page" : "widget"; } m.Targets = targets.OrderBy(t => t.Inherited); // get areas for target var target = m.Targets.Where(t => t.Name == m.TargetName && t.IsPage == (m.TargetType == "page")).FirstOrDefault(); m.Areas = (target != null) ? target.Areas.OrderBy(a => a.Inherited).ToArray() : new Area[] { }; // select first area if (m.AreaName == null && m.Areas.Count() > 0) m.AreaName = m.Areas.First().Name; var area = m.Areas.Where(a => a.Name == m.AreaName).FirstOrDefault(); m.Includes = (area != null) ? area.Includes.OrderBy(a => a.Inherited).ToArray() : new WidgetInclude[] { }; }