Пример #1
0
        private void CreateControl(string viewPath, bool createCodeBehind, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var codeBehindPath           = PathHelpers.ChangeExtension(viewPath, "cs");
            var codeBehindClassName      = NamingHelpers.GetClassNameFromPath(viewPath);
            var codeBehindClassNamespace = NamingHelpers.GetNamespaceFromPath(viewPath, dotvvmProjectMetadata.ProjectDirectory, dotvvmProjectMetadata.RootNamespace);

            // create control
            var controlTemplate = new ControlTemplate()
            {
                CreateCodeBehind = createCodeBehind
            };

            if (createCodeBehind)
            {
                controlTemplate.CodeBehindClassName          = codeBehindClassName;
                controlTemplate.CodeBehindClassNamespace     = codeBehindClassNamespace;
                controlTemplate.CodeBehindClassRootNamespace = dotvvmProjectMetadata.RootNamespace;
            }
            FileSystemHelpers.WriteFile(viewPath, controlTemplate.TransformText());

            // create code behind
            if (createCodeBehind)
            {
                var codeBehindTemplate = new ControlCodeBehindTemplate()
                {
                    CodeBehindClassNamespace = codeBehindClassNamespace,
                    CodeBehindClassName      = codeBehindClassName
                };
                FileSystemHelpers.WriteFile(codeBehindPath, codeBehindTemplate.TransformText());
            }
        }
Пример #2
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var name = args[0];

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidCommandUsageException("You have to specify the NAME.");
            }

            if (PathHelpers.IsCurrentDirectory(dotvvmProjectMetadata.ProjectDirectory) && !name.Contains("/") && !name.Contains("\\"))
            {
                name = "Views/" + name;
            }
            name = PathHelpers.EnsureFileExtension(name, "dotmaster");

            var masterPage = args.GetOptionValue("-m", "--master", "--masterpage");

            if (!string.IsNullOrEmpty(masterPage))
            {
                masterPage = PathHelpers.EnsureFileExtension(masterPage, "dotmaster");

                if (PathHelpers.IsCurrentDirectory(dotvvmProjectMetadata.ProjectDirectory) && !masterPage.Contains("/") && !masterPage.Contains("\\"))
                {
                    masterPage = "Views/" + masterPage;
                }
            }

            CreatePage(name, masterPage, dotvvmProjectMetadata);
        }
Пример #3
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());
        }
Пример #4
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var name = args[0];

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidCommandUsageException("You have to specify the NAME.");
            }

            // TODO: create the viewmodel
        }
Пример #5
0
        public override bool TryConsumeArgs(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            if (string.Equals(args[0], "api", StringComparison.CurrentCultureIgnoreCase) &&
                string.Equals(args[1], "regen", StringComparison.CurrentCultureIgnoreCase))
            {
                args.Consume(2);
                return(true);
            }

            return(false);
        }
Пример #6
0
        public static string GetDothtmlFileRelativePath(DotvvmProjectMetadata dotvvmProjectMetadata, string file)
        {
            var relativePath = PathHelpers.GetRelativePathFrom(dotvvmProjectMetadata.ProjectDirectory, file);

            if (relativePath.StartsWith("views/", StringComparison.CurrentCultureIgnoreCase) ||
                relativePath.StartsWith("views\\", StringComparison.CurrentCultureIgnoreCase))
            {
                relativePath = relativePath.Substring("views/".Length);
            }
            return(relativePath);
        }
Пример #7
0
        public override bool CanHandle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            if (string.Equals(args[0], "api", StringComparison.CurrentCultureIgnoreCase) &&
                string.Equals(args[1], "regen", StringComparison.CurrentCultureIgnoreCase))
            {
                // ahhh, yes, you are not drunk, this function that should only detect if it can be handled has side effects on the args parameter...
                args.Consume(2);
                return(true);
            }

            return(false);
        }
Пример #8
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var name = args[0];

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidCommandUsageException("You have to specify the NAME.");
            }

            var masterPage = args.GetOptionValue("-m", "-master", "-masterPage");

            // TODO: create a new master page (with the master page)
        }
Пример #9
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var name = args[0];

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidCommandUsageException("You have to specify the NAME.");
            }
            name = PathHelpers.EnsureFileExtension(name, "dotcontrol");

            var codeBehind = args.HasOption("-c", "--code", "--codebehind");

            CreateControl(name, codeBehind, dotvvmProjectMetadata);
        }
Пример #10
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());
        }
