예제 #1
0
 public static DymeCaseProperty Clone(this DymeCaseProperty property)
 {
     return(new DymeCaseProperty()
     {
         Name = property.Name,
         CorrelationKey = property.CorrelationKey,
         ExpansionType = property.ExpansionType,
         OriginConfigPath = property.OriginConfigPath,
         OriginPath = property.OriginPath,
         PropertyIndex = property.PropertyIndex,
         Value = property.Value,
         ValueIndexFromOriginalList = property.ValueIndexFromOriginalList
     });
 }
예제 #2
0
        private IEnumerable <DymeCase> CreatePoolProperties(IEnumerable <DymeCase> dymeCases, IEnumerable <DymeConfigProperty> postApplyProperties)
        {
            Dictionary <string, int> poolPropertyPickedCount = postApplyProperties.ToDictionary(i => i.CorrelationKey, i => 0);

            foreach (var postApplyProp in postApplyProperties)
            {
                foreach (var dymeCase in dymeCases)
                {
                    /// Find the place-holder property in the case (if it exists)...
                    var matchingProperty = dymeCase.Properties.SingleOrDefault(caseProp => caseProp.Name == postApplyProp.Name && caseProp.CorrelationKey == postApplyProp.CorrelationKey);
                    var newProperty      = new DymeCaseProperty();
                    if (matchingProperty != null)
                    {
                        /// Remove the existing placeholder property...
                        dymeCase.Properties = dymeCase.Properties.Except(new[] { matchingProperty }).ToList();
                        /// Create a replacement for the placeholder property...
                        newProperty = matchingProperty.Clone();
                    }
                    else
                    {
                        /// If an explicit placeholder doesn't exist then check for any correlated properties...
                        matchingProperty = dymeCase.Properties.FirstOrDefault(caseProp => caseProp.CorrelationKey == postApplyProp.CorrelationKey);
                        /// Create a new property to inject into the case...
                        newProperty = new DymeCaseProperty(postApplyProp.Name, null, postApplyProp.CorrelationKey);
                    }
                    if (matchingProperty == null)
                    {
                        continue;
                    }
                    /// Pick the next value for this specific pool property...
                    var caseIndex = poolPropertyPickedCount[postApplyProp.CorrelationKey];
                    /// Update the picked tracking count...
                    poolPropertyPickedCount[postApplyProp.CorrelationKey] += 1;
                    /// Determine the actual pool index...
                    var poolIndex = caseIndex % postApplyProp.Values.Count();
                    /// Assign the appropriate pool value to the property...
                    newProperty.Value = postApplyProp.Values.ElementAt(poolIndex);
                    newProperty.ValueIndexFromOriginalList = poolIndex;
                    /// Add new the case property back to the case...
                    dymeCase.Properties = dymeCase.Properties.Append(newProperty);
                }
            }
            return(dymeCases);
        }
예제 #3
0
        private bool CorrelationPathsMatchButIndexesDontMatch(DymeCaseProperty case1Property, DymeCaseProperty case2Property)
        {
            var case1CorrelationKeys = case1Property.CorrelationPath
                                       .Split('/')                          /// ...Split into path elements
                                       .Select(el => el.Split(':').First()) ///...Select the correlation keys
                                       .Skip(1)                             /// ...The first value index is the top config's index, which won't have a correlation key.
                                       .ToList();

            var case2CorrelationKeys = case2Property.CorrelationPath
                                       .Split('/')                          /// ...Split into path elements
                                       .Select(el => el.Split(':').First()) ///...Select the correlation keys
                                       .Skip(1)                             /// ...The first value index is the top config's index, which won't have a correlation key.
                                       .ToList();

            var amountOfSharedPath = Math.Min(case1CorrelationKeys.Count, case2CorrelationKeys.Count);

            var case1ValueIndexes = case1Property.CorrelationPath
                                    .Split('/')                         /// ...Split into path elements
                                    .Select(el => el.Split(':').Last()) ///...Select the value indexes
                                    .Skip(1)                            /// ...The first value index is the top config's index, which won't have a correlation key.
                                    .ToList();

            var case2ValueIndexes = case2Property.CorrelationPath
                                    .Split('/')                         /// ...Split into path elements
                                    .Select(el => el.Split(':').Last()) ///...Select the value indexes
                                    .Skip(1)                            /// ...The first value index is the top config's index, which won't have a correlation key.
                                    .ToList();

            for (var commonIndex = 0; commonIndex < amountOfSharedPath; commonIndex++)
            {
                if (case1CorrelationKeys[commonIndex] != case2CorrelationKeys[commonIndex])
                {
                    return(false); /// ...Paths don't match, Non-correlated field
                }
                if (case1ValueIndexes[commonIndex] != case2ValueIndexes[commonIndex])
                {
                    return(true); /// ...correlated field, but uncorrelated values
                }
            }
            return(false);
        }
예제 #4
0
        /// <summary>
        /// This method gets called at the leaf-most parts of the node-tree.
        /// </summary>
        /// <param name="valueNode"></param>
        /// <param name="parent"></param>
        /// <param name="treePath"></param>
        /// <param name="configPath"></param>
        /// <returns></returns>
        private static IEnumerable <DymeCase> CaseFromValueNode(Node valueNode, Node parent, string treePath, string[] configPath, string correlationPath)
        {
            var propertyNamePart  = parent;
            var propertyValuePart = valueNode;

            var newProperty = new DymeCaseProperty(propertyNamePart.Value, propertyValuePart.Value, propertyNamePart.CorrelationKey);

            newProperty.PropertyIndex = propertyNamePart.ValueIndex;
            newProperty.ValueIndexFromOriginalList = propertyValuePart.ValueIndex;
            newProperty.OriginPath       = treePath;
            newProperty.OriginConfigPath = configPath;
            newProperty.CorrelationPath  = correlationPath;

            var newCase = new DymeCase();

            newCase.Properties = new[] { newProperty };
            return(new List <DymeCase>()
            {
                newCase
            });
        }