示例#1
0
 public FieldBase(FieldType Type, FieldBase Base)
 {
     this.Type = Type;
     this.Name = Type.Name;
     this.TenantID = Configure.GetTenantResolutionProvider().GetTenantID();
     LoadUpValues(Base);
 }
 public FieldEntityReference(FieldType Type, FieldBase Base, EntityBase Entity, Db.IDbContext ctx = null)
     : base(Type, Base, Entity, ctx)
 {
     if (Type.DataType != DataType.EntityReference)
     {
         throw new ArgumentOutOfRangeException("Cannot create an entity reference field from a non-entity-reference type.");
     }
 }
 public FieldLazyBinary(FieldType Type, FieldBase Base, EntityBase Entity, Db.IDbContext ctx = null)
     : base(Type, Base, Entity, ctx)
 {
     if (Type.DataType != DataType.Binary)
     {
         throw new ArgumentOutOfRangeException("Cannot create a binary field from a non-binary type.");
     }
 }
示例#4
0
 public FieldString(FieldType Type, FieldBase Base, EntityBase Entity, Db.IDbContext ctx = null)
     : base(Type, Base, Entity, ctx)
 {
     if (Type.DataType != DataType.Text)
     {
         throw new ArgumentOutOfRangeException("Cannot create a string field from a non-string type.");
     }
 }
 public FieldDecimal(FieldType Type, FieldBase Base, EntityBase Entity, Db.IDbContext ctx = null)
     : base(Type, Base, Entity, ctx)
 {
     if (Type.DataType != DataType.Decimal)
     {
         throw new ArgumentOutOfRangeException("Cannot create a decimal field from a non-decimal type.");
     }
 }
示例#6
0
 public FieldLookup(FieldType Type, FieldBase Base, EntityBase Entity, Db.IDbContext ctx = null)
     : base(Type, Base, Entity, ctx)
 {
     if (Type.DataType != DataType.Lookup)
     {
         throw new ArgumentOutOfRangeException("Cannot create a lookup field from a non-lookup type.");
     }
 }
示例#7
0
 public FieldBase(FieldType Type, FieldBase Base, EntityBase Entity, IDbContext ctx = null)
 {
     this.Type = Type;
     this.Name = Type.Name;
     this.Entity = Entity;
     this.TenantID = Configure.GetTenantResolutionProvider().GetTenantID();
     LoadUpValues(Base);
     TryLoadFieldMeta(ctx);
 }
示例#8
0
        /// <summary>
        /// Compares the value of this binary field to another and return true if they are identical, byte for byte.
        /// </summary>
        /// <param name="OtherField">The other field.</param>
        /// <returns>true if the field values are identical, false otherwise</returns>
        public override bool IsIdenticalTo(FieldBase OtherField)
        {
            if (OtherField == null)
            {
                Log.Warn("Trying to compare Field to a null Field. FieldID: {0}",
                        FieldID.HasValue ? FieldID.Value.ToString() : "null");

                throw new ArgumentNullException(nameof(OtherField));
            }
            if (OtherField.Type.DataType != this.Type.DataType)
            {
                Log.Warn("Trying to compare Field to a Field of a different type. FieldID: {0}, Other FieldID: {1}, Field Type: {2}, Other Field Type: {3}",
                    FieldID.HasValue ? FieldID.Value.ToString() : "null",
                    OtherField.FieldID.HasValue ? OtherField.FieldID.Value.ToString() : "null",
                    Type.Name, OtherField.Type.Name);

                throw new InvalidOperationException("Cannot compare two fields of different types.");
            }

            if (((IField)this).Value == null && ((IField)OtherField).Value == null) // Both are null, identical
            {
                return true;
            }

            if ((((IField)this).Value == null && ((IField)OtherField).Value != null) ||  // If a is null and b is not, not identical
                 (((IField)this).Value != null && ((IField)OtherField).Value == null))   // If b is null and a is not, not identical
            {
                return false;
            }

            // Both are not null, use byte-by-byte comparison.
            return this.Value.SequenceEqual(((FieldBinary)OtherField).Value);
        }
示例#9
0
        /// <summary>
        /// Gets the name of the field bound to this member on the form
        /// if it exists, otherwise null.
        /// </summary>
        /// <param name="Field">The field to search for</param>
        /// <returns>The name of the bound field, or null</returns>
        public string GetFormFieldNameIfBound(FieldBase Field)
        {
            if (Field == null)
            {
                return null;
            }

            var AllFields = GetBoundFields();

            foreach (var _Field in AllFields)
            {
                var BoundField = (FieldBase)GetBoundField(_Field.Name);
                if (BoundField.Entity.Item.Type == Field.Entity.Item.Type &&
                    BoundField.Entity.Type == Field.Entity.Type &&
                    BoundField.Type == Field.Type)
                {
                    return _Field.Name;
                }
            }

            return null;
        }
 public ValidationResult(FieldBase Field, string Message)
 {
     this._Field = Field;
     this.Message = Message;
 }
