Exemple #1
0
        public async void Save()
        {
            var entity = new TextFileTemplate();

            entity.InjectFrom(SelectedTemplate);
            await repository.SaveOrUpdateAsync(entity, entity.Id);

            textFilesManager.Refresh();
        }
Exemple #2
0
        public async Task Text()
        {
            using TempFile temp = new TempFile();
            ResolveContext   context = new ResolveContext().WithVariable("name", "lily").WithVariable(FileTemplate.Var, temp.File.FullName);
            TextFileTemplate tf      = new TextFileTemplate(new StringTemplate(StringTemplate.GetVariableTemplate("name"), new Variable[] { new Variable("name").NotRequired("") }));
            FileInfo         fi      = await tf.Resolve(context);

            Assert.AreEqual("lily", File.ReadAllText(fi.FullName));
        }
Exemple #3
0
        /// <summary>
        /// Creates a template from a file.
        /// </summary>
        /// <param name="textFileTemplate"></param>
        /// <param name="color"></param>
        public MapTemplate(string textFileTemplatePath, ConsoleColor color)
        {
            TextFileTemplatePath = textFileTemplatePath;

            TextFileTemplate = System.IO.File.ReadAllText(textFileTemplatePath);
            TextFileTemplate = TextFileTemplate.Replace("\r", "");
            string[] lines = TextFileTemplate.Split('\n');
            MapHeight = lines.Length;
            MapWidth  = Helper.GetLongestStringLength(lines);
            Color     = color;

            Layout = new char[MapWidth, MapHeight];
            for (int lineNum = 0; lineNum < lines.Length; lineNum++)
            {
                for (int charNum = 0; charNum < lines[lineNum].Length; charNum++)
                {
                    Layout[charNum, lineNum] = lines[lineNum][charNum];
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Attempts to parse the templtae file.
        /// </summary>
        /// <param name="path">The path to the template file.</param>
        /// <param name="fileTemplate">The instance of the parsed template file, null if failed.</param>
        /// <returns>True if was able to parse succesfully.</returns>
        public static bool TryParseTemplate(FileInfo path, out FileTemplate fileTemplate)
        {
            if (!(path?.Exists ?? throw new ArgumentNullException(nameof(path))))
            {
                throw new FileNotFoundException("Can't parse template because the file is missing.", path.FullName);
            }

            if (path.Extension != TemplateExtension)
            {
                throw new InvalidDataException($"The given file '{path.FullName}' is not a {TemplateExtension} file.");
            }

            int    indexOfTemplateExtensionPeriod = path.FullName.Length - TemplateExtension.Length;
            int    indexOfPreviousPeriod          = path.FullName.LastIndexOf('.', indexOfTemplateExtensionPeriod - 1);
            string templateExtension = path.FullName.Substring(indexOfPreviousPeriod, indexOfTemplateExtensionPeriod - indexOfPreviousPeriod);

            switch (templateExtension)
            {
            case ".csproj":
            case ".props":
            case ".targets":
                fileTemplate = new XmlFileTemplate(path);
                break;

            case ".sln":
            case ".meta":
                fileTemplate = new TextFileTemplate(path);
                break;

            default:
                fileTemplate = null;
                return(false);
            }

            fileTemplate.Parse();
            return(true);
        }
 public async void Save()
 {
     var entity = new TextFileTemplate();
     entity.InjectFrom(SelectedTemplate);
     await repository.SaveOrUpdateAsync(entity, entity.Id);
     textFilesManager.Refresh();
 }
Exemple #6
0
        public void Variable()
        {
            TextFileTemplate tp = new TextFileTemplate(new StringTemplate("content", new Variable[] { new Variable("var") }));

            Assert.IsTrue(tp.GetVariables().Contains(new Variable("var")));
        }