Ejemplo n.º 1
0
        private void CreatePage(string viewPath, string masterPagePath, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var viewModelPath      = NamingHelpers.GenerateViewModelPath(viewPath);
            var viewModelName      = NamingHelpers.GetClassNameFromPath(viewModelPath);
            var viewModelNamespace = NamingHelpers.GetNamespaceFromPath(viewModelPath, dotvvmProjectMetadata.ProjectDirectory, dotvvmProjectMetadata.RootNamespace);

            // create page
            var pageTemplate = new PageTemplate()
            {
                ViewModelRootNamespace = dotvvmProjectMetadata.RootNamespace,
                ViewModelName          = viewModelName,
                ViewModelNamespace     = viewModelNamespace,
                IsMasterPage           = true
            };

            if (!string.IsNullOrEmpty(masterPagePath))
            {
                pageTemplate.EmbedInMasterPage     = true;
                pageTemplate.MasterPageLocation    = masterPagePath;
                pageTemplate.ContentPlaceHolderIds = new MasterPageBuilder().ExtractPlaceHolderIds(masterPagePath);
            }
            FileSystemHelpers.WriteFile(viewPath, pageTemplate.TransformText());

            // create viewmodel
            var viewModelTemplate = new ViewModelTemplate()
            {
                ViewModelName      = viewModelName,
                ViewModelNamespace = viewModelNamespace
                                     // TODO: BaseViewModel
            };

            FileSystemHelpers.WriteFile(viewModelPath, viewModelTemplate.TransformText());
        }
Ejemplo n.º 2
0
        public void RenderViewModel(List <EntityModel> entity, List <EnumModel> enums)
        {
            if (!Directory.Exists(_outputPath + "Model\\"))
            {
                Directory.CreateDirectory(_outputPath + "Model\\");
            }
            var controllerTemplate = new ViewModelTemplate(_projectName, _tableName, enums, entity);
            var output             = controllerTemplate.TransformText();
            var outputpath         = _outputPath + "Model\\" + NormalizeTableName + "Model.cs";

            File.WriteAllText(outputpath, output);
        }
        public void ViewModel_Template_Test()
        {
            var template = new ViewModelTemplate(new EntityInfo()
            {
                Id = _entityId
            }, ApplicationId, Constants.ViewModelNamespace, new Dictionary <string, string> {
                { "Test", "Test" }
            });
            var output = template.TransformText();

            Assert.NotNull(output);
            Assert.NotEmpty(output);
            Assert.Contains($"namespace {ApplicationId}.Backend.{Constants.ViewModelNamespace}", output);
        }
Ejemplo n.º 4
0
        private void CreateViewModel(string viewModelPath, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var viewModelName      = NamingHelpers.GetClassNameFromPath(viewModelPath);
            var viewModelNamespace = NamingHelpers.GetNamespaceFromPath(viewModelPath, dotvvmProjectMetadata.ProjectDirectory, dotvvmProjectMetadata.RootNamespace);

            // create viewmodel
            var viewModelTemplate = new ViewModelTemplate()
            {
                ViewModelName      = viewModelName,
                ViewModelNamespace = viewModelNamespace
                                     // TODO: BaseViewModel
            };

            FileSystemHelpers.WriteFile(viewModelPath, viewModelTemplate.TransformText());
        }
        public void ViewModel_Template_NullParameter_Test()
        {
            var template = new ViewModelTemplate(null, null, null, null);

            Assert.Throws <ArgumentNullException>(() => template.TransformText());
        }
Ejemplo n.º 6
0
        private void TransformControllerApiParameters(SmartAppInfo manifest, ApiActionInfo action)
        {
            bool result = true;

            foreach (var param in action.Parameters.AsEnumerable())
            {
                if (!result)
                {
                    break;
                }

                Dictionary <string, string> entityTypes = GetAllReferencedTypes(param);

                if (param.DataModel != null)
                {
                    var dataTemplate = new ViewModelTemplate(param.DataModel, manifest.Id, Constants.ViewModelNamespace, entityTypes);
                    try
                    {
                        result = _writingService.WriteFile(Path.Combine(_context.BasePath, dataTemplate.OutputPath, param.DataModel.Id + ".g.cs"), dataTemplate.TransformText());
                    }
                    catch (Exception ex)
                    {
                        result = false;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void TransformControllerApiReturnTypes(SmartAppInfo manifest, ApiActionInfo action)
        {
            if (action.ReturnType != null)
            {
                Dictionary <string, string> entityTypes = GetAllReferencedTypes(action.ReturnType);

                var dataTemplate = new ViewModelTemplate(action.ReturnType, manifest.Id, Constants.ViewModelNamespace, entityTypes);
                _writingService.WriteFile(Path.Combine(_context.BasePath, dataTemplate.OutputPath, action.ReturnType.Id + ".g.cs"), dataTemplate.TransformText());
            }
        }