Пример #11
0
        public static void Main(string[] args)
        {
            //Console.WriteLine("pid: " + Process.GetCurrentProcess().Id);
            //while (!Debugger.IsAttached)
            //{
            //    Thread.Sleep(1000);
            //}

            //Debugger.Break();

            try
            {
                var arguments = new Arguments(args);

                DotvvmProjectMetadata dotvvmProjectMetadata = null;
                if (string.Equals(arguments[0], "--json", StringComparison.CurrentCultureIgnoreCase))
                {
                    dotvvmProjectMetadata = JsonConvert.DeserializeObject <DotvvmProjectMetadata>(args[1]);
                    dotvvmProjectMetadata.WebAssemblyPath  = dotvvmProjectMetadata.WebAssemblyPath.Replace(@"\\", @"\");
                    dotvvmProjectMetadata.ProjectDirectory = dotvvmProjectMetadata.ProjectDirectory.Replace(@"\\", @"\");
                    dotvvmProjectMetadata.MetadataFilePath = dotvvmProjectMetadata.MetadataFilePath.Replace(@"\\", @"\");
                    arguments.Consume(2);
                }
                else
                {
                    Console.WriteLine(@"Provide correct metadata.");
                    Environment.Exit(1);
                }

                ResolveTestProject(dotvvmProjectMetadata);
                CreatePageObjectsDirectory(dotvvmProjectMetadata.GetUITestProjectFullPath());

                var config = ConfigurationHost.InitDotVVM(Assembly.LoadFile(dotvvmProjectMetadata.WebAssemblyPath),
                                                          dotvvmProjectMetadata.ProjectDirectory,
                                                          services => services.TryAddSingleton <IViewModelProtector, FakeViewModelProtector>());

                // generate the test stubs
                GeneratePageObjects(dotvvmProjectMetadata, config, arguments);

                Console.WriteLine(@"#$ Exit 0 - DotVVM Selenium Generator Ended");
                Environment.Exit(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(@"#$ Exit 1 - DotVVM Selenium Generator Failed" + e);
                throw;
            }
        }
Пример #12
0
        public override bool CanHandle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            if (string.Equals(args[0], "add", StringComparison.CurrentCultureIgnoreCase) &&
                string.Equals(args[1], "master", StringComparison.CurrentCultureIgnoreCase))
            {
                args.Consume(2);
                return(true);
            }

            if (string.Equals(args[0], "am", StringComparison.CurrentCultureIgnoreCase))
            {
                args.Consume(1);
                return(true);
            }

            return(false);
        }
Пример #13
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var name = args[0];

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidCommandUsageException("You have to specify the NAME.");
            }
            name = PathHelpers.EnsureFileExtension(name, "cs");

            if (PathHelpers.IsCurrentDirectory(dotvvmProjectMetadata.ProjectDirectory) && !name.Contains("/") && !name.Contains("\\"))
            {
                name = "ViewModels/" + name;
            }

            CreateViewModel(name, dotvvmProjectMetadata);
        }
Пример #14
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var swaggerFile = args[0] ??
                              throw new InvalidCommandUsageException("You have to specify the swagger file.");

            if (!Uri.TryCreate(swaggerFile, UriKind.RelativeOrAbsolute, out var swaggerFileUri))
            {
                throw new InvalidCommandUsageException($"'{swaggerFile}' is not a valid uri.");
            }
            var @namespace = args[1] ??
                             throw new InvalidCommandUsageException("You have to specify the namespace.");
            var csharpFile = args[2] ??
                             throw new InvalidCommandUsageException("You have to specify the csharp output file.");
            var typescriptFile = args[3] ??
                                 throw new InvalidCommandUsageException("You have to specify the typescript output file.");

            ApiClientManager.AddApiClient(swaggerFileUri, @namespace, csharpFile, typescriptFile, dotvvmProjectMetadata);
        }
Пример #15
0
        private static void GeneratePageObjects(DotvvmProjectMetadata dotvvmProjectMetadata,
                                                DotvvmConfiguration dotvvmConfig,
                                                Arguments arguments)
        {
            var options   = PrepareSeleniumGeneratorOptions(dotvvmConfig);
            var generator = new SeleniumPageObjectGenerator(options, dotvvmConfig);

            IEnumerable <string> controlFiles = new List <string>();
            IEnumerable <string> viewFiles;

            if (arguments[0] != null)
            {
                var parsedArguments = SplitArguments(arguments);
                viewFiles = GetViewsFiles(parsedArguments);
            }
            else
            {
                // generate all views and user controls files if no argument was specified
                viewFiles    = dotvvmConfig.RouteTable.Where(b => b.VirtualPath != null).Select(r => r.VirtualPath);
                controlFiles = dotvvmConfig.Markup.Controls.Where(b => b.Src != null).Select(c => c.Src);
            }

            var allFiles = controlFiles.Concat(viewFiles).Distinct();

            foreach (var file in allFiles)
            {
                if (File.Exists(file))
                {
                    Console.WriteLine($"Generating stub for {file}...");

                    // determine full type name and target file
                    var relativePath     = PathHelpers.GetDothtmlFileRelativePath(dotvvmProjectMetadata, file);
                    var relativeTypeName = $"{PathHelpers.TrimFileExtension(relativePath)}PageObject";
                    var fullTypeName     = $"{dotvvmProjectMetadata.UITestProjectRootNamespace}.{PageObjectsText}.{PathHelpers.CreateTypeNameFromPath(relativeTypeName)}";
                    var targetFileName   = Path.Combine(dotvvmProjectMetadata.UITestProjectPath, PageObjectsText, relativeTypeName + ".cs");

                    var config = GetSeleniumGeneratorConfiguration(fullTypeName, targetFileName, file);

                    GeneratePageObject(generator, config);
                }
            }
        }
