Example #1
0
        /// <summary>
        /// A consolidated version of ConvertInput.
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        static public string Parse(Generator.Export.Intrinsic.IDataConfig config)
        {
            // TableElement tableElementbackup = config.Table;
            string            tableOut = Parse(config.Databases, config.Table, config.Template);
            List <QuickMatch> list;

            while (0 != (list = TemplateReferenceUtil.GetReferences(tableOut)).Count)
            {
                // we could restore the table if it was changed
                QuickMatch match0 = list[0];

                if (!list[0].HasParams) /* error no parameters  */ continue {
                    ;
                }
                string newOut = string.Empty;
                // TableTemplate tbltmpl = null;

                if (!match0.HasMultipleParams)                   // single parameter-match

                {
                    bool checker = config.HasTemplate(list[0].Params[0]);
                    Debug.Assert(checker, string.Format("Template {0} not found! if you continue, the generated content will have errors.", match0.Params[0]));
                    if (checker)
                    {
                        config.Template = config.Templates[list[0].Params[0]];
                        newOut          = Parse(config);
                        tableOut        = tableOut.Replace(list[0].FullString, newOut);
                    }
                }
                else                     // Multiple param-matches

                {
                    for (int i = 1; i < match0.Params.Length; i++)
                    {
                        bool checker = config.HasTemplate(match0.Params[0]);
                        Debug.Assert(checker, string.Format("Template {0} not found! if you continue, the generated content will have errors.", match0.Params[0]));
                        if (checker)
                        {
                            config.Template = config.Templates[match0.Params[0]];
                            config.Table    = config.Database[match0.Params[i]];
                            newOut         += Parse(config);
                        }
                    }
                    tableOut = tableOut.Replace(list[0].FullString, newOut);
                }
            }
Example #2
0
        /// <summary>#1 Starting Point
        ///
        ///
        /// The selection must have at the least a table and selected template.
        /// Converts a selection (table or view) provided by IDbConfiguration4.
        ///
        /// - prepares parsing
        ///
        /// - performs initial layer of parsing.
        /// </summary>
        /// <param name="config">IDbConfiguration4; (selection)</param>
        /// <returns>parsed string result.</returns>
        static public string Generate(GenConfig config)
        {
            string output = string.Empty;

            var view = TemplateModel.LoadSelection(config);

            if (view.T != null)
            {
                output = Gen_Pass2(view);

                List <QuickMatch> list; // holds a list of template-tag matches.

                while (0 != (list = TemplateReferenceUtil.GetReferences(output)).Count)
                {
                    output = WritePart(view, list[0], output);
                }
            }

            #region IF View IS SELECTION
            else if (config.SelectedView != null)
            {
                view        = TemplateModel.LoadView(config);
                output      = Gen_Pass2(view);
                view.T.View = null;

                // check for errors
                if (view.DB == null || view.T == null)
                {
                    System.Windows.Forms.MessageBox.Show("Error finding database or table for view-link", "Exiting generation..."); return("Error finding database or table for view.");
                }

                List <QuickMatch> list;
                while (0 != (list = TemplateReferenceUtil.GetReferences(output)).Count)
                {
                    var m1 = list[0]; // m1.Value = the name of our Template, right?

                    Logger.LogY("Template?", "QuickMatch[0].Value={0}, QuickMatch[0].Name={1}", m1.Value, m1.Name);

                    if (!m1.HasParams)
                    {
                        Logger.LogC("TemplateFactory.Write ERROR", "No Params"); continue;
                    }

                    if (!m1.HasMultipleParams)
                    {
                        #region Single Table Reference

                        view.TT = config.Templates[m1.Params[0]];
                        if (view.TT == null)
                        {
                            Logger.Warn("TemplateFactory.Write ERROR", "Tag: ‘{0}’ value.", m1.Name); continue;
                        }                                                                                             // return tableOut;

                        // reset the current view?

                        view.T.View = config.SelectedView;
                        string newOut = Gen_Pass2(view);

                        output = output.Replace(m1.FullString, newOut);

                        view.T.View = null;

                        Logger.LogM("TemplateFactory.Write", "{0}", m1.Params[0]);

                        #endregion
                    }
                    else if (m1.Name == "Directory")
                    {
                        #region Directory

                        if (System.IO.Directory.Exists(m1.Value))
                        {
                            var listf = new List <string>();
                            foreach (string dir in System.IO.Directory.GetDirectories(m1.Value))
                            {
                                listf.Add(dir);
                            }
                            output = output.Replace(m1.FullString, string.Join(",", listf.ToArray()));
                        }

                        #endregion
                    }
                    else
                    {
                        #region Main Parser Section

                        Logger.LogC("TemplateFactory.Write", "Match0.Value = “{0}”", m1.Value);
                        Logger.LogC("TemplateFactory.Write", ".Name = “{0}”", m1.Name);
                        Logger.LogC("TemplateFactory.Write", "{0}", m1.Params[0]);

                        string newOut = string.Empty;

                        for (int i = 0, match0ParamsLength = m1.Params.Length; i < match0ParamsLength; i++)
                        {
                            var param = m1.Params[i];

                            Logger.LogG("TemplateFactory.Write", "table: “{0}”", m1.Params[i]);

                            view.SetTemplate(m1.Params[0]);
                            view.T.View = config.SelectedView; // but why?

                            newOut += string.Format("{0}", Gen_Pass2(view));

                            view.T.View = null;
                        }

                        output = output.Replace(m1.FullString, newOut);
                        #endregion
                    }
                }
            }
            #endregion

            return(output);
        }