Exemple #1
0
        public void InstallModels()
        {
            // install or update models
            foreach (IViewModel viewModel in _viewModels)
            {
                ModelAttribute modelAttribute = GetAttribute <ModelAttribute>(viewModel);
                Model          model          = _entityBuilder.BuildModel(viewModel.GetType(), modelAttribute);
                _modelRepository.SaveModel(model);
            }

            foreach (IViewModel viewModel in _viewModels)
            {
                ModelId modelId = GetAttribute <ModelAttribute>(viewModel).ModelId;
                _modelRepository.SaveConditionals(GetConditionals(modelId, viewModel));
                _modelRepository.SaveProperties(GetProperties(modelId, viewModel));
            }

            foreach (IViewModelService service in _services)
            {
                MethodInfo[] methods = service.GetType().GetMethods();
                foreach (MethodInfo method in methods)
                {
                    if (TryGetAttribute(method, out EndpointAttribute attribute))
                    {
                        Endpoint endpoint = _entityBuilder.BuildEndpoint(method.Name, attribute);
                        endpoint.ModelId = service.ModelId;
                        _modelRepository.SaveEndpoint(endpoint);

                        List <Parameter> parameters = GetAttributes <ParameterAttribute>(method)
                                                      .Select(p => _entityBuilder.BuildParameter(endpoint.EndpointId, p)).ToList();
                        _modelRepository.SaveParameters(parameters);
                    }
                }
            }
        }