Пример #16
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var template = args[0];

            if (string.IsNullOrEmpty(template))
            {
                throw new InvalidCommandUsageException("You have to specify the TEMPLATE.");
            }

            // TODO: download template from web

            var name = args[1];

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidCommandUsageException("You have to specify the NAME.");
            }

            // TODO: substitute name and other parameters
        }
Пример #17
0
        private static void ResolveTestProject(DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var metadataService = new DotvvmProjectMetadataService();

            if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectPath))
            {
                var hintProjectName = $"..\\{dotvvmProjectMetadata.ProjectName}.Tests";

                if (!Console.IsInputRedirected)
                {
                    dotvvmProjectMetadata.UITestProjectPath =
                        ConsoleHelpers.AskForValue($"Enter the path to the test project\n(relative to DotVVM project directory, e.g. '{hintProjectName}'): ",
                                                   hintProjectName);
                }
                else
                {
                    dotvvmProjectMetadata.UITestProjectPath = hintProjectName;
                }

                Console.WriteLine($@"Path to test project is set to ""{dotvvmProjectMetadata.UITestProjectPath}""");
            }

            // make sure the test directory exists
            var testProjectDirectory = dotvvmProjectMetadata.GetUITestProjectFullPath();

            if (!Directory.Exists(testProjectDirectory))
            {
                var relativeWebDirectory = Path.GetRelativePath(dotvvmProjectMetadata.GetUITestProjectFullPath(), dotvvmProjectMetadata.ProjectDirectory);

                GenerateTestProject(testProjectDirectory, relativeWebDirectory);
            }

            // make sure we know the test project namespace
            if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectRootNamespace))
            {
                dotvvmProjectMetadata.UITestProjectRootNamespace = Path.GetFileName(testProjectDirectory);
            }

            // save the metadata
            metadataService.Save(dotvvmProjectMetadata);
        }
Пример #18
0
        public void Initialize()
        {
            initialized = true;

            // prepare temp directories
            Directory.CreateDirectory(workingDirectory);
            Directory.CreateDirectory(webAppDirectory);

            // copy application in the working directory
            Process.Start("xcopy", $"/E \"{webApplicationTemplatePath}\" \"{webAppDirectory}\"")?.WaitForExit();

            // set test project path in .dotvvm.json
            var metadataService = new DotvvmProjectMetadataService();

            metadata = metadataService.LoadFromFile(dotvvmJsonPath);
            metadata.UITestProjectPath          = $"../{testProjectName}";
            metadata.UITestProjectRootNamespace = testProjectName;

            // change current directory
            Environment.CurrentDirectory = webAppDirectory;
        }
Пример #19
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var swaggerFile = args[0];

            if (swaggerFile != null)
            {
                if (!Uri.TryCreate(swaggerFile, UriKind.RelativeOrAbsolute, out var swaggerFileUri))
                {
                    throw new InvalidCommandUsageException($"'{swaggerFile}' is not a valid uri.");
                }
                ApiClientManager.RegenApiClient(
                    dotvvmProjectMetadata.ApiClients.FirstOrDefault(a => a.SwaggerFile == swaggerFileUri) ??
                    throw new InvalidCommandUsageException($"No registered api client with with '{swaggerFile}' was found.")
                    ).Wait();
            }
            else
            {
                dotvvmProjectMetadata.ApiClients
                .Select(ApiClientManager.RegenApiClient)
                .ToArray()
                .ApplyAction(Task.WaitAll);
            }
        }
Пример #20
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var swaggerFile = args[0];

            if (swaggerFile != null)
            {
                var apiClient =
                    (Uri.TryCreate(swaggerFile, UriKind.Absolute, out var swaggerFileUri) ?
                     dotvvmProjectMetadata.ApiClients.FirstOrDefault(a => a.SwaggerFile == swaggerFileUri) : null) ??
                    dotvvmProjectMetadata.ApiClients.FirstOrDefault(a => a.CSharpClient == swaggerFile || a.TypescriptClient == swaggerFile);
                if (apiClient == null)
                {
                    throw new InvalidCommandUsageException($"No api client is using {swaggerFile} url or file.");
                }
                ApiClientManager.RegenApiClient(apiClient).Wait();
            }
            else
            {
                dotvvmProjectMetadata.ApiClients
                .Select(ApiClientManager.RegenApiClient)
                .ToArray()
                .ApplyAction(Task.WaitAll);
            }
        }
