public ActionResult RenderDashboard(DashboardItemModel model)
        {
            switch (model.DashboardType)
            {
                case DashboardType.PartialView:
                    return PartialView(model.ViewName);
                case DashboardType.ChildAction:
                    MethodInfo childAction;
                    var editorController = model.GetEditorDashboardAction(BackOfficeRequestContext.RegisteredComponents, out childAction);

                    if (!TypeFinder.IsTypeAssignableFrom<PartialViewResult>(childAction.ReturnType)
                        && !TypeFinder.IsTypeAssignableFrom<ContentResult>(childAction.ReturnType))
                    {
                        throw new InvalidOperationException("ChildAction dashboards should have a return type of " + typeof(PartialViewResult).Name + " or " + typeof(ContentResult).Name);
                    }

                    //proxy the request to the controller                    
                    var result = this.ProxyRequestToController(
                        ControllerExtensions.GetControllerName(editorController.Metadata.ComponentType), 
                        childAction.Name,
                        editorController.Metadata,
                        BackOfficeRequestContext.Application.Settings.RebelPaths.BackOfficePath,
                        "editorId",
                        new Dictionary<string, object>());

                    return Content(result.RenderedOutput);
                default:
                    throw new ArgumentOutOfRangeException();
            }


        }
예제 #2
0
        public ActionResult RenderDashboard(DashboardItemModel model)
        {
            switch (model.DashboardType)
            {
            case DashboardType.PartialView:
                return(PartialView(model.ViewName));

            case DashboardType.ChildAction:
                MethodInfo childAction;
                var        editorController = model.GetEditorDashboardAction(BackOfficeRequestContext.RegisteredComponents, out childAction);

                if (!TypeFinder.IsTypeAssignableFrom <PartialViewResult>(childAction.ReturnType))
                {
                    throw new InvalidOperationException("ChildAction dashboards should have a return type of " + typeof(PartialViewResult).Name);
                }

                using (var controller = editorController.Value)
                {
                    if (controller == null)
                    {
                        throw new TypeLoadException("Could not create controller: " + UmbracoController.GetControllerName(editorController.Metadata.ComponentType));
                    }

                    //proxy the request to the controller
                    return(this.ProxyRequestToController(controller, childAction));
                }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #3
0
        public ActionResult RenderDashboard(DashboardItemModel model)
        {
            switch (model.DashboardType)
            {
            case DashboardType.PartialView:
                return(PartialView(model.ViewName));

            case DashboardType.ChildAction:
                MethodInfo childAction;
                var        editorController = model.GetEditorDashboardAction(BackOfficeRequestContext.RegisteredComponents, out childAction);

                if (!TypeFinder.IsTypeAssignableFrom <PartialViewResult>(childAction.ReturnType) &&
                    !TypeFinder.IsTypeAssignableFrom <ContentResult>(childAction.ReturnType))
                {
                    throw new InvalidOperationException("ChildAction dashboards should have a return type of " + typeof(PartialViewResult).Name + " or " + typeof(ContentResult).Name);
                }

                //proxy the request to the controller
                var result = this.ProxyRequestToController(
                    ControllerExtensions.GetControllerName(editorController.Metadata.ComponentType),
                    childAction.Name,
                    editorController.Metadata,
                    BackOfficeRequestContext.Application.Settings.RebelPaths.BackOfficePath,
                    "editorId",
                    new Dictionary <string, object>());

                return(Content(result.RenderedOutput));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #4
0
        public IQueryable <EquipmentModel> GetEquipment(int customerId)
        {
            var equipmentList = new List <EquipmentModel>();
            var ditem         = new DashboardItemModel();

            // TEMPORARY
            // MOCK DATA
            if (customerId != CustomerController.kMockCustomerId)
            {
                var equipment = _dataRep.Equipment.Where(e => e.Customer.Id == customerId).ToList();
                foreach (var meter in equipment)
                {
                    equipmentList.Add(_mapEquipmentToEquipmentModel(meter));
                }
            }

            return(equipmentList.AsQueryable <EquipmentModel>());
        }
예제 #5
0
        //[Route("customer/{customerId}/orders")]
        public IQueryable <DashboardItemModel> GetAllDashboardItem(string customerGuid)
        {
            var dashboarditems = new List <DashboardItemModel>();
            var ditem          = new DashboardItemModel();

            // TEMPORARY
            // MOCK DATA
            if (customerGuid == "123mock123")
            {
                dashboarditems = _mockData();
            }
            else
            {
                var equipment = _db.Equipment.Where(e => e.Customer.Guid == customerGuid).ToList();
                foreach (var meter in equipment)
                {
                    dashboarditems.Add(_mapEquipmentToDashboardItem(meter));
                }
            }

            return(dashboarditems.AsQueryable <DashboardItemModel>());
        }
예제 #6
0
        public static Lazy <AbstractEditorController, EditorMetadata> GetEditorDashboardAction(
            this DashboardItemModel dashboard,
            ComponentRegistrations components,
            out MethodInfo action)
        {
            //we need to get the surface controller by name
            var parts = dashboard.ViewName.Split('.');

            if (parts.Length != 2)
            {
                throw new FormatException("The string format for dashboard.ViewName for child actions must be: ControllerName.ActionName");
            }
            var controllerName   = parts[0];
            var controllerAction = parts[1];
            var editorController = components.EditorControllers
                                   .Where(x => x.Metadata.ControllerName == controllerName).SingleOrDefault();

            if (editorController == null)
            {
                throw new ApplicationException("Could not find the Editor controller '" + controllerName);
            }
            if (!editorController.Metadata.HasChildActionDashboards)
            {
                throw new ApplicationException("The Editor controller '" + controllerName + "' is not advertising that it HasChildActionDashboards");
            }
            //now we need to get the controller's referenced child action
            var childAction = editorController.Metadata.ComponentType.GetMethods()
                              .Where(x => x.Name == controllerAction && x.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any())
                              .SingleOrDefault();

            if (childAction == null)
            {
                throw new ApplicationException("The Editor controller '" + controllerName + "' with Action: '" + controllerAction + "' could not be found or was not attributed with a ChildActionOnlyAttribute");
            }

            action = childAction;
            return(editorController);
        }
예제 #7
0
        public IHttpActionResult GetDashboardItemModel(string customerGuid, int id)
        {
            var dashboarditem = new DashboardItemModel();

            // TEMPORARY
            // MOCK DATA
            if (customerGuid == "123mock123")
            {
                dashboarditem = _mockData().FirstOrDefault((p) => p.Id == id);
            }
            else
            {
                var equip = _db.Equipment.First(e => e.Customer.Guid == customerGuid && e.id == id);

                if (equip == null)
                {
                    return(NotFound());
                }
                dashboarditem = _mapEquipmentToDashboardItem(equip);
            }

            return(Ok(dashboarditem));
        }
 /// <summary>
 /// Renders a dashboard item
 /// </summary>
 /// <param name="html"></param>
 /// <param name="model"></param>
 /// <returns></returns>
 public static IHtmlString RenderDashboard(this HtmlHelper html, DashboardItemModel model)
 {
     return(html.Action("RenderDashboard", "DashboardEditor", new { model }));
 }
예제 #9
0
        private List <DashboardItemModel> _mockData()
        {
            List <DashboardItemModel> meters = new List <DashboardItemModel>();

            var m = new DashboardItemModel
            {
                Id         = 1,
                Location   = "507 Michigan",
                Name       = "Main utility meter",
                Demand     = 340,
                Inc        = -2,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15))
            };

            meters.Add(m);
            m = new DashboardItemModel
            {
                Id         = 2,
                Location   = "5757 Corporate",
                Name       = "Main meter",
                Demand     = 680,
                Inc        = .3,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(45))
            };
            meters.Add(m);
            m = new DashboardItemModel
            {
                Id         = 3,
                Location   = "Mke Hangar",
                Name       = "Utility meter",
                Demand     = 430,
                Inc        = 5,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15))
            };
            meters.Add(m);
            m = new DashboardItemModel
            {
                Id         = 4,
                Location   = "Plymouth",
                Name       = "Building 36 meter",
                Demand     = 298,
                Inc        = .2,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15))
            };
            meters.Add(m);
            m = new DashboardItemModel
            {
                Id         = 5,
                Location   = "York",
                Name       = "CTU meter",
                Demand     = 1200,
                Inc        = -2,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15))
            };
            meters.Add(m);
            m = new DashboardItemModel
            {
                Id         = 2,
                Location   = "5757 solar",
                Name       = "Roof Array meter",
                Demand     = 545,
                Inc        = .7,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15))
            };
            meters.Add(m);
            m = new DashboardItemModel
            {
                Id         = 2,
                Location   = "5757 Corporate",
                Name       = "Pumps eletric meter",
                Demand     = 680,
                Inc        = 1.1,
                lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(30))
            };
            meters.Add(m);
            return(meters);
        }