Example #1
0
        private IEnumerable <KeyValuePair <string, object> > EnumerateKeyValuePairs(
            Hashtable sourceRow,
            NullValueHandling nullValueHandling,
            IEnumerable <string> keysToProcess,
            Dictionary <string, object> descriptorNamespaceByKey,
            HashSet <string> selectedKeys)
        {
            foreach (string key in keysToProcess)
            {
                string renamedKey = null;

                // Handle Pass through values
                if (key.EndsWith(CompositeDefinitionHelper.PassThroughMarker))
                {
                    renamedKey = key.TrimSuffix(CompositeDefinitionHelper.PassThroughMarker);
                    yield return(new KeyValuePair <string, object>(renamedKey ?? key, sourceRow[key]));
                }
                else
                {
                    // Remove null values, if appropriate
                    object value;

                    if (sourceRow[key] == null)
                    {
                        if (nullValueHandling == NullValueHandling.Include)
                        {
                            value = sourceRow[key];
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (descriptorNamespaceByKey.TryGetValue(key, out object namespaceForDescriptor))
                        {
                            value =
                                EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference(
                                    namespaceForDescriptor.ToString(),
                                    sourceRow[key]
                                    .ToString());
                        }
                        else
                        {
                            // See if we need to convert an USI to a UniqueId
                            if (UniqueIdSpecification.IsUSI(key) &&
                                UniqueIdSpecification.TryGetUSIPersonTypeAndRoleName(key, out string personType, out string roleName))
                            {
                                // Translate to UniqueId
                                string uniqueId    = _personUniqueIdToUsiCache.GetUniqueId(personType, (int)sourceRow[key]);
                                string uniqueIdKey = (roleName + personType + CompositeDefinitionHelper.UniqueId).ToCamelCase();

                                renamedKey = uniqueIdKey;
                                value      = uniqueId;
                            }