public void LoadSettingFromUiConfig(UiConfigurationRoot configurationRoot)
        {
            if (configurationRoot.Id == null)
            {
                return;
            }

            var id = configurationRoot.Id.Value.ToString();

            if (!_configurationMapping.ContainsKey(id))
            {
                _configurationMapping.Add(id, new List <string>());
            }
            else
            {
                _configurationMapping[id].Clear();
            }

            foreach (var category in configurationRoot.Categories)
            {
                foreach (var controlModel in category.ControlModels)
                {
                    var convertedControlModel = _controlModelService.Convert(controlModel);
                    if (convertedControlModel != null)
                    {
                        var identifier = $"{convertedControlModel.Adapter}:{convertedControlModel.Identifier}";
                        if (!_configurationMapping[id].Contains(identifier))
                        {
                            _configurationMapping[id].Add(identifier);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public IActionResult CurrentUser(string userName, string categoryName)
        {
            if (HttpContext.Request.Cookies.ContainsKey("userName") && HttpContext.Request.Cookies["userName"] != userName)
            {
                Response.Cookies.Delete("userName");
            }

            Response.Cookies.Append("userName", userName, new Microsoft.AspNetCore.Http.CookieOptions()
            {
                Expires = DateTime.Now.AddYears(1)
            });

            var rootConfig = _uiConfigurationService.GetConfiguration(userName);

            ViewData["Title"] = userName;
            var controlModels = new List <IControlModel>();

            var currentCategory = rootConfig.Categories.FirstOrDefault(cat => cat.Name == categoryName) ??
                                  rootConfig.Categories.First();

            foreach (var controlModel in currentCategory.ControlModels)
            {
                var model = _controlModelService.Convert(controlModel);
                if (model != null)
                {
                    controlModels.Add(model);
                }
            }

            ViewData["Notifications"] = _notificationService.GetSystemNotifications();
            ViewData["CategoryName"]  = currentCategory.Name;
            ViewData["Controls"]      = controlModels;
            ViewData["UiCategories"]  = rootConfig.Categories ?? Array.Empty <UiConfigurationCategory>();
            ViewData["UiConfigRoot"]  = rootConfig;
            return(View());
        }