Example #1
0
        public void Set <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey, T value)
        {
            Dictionary <Guid, object> conceptInfoMetadata;
            string conceptKey = conceptInfo.GetKey();

            if (!_metadata.TryGetValue(conceptKey, out conceptInfoMetadata))
            {
                conceptInfoMetadata = new Dictionary <Guid, object>();
                _metadata.Add(conceptKey, conceptInfoMetadata);
            }

            object oldValue;

            if (!conceptInfoMetadata.TryGetValue(metadataKey.Id, out oldValue))
            {
                conceptInfoMetadata.Add(metadataKey.Id, value);
            }
            else
            {
                if (!SameValue(value, oldValue))
                {
                    throw new FrameworkException(
                              $"Different metadata value is already set for concept {conceptInfo.GetUserDescription()}, key {metadataKey}." +
                              $" Previous value '{oldValue}', new value '{value}'.");
                }
            }
        }
Example #2
0
        public T Get <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey)
        {
            Func <string> missingMetadataMessage = () => "There is no requested metadata for concept " + conceptInfo.GetUserDescription() + ". Metadata key is " + metadataKey + ".";
            var           conceptInfoMetadata    = _metadata.GetValue(conceptInfo.GetKey(), missingMetadataMessage);
            var           metadataValue          = conceptInfoMetadata.GetValue(metadataKey.Id, missingMetadataMessage);

            return((T)metadataValue);
        }
Example #3
0
        public bool Contains <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey)
        {
            Dictionary <Guid, object> conceptInfoMetadata;

            if (!_metadata.TryGetValue(conceptInfo.GetKey(), out conceptInfoMetadata))
            {
                return(false);
            }
            return(conceptInfoMetadata.ContainsKey(metadataKey.Id));
        }
Example #4
0
 public T GetOrDefault <T>(IConceptInfo conceptInfo, ConceptMetadataKey <T> metadataKey, T defaultValue)
 {
     return(Contains(conceptInfo, metadataKey)
         ? Get(conceptInfo, metadataKey)
         : defaultValue);
 }