Ejemplo n.º 1
0
        public static bool AddMultiValue <T>(this Cursor cursor, Columnid columnId, T newValue, IEqualityComparer <T> equalityComparer)
        {
            // Note: Must be in transaction and record must be in editing state.
            ColumnAccessor record        = cursor.EditRecord;
            int            insertAtIndex = 0;
            bool           doUpdate      = true;
            // Move after the last newValue, if any
            // HACK: Report bad behavior of record.SizeOf(columnId, insertAtIndex): It returns 0 even if there has been a value inserted.
            object currentObject;

            while ((currentObject = record[columnId, insertAtIndex]) != DBNull.Value)
            {
                T currentValue = (T)currentObject;
                if (equalityComparer.Equals(currentValue, newValue))
                {
                    // Record already contains the newValue to be inserted, so skip the update
                    doUpdate = false;
                    break;
                }
                insertAtIndex++;
            }
            if (doUpdate)
            {
                record[columnId, insertAtIndex] = newValue;
            }
            return(doUpdate);
        }
Ejemplo n.º 2
0
        public void UpdateAttributeMeta(string[] attributeNames, long usn, DateTime time)
        {
            Validator.AssertNotNull(attributeNames, "attributeNames");

            ColumnAccessor record = this.cursor.EditRecord;

            // Update the uSNChanged attribute
            this.SetAttribute <long>(CommonDirectoryAttributes.USNChanged, usn);

            // Update the whenChanged attribute
            this.SetAttribute <long>(CommonDirectoryAttributes.WhenChanged, time.ToGeneralizedTime());

            // Update the replPropertyMetaData attribute (read-modify-write)
            AttributeMetadataCollection meta;

            this.ReadAttribute(CommonDirectoryAttributes.PropertyMetaData, out meta);

            foreach (var attributeName in attributeNames)
            {
                // We go through all attributes that are changed in this transaction
                int attributeId = this.context.Schema.FindAttribute(attributeName).Id.Value;
                meta.Update(attributeId, this.context.DomainController.InvocationId, time, usn);
            }

            this.SetAttribute(CommonDirectoryAttributes.PropertyMetaData, meta.ToByteArray());
        }
Ejemplo n.º 3
0
        public bool HasChanged(IGenericColumns current, object updated)
        {
            var objectValue = ObjectAccessor.ReadProperty(updated);
            var columnValue = ColumnAccessor.ReadProperty(current);

            if (columnValue == null)
            {
                return(objectValue != null);
            }

            return(!columnValue.Equals(objectValue));
        }
Ejemplo n.º 4
0
        public void UpdateAttributeMeta(string attributeName, long usn, DateTime time)
        {
            ColumnAccessor record = this.cursor.EditRecord;

            // Update the uSNChanged attribute
            this.SetAttribute <long>(CommonDirectoryAttributes.USNChanged, usn);
            // Update the whenChanged attribute
            // TODO: Add time as parameter?
            DateTime now = DateTime.Now;

            this.SetAttribute <long>(CommonDirectoryAttributes.WhenChanged, now.ToGeneralizedTime());
            // Update the replPropertyMetaData attribute
            AttributeMetadataCollection meta;

            this.ReadAttribute(CommonDirectoryAttributes.PropertyMetaData, out meta);
            int attributeId = this.context.Schema.FindAttribute(attributeName).Id.Value;

            meta.Update(attributeId, this.context.DomainController.InvocationId, now, usn);
            this.SetAttribute(CommonDirectoryAttributes.PropertyMetaData, meta.ToByteArray());
        }
Ejemplo n.º 5
0
        public static bool SetValue <T>(this Cursor cursor, Columnid columnId, Nullable <T> newValue) where T : struct
        {
            // Note: Must be in transaction and record must be in editing state.
            ColumnAccessor record       = cursor.EditRecord;
            object         currentValue = record[columnId];
            bool           hasChanged   = currentValue != DBNull.Value ? !currentValue.Equals(newValue) : newValue != null;

            if (hasChanged)
            {
                if (newValue.HasValue)
                {
                    record[columnId] = newValue.Value;
                }
                else
                {
                    record[columnId] = DBNull.Value;
                }
            }
            return(hasChanged);
        }
Ejemplo n.º 6
0
        public static bool SetValue <T>(this Cursor cursor, Columnid columnId, T newValue, Func <T, T, bool> equalityComparer) where T : class
        {
            ColumnAccessor record = cursor.EditRecord;
            T    currentValue     = (T)record[columnId];
            bool hasChanged       = !equalityComparer.Invoke(currentValue, newValue);

            if (hasChanged)
            {
                if (newValue != null)
                {
                    record[columnId] = newValue;
                }
                else
                {
                    // TODO: Test nulling an attribute
                    record[columnId] = DBNull.Value;
                }
            }
            return(hasChanged);
        }
Ejemplo n.º 7
0
        public static bool SetValue <T>(this Cursor cursor, Columnid columnId, T newValue, IEqualityComparer <T> equalityComparer) where T : class
        {
            // Retrieve the current value and compare it to the new one
            ColumnAccessor record          = cursor.EditRecord;
            object         currentRawValue = record[columnId];
            T    currentValue = currentRawValue != DBNull.Value ? (T)record[columnId] : null;
            bool hasChanged   = !equalityComparer.Equals(currentValue, newValue);

            if (hasChanged)
            {
                if (newValue != null)
                {
                    record[columnId] = newValue;
                }
                else
                {
                    record[columnId] = DBNull.Value;
                }
            }
            return(hasChanged);
        }
Ejemplo n.º 8
0
        public void WriteValue(object source, IGenericColumns target)
        {
            var value = ObjectAccessor.ReadProperty(source);

            ColumnAccessor.WriteProperty(target, value);
        }
Ejemplo n.º 9
0
        public void ReadValue(IGenericColumns source, object target)
        {
            var value = ColumnAccessor.ReadProperty(source);

            ObjectAccessor.WriteProperty(target, value);
        }