Example #1
0
        /// <summary>
        /// Flavor a project directory
        /// </summary>
        /// <param name="inputDir">the directory to flavor</param>
        /// <param name="outputDir">where the project directory is mirrored to, flavored</param>
        /// <param name="activeFlavors">a list of all active flavors</param>
        /// <param name="parallelProcessing">should files be processed in parallel?</param>
        public void FlavorProject(DirectoryInfo inputDir, DirectoryInfo outputDir, List <string> activeFlavors, bool parallelProcessing = false)
        {
            //counters for flavoring results
            int flavoredChanged   = 0,
                flavoredUnchanged = 0,
                copied            = 0,
                skipped           = 0;

            //setup function for each file (~= loop body)
            Action <FileInfo> processAction = (FileInfo input) =>
            {
                using (Log.AsyncLogSession logSession = Log.StartAsync())
                {
                    //set tag of session
                    logSession.PushTag(input.Name);

                    //create output fileinfo
                    FileInfo output = new FileInfo(Path.Combine(outputDir.FullName, Path.GetRelativePath(inputDir.FullName, input.FullName)));

                    //flavor the file, count results
                    switch (FlavorFile(input, output, activeFlavors, logSession))
                    {
                    case FlavorResult.FlavoredReplace:
                        flavoredChanged++;
                        break;

                    case FlavorResult.FlavoredSkipped:
                        flavoredUnchanged++;
                        break;

                    case FlavorResult.Copied:
                        copied++;
                        break;

                    case FlavorResult.Skipped:
                        skipped++;
                        break;
                    }
                }
            };

            //enumerate files
            if (parallelProcessing)
            {
                inputDir.EnumerateAllFilesParallel("*.*", true, processAction);
            }
            else
            {
                inputDir.EnumerateAllFiles("*.*", true, processAction);
            }

            //log results
            Log.i($"Finished processing. {flavoredChanged} flavored files changed, {flavoredUnchanged} unchanged, {copied} files copied and {skipped} files skipped entirely.");
        }
Example #2
0
        /// <summary>
        /// flavors a stream of text
        /// </summary>
        /// <param name="input">the input stream (eg. source file)</param>
        /// <param name="output">the output file (eg. output file)</param>
        /// <param name="activeFlavors">a list of currently active flavors</param>
        /// <param name="logSession">log session for logging</param>
        public void FlavorStream(StreamReader input, StreamWriter output, List <string> activeFlavors, Log.AsyncLogSession logSession)
        {
            //log processing the file
            logSession?.v($"Start processing stream...");

            //process line by line
            string ln;
            int    lnCount = 0;

            while ((ln = input.ReadLine()) != null)
            {
                //set logging tag
                logSession?.PushTag($"{logSession?.GetTag()}:{lnCount++}");

                //flavor string and write to output
                ln = FlavorString(ln, activeFlavors, logSession);
                output.WriteLine(ln);

                //pop back tag
                logSession?.PopTag();
            }
        }