Ejemplo n.º 1
0
            public table(string file_path, table_config config)
            {
                this.config = config;
                string[] rows  = System.IO.File.ReadAllLines(file_path);
                int      index = 0;

                foreach (string row in rows)
                {
                    row processed_row = new row(row, config, index);
                    items.Add(processed_row);
                    ++index;
                }

                populate_min_max();
                derive_columns();
                derive_array();
                derive_column_data();
            }//end constructor
Ejemplo n.º 2
0
        public table_translator(string file_path)
        {
            // after all the column definitions are created
            // static data is populated
            // then derived columns are generated if desired
            // finally the derived data is populated from the standard data


            table_config config = new table_config('#', ':', ',', '=');
            //config.columns.Add("node"        );
            //config.columns.Add("hostname"    );
            //config.columns.Add("interface"   );
            //config.columns.Add("ip"          );
            //config.columns.Add("network"     );
            //config.columns.Add("defaultroute");
            //config.columns.Add("routeset"    );
            //config.columns.Add("MAC"         );
            //config.columns.Add("link_setting");

            table table = new table(file_path, config);



            //display columns
            foreach (column_definition cd in config.columns.items)
            {
                string line = string.Format("Name: {0} Ordinal: {1} Derived: {2} min_items: {3} max_items: {4}", cd.name, cd.ordinal, cd.derived, cd.min_items, cd.max_items);
                Console.WriteLine(line);
            }


            foreach (row r in table.items)
            {
                string o = "";
                foreach (column c in r.items)
                {
                    foreach (data_item d in c.items)
                    {
                        o += string.Format("{0}.{1}={2},", c.index, d.index, d.value);
                    }
                }
                Console.WriteLine(o);
            }
        }
Ejemplo n.º 3
0
            public column(string data, table_config config, int index)
            {
                this.index  = index;
                this.config = config;
                //this.items = new items();
                string[] column_elements = data.Split(config.array_delimiter);

                //loop through the elements
                int element_index            = 0;
                column_definition column_def = config.columns.get_column_by_ordinal(index);

                if (column_def == null)
                {
                    // if we have no column. its because it wasnt defined. so add a default name based on index
                    // then set it to derived and arry type, the least restrictive
                    bool new_col_results = config.columns.Add("COLUMN_" + index, index, index, 2, true);
                    if (false == new_col_results)
                    {
                        //error
                    }

                    column_def = config.columns.get_column_by_ordinal(index);
                    if (column_def == null)
                    {
                        //cant add it at all error
                    }
                }
                if (column_def.type == 1 && column_elements.Length > 1)
                {
                    this.error = true;
                }

                foreach (string element in column_elements)
                {
                    //process the data_item
                    data_item new_item = new data_item(element, config, element_index);
                    items.Add(new_item);
                    if (new_item.error == true)
                    {
                        this.error = true;
                    }
                } //end elements loop
            }
Ejemplo n.º 4
0
            public data_item(string data, table_config config, int index)
            {
                this.index = index;
                string[] tokens = data.Split(config.key_value_delimiter, 2);

                //is it a key value?, there will never be an option other than 0,1,2.
                switch (tokens.Length)
                {
                case 0:
                    this.error = true;                                   //error nothing?
                    break;

                case 1:
                    this.value    = tokens[0].Trim();                           //must not be a key value. so its just a value
                    this.is_value = true;
                    break;

                case 2:
                    this.key          = tokens[0].Trim();                       // key value
                    this.value        = tokens[1].Trim();
                    this.is_key_value = true;
                    break;
                }
            } //end constructor
Ejemplo n.º 5
0
            public row(string data, table_config config, int index)
            {
                this.config = config;
                //clean data by trimming
                this.index = index;
                string clean_row = data.Trim();


                //if its empty skip. we dont need it
                if (clean_row.Length == 0)
                {
                    return;
                }

                //comments are skipped...
                if (clean_row[0] == config.comment_delimiter)
                {
                    return;
                }


                //process whats left into columns
                //split the ros on the column delimiter
                string[] raw_colums = data.Split(config.column_delimiter);

                int column_index = 0;

                //loop through the columns and append them
                foreach (string raw_column in raw_colums)
                {
                    column processed_column = new column(raw_column, config, column_index);
                    //add proccessed row, with or without errors
                    items.Add(processed_column);
                    ++column_index;
                } //end column loop
            }     //end constructor