Пример #1
0
        /// <summary>
        /// Initialize the column metadata for the result set.
        /// </summary>
        public void InitializeColumns(object obj)
        {
            LogUtilities.LogFunctionEntrance(Log);

            //get the info the build the columns
            ResultEntityType = obj.GetType();
            ResultFields     = ResultEntityType.GetFields().ToList();

            //fields to remove that we do not want in results
            List <FieldInfo> remove = new List <FieldInfo>();

            //parse the fields
            foreach (var field in ResultFields)
            {
                //make sure this not collection type
                if (field.FieldType.GetInterface("ICollection") != null)
                {
                    //remove this field
                    remove.Add(field);
                }
                else
                {
                    //create the column
                    DSIColumn column = new DSIColumn(TypeMetadataHelper.CreateTypeMetadata(field.FieldType));
                    column.IsNullable = Nullability.Nullable;
                    column.Catalog    = m_Properties.Catalog;
                    column.Schema     = Driver.B_SCHEMA;
                    column.TableName  = "Results";
                    column.Name       = field.Name;
                    column.Label      = column.Name;
                    if (field.FieldType == typeof(string))
                    {
                        column.Size         = 1000;
                        column.IsSearchable = Searchable.Searchable;
                    }
                    else
                    {
                        column.IsSearchable = Searchable.PredicateBasic;
                    }
                    m_Columns.Add(column);
                }
            }
            //remove the fields
            foreach (var field in remove)
            {
                ResultFields.Remove(field);
            }
        }
Пример #2
0
        /// <summary>
        /// Initialize the column metadata for the result set.
        /// </summary>
        public void InitializeColumns(object obj)
        {
            LogUtilities.LogFunctionEntrance(Log);

            //get the info the build the columns
            ResultEntityType = obj.GetType();
            ResultFields = ResultEntityType.GetFields().ToList();

            //fields to remove that we do not want in results
            List<FieldInfo> remove = new List<FieldInfo>();

            //parse the fields
            foreach(var field in ResultFields)
            {
                //make sure this not collection type
                if (field.FieldType.GetInterface("ICollection") != null)
                {
                    //remove this field
                    remove.Add(field);
                }
                else
                {
                    //create the column
                    DSIColumn column = new DSIColumn(TypeMetadataHelper.CreateTypeMetadata(field.FieldType));
                    column.IsNullable = Nullability.Nullable;
                    column.Catalog = m_Properties.Catalog;
                    column.Schema = Driver.B_SCHEMA;
                    column.TableName = "Results";
                    column.Name = field.Name;
                    column.Label = column.Name;
                    if (field.FieldType == typeof(string))
                    {
                        column.Size = 1000;
                        column.IsSearchable = Searchable.Searchable;
                    }
                    else
                        column.IsSearchable = Searchable.PredicateBasic;
                    m_Columns.Add(column);
                }
            }
            //remove the fields
            foreach (var field in remove)
            {
                ResultFields.Remove(field);
            }
        }
Пример #3
0
        /// <summary>
        /// Initialize the fake data
        /// </summary>
        public void InitializeFakeData(string sql)
        {
            LogUtilities.LogFunctionEntrance(Log);

            List <object> fake_row = new List <object>();

            string sql_no_select = sql.Substring(sql.IndexOf("SELECT ") + 7);
            string sql_no_top    = sql_no_select;

            if (sql_no_select.IndexOf("TOP ") != -1)
            {
                sql_no_top = sql_no_select.Substring(sql_no_select.IndexOf("TOP ") + 4).Trim();
                sql_no_top = sql_no_top.Substring(sql_no_top.IndexOf(" ") + 1).Trim();
            }
            string sql_no_from = sql_no_top.Substring(0, sql_no_top.IndexOf("FROM "));

            string[] columns_with_alias = sql_no_from.Split(',');

            foreach (var field_alias in columns_with_alias)
            {
                string[] aliases = field_alias.Split(new string[] { " AS ", " as " }, StringSplitOptions.None);

                string field = "";
                string alias = "";
                if (aliases.Length > 0)
                {
                    field = aliases[0].Trim();
                }
                if (aliases.Length > 1)
                {
                    alias = aliases[1].Trim();
                }

                field = field.Replace("\"", "");
                alias = alias.Replace("\"", "");

                string table = "";
                if (field.IndexOf('.') != -1)
                {
                    table = field.Substring(0, field.IndexOf('.'));
                    field = field.Substring(field.IndexOf('.') + 1);
                }

                var  column_meta = m_TableColumns.Where(c => c.Table == table && c.Column == field).FirstOrDefault();
                Type type;
                bool added = false;
                if (column_meta != null)
                {
                    type = Type.GetType(column_meta.DataType);
                }
                else
                {
                    double num;
                    if (double.TryParse(field, out num))
                    {
                        type = typeof(double);
                        fake_row.Add(num);
                        added = true;
                    }
                    else
                    {
                        type = typeof(string);
                        fake_row.Add(field);
                    }
                }
                if (!added)
                {
                    if (type == typeof(string))
                    {
                        fake_row.Add("FakeData");
                    }
                    else if (type == typeof(DateTime))
                    {
                        fake_row.Add(DateTime.UtcNow);
                    }
                    else if (type == typeof(bool))
                    {
                        byte b = 0;
                        fake_row.Add(b);
                    }
                    else
                    {
                        fake_row.Add(Activator.CreateInstance(type));
                    }
                }


                DSIColumn column = new DSIColumn(TypeMetadataHelper.CreateTypeMetadata(type));
                column.IsNullable = Nullability.Nullable;
                column.Catalog    = m_Properties.Catalog;
                column.Schema     = Driver.B_SCHEMA;
                column.TableName  = "Results";
                column.Name       = alias;
                column.Label      = alias;
                if (type == typeof(string))
                {
                    column.Size         = 1000;
                    column.IsSearchable = Searchable.Searchable;
                }
                else
                {
                    column.IsSearchable = Searchable.PredicateBasic;
                }
                m_Columns.Add(column);
            }
            RowCount = 10;
            for (int x = 0; x < RowCount; x++)
            {
                m_Data.Add(fake_row);
            }
        }
