/// <summary> /// Retrieves the first occurance out of the list of matching IshFields; preferring Id over Element and then Value. /// So first Id '4484', if not present then Element 'VUSERADMIN', again if not present Value 'Admin'. /// </summary> /// <returns>The first <see cref="IshField"/> in the current list.</returns> public IshField RetrieveFirst(string fieldName, Enumerations.Level fieldLevel) { IshField ishField = RetrieveFirst(fieldName, fieldLevel, Enumerations.ValueType.Id); if (ishField == null) { ishField = RetrieveFirst(fieldName, fieldLevel, Enumerations.ValueType.Element); } if (ishField == null) { ishField = RetrieveFirst(fieldName, fieldLevel, Enumerations.ValueType.Value); } return(ishField); }
/// <summary> /// Remove a field from the current list. /// </summary> /// <param name="compareField">The <see cref="IshField"/> that needs to be removed.</param> /// <returns>The current list of <see cref="IshFields"/>.</returns> public IshFields RemoveField(IshField compareField) { List <IshField> returnFields = new List <IshField>(); foreach (IshField ishField in _fields) { if (!((IshField)ishField).Equals(compareField)) { returnFields.Add(ishField); } } _fields = returnFields; return(this); }
/// <summary> /// Removes all previous fields and insert the given field /// </summary> /// <returns>The current list of <see cref="IshFields"/>.</returns> public IshFields AddOrUpdateField(IshField ishField, Enumerations.ActionMode actionMode) { switch (actionMode) { // Remove all value types to avoid ambiguity, no preference of element over value, so last one wins case Enumerations.ActionMode.Create: case Enumerations.ActionMode.Update: RemoveField(ishField.Name, ishField.Level, Enumerations.ValueType.All); break; case Enumerations.ActionMode.Find: case Enumerations.ActionMode.Search: case Enumerations.ActionMode.Read: default: RemoveField(ishField); break; } AddField(ishField); return(this); }
/// <summary> /// Gets the value for a field. /// </summary> /// <param name="fieldName">The fieldname to get the value from.</param> /// <param name="fieldLevel">The fieldlevel (<see cref="Enumerations.Level"/>).</param> /// <param name="valueType">The valuetype (<see cref="Enumerations.ValueType"/>).</param> /// <returns></returns> public string GetFieldValue(string fieldName, Enumerations.Level fieldLevel, Enumerations.ValueType valueType) { if (_fields == null) { throw new InvalidOperationException("No fields are set."); } IshField field = RetrieveFirst(fieldName, fieldLevel, valueType); string fieldValue = string.Empty; if (field != null) { var filterField = field.ToMetadataFilterField() as IshMetadataFilterField; if (filterField == null) { throw new InvalidOperationException("field.ToMetadataFilterField() is not IshMetadataFilterField"); } fieldValue = filterField.Value; } return(fieldValue); }
/// <summary> /// Add a field to the current list. /// </summary> /// <param name="ishField">The field that needs to be added.</param> /// <returns>The current list of <see cref="IshFields"/>.</returns> public IshFields AddField(IshField ishField) { _fields.Add(ishField); return(this); }
/// <summary> /// Outputs an filename based on an ishobject. /// </summary> /// <param name="path">The path where the file needs to be stored.</param> /// <param name="ishObject">The <see cref="IshObject"/>.</param> /// <param name="extension">The file extension.</param> /// <returns> /// A string with following format #Title#=#LogicalId#=#Version#=(#Language#=)(#Resolution#).#Extension# /// Values between brackets are optional. /// </returns> internal static string GetDefaultObjectFileName(string path, IshObject ishObject, string extension) { //Prereqs if (ishObject == null) { throw new ArgumentNullException("ishObject"); } if (path == null) { path = ""; } if (extension == null) { extension = ""; } string fileName = ""; //Logical id if (ishObject.IshRef != null) { fileName += Encode(ishObject.IshRef) + "="; } else { throw new ArgumentException("There is no logicalid available."); } //Version IshField versionField = ishObject.IshFields.RetrieveFirst("VERSION", Enumerations.Level.Version, Enumerations.ValueType.Value); if (versionField != null) { fileName += Encode(((IshMetadataField)versionField.ToMetadataField()).Value) + "="; } else { throw new ArgumentException("There is no version available."); } //Language IshField languageField = ishObject.IshFields.RetrieveFirst("DOC-LANGUAGE", Enumerations.Level.Lng, Enumerations.ValueType.Value); if (languageField != null) { fileName += Encode(((IshMetadataField)languageField.ToMetadataField()).Value) + "="; } //Resolution IshField resolutionField = ishObject.IshFields.RetrieveFirst("FRESOLUTION", Enumerations.Level.Lng, Enumerations.ValueType.Value); if (resolutionField != null) { fileName += Encode(((IshMetadataField)resolutionField.ToMetadataField()).Value); } //Escape the current filename fileName = EscapeFileName(fileName); //Extension if ((!string.IsNullOrEmpty(extension))) { fileName += "." + extension.Trim(' ', '.'); } //Title string title = string.Empty; IshField titleField = ishObject.IshFields.RetrieveFirst("FTITLE", Enumerations.Level.Logical, Enumerations.ValueType.Value); if (titleField != null) { title = EscapeFileName(Encode(((IshMetadataField)titleField.ToMetadataField()).Value)); } //Calculate the maximum length of the title int maxLengthTitle = 0; if (System.IO.Path.IsPathRooted(path)) { maxLengthTitle = MaximumFilePathSize - (path.Length + fileName.Length + 2); } else if (path.Length > 0) { maxLengthTitle = MaximumFileNameSize - (path.Length + fileName.Length + 2); } else { maxLengthTitle = MaximumFileNameSize - (fileName.Length + 1); } //Strip title if (maxLengthTitle > 0) { if (maxLengthTitle < title.Length) { fileName = title.Substring(0, maxLengthTitle) + "=" + fileName; } else { fileName = title + "=" + fileName; } } //Combine filename + path if ((path.Length > 0)) { return(System.IO.Path.Combine(path, fileName)); } return(fileName); }