示例#11
0
        protected void LoadUpValues(FieldBase Base)
        {
            Log.Trace("Loading values for Field. FieldID: {0}",
                Base == null || !Base.FieldID.HasValue ? "null" : Base.FieldID.Value.ToString());

            this.TenantID = Configure.GetTenantResolutionProvider().GetTenantID();
            if (Base == null)
            {
                this.FieldID      = null;

                this.ValueString  = null;
                this.ValueDate    = null;
                this.ValueDecimal = null;
                this.ValueBool    = null;
                this.ValueLookup  = null;
                this.ValueBinary  = null;
                this.ValueEntityReference = null;
                this.ValueItemReference = null;
            }
            else
            {
                if (Base.TenantID != this.TenantID)
                {
                    Log.Fatal("TenantID Does not match. FieldID: {0}, Global TenantID: {1}, Other Field TenantID : {2}",
                        this.FieldID, this.TenantID, Base.TenantID);
                    throw new FatalException("Data error.");
                }

                this.FieldID      = Base.FieldID;

                this.ValueString  = Base.ValueString;
                this.ValueDate    = Base.ValueDate;
                this.ValueDecimal = Base.ValueDecimal;
                this.ValueBool    = Base.ValueBool;
                this.ValueLookup  = Base.ValueLookup;
                this.ValueBinary  = Base.ValueBinary;
                this.ValueEntityReference = Base.ValueEntityReference;
                this.ValueItemReference = Base.ValueItemReference;

                this.Guid         = Base.Guid;
            }
            this.Dirty = false;

            if (this is ISerializableField)
            {
                ((ISerializableField)this).DeserializeField();
            }

            RefreshOriginalValues();
        }
示例#12
0
        /// <summary>
        /// Compares the value of this field to another and return true if they are identical. This
        /// method may be overridden in subclasses.
        /// </summary>
        /// <param name="OtherField">The other field.</param>
        /// <returns>true if the field values are identical, false otherwise</returns>
        public virtual bool IsIdenticalTo(FieldBase OtherField)
        {
            if (OtherField == null)
            {
                Log.Warn("Trying to compare Field to a null Field. FieldID: {0}",
                    FieldID.HasValue ? FieldID.Value.ToString() : "null");

                throw new ArgumentNullException(nameof(OtherField));
            }
            if (OtherField.Type.DataType != this.Type.DataType)
            {
                Log.Warn("Trying to compare Field to a Field of a different type. FieldID: {0}, Other FieldID: {1}, Field Type: {2}, Other Field Type: {3}",
                    FieldID.HasValue ? FieldID.Value.ToString() : "null",
                    OtherField.FieldID.HasValue ? OtherField.FieldID.Value.ToString() : "null",
                    Type.Name, OtherField.Type.Name);

                throw new InvalidOperationException("Cannot compare two fields of different types.");
            }
            if (OtherField.TenantID != this.TenantID)
            {
                Log.Error("TenantID Does not match. FieldID: {0}, Other Field ID: {1}, TenantID: {2}, Other TenantID: {3}",
                    FieldID, OtherField.FieldID, TenantID, OtherField.TenantID);
                throw new FatalException("Data error.");
            }

            if (((IField)this).Value == null && ((IField)OtherField).Value == null) // Both are null, identical
            {
                return true;
            }

            if ((((IField)this).Value == null && ((IField)OtherField).Value != null) ||  // If a is null and b is not, not identical
                (((IField)this).Value != null && ((IField)OtherField).Value == null))    // If b is null and a is not, not identical
            {
                return false;
            }

            // Both are not null, use the default comparison
            return ((IField)this).Value.Equals(((IField)OtherField).Value);
        }
示例#13
0
 public void FillFromDatabase(EntityBase Entity, FieldBase Field, IDbContext ctx = null)
 {
     if (Entity.TenantID != this.TenantID ||
         Field.TenantID != this.TenantID)
     {
         Log.Fatal("TenantID Does not match. EntityID: {0}, Entity TenantID {1}, Field ID: {2}, Field TenantID : {3}, this FieldID: {4}, this TenantID {5}",
             Entity.EntityID, Entity.TenantID, Field.FieldID, Field.TenantID, this.FieldID, this.TenantID);
         throw new FatalException("Data error.");
     }
     FieldBase Base = PersistenceService.RetreiveSingleFieldOrDefault(Entity, Field.Type, ctx);
     LoadUpValues(Base);
 }