Ejemplo n.º 1
0
        /// <summary>
        /// Executes a <see cref="CodeGenTemplate"/> replacing the placeholders with their respective values.
        /// </summary>
        public void Execute()
        {
            // Get the generated directory name.
            _eventArgs = new CodeGeneratorEventArgs {
                OutputGenDirName = CodeGenConfig.GetXmlVal <string>(_xmlTemplate, "OutputGenDirName", null, false)
            };

            // Invoke the XML.
            ExecuteXml(_xmlTemplate, _codeGenerator.Root);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle the generation of an output file.
        /// </summary>
        private void CodeGenerated(string outputDir, CodeGeneratorEventArgs e)
        {
            string dir = outputDir;

            if (!string.IsNullOrEmpty(e.OutputDirName))
            {
                dir = Path.Combine(dir, e.OutputDirName);
            }

            if (!string.IsNullOrEmpty(e.OutputGenDirName))
            {
                dir = Path.Combine(dir, e.OutputGenDirName);
            }

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            var fi = new FileInfo(Path.Combine(dir, e.OutputFileName));

            if (fi.Exists)
            {
                if (e.IsOutputNewOnly)
                {
                    return;
                }

                var prevContent = File.ReadAllText(fi.FullName);
                if (string.Compare(e.Content, prevContent) == 0)
                {
                    NotChangedCount++;
                    return;
                }

                UpdatedCount++;
                File.WriteAllText(fi.FullName, e.Content);
                Logger.Default.Warning("    Updated -> {0}", fi.FullName.Substring(outputDir.Length));
            }
            else
            {
                CreatedCount++;
                File.WriteAllText(fi.FullName, e.Content);
                Logger.Default.Warning("    Created -> {0}", fi.FullName.Substring(outputDir.Length));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Close the generated output writer and raise the code generated event.
        /// </summary>
        private void CloseOutputWriter(CodeGenConfig config)
        {
            if (_tw != null)
            {
                // Output the footer.
                ExecuteTemplateNamed("Footer", config);

                // Close and cleanup.
                _tw.Flush();
                _tw.Dispose();
                _tw = null;

                // Raise the code generated event.
                _eventArgs.Content = Regex.Replace(_sb.ToString(), "(?<!\r)\n", "\r\n");
                _codeGenerator.RaiseCodeGenerated(_eventArgs);
            }

            // Initialize for a potential subsequent file.
            _sb        = null;
            _eventArgs = new CodeGeneratorEventArgs {
                OutputGenDirName = _eventArgs.OutputGenDirName
            };
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Raises the <see cref="CodeGenerated"/> event.
 /// </summary>
 internal void RaiseCodeGenerated(CodeGeneratorEventArgs e)
 {
     CodeGenerated?.Invoke(this, e);
 }