Esempio n. 1
0
        // Bind
        internal void Bind(IntervalLogger il, IEntity instance)
        {
            this.CurrentSchema = instance;

            foreach(Column column in instance.__Columns) {
                this.CurrentColumn = column;

                string asName = Contains(column.ColumnName)
                    ? column.ColumnName
                    : Contains(column.Alias)
                        ? column.Alias
                        : null;
                if(null == asName) { continue; }

                try {
                    object val = null;

                    switch(column.Format) {
                        case DataFormat.String:
                            val = this.GetString(asName);
                            break;
                        case DataFormat.DateTime:
                            val = this.GetDateTime(asName);
                            break;
                        case DataFormat.Boolean:
                            val = this.GetInteger(asName) == 1
                                ? true
                                : false;
                            break;
                        case DataFormat.Char:
                            val = this.GetString(asName);
                            break;
                        case DataFormat.Byte:
                            val = this.GetByte(asName);
                            break;
                        case DataFormat.Short:
                            val = this.GetShort(asName);
                            break;
                        case DataFormat.Integer:
                            val = this.GetInteger(asName);
                            break;
                        case DataFormat.Long:
                            val = this.GetLong(asName);
                            break;
                        case DataFormat.Float:
                            val = this.GetFloat(asName);
                            break;
                        case DataFormat.Double:
                            val = this.GetDouble(asName);
                            break;
                        case DataFormat.Decimal:
                            val = this.GetDecimal(asName);
                            break;
                        case DataFormat.ByteArray:
                            val = this.GetBytes(asName);
                            break;
                        case DataFormat.Color:
                            int color = this.GetInteger(asName);
                            val = Color.FromArgb(color);
                            break;
                        case DataFormat.Guid:
                            val = this.GetGuid(asName);
                            break;
                        case DataFormat.Enum:
                            string original = this.GetString(asName);
                            if(original.IsNullOrEmpty()) {
                                original = string.Empty;
                            }

                            var enumRef = EnumCache.Get(
                                column.Property.PropertyType
                            );
                            var enumItem = enumRef.Get(original);

                            if(
                                !original.IsNullOrEmpty()
                                &&
                                null == enumItem) {
                                LogRecord
                                    .Create()
                                    .SetMessage(
                                        "Dirty enum value alert!"
                                    )
                                    .AddRange(Currents)
                                    .Add("Dirty Value", original)
                                    .Add(
                                        "Possible Values",
                                        enumRef
                                            .Items
                                            .Join(x => x.Name, ", ")
                                    )
                                    .Error();
                            }

                            var enumVal = null == enumItem
                                ? enumRef.DefaultValue
                                : enumItem.Name;
                            val = Enum.Parse(
                                column.Property.PropertyType,
                                enumVal,
                                true
                            );
                            break;
                        case DataFormat.TimeSpan:
                            val = this.GetValue(asName).ToTimeSpan();
                            break;

                        default:
                            throw new NotImplementedException(
                                LogRecord
                                    .Create()
                                    .SetMessage(
                                        "Unhandled Property Type: ",
                                        column.Property.PropertyType.Name,
                                        " at ",
                                        column.EntityFullName
                                    )
                                    .Error()
                                    .Message
                            );
                    }
                    column.Property.SetValue(
                        instance, val, new Object[0]
                    );

                } catch(Exception ex) {
                    WriteErrorMessage("Bind", ex);
                }
            }
        }
Esempio n. 2
0
        // Bind
        internal void Bind(IntervalLogger il, IEntity instance)
        {
            this.CurrentSchema = instance;

            foreach (Column column in instance.__Columns)
            {
                this.CurrentColumn = column;

                string asName = Contains(column.ColumnName)
                                        ? column.ColumnName
                                        : Contains(column.Alias)
                                                ? column.Alias
                                                : null;
                if (null == asName)
                {
                    continue;
                }

                try {
                    object val = null;

                    switch (column.Format)
                    {
                    case DataFormat.String:
                        val = this.GetString(asName);
                        break;

                    case DataFormat.DateTime:
                        val = this.GetDateTime(asName);
                        break;

                    case DataFormat.Boolean:
                        val = this.GetInteger(asName) == 1
                                                                ? true
                                                                : false;
                        break;

                    case DataFormat.Char:
                        val = this.GetString(asName);
                        break;

                    case DataFormat.Byte:
                        val = this.GetByte(asName);
                        break;

                    case DataFormat.Short:
                        val = this.GetShort(asName);
                        break;

                    case DataFormat.Integer:
                        val = this.GetInteger(asName);
                        break;

                    case DataFormat.Long:
                        val = this.GetLong(asName);
                        break;

                    case DataFormat.Float:
                        val = this.GetFloat(asName);
                        break;

                    case DataFormat.Double:
                        val = this.GetDouble(asName);
                        break;

                    case DataFormat.Decimal:
                        val = this.GetDecimal(asName);
                        break;

                    case DataFormat.ByteArray:
                        val = this.GetBytes(asName);
                        break;

                    case DataFormat.Color:
                        int color = this.GetInteger(asName);
                        val = Color.FromArgb(color);
                        break;

                    case DataFormat.Guid:
                        val = this.GetGuid(asName);
                        break;

                    case DataFormat.Enum:
                        string original = this.GetString(asName);
                        if (original.IsNullOrEmpty())
                        {
                            original = string.Empty;
                        }

                        var enumRef = EnumCache.Get(
                            column.Property.PropertyType
                            );
                        var enumItem = enumRef.Get(original);

                        if (
                            !original.IsNullOrEmpty()
                            &&
                            null == enumItem)
                        {
                            LogRecord
                            .Create()
                            .SetMessage(
                                "Dirty enum value alert!"
                                )
                            .AddRange(Currents)
                            .Add("Dirty Value", original)
                            .Add(
                                "Possible Values",
                                enumRef
                                .Items
                                .Join(x => x.Name, ", ")
                                )
                            .Error();
                        }

                        var enumVal = null == enumItem
                                                                ? enumRef.DefaultValue
                                                                : enumItem.Name;
                        val = Enum.Parse(
                            column.Property.PropertyType,
                            enumVal,
                            true
                            );
                        break;

                    case DataFormat.TimeSpan:
                        val = this.GetValue(asName).ToTimeSpan();
                        break;

                    default:
                        throw new NotImplementedException(
                                  LogRecord
                                  .Create()
                                  .SetMessage(
                                      "Unhandled Property Type: ",
                                      column.Property.PropertyType.Name,
                                      " at ",
                                      column.EntityFullName
                                      )
                                  .Error()
                                  .Message
                                  );
                    }
                    column.Property.SetValue(
                        instance, val, new Object[0]
                        );
                } catch (Exception ex) {
                    WriteErrorMessage("Bind", ex);
                }
            }
        }