public void TestInitialize()
        {
            _template       = Templates.Get(GetType(), "tt");
            _expectedResult = Templates.Get(GetType(), "result");

            ITextTransformer transformer = CreateTransformer();

            _runner.Arrange(transformer);
            BefortAct(transformer);

            try
            {
                _actualResult = _runner.Act(transformer, Template);
            }
            catch (Exception exception)
            {
                _exception = exception;
            }
            var disposable = transformer as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
Esempio n. 2
0
        protected override void Arrange()
        {
            TextTransformer = new Mock <ITextTransformer>();

            _previousTextTransformer = Template.TextTransformer;
            Template.TextTransformer = TextTransformer.Object;
        }
Esempio n. 3
0
 private void Window_Initialized(object sender, EventArgs e)
 {
     _manager = new HookManager(this);
     _textTransformer = new TextTransformer();
     _manager.HotkeyPressed += (o, args) =>
     {
         _input.Keyboard
             .Sleep(50)
             .ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_A)
             .Sleep(50)
             .ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_X)
             .Sleep(50);
         string buffer = String.Empty;
         Thread staThread = new Thread(o1 =>
         {
             try
             {
                 buffer = Clipboard.GetText(TextDataFormat.UnicodeText);
             }
             catch (Exception ex)
             {
                 buffer = ex.Message;
             }
         });
         staThread.SetApartmentState(ApartmentState.STA);
         staThread.Start();
         staThread.Join();
         Clipboard.SetText(_textTransformer.TransformText(buffer.ToLower()));
         _input.Keyboard.Sleep(50).ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);
     };
 }
 public PayloadGeneratorWorker(DigitalSigner signer, ITextTransformer transformer,
                               ManualResetEventSlim payloadReadEvent, ILogger <PayloadGeneratorWorker> logger)
 {
     _signer           = signer;
     _transformer      = transformer;
     _payloadReadEvent = payloadReadEvent;
     _logger           = logger;
 }
        public override void Arrange(ITextTransformer transformer)
        {
            var folder = Path.GetTempPath();

            _file = Path.Combine(folder, "inner.tt");

            File.WriteAllText(_file, "This is the inner template!");
            transformer.Path = folder;
        }
Esempio n. 6
0
 public Application(
     ITextTransformer textTransformer,
     IInputFactory inputFactory,
     IOutputFactory outputFactory)
 {
     this.textTransformer = textTransformer ?? throw new ArgumentNullException(nameof(textTransformer));
     this.inputFactory    = inputFactory ?? throw new ArgumentNullException(nameof(inputFactory));
     this.outputFactory   = outputFactory ?? throw new ArgumentNullException(nameof(outputFactory));
 }
 //Todo: try to remove textTransformer and fileParser from below constructor
 public Command(string commandName,
                ITextTransformer textTransformer,
                IFilesProcessor <ParsedFilesResultType> filesProcessor)
     : this(commandName,
            textTransformer,
            filesProcessor,
            new FileReader(),
            new FileWriter())
 {
 }
