Ejemplo n.º 1
0
        static string WritePart(TemplateModel view, QuickMatch match, string generatedIn)
        {
            string generatedOut = generatedIn; //  QuickMatch match0 = list[0]; // Logger.LogY("TemplateFactory.WritePart","{0}", match.Value);// this is "TemplateName,TableName"

            if (!match.HasParams)
            {
                Logger.Warn("TemplateFactory.WritePart", "ERROR: No Params"); return(generatedIn);
            }

            if (!match.HasMultipleParams)
            {
                view.SetTemplate(match.Params[0]);
                if (view.TT == null)
                {
                    Logger.Warn("TemplateFactory.WritePart ERROR", "Tag: ‘{0}’ value.", match.Name); return(generatedIn);
                }
                generatedOut = generatedIn.Replace(match.FullString, Gen_Pass2(view)); // replace the template tag with the parsed content.
            }
            // the Directory Element is not parsed.
            else if (match.Name == "Directory")
            {
                if (System.IO.Directory.Exists(match.Value))
                {
                    var listf = new List <string>();
                    foreach (string dir in System.IO.Directory.GetDirectories(match.Value))
                    {
                        listf.Add(dir);
                    }
                    generatedOut = generatedIn.Replace(match.FullString, string.Join(",", listf.ToArray()));
                }
            }
            // ¡MAIN PARSER LOOP!
            else
            {
                string newOut = string.Empty;
                for (int i = 1; i < match.Params.Length; i++) // match.Params[i] = table-name; notice I starts at one
                {
                    view.SetTemplate(match.Params[0]);
                    view.SetView(match.Params[i]);
                    newOut += Gen_Pass2(view);
                }
                generatedOut = generatedIn.Replace(match.FullString, newOut);
            }
            return(generatedOut);
        }
Ejemplo n.º 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);
        }