Exemple #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
        }
Exemple #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);
        }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>Removes the given (custom) field from this file's meta-data and also
        /// updates all other component files of this type if possible.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public virtual void RemoveField(string idToRemove)
        {
            var existingValue = MetaDataFieldValues.Find(f => f.FieldId == idToRemove);

            if (existingValue != null)
            {
                MetaDataFieldValues.Remove(existingValue);
            }

            if (FieldUpdater != null)
            {
                FieldUpdater.DeleteField(this, idToRemove);
            }
        }
Exemple #4
0
        /// ------------------------------------------------------------------------------------
        public virtual void RenameId(string oldId, string newId)
        {
            var fieldValue = MetaDataFieldValues.Find(v => v.FieldId == oldId);

            if (fieldValue != null)
            {
                fieldValue.FieldId = newId;
            }

            if (FieldUpdater != null)
            {
                FieldUpdater.RenameField(this, oldId, newId);
            }
        }
Exemple #5
0
        /// ------------------------------------------------------------------------------------
        public virtual string GetStringValue(string key, string defaultValue)
        {
            string computedValue = null;

            var computedFieldInfo =
                FileType.GetComputedFields().FirstOrDefault(computedField => computedField.Key == key);

            if (computedFieldInfo != null && StatisticsProvider != null)
            {
                var mediaFileInfo = StatisticsProvider.GetFileData(PathToAnnotatedFile);
                if (mediaFileInfo != null)
                {
                    if (mediaFileInfo.Audio == null &&
                        PathToAnnotatedFile.EndsWith(Settings.Default.OralAnnotationGeneratedFileSuffix))
                    {
                        return("Not Generated");
                    }
                    // Get the computed value (if there is one).
                    computedValue = computedFieldInfo.GetFormatedStatProvider(
                        mediaFileInfo, computedFieldInfo.DataItemChooser, computedFieldInfo.Suffix);
                }
            }

            // Get the value from the metadata file.
            var field      = MetaDataFieldValues.FirstOrDefault(v => v.FieldId == key);
            var savedValue = (field == null ? defaultValue : field.ValueAsString);

            if (!string.IsNullOrEmpty(computedValue))
            {
                // If the computed value is different from the value found in the metadata
                // file, then save the computed value to the metadata file.
                if (computedValue != savedValue)
                {
                    // REVIEW: We probably don't want to save the formatted value to the
                    // metadata file, which is what we're doing here. In the future we'll
                    // probably want to change things to save the raw computed value.
                    SetStringValue(key, computedValue);
                    Save();
                    return(computedValue);
                }
            }

            return(savedValue);
        }
Exemple #6
0
        /// ------------------------------------------------------------------------------------
        public virtual object GetValue(string key, object defaultValue)
        {
            var field = MetaDataFieldValues.FirstOrDefault(v => v.FieldId == key);

            return(field == null ? defaultValue : field.Value);
        }
 /// ------------------------------------------------------------------------------------
 public virtual IEnumerable <FieldInstance> GetCustomFields()
 {
     return(MetaDataFieldValues.Where(
                val => val.FieldId.StartsWith(XmlFileSerializer.kCustomFieldIdPrefix)));
 }