Пример #1
0
        private static async Task <int> WriteFileAsync(Project project, string file, FileNameDialogResult input)
        {
            var extension = Path.GetExtension(file);
            var template  = await TemplateMap.GetTemplateFilePathAsync(project, file, input);

            if (!string.IsNullOrEmpty(template))
            {
                var index = template.IndexOf('$');

                if (index > -1)
                {
                    template = template.Remove(index, 1);
                }

                await WriteToDiskAsync(file, template);

                return(index);
            }

            await WriteToDiskAsync(file, string.Empty);

            return(0);
        }
Пример #2
0
        private static string AdjustForSpecific(string safeName, string extension, FileNameDialogResult type)
        {
            if (type.BaseClass)
            {
                return(extension += "-base");
            }

            if (type.Enum)
            {
                return(extension += "-enum");
            }

            if (type.Controller)
            {
                return(extension += "-controller");
            }

            if (type.Interface)
            {
                return(extension += "-interface");
            }

            return(extension);
        }
Пример #3
0
        public static async Task <string> GetTemplateFilePathAsync(Project project, string file, FileNameDialogResult type)
        {
            var extension = Path.GetExtension(file).ToLowerInvariant();
            var name      = Path.GetFileName(file);
            var safeName  = name.StartsWith(".") ? name : Path.GetFileNameWithoutExtension(file);
            var relative  = PackageUtilities.MakeRelative(project.GetRootFolder(), Path.GetDirectoryName(file));

            string templateFile = null;

            // Look for direct file name matches
            if (_templateFiles.Any(f => Path.GetFileName(f).Equals(name + _defaultExt, StringComparison.OrdinalIgnoreCase)))
            {
                templateFile = GetTemplate(name);
            }

            // Look for file extension matches
            else if (_templateFiles.Any(f => Path.GetFileName(f).Equals(extension + _defaultExt, StringComparison.OrdinalIgnoreCase)))
            {
                var tmpl = AdjustForSpecific(safeName, extension, type);
                templateFile = GetTemplate(tmpl);
            }

            var template = await ReplaceTokensAsync(project, safeName, relative, templateFile);

            return(NormalizeLineEndings(template));
        }