/// <summary> /// Gets a value of of the property specified by name from ConfigDictionary. /// </summary> /// <param name="propertyId">Name of the property to retrieve.</param> /// <param name="md">Dictionary (data source) containing the data for the property.</param> /// <exception cref="PropertyRetrievalException">Thrown when either data source is null or when the data source does not contain the string value for the specified property name.</exception> private static Property GetConfigDictionaryProperty(LocResource.LocResourceProps propertyId, ConfigDictionary md) { if (md == null) { throw new PropertyRetrievalException(String.Format(CultureInfo.CurrentCulture, "DataSource must not be null. DataSource name: {0}", md.GetType().Name)); } string value; md.TryGetValue(propertyId.ToString(), out value); switch (propertyId) { case LocResource.LocResourceProps.ResourceId: return(new StringProperty((byte)propertyId, value)); case LocResource.LocResourceProps.SourceString: return(new StringProperty((byte)propertyId, value)); case LocResource.LocResourceProps.Comments: return(new StringProperty((byte)propertyId, value)); case LocResource.LocResourceProps.FilePath: return(new StringProperty((byte)propertyId, value)); default: throw new PropertyRetrievalException(String.Format(CultureInfo.CurrentCulture, "Cannot provide property {0} from datasource of type {1}.", propertyId.ToString(), md.GetType().Name)); } }
/// <summary> /// Define the logic of how to provide each of the properties below /// </summary> /// <param name="propertyId">Numerical id of the property. This replaces string property name. A Classification Object type should expose an enum type listing all properties.</param> /// <param name="entry">A single entry in the file</param> /// <returns>Returns a Property given the propertyId.</returns> static Property GetResourceFileEntryProperty(LocResource.LocResourceProps propertyId, ResourceFileEntry entry) { if (entry == null) { throw new NullReferenceException(String.Format("DataSource must not be null. DataSource name: {0}", entry.GetType().Name)); } try { switch (propertyId) { case LocResource.LocResourceProps.ResourceId: return(new StringProperty((byte)propertyId, String.IsNullOrEmpty(entry.ResourceId) ? string.Empty : entry.ResourceId)); case LocResource.LocResourceProps.SourceString: return(new StringProperty((byte)propertyId, String.IsNullOrEmpty(entry.SourceString) ? string.Empty : entry.SourceString)); case LocResource.LocResourceProps.Comments: return(new StringProperty((byte)propertyId, String.IsNullOrEmpty(entry.Comment) ? string.Empty : entry.Comment)); case LocResource.LocResourceProps.FilePath: return(new StringProperty((byte)propertyId, String.IsNullOrEmpty(entry.FilePath) ? String.Empty : entry.FilePath)); default: { string message = string.Format("Cannot provide property {0} from datasource of type {1}.", propertyId.ToString(), entry.GetType().Name); Trace.TraceInformation(message); throw new InvalidOperationException(message); } } } catch (NullReferenceException e) { Trace.TraceInformation("Exception in ProvideProperty('{1}'): {0}", e.Message, propertyId.ToString()); return(null); } }
private static Property GetSelfProperty(LocResource.LocResourceProps propertyId, LocResource lr) { if (Object.ReferenceEquals(lr, null)) { throw new NullReferenceException(String.Format(CultureInfo.CurrentCulture, "DataSource must not be null. DataSource name: {0}", lr.GetType().Name)); } switch (propertyId) { case LocResource.LocResourceProps.ResourceId: return(new StringProperty((byte)propertyId, lr.ResourceId)); case LocResource.LocResourceProps.SourceString: return(new StringProperty((byte)propertyId, lr.SourceString)); case LocResource.LocResourceProps.Comments: return(new StringProperty((byte)propertyId, lr.Comments)); case LocResource.LocResourceProps.FilePath: return(new StringProperty((byte)propertyId, lr.FilePath)); default: throw new PropertyRetrievalException(String.Format(CultureInfo.CurrentCulture, "Cannot provide property {0} from datasource of type {1}.", propertyId.ToString(), lr.GetType().Name)); } }