Esempio n. 8
0
 public ProcessHandlerWorker(PayloadProcessingChannel payloadChannel, DigitalSigner signer,
                             ITextTransformer transformer, IHostApplicationLifetime applicationLifetime,
                             ILogger <ProcessHandlerWorker> logger)
 {
     _payloadChannel      = payloadChannel;
     _signer              = signer;
     _transformer         = transformer;
     _applicationLifetime = applicationLifetime;
     _logger              = logger;
 }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Host"/> class.
        /// </summary>
        /// <param name="transformer">The transformer.</param>
        /// <param name="pathResolver">The path resolver.</param>
        /// <param name="fileLoader">The file loader.</param>
        internal Host(ITextTransformer transformer, IPathResolver pathResolver, IFileLoader fileLoader)
        {
            if (transformer == null) throw new ArgumentNullException("transformer");
            if (pathResolver == null) throw new ArgumentNullException("pathResolver");
            if (fileLoader == null) throw new ArgumentNullException("fileLoader");

            _transformer = transformer;
            _pathResolver = pathResolver;
            _fileLoader = fileLoader;
        }
        public static IList <ITextTransformer> GenerateTransformersForEachRule(this ITextTransformer transformer)
        {
            var transformers = new List <ITextTransformer>();

            for (int i = 1; i <= transformer.Rules.Count; i++)
            {
                transformers.Add(new TextTransformer(transformer.Rules.Take(i).ToList()));
            }
            return(transformers);
        }
 public TextTransformerTabPage()
 {
     textTransformer = new TransparentTextTransformer();
     #if !USEIE
     outTextBox = new RichTextBox();
     outTextBox.Dock = DockStyle.Fill;
     Controls.Add(outTextBox);
     #else
     outBrowser = new WebBrowser();
     outBrowser.Dock = DockStyle.Fill;
     Controls.Add(outBrowser);
     #endif
 }
 public Command(string commandName,
                ITextTransformer textTransformer,
                IFilesProcessor <ParsedFilesResultType> filesProcessor,
                IFileReader fileReader,
                IFileWriter fileWriter)
 {
     _commandName     = commandName;
     _textTransformer = textTransformer;
     _filesProcessor  = filesProcessor;
     _fileReader      = fileReader;
     _fileWriter      = fileWriter;
     ParameterBuilder = new ParameterBuilder();
 }
        public override string Act(ITextTransformer transformer, string template)
        {
            var arguments = new TemplateArgumentCollection
            {
                new TemplateArgument("Argument1", "This is argument1 Value!"),
                new TemplateArgument {
                    Name = "Argument2", Value = "This is argument2 Value!"
                },
                new TemplateArgument("Argument3", "This is argument3 Value!")
            };

            return(transformer.Transform(template, arguments));
        }
 public static void WriteStepsToFiles(this ITextTransformer transformer, string sourceText, string targetPath, bool skipFilesWithNoChanges)
 {
     if (transformer != null && !transformer.Rules.IsNullOrEmpty())
     {
         targetPath.GetPathParts(out var directoryName, out var targetFilename, out var targetExtension);
         Steps.DeleteAllSteps(directoryName, targetFilename, targetExtension);
         var lastText           = "";
         var steppedTransformer = new TextSteppedTransformer(transformer.Rules, sourceText);
         while (steppedTransformer.Next())
         {
             var newText = steppedTransformer.Text;
             Steps.WriteStep(transformer, directoryName, targetFilename, targetExtension, steppedTransformer.Current, ref lastText, newText, skipFilesWithNoChanges);
         }
     }
 }
        public override string Act(ITextTransformer transformer, string template)
        {
            //Prepare the argument that will be passes to the template
            var classDefinition = new ClassDefinition
            {
                Name      = "TestClass",
                Namespace = "TC.CustomTemplating.Example.Generated"
            };

            classDefinition.Properties.Add(new Property("Name", typeof(string)));
            classDefinition.Properties.Add(new Property("Lenght", typeof(int)));
            classDefinition.Properties.Add(new Property("L", typeof(int)));

            return(transformer.Transform(template, "Class", classDefinition));
        }
 public static IList <string> GetSteps(this ITextTransformer transformer, string sourceText)
 {
     if (transformer != null && !transformer.Rules.IsNullOrEmpty())
     {
         var steps = new List <string>();
         var steppedTransformer = new TextSteppedTransformer(transformer.Rules, sourceText);
         while (steppedTransformer.Next())
         {
             steps.Add(steppedTransformer.Text);
         }
         return(steps);
     }
     else
     {
         return(Array.Empty <string>());
     }
 }
        public override string Act(ITextTransformer transformer, string template)
        {
            var dictionary = new Dictionary <int, List <string> >
            {
                { 0, new List <string> {
                      "one", "two", "three"
                  } },
                { 4, new List <string> {
                      "four", "five", "six"
                  } },
                { 7, new List <string> {
                      "seven", "eight", "nine"
                  } }
            };

            return(transformer.Transform(template, "Argument", dictionary));
        }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Host"/> class.
        /// </summary>
        /// <param name="transformer">The transformer.</param>
        /// <param name="pathResolver">The path resolver.</param>
        /// <param name="fileLoader">The file loader.</param>
        internal Host(ITextTransformer transformer, IPathResolver pathResolver, IFileLoader fileLoader)
        {
            if (transformer == null)
            {
                throw new ArgumentNullException("transformer");
            }
            if (pathResolver == null)
            {
                throw new ArgumentNullException("pathResolver");
            }
            if (fileLoader == null)
            {
                throw new ArgumentNullException("fileLoader");
            }

            _transformer  = transformer;
            _pathResolver = pathResolver;
            _fileLoader   = fileLoader;
        }