Пример #4
0
        /// <summary>
        /// Initialize the fake data
        /// </summary>
        public void InitializeFakeData(string sql)
        {
            LogUtilities.LogFunctionEntrance(Log);

            List<object> fake_row = new List<object>();

            string sql_no_select = sql.Substring(sql.IndexOf("SELECT ") + 7);
            string sql_no_top = sql_no_select;
            if (sql_no_select.IndexOf("TOP ") != -1)
            {
                sql_no_top = sql_no_select.Substring(sql_no_select.IndexOf("TOP ") + 4).Trim();
                sql_no_top = sql_no_top.Substring(sql_no_top.IndexOf(" ") + 1).Trim();
            }
            string sql_no_from = sql_no_top.Substring(0, sql_no_top.IndexOf("FROM "));
            string[] columns_with_alias = sql_no_from.Split(',');

            foreach (var field_alias in columns_with_alias)
            {
                string[] aliases = field_alias.Split(new string[] { " AS ", " as " }, StringSplitOptions.None);

                string field = "";
                string alias = "";
                if (aliases.Length > 0)
                    field = aliases[0].Trim();
                if (aliases.Length > 1)
                    alias = aliases[1].Trim();

                field = field.Replace("\"", "");
                alias = alias.Replace("\"", "");

                string table = "";
                if (field.IndexOf('.') != -1)
                {
                    table = field.Substring(0, field.IndexOf('.'));
                    field = field.Substring(field.IndexOf('.') + 1);

                }

                var column_meta = m_TableColumns.Where(c => c.Table == table && c.Column == field).FirstOrDefault();
                Type type;
                bool added = false;
                if (column_meta != null)
                {
                    type = Type.GetType(column_meta.DataType);
                    
                }
                else
                {
                    double num;
                    if (double.TryParse(field, out num))
                    {
                        type = typeof(double);
                        fake_row.Add(num);
                        added = true;
                    }
                    else
                    {
                        type = typeof(string);
                        fake_row.Add(field);
                    }
                }
                if (!added)
                {
                    if (type == typeof(string))
                    {
                        fake_row.Add("FakeData");
                    }
                    else if (type == typeof(DateTime))
                    {
                        fake_row.Add(DateTime.UtcNow);
                    }
                    else if (type == typeof(bool))
                    {
                        byte b = 0;
                        fake_row.Add(b);
                    }
                    else
                    {
                        fake_row.Add(Activator.CreateInstance(type));
                    }
                }


                DSIColumn column = new DSIColumn(TypeMetadataHelper.CreateTypeMetadata(type));
                column.IsNullable = Nullability.Nullable;
                column.Catalog = m_Properties.Catalog;
                column.Schema = Driver.B_SCHEMA;
                column.TableName = "Results";
                column.Name = alias;
                column.Label = alias;
                if (type == typeof(string))
                {
                    column.Size = 1000;
                    column.IsSearchable = Searchable.Searchable;
                }
                else
                    column.IsSearchable = Searchable.PredicateBasic;
                m_Columns.Add(column);
            }
            RowCount = 10;
            for(int x=0;x<RowCount;x++)
                m_Data.Add(fake_row);
            
        }