예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the value for persisting, and returns the same value, potentially modified
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public virtual string SetStringValue(FieldInstance newFieldInstance)
        {
            newFieldInstance.Value = (newFieldInstance.ValueAsString ?? string.Empty).Trim();
            var oldFieldValue = MetaDataFieldValues.Find(v => v.FieldId == newFieldInstance.FieldId);

            if (oldFieldValue == newFieldInstance)
            {
                return(newFieldInstance.ValueAsString);
            }

            string oldValue = null;

            if (oldFieldValue == null)
            {
                MetaDataFieldValues.Add(newFieldInstance);
            }
            else
            {
                oldValue = oldFieldValue.ValueAsString;
                oldFieldValue.Copy(newFieldInstance);
            }

            LoadFileSizeAndDateModified();
            OnMetadataValueChanged(newFieldInstance.FieldId, oldValue, newFieldInstance.ValueAsString);
            return(newFieldInstance.ValueAsString);            //overrides may do more
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the value for persisting, and returns the same value, potentially modified
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public virtual object SetValue(string key, object newValue, out string failureMessage)
        {
            failureMessage = null;

            object oldFieldValue    = null;
            var    oldFieldInstance = MetaDataFieldValues.Find(v => v.FieldId == key);

            if (oldFieldInstance == null)
            {
                if (newValue == null)
                {
                    return(null);
                }

                MetaDataFieldValues.Add(new FieldInstance(key, newValue));
            }
            else if (oldFieldInstance.Value.Equals(newValue))
            {
                return(newValue);
            }
            else
            {
                oldFieldValue = oldFieldInstance.Value;
            }

            LoadFileSizeAndDateModified();
            OnMetadataValueChanged(key, oldFieldValue, newValue);

            if (oldFieldInstance != null)
            {
                oldFieldInstance.Value = newValue;
            }

            return(newValue);
        }