Esempio n. 19
0
        public static TokenSelector ToTokenSelector(ITextTransformer parser, string selector)
        {
            if (IsIdSelector(selector))
            {
                if (!parser.Selectors.ContainsKey(selector))
                {
                    throw new Exception(string.Format("Selector '{0}' is not found in the predefined selectors", selector));
                }

                return parser.Selectors[selector];
            }

            selector = TrimTailingSlash(selector);

            TokenSelector tSelector = new TokenSelector();
            Match match = selectorRegex.Match(selector);

            if (!match.Success)
            {
                throw new Exception(string.Format("Selector regex ({0}) is invalid", selector));
            }

            if (match.Groups["position"].Success)
            {
                tSelector.Position = (SelectorPosition)Enum.Parse(typeof(SelectorPosition), match.Groups["position"].Value, true);
            }

            if (match.Groups["selector"].Success)
            {
                string group = match.Groups["selector"].Value;

                if (IsInteger(group))
                {
                    tSelector.GroupIndex = int.Parse(group);
                }
                else
                {
                    tSelector.GroupName = group;
                }
            }

            if (match.Groups["pseudo"].Success)
            {
                tSelector.Pseudo = match.Groups["pseudo"].Value;

                if (match.Groups["pseudoArg"].Success)
                {
                    tSelector.PseudoArg = match.Groups["pseudoArg"].Value;
                }
            }

            if (match.Groups["flags"].Success)
            {
                tSelector.Flags = BuildFlags(match.Groups["flags"].Value);
            }

            string regexStr;

            if (match.Groups["regex1"].Success)
            {
                regexStr = match.Groups["regex1"].Value;
            }
            else if (match.Groups["regex2"].Success)
            {
                regexStr = match.Groups["regex2"].Value;
            }
            else
            {
                throw new Exception("Regex is not found");
            }

            tSelector.Regex = new Regex(regexStr, tSelector.Flags);

            return tSelector;
        }
 public override void Arrange(ITextTransformer transformer)
 {
     base.Arrange(transformer);
 }
 public override string Act(ITextTransformer transformer, string template)
 {
     return(transformer.Transform(template));
 }
 protected virtual void BefortAct(ITextTransformer transformer)
 {
 }
 protected override void BefortAct(ITextTransformer transformer)
 {
     transformer.ClassDefinitionGenerated += (a, e) => _classDefinitionGeneratedRaised = true;
     base.BefortAct(transformer);
 }
Esempio n. 24
0
        public static TokenSelector ToTokenSelector(ITextTransformer parser, string selector)
        {
            if (IsIdSelector(selector))
            {
                if (!parser.Selectors.ContainsKey(selector))
                {
                    throw new Exception(string.Format("Selector '{0}' is not found in the predefined selectors", selector));
                }

                return(parser.Selectors[selector]);
            }

            selector = TrimTailingSlash(selector);

            TokenSelector tSelector = new TokenSelector();
            Match         match     = selectorRegex.Match(selector);

            if (!match.Success)
            {
                throw new Exception(string.Format("Selector regex ({0}) is invalid", selector));
            }

            if (match.Groups["position"].Success)
            {
                tSelector.Position = (SelectorPosition)Enum.Parse(typeof(SelectorPosition), match.Groups["position"].Value, true);
            }

            if (match.Groups["selector"].Success)
            {
                string group = match.Groups["selector"].Value;

                if (IsInteger(group))
                {
                    tSelector.GroupIndex = int.Parse(group);
                }
                else
                {
                    tSelector.GroupName = group;
                }
            }

            if (match.Groups["pseudo"].Success)
            {
                tSelector.Pseudo = match.Groups["pseudo"].Value;

                if (match.Groups["pseudoArg"].Success)
                {
                    tSelector.PseudoArg = match.Groups["pseudoArg"].Value;
                }
            }

            if (match.Groups["flags"].Success)
            {
                tSelector.Flags = BuildFlags(match.Groups["flags"].Value);
            }

            string regexStr;

            if (match.Groups["regex1"].Success)
            {
                regexStr = match.Groups["regex1"].Value;
            }
            else if (match.Groups["regex2"].Success)
            {
                regexStr = match.Groups["regex2"].Value;
            }
            else
            {
                throw new Exception("Regex is not found");
            }

            tSelector.Regex = new Regex(regexStr, tSelector.Flags);

            return(tSelector);
        }
Esempio n. 25
0
 public abstract string Act(ITextTransformer transformer, string template);
 public TextTransformerTabPage(ITextTransformer textTransformer)
     : this()
 {
     this.textTransformer = textTransformer;
 }
Esempio n. 27
0
 public LoggingFileTransformer(ITextTransformer textTransformer, string sourceFileExtension, string targetFileExtension) : base(textTransformer, sourceFileExtension, targetFileExtension)
 {
 }
Esempio n. 28
0
 public virtual void Arrange(ITextTransformer transformer)
 {
 }
 public override string Act(ITextTransformer transformer, string template)
 {
     return(transformer.Transform(template, "Argument", "This is the argument value"));
 }