Ejemplo n.º 1
0
        void ProcessSystemRecord(IDataReader rdr)
        {
            ExpandoObject _createModelInfo(String elem)
            {
                return(_root.GetOrCreate <ExpandoObject>("$ModelInfo").GetOrCreate <ExpandoObject>(elem));
            }

            // from 1
            for (Int32 i = 1; i < rdr.FieldCount; i++)
            {
                var fn      = rdr.GetName(i);
                var fi      = new FieldInfo(fn);
                var dataVal = rdr.GetValue(i);
                switch (fi.SpecType)
                {
                case SpecType.Id:
                    _sys.Add("Id", dataVal);
                    break;

                case SpecType.PageSize:
                    Int32 pageSize = (Int32)dataVal;
                    if (!String.IsNullOrEmpty(fi.TypeName))
                    {
                        _createModelInfo(fi.TypeName).Set("PageSize", pageSize);
                    }
                    else
                    {
                        // for compatibility with older versions
                        _sys.Add("PageSize", pageSize);
                    }
                    break;

                case SpecType.Offset:
                    if (String.IsNullOrEmpty(fi.TypeName))
                    {
                        throw new DataLoaderException("For the Offset modifier, the field name must be specified");
                    }
                    Int32 offset = (Int32)dataVal;
                    _createModelInfo(fi.TypeName).Set("Offset", offset);
                    break;

                case SpecType.HasRows:
                    if (String.IsNullOrEmpty(fi.TypeName))
                    {
                        throw new DataLoaderException("For the HasRows modifier, the field name must be specified");
                    }
                    if (dataVal is Int32 intHasRows)
                    {
                        _createModelInfo(fi.TypeName).Set("HasRows", intHasRows != 0);
                    }
                    else if (dataVal is Boolean boolHasRows)
                    {
                        _createModelInfo(fi.TypeName).Set("HasRows", boolHasRows);
                    }
                    else
                    {
                        throw new DataLoaderException("Invalid data type for the TotalRows modifier. Expected 'int' or 'bit'");
                    }
                    break;

                case SpecType.SortDir:
                    if (String.IsNullOrEmpty(fi.TypeName))
                    {
                        throw new DataLoaderException("For the SortDir modifier, the field name must be specified");
                    }
                    String dir = dataVal.ToString();
                    _createModelInfo(fi.TypeName).Set("SortDir", dir);
                    break;

                case SpecType.SortOrder:
                    if (String.IsNullOrEmpty(fi.TypeName))
                    {
                        throw new DataLoaderException("For the SortOrder modifier, the field name must be specified");
                    }
                    String order = dataVal.ToString();
                    _createModelInfo(fi.TypeName).Set("SortOrder", order);
                    break;

                case SpecType.GroupBy:
                    if (String.IsNullOrEmpty(fi.TypeName))
                    {
                        throw new DataLoaderException("For the Group modifier, the field name must be specified");
                    }
                    String group = dataVal.ToString();
                    _createModelInfo(fi.TypeName).Set("GroupBy", group);
                    break;

                case SpecType.Filter:
                    if (String.IsNullOrEmpty(fi.TypeName))
                    {
                        throw new DataLoaderException("For the Filter modifier, the field name must be specified");
                    }
                    Object filter = dataVal;
                    var    xs     = fi.TypeName.Split('.');
                    if (xs.Length < 2)
                    {
                        throw new DataLoaderException("For the Filter modifier, the field name must be as ItemProperty.FilterProperty");
                    }
                    var fmi = _createModelInfo(xs[0]).GetOrCreate <ExpandoObject>("Filter");
                    if (filter is DateTime)
                    {
                        filter = DataHelpers.DateTime2StringWrap(filter);
                    }
                    else if (filter is String)
                    {
                        filter = _localizer.Localize(filter.ToString());
                    }
                    for (Int32 ii = 1; ii < xs.Length; ii++)
                    {
                        if (ii == xs.Length - 1)
                        {
                            fmi.Set(xs[ii], filter);
                        }
                        else
                        {
                            fmi = fmi.GetOrCreate <ExpandoObject>(xs[ii]);
                        }
                    }
                    break;

                case SpecType.ReadOnly:
                    _sys.Add("ReadOnly", DataHelpers.SqlToBoolean(dataVal));
                    break;

                case SpecType.Copy:
                    _sys.Add("Copy", DataHelpers.SqlToBoolean(dataVal));
                    break;

                default:
                    _sys.Add(fn, dataVal);
                    break;
                }
            }
        }
 public Object DateTime2StringWrap(Object val)
 {
     return(DataHelpers.DateTime2StringWrap(val));
 }