Пример #1
0
        public static string FindField(this ICrateStorage payloadStorage, FieldDTO fieldToMatch)
        {
            if (payloadStorage == null)
            {
                throw new ArgumentNullException(nameof(payloadStorage));
            }
            if (fieldToMatch == null)
            {
                throw new ArgumentNullException(nameof(fieldToMatch));
            }
            if (string.IsNullOrWhiteSpace(fieldToMatch.Key))
            {
                return(null);
            }
            var filteredCrates = payloadStorage.AsQueryable();

            if (!string.IsNullOrWhiteSpace(fieldToMatch.SourceActivityId))
            {
                filteredCrates = filteredCrates.Where(x => x.SourceActivityId == fieldToMatch.SourceActivityId);
            }
            if (!string.IsNullOrEmpty(fieldToMatch.SourceCrateLabel))
            {
                filteredCrates = filteredCrates.Where(x => x.Label == fieldToMatch.SourceCrateLabel);
            }
            if (fieldToMatch.SourceCrateManifest != CrateManifestType.Any && fieldToMatch.SourceCrateManifest != CrateManifestType.Unknown)
            {
                filteredCrates = filteredCrates.Where(x => x.ManifestType.Equals(fieldToMatch.SourceCrateManifest));
            }
            var operationalState = payloadStorage.CrateContentsOfType <OperationalStateCM>().Single();

            //iterate through found crates to find the payload
            foreach (var foundCrate in filteredCrates)
            {
                var foundField = FindField(operationalState, foundCrate, fieldToMatch.Key);
                if (foundField != null)
                {
                    return(foundField.Value);
                }
            }
            return(null);
        }