示例#1
0
        private static void ValidMandatoryFields(AzureTablePropertyBag azureOnRecord)
        {
            if (!azureOnRecord.UserDataMap.ContainsKey(WellKnownFields.EventType))
            {
                throw new PropertyMissingException(WellKnownFields.EventType);
            }

            if (!azureOnRecord.UserDataMap.ContainsKey(WellKnownFields.TaskName))
            {
                throw new PropertyMissingException(WellKnownFields.TaskName);
            }
        }
        private static bool IsMatch(AzureTablePropertyBag oneResult, IEnumerable <TraceRecordFilter> filters)
        {
            if (!oneResult.UserDataMap.ContainsKey(WellKnownFields.EventType))
            {
                throw new MissingFieldException("Well Known field Event Type is Missing in Azure Data");
            }

            // First check for Type filter.
            var matchingFilter = filters.SingleOrDefault(item =>
            {
                var azureEventType = Mapping.TraceRecordAzureDataMap.First(firstMapping => firstMapping.Type == item.RecordType).EventType;
                return(azureEventType.Equals(oneResult.UserDataMap[WellKnownFields.EventType]));
            });

            // If filter for a Type is missing, it implies requester is not interested in that Type, so we move on.
            if (matchingFilter == null)
            {
                // This implies we are not interested in this record
                return(false);
            }

            // If no property level filter is specified, it implies user needs all records of this type and we keep the record.
            if (!matchingFilter.Filters.Any())
            {
                return(true);
            }

            // If requester has specified property level filtering, we apply those filters.
            bool allFieldFiltersMatch = true;

            foreach (var onePropertyFilter in matchingFilter.Filters)
            {
                if (!oneResult.UserDataMap.ContainsKey(onePropertyFilter.Name))
                {
                    throw new MissingFieldException(string.Format("Filter field : {0} is Missing in data", onePropertyFilter.Name));
                }

                if (!oneResult.UserDataMap[onePropertyFilter.Name].Equals(onePropertyFilter.Value.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    allFieldFiltersMatch = false;
                    break;
                }
            }

            return(allFieldFiltersMatch);
        }