Ejemplo n.º 1
1
        public static Dictionary<String, String> SplitByKey(this String source, String keyRegexPattern, Boolean overwrite)
        {
            if (source.IsNullOrEmpty() || keyRegexPattern.IsNullOrEmpty()) throw new ArgumentNullException("source");

            Dictionary<String, String> results = new Dictionary<string, string>();

            Match match = null;
            Match lastMatch = null;

            while ((match = Regex.Match(source, keyRegexPattern)).Success)
            {
                if (lastMatch != null)
                {
                    Boolean flag = results.ContainsKey(lastMatch.Value);
                    if (flag && overwrite)
                    {
                        results[lastMatch.Value] = source.Substring(0, match.Index);
                    }
                    else if (flag == false)
                    {
                        results.Add(lastMatch.Value, source.Substring(0, match.Index));
                    }
                }

                lastMatch = match;
                source = source.Substring(match.Index + match.Length);
            }

            if (lastMatch != null)
            {
                Boolean flag = results.ContainsKey(lastMatch.Value);
                if (flag && overwrite)
                {
                    results[lastMatch.Value] = source.Substring(0, match.Index);
                }
                else if (flag == false)
                {
                    results.Add(lastMatch.Value, source.Substring(0));
                }
            }

            if (!results.IsNullOrEmpty())
                return results;
            else
                return null;
        }
 private static OverloadGroupEquivalenceInfo GetOverloadGroupEquivalence(Dictionary<string, List<RuntimeArgument>> groupDefinitions)
 {
     OverloadGroupEquivalenceInfo info = new OverloadGroupEquivalenceInfo();
     if (!groupDefinitions.IsNullOrEmpty())
     {
         string[] array = new string[groupDefinitions.Count];
         groupDefinitions.Keys.CopyTo(array, 0);
         for (int i = 0; i < array.Length; i++)
         {
             string str = array[i];
             HashSet<RuntimeArgument> set = new HashSet<RuntimeArgument>(groupDefinitions[str]);
             for (int j = i + 1; j < array.Length; j++)
             {
                 string str2 = array[j];
                 HashSet<RuntimeArgument> other = new HashSet<RuntimeArgument>(groupDefinitions[str2]);
                 if (set.IsProperSupersetOf(other))
                 {
                     info.SetAsSuperset(str, str2);
                 }
                 else if (set.IsProperSubsetOf(other))
                 {
                     info.SetAsSuperset(str2, str);
                 }
                 else if (set.SetEquals(other))
                 {
                     info.SetAsEquivalent(str, str2);
                 }
                 else if (set.Overlaps(other))
                 {
                     info.SetAsOverlapping(str, str2);
                 }
                 else
                 {
                     info.SetAsDisjoint(str, str2);
                 }
             }
         }
     }
     return info;
 }
        static OverloadGroupEquivalenceInfo GetOverloadGroupEquivalence(Dictionary<string, List<RuntimeArgument>> groupDefinitions)
        {
            OverloadGroupEquivalenceInfo overloadGroupsInfo = new OverloadGroupEquivalenceInfo();

            if (!groupDefinitions.IsNullOrEmpty())
            {
                string[] groupNames = new string[groupDefinitions.Count];
                groupDefinitions.Keys.CopyTo(groupNames, 0);

                for (int i = 0; i < groupNames.Length; i++)
                {
                    string group1 = groupNames[i];
                    HashSet<RuntimeArgument> group1Args = new HashSet<RuntimeArgument>(groupDefinitions[group1]);
                    for (int j = i + 1; j < groupNames.Length; j++)
                    {
                        string group2 = groupNames[j];
                        HashSet<RuntimeArgument> group2Args = new HashSet<RuntimeArgument>(groupDefinitions[group2]);

                        if (group1Args.IsProperSupersetOf(group2Args))
                        {
                            overloadGroupsInfo.SetAsSuperset(group1, group2);
                        }
                        else if (group1Args.IsProperSubsetOf(group2Args))
                        {
                            overloadGroupsInfo.SetAsSuperset(group2, group1);
                        }
                        else if (group1Args.SetEquals(group2Args))
                        {
                            overloadGroupsInfo.SetAsEquivalent(group1, group2);
                        }
                        else if (group1Args.Overlaps(group2Args))
                        {
                            overloadGroupsInfo.SetAsOverlapping(group1, group2);
                        }
                        else // the groups are disjoint.
                        {
                            overloadGroupsInfo.SetAsDisjoint(group1, group2);
                        }
                    }
                }
            }

            return overloadGroupsInfo;
        }
        public static void ValidateArguments(Activity activity, OverloadGroupEquivalenceInfo equivalenceInfo, Dictionary<string, List<RuntimeArgument>> overloadGroups, List<RuntimeArgument> requiredArgumentsNotInOverloadGroups, IDictionary<string, object> inputs, ref IList<ValidationError> validationErrors)
        {
            if (!requiredArgumentsNotInOverloadGroups.IsNullOrEmpty())
            {
                // 1. Check if there are any Required arguments (outside overload groups) that were not specified.
                foreach (RuntimeArgument argument in requiredArgumentsNotInOverloadGroups)
                {
                    if (CheckIfArgumentIsNotBound(argument, inputs))
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.RequiredArgumentValueNotSupplied(argument.Name), false, argument.Name, activity));
                    }
                }
            }

            if (!overloadGroups.IsNullOrEmpty())
            {
                //1. Check to see if any of the overload groups are configured. 
                // An overload group is considered to be completely configured if all it's required arguments
                // are non-null. If an overload group does not have any required arguments then the group is 
                // considered configured if any of the optional arguments are configured.
                Dictionary<string, bool> configurationResults = new Dictionary<string, bool>();
                string configuredGroupName = string.Empty;
                int configuredCount = 0;
                int overloadGroupsWithNoRequiredArgs = 0;

                foreach (KeyValuePair<string, List<RuntimeArgument>> entry in overloadGroups)
                {
                    string groupName = entry.Key;
                    configurationResults.Add(groupName, false);
                    IEnumerable<RuntimeArgument> requiredArguments = entry.Value.Where((a) => a.IsRequired);

                    if (requiredArguments.Count() > 0)
                    {
                        if (requiredArguments.All(localArgument => CheckIfArgumentIsBound(localArgument, inputs)))
                        {
                            configurationResults[groupName] = true;
                            configuredGroupName = groupName;
                            configuredCount++;
                        }
                    }
                    else
                    {
                        overloadGroupsWithNoRequiredArgs++;
                        IEnumerable<RuntimeArgument> optionalArguments = entry.Value.Where((a) => !a.IsRequired);
                        if (optionalArguments.Any(localArgument => CheckIfArgumentIsBound(localArgument, inputs)))
                        {
                            configurationResults[groupName] = true;
                            configuredGroupName = groupName;
                            configuredCount++;
                        }
                    }
                }

                //2. It's an error if none of the groups are configured unless there
                // is atleast one overload group with no required arguments in it.
                if (configuredCount == 0)
                {
                    if (overloadGroupsWithNoRequiredArgs == 0)
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.NoOverloadGroupsAreConfigured, false, activity));
                    }
                }
                //3. If only one overload group was configured, ensure none of the disjoint/overlapping groups have any 
                // required or optional activity arguments set.
                else if (configuredCount == 1)
                {
                    HashSet<RuntimeArgument> configuredOverloadSet = new HashSet<RuntimeArgument>(overloadGroups[configuredGroupName]);
                    Predicate<RuntimeArgument> checkIfArgumentIsBound = new Predicate<RuntimeArgument>(localArgument => CheckIfArgumentIsBound(localArgument, inputs));

                    List<string> disjointGroups = null;
                    if (!equivalenceInfo.DisjointGroupsDictionary.IsNullOrEmpty())
                    {
                        equivalenceInfo.DisjointGroupsDictionary.TryGetValue(configuredGroupName, out disjointGroups);
                    }

                    List<string> overlappingGroups = null;
                    if (!equivalenceInfo.OverlappingGroupsDictionary.IsNullOrEmpty())
                    {
                        equivalenceInfo.OverlappingGroupsDictionary.TryGetValue(configuredGroupName, out overlappingGroups);
                    }

                    // Iterate over the groups that may not be completely configured.
                    foreach (string groupName in configurationResults.Keys.Where((k) => configurationResults[k] == false))
                    {
                        // Check if the partially configured group name is in the disjoint groups list. 
                        // If so, find all configured arguments.
                        if (disjointGroups != null && disjointGroups.Contains(groupName))
                        {
                            foreach (RuntimeArgument configuredArgument in overloadGroups[groupName].FindAll(checkIfArgumentIsBound))
                            {
                                ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ExtraOverloadGroupPropertiesConfigured(configuredGroupName,
                                    configuredArgument.Name, groupName), false, activity));
                            }
                        }
                        else if (overlappingGroups != null && overlappingGroups.Contains(groupName))
                        {
                            // Find all arguments of the Overlapping group that are not in the configuredOverloadSet.
                            HashSet<RuntimeArgument> overloadGroupSet = new HashSet<RuntimeArgument>(overloadGroups[groupName]);
                            IEnumerable<RuntimeArgument> intersectSet = overloadGroupSet.Intersect(configuredOverloadSet);
                            List<RuntimeArgument> exceptList = overloadGroupSet.Except(intersectSet).ToList();

                            foreach (RuntimeArgument configuredArgument in exceptList.FindAll(checkIfArgumentIsBound))
                            {
                                ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ExtraOverloadGroupPropertiesConfigured(configuredGroupName,
                                    configuredArgument.Name, groupName), false, activity));
                            }
                        }
                    }
                }
                //4. If more than one overload group is configured, generate an error.
                else
                {
                    IEnumerable<string> configuredGroups = configurationResults.Keys.Where((k) => configurationResults[k]).OrderBy((k) => k, StringComparer.Ordinal);
                    ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.MultipleOverloadGroupsConfigured(configuredGroups.AsCommaSeparatedValues()), false, activity));
                }
            }
        }
        public static void ValidateArguments(Activity activity, OverloadGroupEquivalenceInfo equivalenceInfo, Dictionary<string, List<RuntimeArgument>> overloadGroups, List<RuntimeArgument> requiredArgumentsNotInOverloadGroups, IDictionary<string, object> inputs, ref IList<ValidationError> validationErrors)
        {
            Func<RuntimeArgument, bool> func3 = null;
            Func<RuntimeArgument, bool> func4 = null;
            Predicate<RuntimeArgument> predicate2 = null;
            if (!requiredArgumentsNotInOverloadGroups.IsNullOrEmpty())
            {
                foreach (RuntimeArgument argument in requiredArgumentsNotInOverloadGroups)
                {
                    if (CheckIfArgumentIsNotBound(argument, inputs))
                    {
                        ActivityUtilities.Add<ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.RequiredArgumentValueNotSupplied(argument.Name), false, argument.Name, activity));
                    }
                }
            }
            if (!overloadGroups.IsNullOrEmpty())
            {
                Func<string, bool> func = null;
                Func<string, bool> func2 = null;
                Dictionary<string, bool> configurationResults = new Dictionary<string, bool>();
                string key = string.Empty;
                int num = 0;
                int num2 = 0;
                foreach (KeyValuePair<string, List<RuntimeArgument>> pair in overloadGroups)
                {
                    string str2 = pair.Key;
                    configurationResults.Add(str2, false);
                    IEnumerable<RuntimeArgument> source = from a in pair.Value
                        where a.IsRequired
                        select a;
                    if (source.Count<RuntimeArgument>() > 0)
                    {
                        if (func3 == null)
                        {
                            func3 = localArgument => CheckIfArgumentIsBound(localArgument, inputs);
                        }
                        if (source.All<RuntimeArgument>(func3))
                        {
                            configurationResults[str2] = true;
                            key = str2;
                            num++;
                        }
                    }
                    else
                    {
                        num2++;
                        if (func4 == null)
                        {
                            func4 = localArgument => CheckIfArgumentIsBound(localArgument, inputs);
                        }
                        if ((from a in pair.Value
                            where !a.IsRequired
                            select a).Any<RuntimeArgument>(func4))
                        {
                            configurationResults[str2] = true;
                            key = str2;
                            num++;
                        }
                    }
                }
                switch (num)
                {
                    case 0:
                        if (num2 == 0)
                        {
                            ActivityUtilities.Add<ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.NoOverloadGroupsAreConfigured, false, activity));
                            return;
                        }
                        return;

                    case 1:
                    {
                        HashSet<RuntimeArgument> second = new HashSet<RuntimeArgument>(overloadGroups[key]);
                        if (predicate2 == null)
                        {
                            predicate2 = localArgument => CheckIfArgumentIsBound(localArgument, inputs);
                        }
                        Predicate<RuntimeArgument> match = predicate2;
                        List<string> list = null;
                        if (!equivalenceInfo.DisjointGroupsDictionary.IsNullOrEmpty())
                        {
                            equivalenceInfo.DisjointGroupsDictionary.TryGetValue(key, out list);
                        }
                        List<string> list2 = null;
                        if (!equivalenceInfo.OverlappingGroupsDictionary.IsNullOrEmpty())
                        {
                            equivalenceInfo.OverlappingGroupsDictionary.TryGetValue(key, out list2);
                        }
                        if (func == null)
                        {
                            func = k => !configurationResults[k];
                        }
                        foreach (string str3 in configurationResults.Keys.Where<string>(func))
                        {
                            if ((list != null) && list.Contains(str3))
                            {
                                foreach (RuntimeArgument argument2 in overloadGroups[str3].FindAll(match))
                                {
                                    ActivityUtilities.Add<ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ExtraOverloadGroupPropertiesConfigured(key, argument2.Name, str3), false, activity));
                                }
                            }
                            else if ((list2 != null) && list2.Contains(str3))
                            {
                                HashSet<RuntimeArgument> first = new HashSet<RuntimeArgument>(overloadGroups[str3]);
                                IEnumerable<RuntimeArgument> enumerable3 = first.Intersect<RuntimeArgument>(second);
                                foreach (RuntimeArgument argument3 in first.Except<RuntimeArgument>(enumerable3).ToList<RuntimeArgument>().FindAll(match))
                                {
                                    ActivityUtilities.Add<ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ExtraOverloadGroupPropertiesConfigured(key, argument3.Name, str3), false, activity));
                                }
                            }
                        }
                        return;
                    }
                }
                if (func2 == null)
                {
                    func2 = k => configurationResults[k];
                }
                IEnumerable<string> c = configurationResults.Keys.Where<string>(func2).OrderBy<string, string>(k => k, StringComparer.Ordinal);
                ActivityUtilities.Add<ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.MultipleOverloadGroupsConfigured(c.AsCommaSeparatedValues()), false, activity));
            }
        }