public void Transform(IOutputFile output)
        {
            if (output.FileMetadata.OverwriteBehaviour == OverwriteBehaviour.OnceOff && _appendHeadersToOnceOffTemplates)
            {
                output.ChangeContent(AppendHeader(output));
                return;
            }

            HeaderAppendBehaviour behaviour;

            if (!_codeGenTypeMap.TryGetValue(output.FileMetadata.CodeGenType, out behaviour))
            {
                behaviour = _unspecifiedBehaviour;
            }

            switch (behaviour)
            {
            case HeaderAppendBehaviour.Always:
                output.ChangeContent(AppendHeader(output));
                break;

            case HeaderAppendBehaviour.OnCreate:
                if (!File.Exists(output.FileMetadata.GetFullLocationPathWithFileName()))
                {
                    output.ChangeContent(AppendHeader(output));
                }
                break;

            case HeaderAppendBehaviour.Never:
                break;
            }
        }
Exemple #2
0
        public void Transform(IOutputFile output)
        {
            if (!(output.Template is ISqlTemplate sqlTemplate))
            {
                return;
            }

            var existingFile = sqlTemplate.GetExistingFile();

            if (existingFile == null)
            {
                return;
            }

            try
            {
                var instruction = existingFile.TrimStart().Substring(0, Math.Min(50, existingFile.Length)).Replace(" ", "");
                if (instruction.StartsWith("--INTENTIGNORE", StringComparison.InvariantCultureIgnoreCase))
                {
                    output.ChangeContent(existingFile);
                }
            }
            catch (Exception e)
            {
                Logging.Log.Warning($"Error while managing SQL file: {output.FileMetadata.GetFilePath()}");
                Logging.Log.Warning(e.ToString());
            }
        }
        public void Transform(IOutputFile output)
        {
            if (!(output.Template is IKotlinMerged KotlinMerged))
            {
                return;
            }

            var existingFile = KotlinMerged.GetExistingFile();

            if (existingFile == null)
            {
                return;
            }

            try
            {
                var merger = new KotlinWeavingMerger();

                var sw         = Stopwatch.StartNew();
                var newContent = merger.Merge(existingFile, output.Content);
                Logging.Log.Debug($"Merged file: {output.FileMetadata.GetFilePath()} ({sw.ElapsedMilliseconds}ms)");

                output.ChangeContent(newContent);
            }
            catch (Exception e)
            {
                output.ChangeContent(existingFile.GetSource());

                Logging.Log.Failure($"Error while weaving Kotlin file: {output.FileMetadata.GetFilePath()}");
                Logging.Log.Failure(e.ToString());
            }
        }
Exemple #4
0
        private static int GenerateSharedCode(string inputPath, string outputBasePath)
        {
            if (!File.Exists(inputPath))
            {
                Console.Error.WriteLine("Input path is not an existing file.");
                return(ExitFailure);
            }

            if (!Directory.Exists(outputBasePath))
            {
                Console.Error.WriteLine("Output path base is not an existing directory.");
                return(ExitFailure);
            }

            var input = LoadFromString <List <ConstantCollection> >(File.ReadAllText(inputPath));

            foreach (ConstantCollection col in input)
            {
                col.SourcePath = inputPath; // This isn't set by YamlDotNet, so it's added manually

                foreach (Dictionary <string, string> outputInfo in col.Outputs)
                {
                    IOutputFile output   = OutputFactory.CreateByType(outputInfo, col);
                    string      filePath = Path.Combine(outputBasePath, output.GetPath());
                    using (StreamWriter writer = new StreamWriter(filePath))
                    {
                        Console.WriteLine("Writing file '{0}'", filePath);
                        writer.Write(output.GetContent());
                    }
                }
            }

            return(ExitSuccess);
        }