Пример #21
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            var swaggerFile = args[0];

            if (swaggerFile != null)
            {
                var apiClient =
                    (Uri.TryCreate(swaggerFile, UriKind.Absolute, out var swaggerFileUri) ?
                     dotvvmProjectMetadata.ApiClients.FirstOrDefault(a => a.SwaggerFile == swaggerFileUri) : null) ??
                    dotvvmProjectMetadata.ApiClients.FirstOrDefault(a => a.CSharpClient == swaggerFile || a.TypescriptClient == swaggerFile);
                if (apiClient == null)
                {
                    throw new InvalidCommandUsageException($"No API client with the following URL or path was found: {swaggerFile}");
                }
                ApiClientManager.RegenApiClient(apiClient, promptOnFileOverwrite: false).Wait();
            }
            else
            {
                dotvvmProjectMetadata.ApiClients
                .Select(c => ApiClientManager.RegenApiClient(c, promptOnFileOverwrite: false))
                .ToArray()
                .ApplyAction(Task.WaitAll);
            }
        }
Пример #22
0
 public abstract bool CanHandle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata);
Пример #23
0
        public static void AddApiClient(Uri swaggerFile, string @namespace, string csharpoutput, string typescriptOutput, DotvvmProjectMetadata project)
        {
            var definition = new ApiClientDefinition {
                CSharpClient     = csharpoutput,
                TypescriptClient = typescriptOutput,
                SwaggerFile      = swaggerFile,
                Namespace        = @namespace
            };

            project.ApiClients.Add(definition);
            RegenApiClient(definition).Wait();
        }
Пример #24
0
 public abstract bool TryConsumeArgs(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata);
Пример #25
0
        public override void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata)
        {
            // make sure the test directory exists
            if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectPath))
            {
                dotvvmProjectMetadata.UITestProjectPath = ConsoleHelpers.AskForValue($"Enter the path to the test project\n(relative to DotVVM project directory, e.g. '..\\{dotvvmProjectMetadata.ProjectName}.Tests'): ");
            }
            var testProjectDirectory = dotvvmProjectMetadata.GetUITestProjectFullPath();

            if (!Directory.Exists(testProjectDirectory))
            {
                throw new Exception($"The directory {testProjectDirectory} doesn't exist!");
            }

            // make sure we know the test project namespace
            if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectRootNamespace))
            {
                var csprojService = new CSharpProjectService();
                var csproj        = csprojService.FindCsprojInDirectory(testProjectDirectory);
                if (csproj != null)
                {
                    csprojService.Load(csproj);
                    dotvvmProjectMetadata.UITestProjectRootNamespace = csprojService.GetRootNamespace();
                }
                else
                {
                    dotvvmProjectMetadata.UITestProjectRootNamespace = ConsoleHelpers.AskForValue("Enter the test project root namespace: ");
                    if (string.IsNullOrEmpty(dotvvmProjectMetadata.UITestProjectRootNamespace))
                    {
                        throw new Exception("The test project root namespace must not be empty!");
                    }
                }
            }

            // generate the test stubs
            var name  = args[0];
            var files = ExpandFileNames(name);

            foreach (var file in files)
            {
                Console.WriteLine($"Generating stub for {file}...");

                // determine full type name and target file
                var relativePath     = PathHelpers.GetDothtmlFileRelativePath(dotvvmProjectMetadata, file);
                var relativeTypeName = PathHelpers.TrimFileExtension(relativePath) + "Helper";
                var fullTypeName     = dotvvmProjectMetadata.UITestProjectRootNamespace + "." + PathHelpers.CreateTypeNameFromPath(relativeTypeName);
                var targetFileName   = Path.Combine(dotvvmProjectMetadata.UITestProjectPath, "Helpers", relativeTypeName + ".cs");

                // generate the file
                //var generator = new SeleniumHelperGenerator();
                //var config = new SeleniumGeneratorConfiguration()
                //{
                //    TargetNamespace = PathHelpers.GetNamespaceFromFullType(fullTypeName),
                //    HelperName = PathHelpers.GetTypeNameFromFullType(fullTypeName),
                //    HelperFileFullPath = targetFileName,
                //    ViewFullPath = file
                //};

                //generator.ProcessMarkupFile(DotvvmConfiguration.CreateDefault(), config);
            }
        }
Пример #26
0
 public abstract void Handle(Arguments args, DotvvmProjectMetadata dotvvmProjectMetadata);