private static GenFragmentGenerator Create(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
        {
            switch (fragment.FragmentType)
            {
            case FragmentType.Profile:
                return(new GenContainerGenerator(genDataDef, genWriter, genObject, fragment));

            case FragmentType.Segment:
                return(new GenSegmentGenerator(genDataDef, genWriter, genObject, fragment));

            case FragmentType.Block:
                return(new GenContainerGenerator(genDataDef, genWriter, genObject, fragment));

            case FragmentType.Lookup:
                return(new GenLookupGenerator(genDataDef, genWriter, genObject, fragment));

            case FragmentType.Condition:
                return(new GenConditionGenerator(genDataDef, genWriter, genObject, fragment));

            case FragmentType.Annotation:
                return(new GenAnnotationGenerator(genDataDef, genWriter, genObject, fragment));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public GenSegmentGenerator(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
     : base(genDataDef, genWriter, genObject, fragment)
 {
     Segment        = (Segment)fragment;
     GenCardinality = Segment.GenCardinality;
     Navigator      = new SegmentNavigator(this);
 }
 protected GenFragmentGenerator(GenDataDef genDataDef, GenWriter writer, Fragment fragment, GenObject genObject)
 {
     _genDataDef = genDataDef;
     _writer     = writer;
     _fragment   = fragment;
     GenObject   = genObject;
 }
 private static bool Write(GenWriter genWriter, string text)
 {
     if (text == "")
     {
         return(false);
     }
     genWriter.Write(text);
     return(true);
 }
        public string GetText(Fragment fragment, TextPosition bodyPosition = null)
        {
            var saveWriter = Writer;

            using (var stream = new MemoryStream(100000))
            {
                using (var writer = new GenWriter(stream))
                {
                    Writer = writer;
                    OutputFragment(fragment, bodyPosition ?? new TextPosition());
                    writer.Flush();
                    stream.Seek(0, SeekOrigin.Begin);
                    Writer = saveWriter;
                    using (var reader = new StreamReader(stream))
                        return(reader.ReadToEnd());
                }
            }
        }
        public static bool Generate(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
        {
            switch (fragment.FragmentType)
            {
            case FragmentType.Null:
                return(false);

            case FragmentType.Text:
                return(Write(genWriter, ((Text)fragment).TextValue));

            case FragmentType.Placeholder:
                return(Write(genWriter, GetPlaceholderValue(fragment, genObject)));

            case FragmentType.Function:
                var fn             = (Function)fragment;
                var paramFragments = fn.Body().FragmentList;
                var param          = new string[paramFragments.Count];
                for (var i = 0; i < paramFragments.Count; i++)
                {
                    var paramFragment = paramFragments[i];
                    param[i] = GenFragmentExpander.Expand(genDataDef, genObject, paramFragment);
                }
                return((fn.FunctionName != "File" || !genWriter.CheckFile(param[0])) &&
                       Write(genWriter, LibraryManager.GetInstance().Execute(fn.FunctionName, param)));

            case FragmentType.TextBlock:
                var sb = new StringBuilder();
                foreach (var f in ((TextBlock)fragment).Body().FragmentList)
                {
                    if (f.GetType().Name == "Text")
                    {
                        sb.Append(((Text)f).TextValue);
                    }
                    else if (f.GetType().Name == "Placeholder")
                    {
                        sb.Append(GetPlaceholderValue(f, genObject));
                    }
                }
                return(Write(genWriter, sb.ToString()));

            default:
                return(Create(genDataDef, genWriter, genObject, fragment).Generate());
            }
        }
 private int GetOutputSize(bool primary)
 {
     using (var stream = new NullStream())
     {
         using (var writer = new GenWriter(stream))
         {
             if (primary)
             {
                 GenFragmentGenerator.Generate(GenDataDef, writer, GenObject, Fragment);
             }
             else
             {
                 GenFragmentGenerator.GenerateSecondary(GenDataDef, writer, GenObject, Fragment);
             }
             writer.Flush();
             return((int)writer.Stream.Length);
         }
     }
 }
        private string ExpandSecondary()
        {
            var outputSize = GetOutputSize(false);

            if (outputSize == 0)
            {
                return("");
            }
            using (var stream = new MemoryStream(outputSize))
            {
                using (var writer = new GenWriter(stream))
                {
                    GenFragmentGenerator.GenerateSecondary(GenDataDef, writer, GenObject, Fragment);
                    writer.Flush();
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(stream))
                        return(reader.ReadToEnd());
                }
            }
        }
 public GenLookupGenerator(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
     : base(genDataDef, genWriter, genObject, fragment)
 {
 }
 public GenContainerGenerator(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
     : base(genDataDef, genWriter, fragment, genObject)
 {
     ContainerFragment = (ContainerFragment)Fragment;
 }
 internal GenConditionGenerator(GenDataDef genDataDef, GenWriter writer, GenObject genObject, Fragment fragment)
     : base(genDataDef, writer, genObject, fragment)
 {
 }
 internal GenAnnotationGenerator(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
     : base(genDataDef, new GenWriter(new NullStream()), genObject, fragment)
 {
 }
 public static bool GenerateSecondary(GenDataDef genDataDef, GenWriter genWriter, GenObject genObject, Fragment fragment)
 {
     return(Create(genDataDef, genWriter, genObject, fragment).GenerateSecondary());
 }
 public void Generate(GenDataBase genDataBase, GenWriter genWriter)
 {
     GenFragmentGenerator.Generate(genDataBase.GenDataDef, genWriter, genDataBase.Root, Profile);
 }