Exemple #5
0
        public void Transform(IOutputFile output)
        {
            WeaveBehaviour behaviour;

            if (!_codeGenTypeMap.TryGetValue(output.FileMetaData.CodeGenType, out behaviour))
            {
                return;
            }

            switch (behaviour)
            {
            case WeaveBehaviour.KeepCodeInTags:
            {
                string targetFile = output.FileMetaData.GetFullLocationPathWithFileName();
                if (File.Exists(targetFile))
                {
                    var fileWeaver = new FileWeaver(_eventDispatcher, output.Project, output.FileMetaData);
                    output.ChangeContent(fileWeaver.Keep(GetTokenParser(output.FileMetaData.FileExtension), output.Content, File.ReadAllText(targetFile)));
                }
            }
            break;

            case WeaveBehaviour.GenerateCodeToTags:
            {
                string targetFile = output.FileMetaData.GetFullLocationPathWithFileName();
                if (File.Exists(targetFile))
                {
                    var fileWeaver = new FileWeaver(_eventDispatcher, output.Project, output.FileMetaData);
                    output.ChangeContent(fileWeaver.Embed(GetTokenParser(output.FileMetaData.FileExtension), output.Content, File.ReadAllText(targetFile)));
                }
            }
            break;
            }
        }
        private string AppendHeader(IOutputFile output)
        {
            string        content      = output.Content;
            IFileMetadata fileMetadata = output.FileMetadata;

            string header = GetHeader(output);

            //Deal with XML Declartions <?xml...>
            switch (fileMetadata.FileExtension.ToLower())
            {
            case "xml":
            case "config":
                if (content.Substring(0, 2) == "<?")
                {
                    int pos = content.IndexOf(">\r\n");
                    return(content.Substring(0, pos + 3) + header + content.Substring(pos + 3));
                }
                break;
            }
            if (!string.IsNullOrWhiteSpace(header))
            {
                content = header + content;
            }
            return(content);
        }
        public void Transform(IOutputFile output)
        {
            if (!(output.Template is ITypeScriptMerged typeScriptMerged))
            {
                return;
            }
            try
            {
                var existingFile = typeScriptMerged.GetExistingFile();

                if (existingFile == null)
                {
                    return;
                }


                var merger = new TypeScriptWeavingMerger();

                var newContent = merger.Merge(existingFile, output.Content);

                output.ChangeContent(newContent);
            }
            catch (Exception e)
            {
                var metadata     = output.FileMetadata;
                var fullFileName = Path.Combine(metadata.GetFullLocationPath(), metadata.FileNameWithExtension());
                output.ChangeContent(File.ReadAllText(fullFileName)); // don't change output

                Logging.Log.Failure($"Error while weaving TypeScript file: {output.FileMetadata.GetRelativeFilePath()}");
                Logging.Log.Failure(e.ToString());
            }
        }
        public void Transform(IOutputFile output)
        {
            if (!(output.Template is IHtmlFileMerge htmlFileMerge))
            {
                return;
            }

            var existingFile = htmlFileMerge.GetExistingFile();

            if (existingFile == null)
            {
                return;
            }

            try
            {
                var merger = new HtmlWeavingMerger();

                var newContent = merger.Merge(existingFile, output.Content);

                output.ChangeContent(newContent);
            }
            catch (Exception e)
            {
                output.ChangeContent(existingFile.GetSource());

                Logging.Log.Failure($"Error while weaving Html file: {output.FileMetadata.GetRelativeFilePath()}");
                Logging.Log.Failure(e.ToString());
            }
        }
Exemple #9
0
 public LinqGrader(
     [NotNull] IInputFileColumnIndices indices,
     [NotNull] IInputFile input,
     [NotNull] IOutputFile output)
 {
     m_Indices = indices;
     m_Input   = input;
     m_Output  = output;
 }
Exemple #10
0
        public static IOutputFile CreateByType(Dictionary <string, string> typeInfo, ConstantCollection constantCollection)
        {
            string typeName = typeInfo["type"];

            typeInfo.Remove("type");

            IOutputFile outputFile = Activator.CreateInstance(OutputsByType[typeName]) as IOutputFile;

            outputFile.Initialize(constantCollection, typeInfo);
            return(outputFile);
        }
        public void Save(string path, IOutputFile outputFile)
        {
            string dir = Path.GetDirectoryName(path);

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

            using (FileStream stream = new FileStream(path, FileMode.Create))
            {
                outputFile.Write(stream);
            }
        }
