Ejemplo n.º 1
0
 public override HashSet <string> GetAllowedMessages()
 {
     return(Subrules.Select(x => x.Value).ToHashSet());
 }
Ejemplo n.º 2
0
            public void ReplaceSubrulesInParents()
            {
                Console.WriteLine($"[{Number}] Enter ReplaceSubrulesInParents");
                for (int i = 0; i < Subrules.Count; i++)
                {
                    Subrule sub = Subrules[i];

                    if (sub.Rules.All(x => x.GetType() == typeof(Rule)))
                    {
                        sub.Ready = true;
                    }
                }

                if (!AlreadyReplacedSubrulesInParents && Subrules.All(x => x.Ready))
                {
                    this.AlreadyReplacedSubrulesInParents = true;
                    Console.WriteLine($"{Number} ready");
                    Console.WriteLine($"[{Number}]: " + string.Join(" | ", Subrules.Select(x => x.Value)));
                    listOfReady.Add(this);
                    listOfReady.Sort((a, b) => a.Number.CompareTo(b.Number));
                    foreach (var parent in Parents)
                    {
                        var subrulesCount = parent.Subrules.Count;
                        for (var parentSubIdx = 0; parentSubIdx < subrulesCount; parentSubIdx++)
                        {
                            if (Subrules.Count == 1)
                            {
                                var end = parent.Subrules[parentSubIdx].Rules.Count;
                                for (var i = 0; i < end; i++)
                                {
                                    if (parent.Subrules[parentSubIdx].Rules[i] == this)
                                    {
                                        var removeIndex = i;
                                        for (var j = 0; j < Subrules[0].Rules.Count; j++, i++, end++)
                                        {
                                            parent.Subrules[parentSubIdx].Rules.Insert(i + 1, Subrules[0].Rules[j]);
                                        }
                                        parent.Subrules[parentSubIdx].Rules.RemoveAt(removeIndex);
                                        i--;
                                        end--;
                                    }
                                }
                            }
                            else if (Subrules.Count > 1)
                            {
                                var removeSubruleAfterInserting = false;
                                var rulesInSubrule = parent.Subrules[parentSubIdx].Rules.Count;
                                for (var ris = 0; ris < rulesInSubrule; ris++)
                                {
                                    if (parent.Subrules[parentSubIdx].Rules[ris] == this)
                                    {
                                        foreach (var childSub in Subrules)
                                        {
                                            var insertRulesFrom = ris;
                                            var copy            = parent.Subrules[parentSubIdx].Copy();
                                            var removeIndex     = ris;
                                            for (var j = 0; j < childSub.Rules.Count; j++, insertRulesFrom++)
                                            {
                                                copy.Rules.Insert(insertRulesFrom + 1, childSub.Rules[j]);
                                            }
                                            copy.Rules.RemoveAt(removeIndex);
                                            parent.Subrules.Add(copy);
                                            subrulesCount++;
                                            removeSubruleAfterInserting = true;
                                        }
                                        if (removeSubruleAfterInserting)
                                        {
                                            parent.Subrules.RemoveAt(parentSubIdx);
                                            parentSubIdx--;
                                            subrulesCount--;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        parent.ReplaceSubrulesInParents();
                    }
                }
            }