Example #1
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)
                {
                    ErrorMessage.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);
        }
Example #2
0
        static List <string> GetParamStrings(TemplateModel view, bool noPrimaryKey)
        {
            var    result_pList   = new List <string>();
            string curr_FieldName = null;

            // this is the primary date conversion or replacement portion of this method.
            // ------------------------------------------------------------
            if (view.T.View == null && view.T.Link == null)
            {
                view.PrepareReformat();
                for (int i = 0, elmTableFieldsCount = view.T.Fields.Count; i < elmTableFieldsCount; i++)
                {
                    curr_FieldName = GetParam(view, noPrimaryKey, i);
                    if (!string.IsNullOrEmpty(curr_FieldName))
                    {
                        result_pList.Add(curr_FieldName);
                    }
                }
                view.TemplateContentReformat = null;
            }
            // ------------------------------------------------------------
            // we're dealing with a DataViewElement -- not sure if this is working so focus more up there...
            // ------------------------------------------------------------
            else if (view.T.View != null)
            // here, we iterate on either of the following:
            // 1.  FieldElement, tbl.Fields
            // 2.  DataViewLink, tableElement.View.LinkItems
            //     2.1 FieldElement, tbl.Fields
            {
                view.SetView();
                view.PrepareReplaceValues();
                if (CheckForError(view.T))
                {
                    Logger.Warn("TemplateFactory.GetParamStrings", "couldn't find table named \"{0}\"", view.T.Name);
                }                                                                                                                       // this semantic really kind of sucks.

                for (int i = 0, tblFieldsCount = view.T.Fields.Count; i < tblFieldsCount; i++)
                {
                    FieldElement field = view.T.Fields[i];
                    field.View = view.T.View;

                    curr_FieldName = GetParam(view, noPrimaryKey, i);


                    if (view.T.View.HasField(view.T, field, true) && !string.IsNullOrEmpty(curr_FieldName))
                    {
                        result_pList.Add(curr_FieldName);
                    }
                    field.View = null;
                }

                foreach (DataViewLink link in view.T.View.LinkItems)
                {
                    view.SetView(link);
                    view.PrepareReplaceValues();
                    if (CheckForError(view.T))
                    {
                        Logger.Warn("GetParamStrings", "Table \"{0}\" wasn't found");
                    }                                                                                 // how about exiting?
                    Logger.LogG("--->", "Found table: {0}", view.T.Name);

                    for (int i = 0, tblFieldsCount = view.T.Fields.Count; i < tblFieldsCount; i++)
                    {
                        FieldElement field = view.T.Fields[i];
                        field.View = view.T.View;
                        field.Link = link;

                        curr_FieldName = GetParam(view, noPrimaryKey, i);

                        bool hasField = link.HasField(view.T, field, true);
                        if (hasField && !string.IsNullOrEmpty(curr_FieldName))
                        {
                            result_pList.Add(curr_FieldName);
                        }
                        field.View = null;
                        field.Link = null;
                    }
                }
                view.TemplateContentReformat = null;
            }
            return(result_pList);
        }