Exemple #12
0
        private static void Main(string[] args)
        {
            string[] data = new string[] { "tom", "jane", "alex" };
            //Console.WriteLine("Choose output type(1:Text; 2:HTML; 3:XML");

            //int type;
            //type = int.Parse(Console.ReadLine());
            //OutputFileContext file = null;
            //switch (type)
            //{
            //	case 1:
            //		file = new OutputFileContext(new OutputHTMLFile());
            //		break;
            //	case 2:
            //		file = new OutputFileContext(new OutputTextFile());
            //		break;
            //	case 3:
            //		file = new OutputFileContext(new OutputXMLFile());
            //		break;
            //	default:
            //		break;
            //}
            //file.OutputFile(data);

            string type = ConfigurationSettings.AppSettings["OutputType"].ToString();

            string assembleName = Assembly.GetExecutingAssembly().GetName().Name;

            IOutputFile outputFile =
                (Assembly.Load(assembleName)
                 .CreateInstance(
                     assembleName + "." + "Output" + type.ToString() + "File",
                     false,
                     BindingFlags.Default,
                     null,
                     args,
                     null,
                     null)) as IOutputFile;
            OutputFileContext fileContext = new OutputFileContext(outputFile);

            fileContext.OutputFile(data);



            Console.ReadLine();
        }
        private string GetHeader(IOutputFile output)
        {
            string        fileExtension = output.FileMetadata.FileExtension;
            IFileMetadata fileMetadata  = output.FileMetadata;

            var codeGenTypeDescription        = output.FileMetadata.CodeGenType;
            var overwriteBehaviourDescription = output.FileMetadata.OverwriteBehaviour.GetDescription();

            var additionalHeaders           = output.Template.GetAllAdditionalHeaderInformation();
            var additionalHeaderInformation = !additionalHeaders.Any()
                ? string.Empty
                : Environment.NewLine + Environment.NewLine + additionalHeaders.Select(x => $" - {x}").Aggregate((x, y) => x + Environment.NewLine + y) + Environment.NewLine;


            var header = $@"
******************************************************************************
   ___       _             _
  |_ _|_ __ | |_ ___ _ __ | |_
   | || '_ \| __/ _ \ '_ \| __|
   | || | | | ||  __/ | | | |_
  |___|_| |_|\__\___|_| |_|\__|

  Gen Type : {codeGenTypeDescription}    {additionalHeaderInformation}
******************************************************************************".TrimStart();

            switch (fileExtension.ToLower())
            {
            // for /*..*/ style comment file extensions
            case "cs":
            case "js":
            case "ts":
                return($@"/*{header}*/{Environment.NewLine}");

            // for <!--..--> style comment file extensions
            case "xaml":
            case "html":
            case "xml":
            case "config":
                return($@"<!--{header}*-->{Environment.NewLine}");

            default:
                return(null);
            }
        }
Exemple #14
0
 public DeployFileAction(IComponentBuilder componentBuilder, IOutputFile outputFile, VersionNumber version)
 {
     _componentBuilder = componentBuilder;
     Version           = version;
     OutputFile        = outputFile;
 }
 public OutputFileContext(IOutputFile outputFile)
 {
     m_outputFile = outputFile;
 }
Exemple #16
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="outputFile">The description of the current output file.</param>
 /// <param name="sum">The sum to use for similar items (or <c>null</c>).</param>
 /// <param name="comparer">The comparer to use for sorting records.</param>
 public SumWriter(IOutputFile <T> outputFile, ISum <T> sum, IComparer <T> comparer)
 {
     _outputFile = outputFile;
     _sum        = sum;
     _comparer   = comparer;
 }
Exemple #17
0
 public CheckOutputFileExistAction(IOutputFile outputFile)
 {
     this.OutputFile = outputFile;
 }
 public OutputFileContext(IOutputFile outputFile)
 {
     m_outputFile = outputFile;
 }