Exemplo n.º 1
0
        public async Task <report> get_report(options options)
        {
            table_base t = this[options.uid];

            if (null == t)
            {
                throw new Exception("Invalid type");
            }
            return(await t.report(options));
        }
Exemplo n.º 2
0
        public async Task <object> perform_operation(options options, bool return_object = false)
        {
            string header = String.Empty;
            object obj    = null;

            table_base t = this[options.uid];

            switch (options.operation.ToLower())
            {
            /***ON SINGULAR TABLE****/
            case "report": if (null == t)
                {
                    throw new Exception("Table did not load properly, Invalid type-report");
                }
                obj = await t.report(options);

                break;

            case "list":  obj = globals.get_list();
                break;

            case "config": if (globals.models.ContainsKey(options.uid))
                {
                    obj = globals.models[options.uid];
                }
                else
                {
                    throw new Exception(String.Format("Config: Model not in global cache. {0}", options.uid));
                }
                break;

            case "stat": if (null == t)
                {
                    throw new Exception("Table did not load properly, Invalid type");
                }
                obj = t.stat();
                break;

            /***ON ALL TABLES****/
//                case "stats" : obj=stats(options);     break;

            default: return("Unknown operation");
            }
            if (return_object)
            {
                return(obj);
            }
            if (options.format == "raw")
            {
                header = options.ToString();
            }
            string base_string = await optupt_converter(options.format, obj);

            return(header + base_string);
        }
Exemplo n.º 3
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
Exemplo n.º 4
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);
            }
        }