Ejemplo n.º 1
0
        public stat  Clone()
        {
            stat clone = new stat();

            clone.name         = this.name;
            clone.file_path    = this.file_path;
            clone.records      = this.records;
            clone.lines        = this.lines;
            clone.visible      = this.visible;
            clone.errors       = this.errors;
            clone.blanks       = this.blanks;
            clone.comments     = this.comments;
            clone.page         = this.page;
            clone.page_length  = this.page_length;
            clone.returned     = this.returned;
            clone.pages        = this.pages;
            clone.record_start = this.record_start;
            clone.record_end   = this.record_end;
            //clone.time              =new string(this.time.ToCharArray());
            clone.load_time  = this.load_time;
            clone.load_start = this.load_start;
            clone.load_end   = this.load_end;

            clone.properties        = this.properties;
            clone.property_ordinals = this.property_ordinals;

            return(clone);
        }
Ejemplo n.º 2
0
        public List <stat> stats(options options)
        {
            List <stat> stats = new List <stat>();

            foreach (table_base instance in tables)
            {
                stat s = instance.stat();
                stats.Add(s);
            }
            return(stats);
        }        //end stats
Ejemplo n.º 3
0
        public async Task <report> report(options options)
        {
            try{
                if (!this.is_loaded)
                {
                    await load();
                }
            } catch (Exception ex) {
                if (globals.debug)
                {
                    Console.WriteLine(string.Format("load:{0}", ex.Message));
                }
                if (globals.debug)
                {
                    Console.WriteLine("model not defined in load");
                }
                throw new Exception("failed to parse table");
            }
            stat report_stats = stats.Clone();

            report_stats.page        = options.page;
            report_stats.page_length = options.page_length;
            report_stats.returned    = 0;
            report_stats.visible     = 0;
            report_stats.errors      = 0;
            report_stats.blanks      = 0;
            report_stats.comments    = 0;
            report_stats.records     = 0;

            List <Tuple <string, string> > expressions = new List <Tuple <string, string> >();

            foreach (int[] expression in options.sort)
            {
                //int calculated_ordinal=report_stats.property_ordinals[expression.Key];
                if (globals.debug)
                {
                    Console.WriteLine(String.Format("SORT: {0}:{1}", expression[0], expression[1]));
                }
                int    calculated_ordinal = expression[0];
                string name = report_stats.properties[calculated_ordinal].name;
                string dir  = "";
                if (!report_stats.properties[calculated_ordinal].sort)                  //we got a bad sort.. lets ignore it
                {
                    report_stats.errors++;
                    if (globals.debug)
                    {
                        Console.WriteLine("Invalid Sort");
                    }
                    return(new report(report_stats, null, "Invalid Sort"));
                }
                if (expression[1] == 0)
                {
                    dir = "asc";
                }
                if (expression[1] == 1)
                {
                    dir = "desc";
                }
                if (expression[1] == 1 || expression[1] == 0)
                {
                    if (globals.debug)
                    {
                        Console.WriteLine(String.Format("{2}.{0}:{1}", name, dir, "model"));
                    }
                    expressions.Add(new Tuple <string, string>("model." + name, dir));
                }
            }
            //if(expressions.Count>0) {

            List <Tuple <string, string, string, string> > filters = new   List <Tuple <string, string, string, string> >();

            if (!string.IsNullOrWhiteSpace(options.multi_search))
            {
                foreach (property p in report_stats.properties)
                {
                    if (p.visible && p.multi_search)
                    {
                        filters.Add(new Tuple <string, string, string, string>("model." + p.name, "=", options.multi_search, "multi"));
                    }
                }
            }

            List <record> computed_records_filter = records.NCDB_Where(filters).ToList();
            List <record> computed_records        = computed_records_filter.NCDB_OrderBy(expressions).ToList();

            //}
            if (null != computed_records)
            {
                report_stats.records = (uint)computed_records.Count;
            }

            uint target_start_index = 0;
            uint start_index        = 0;

            if (report_stats.page_length == 0)
            {
                target_start_index = 0;
            }
            else
            {
                target_start_index = report_stats.page * report_stats.page_length;
            }
            //The length is variable based on what we are hiding...
            for (uint i = 0; i < report_stats.records; i++)
            {
                record item = computed_records[(int)i];

                if (item.is_error)
                {
                    report_stats.errors++;
                }
                if (item.is_blank)
                {
                    report_stats.blanks++;
                }
                if (item.is_comment)
                {
                    report_stats.comments++;
                }
                if ((!globals.models[uid].errors_visible && item.is_error) ||
                    (!globals.models[uid].empty_lines_visible && item.is_blank) ||
                    (!globals.models[uid].comments_visible && item.is_comment))
                {
                    continue;
                }

                report_stats.visible++;
                if (report_stats.visible == target_start_index)
                {
                    start_index = i;
                }
            }
            if (report_stats.page_length > 0)
            {
                if (report_stats.visible < report_stats.page_length)
                {
                    report_stats.pages = 1;
                }
                report_stats.pages = (report_stats.visible + report_stats.page_length - 1) / report_stats.page_length;
                if (report_stats.pages > 0 && report_stats.page >= report_stats.pages)
                {
                    report_stats.page = report_stats.pages - 1;                                                                      //default to last page if past the end of the array
                }
            }
            else
            {
                report_stats.pages = 1;
            }
            if (report_stats.visible == 0)
            {
                report_stats.pages = 0;
            }
            try{
                List <record> page_of_computed_records = new List <record>();

                for (uint i = start_index; i < report_stats.records; i++)
                {
                    record item = computed_records[(int)i];
                    if (null == item)
                    {
                        if (globals.debug)
                        {
                            Console.WriteLine("record null");
                        }
                        continue;
                    }

                    if ((!globals.models[uid].errors_visible && item.is_error) ||
                        (!globals.models[uid].empty_lines_visible && item.is_blank) ||
                        (!globals.models[uid].comments_visible && item.is_comment))
                    {
                        continue;
                    }
                    if (report_stats.page_length > 0 && report_stats.returned >= report_stats.page_length)
                    {
                        break;
                    }
                    report_stats.returned++;
                    page_of_computed_records.Add(item);
                    report_stats.record_end = i;
                }

                report returned_report = new report(report_stats, page_of_computed_records);
                return(returned_report);
            } catch (Exception ex) {
                if (globals.debug)
                {
                    Console.WriteLine(String.Format("report: record transfer failed. {0}", ex.Message));
                }
                report returned_report = new report(report_stats, null);
                returned_report.stats.errors++;
                return(returned_report);
            }
        }
Ejemplo n.º 4
0
 public report(stat stats, List <record> records, string msg = null)
 {
     this.stats   = stats;
     this.records = records;
     this.msg     = msg;
 }