Ejemplo n.º 1
0
        public void TestSplit()
        {
            var splitted = TemplateDefinitionHelper.SplitEscapedString("1,2,3", ',');

            Assert.AreEqual(3, splitted.Length);
            Assert.AreEqual("1", splitted[0]);
            Assert.AreEqual("2", splitted[1]);
            Assert.AreEqual("3", splitted[2]);


            splitted = TemplateDefinitionHelper.SplitEscapedString("1\\,2\\,3", ',');
            Assert.AreEqual(1, splitted.Length);
            Assert.AreEqual("1,2,3", splitted[0]);

            splitted = TemplateDefinitionHelper.SplitEscapedString("1 , 2,3", ',');
            Assert.AreEqual(3, splitted.Length);
            Assert.AreEqual("1", splitted[0]);
            Assert.AreEqual("2", splitted[1]);
            Assert.AreEqual("3", splitted[2]);
        }
Ejemplo n.º 2
0
        public override async Task <bool> OnNavigatedToAsync(IProgress <string> progress, StepContext ctx)
        {
            if (!IsTargetDirectoryValid(ctx))
            {
                return(false);
            }

            var templateDefinitionFile = Path.Combine(ctx.TargetDirectory, "TemplateDefinition.xml");

            if (!File.Exists(templateDefinitionFile))
            {
                return(false);
            }

            var templateDefinition = await Task.Run(() => TemplateDefinitionHelper.Parse(templateDefinitionFile));

            if (templateDefinition == null)
            {
                return(false);
            }

            try
            {
                File.Delete(templateDefinitionFile);
            }
            catch (Exception ex)
            {
                theLogger.Error($"Unable to delete template definition file: '{templateDefinitionFile}'.", ex);
            }

            foreach (var placeholderDefinition in templateDefinition.Placeholders)
            {
                var placeholder = new PlaceholderViewModel()
                {
                    Name          = placeholderDefinition.Name,
                    TextToReplace = string.IsNullOrEmpty(placeholderDefinition.TextToReplace)
                        ? placeholderDefinition.Name
                        : placeholderDefinition.TextToReplace,
                    Replacement = placeholderDefinition.DefaultValue,
                    Suggestions = TemplateDefinitionHelper.SplitEscapedString(placeholderDefinition.SuggestionList),
                    Description = placeholderDefinition.Description
                };

                placeholder.PropertyChanged += (s, e) =>
                {
                    foreach (var example in Examples)
                    {
                        example.UpdateText(Placeholders);
                    }
                };

                Placeholders.Add(placeholder);
            }

            foreach (var example in templateDefinition.Examples ?? new Example[0])
            {
                Examples.Add(new ExampleViewModel(example));
            }

            return(true);
        }