Exemplo n.º 1
0
        static bool ProcessQuestionnaire(string prefix, ITemplater templater, Questionnaire q)
        {
            var tags = templater.Tags.ToArray();

            foreach (var t in tags)
            {
                if ((prefix + "title").Equals(t, StringComparison.CurrentCultureIgnoreCase))
                {
                    templater.ReplaceAll(t, q.Title);
                }
            }

            templater.Resize(new[] { prefix + "Text", prefix + "Question", prefix + "Answer" }, q.Questions.Count);

            foreach (var ask in q.Questions)
            {
                templater.Replace(prefix + "Text", ask.Text);
                templater.Resize(new[] { prefix + "Answer", prefix + "Question" }, ask.Options.Length);
                for (int i = 0; i < ask.Options.Length; i++)
                {
                    if (ask.SelectedOption == i)
                    {
                        templater.Replace(prefix + "Answer", "\u2611");
                    }
                    else
                    {
                        templater.Replace(prefix + "Answer", "\u2610");
                    }
                    templater.Replace(prefix + "Question", ask.Options[i]);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        static bool ProcessQuestionnaire(string prefix, ITemplater templater, Questionnaire q)
        {
            var tags = templater.Tags.ToArray();
            foreach (var t in tags)
                if ((prefix + "title").Equals(t, StringComparison.CurrentCultureIgnoreCase))
                    templater.ReplaceAll(t, q.Title);

            templater.Resize(new[] { prefix + "Text", prefix + "Question", prefix + "Answer" }, q.Questions.Count);

            foreach (var ask in q.Questions)
            {
                templater.Replace(prefix + "Text", ask.Text);
                templater.Resize(new[] { prefix + "Answer", prefix + "Question" }, ask.Options.Length);
                for (int i = 0; i < ask.Options.Length; i++)
                {
                    if (ask.SelectedOption == i)
                        templater.Replace(prefix + "Answer", "\u2611");
                    else
                        templater.Replace(prefix + "Answer", "\u2610");
                    templater.Replace(prefix + "Question", ask.Options[i]);
                }
            }

            return true;
        }
Exemplo n.º 3
0
 static bool CollapseNonEmpty(object value, string metadata, string property, ITemplater templater)
 {
     if (metadata == "collapseNonEmpty" || metadata == "collapseEmpty")
     {
         var dt = value as DataTable;
         if (dt == null)
         {
             return(false);
         }
         var isEmpty = dt.Rows.Count == 0;
         //loop until all tags with the same name are processed
         do
         {
             var md = templater.GetMetadata(property, false);
             var collapseOnEmpty  = md.Contains("collapseEmpty");
             var collapseNonEmpty = md.Contains("collapseNonEmpty");
             if (isEmpty)
             {
                 if (collapseOnEmpty)
                 {
                     templater.Resize(property, 0);
                 }
                 else
                 {
                     templater.Replace(property, "");
                 }
             }
             else
             {
                 if (collapseNonEmpty)
                 {
                     templater.Resize(property, 0);
                 }
                 else
                 {
                     templater.Replace(property, "");
                 }
             }
         } while (templater.Tags.Contains(property));
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 static bool Limit10Table(string prefix, ITemplater templater, DataTable table)
 {
     if (table.Rows.Count > 10)
     {
         //simplified way to match columns against tags
         var tags = table.Columns.Cast<DataColumn>().Select(it => prefix + it.ColumnName).ToList();
         //if any of the found tags matches limit10 condition
         if (tags.Any(t => templater.GetMetadata(t, true).Contains("limit10")))
         {
             templater.Resize(tags, 10);
             for (int i = 0; i < 10; i++)
             {
                 DataRow r = table.Rows[i];
                 foreach (DataColumn c in table.Columns)
                     templater.Replace(prefix + c.ColumnName, r[c]);
             }
             return true;
         }
     }
     return false;
 }
Exemplo n.º 5
0
 static bool Limit10Table(string prefix, ITemplater templater, DataTable table)
 {
     if (table.Rows.Count > 10)
     {
         //simplified way to match columns against tags
         var tags = table.Columns.Cast <DataColumn>().Select(it => prefix + it.ColumnName).ToList();
         //if any of the found tags matches limit10 condition
         if (tags.Any(t => templater.GetMetadata(t, true).Contains("limit10")))
         {
             templater.Resize(tags, 10);
             for (int i = 0; i < 10; i++)
             {
                 DataRow r = table.Rows[i];
                 foreach (DataColumn c in table.Columns)
                 {
                     templater.Replace(prefix + c.ColumnName, r[c]);
                 }
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
        //for this example position is ignored as it is always -1
        static bool CollapseNonEmpty(object value, string metadata, string tag, int position, ITemplater templater)
        {
            var dt = value as DataTable;

            if (dt != null && (metadata == "collapseNonEmpty" || metadata == "collapseEmpty"))
            {
                var isEmpty = dt.Rows.Count == 0;
                //loop until all tags with the same name are processed
                do
                {
                    var md = templater.GetMetadata(tag, false);
                    var collapseOnEmpty  = md.Contains("collapseEmpty");
                    var collapseNonEmpty = md.Contains("collapseNonEmpty");
                    if (isEmpty)
                    {
                        if (collapseOnEmpty)
                        {
                            //when position is -1 it means non sharing tag is being used, in which case we can resize that region via "standard" API
                            //otherwise we need to use "advanced" resize API to specify which exact tag to replace
                            if (position == -1)
                            {
                                templater.Resize(new[] { tag }, 0);
                            }
                            else
                            {
                                templater.Resize(new[] { new TagPosition(tag, position) }, 0);
                            }
                        }
                        else
                        {
                            //when position is -1 it means non sharing tag is being used, in which case we can just replace the first tag
                            //otherwise we can replace that exact tag via position API
                            //replacing the first tag is the same as calling replace(tag, 0, value)
                            if (position == -1)
                            {
                                templater.Replace(tag, "");
                            }
                            else
                            {
                                templater.Replace(tag, position, "");
                            }
                        }
                    }
                    else
                    {
                        if (collapseNonEmpty)
                        {
                            if (position == -1)
                            {
                                templater.Resize(new[] { tag }, 0);
                            }
                            else
                            {
                                templater.Resize(new[] { new TagPosition(tag, position) }, 0);
                            }
                        }
                        else
                        {
                            if (position == -1)
                            {
                                templater.Replace(tag, "");
                            }
                            else
                            {
                                templater.Replace(tag, position, "");
                            }
                        }
                    }
                } while (templater.Tags.Contains(tag));
                return(true);
            }
            return(false);
        }