Exemplo n.º 1
0
        private void CheckRule(List <RuleFeedbackBase> ruleFeedbacks, List <CheckerFeedback> checkerFeedbacks, RuleDescriptor rule)
        {
            if (!rule.ValidContext.Any(context => _allChildrenCache.ContainsKey(context)))
            {
                checkerFeedbacks.Add(new CheckerFeedback {
                    CheckerResultType = CheckerResultTypes.InvalidContext
                });
            }

            var passed = true;

            foreach (var context in rule.ValidContext.Where(context => _allChildrenCache.ContainsKey(context)))
            {
                foreach (var node in _allChildrenCache[context])
                {
                    var feedBacks = rule.CheckRuleDelegate(node).ToList();
                    ruleFeedbacks.AddRange(feedBacks);

                    if ((GMEConsole == null || GMEConsole.Error == null || GMEConsole.Warning == null) && this.Logger == null)
                    {
                        continue;
                    }

                    foreach (var feedBack in feedBacks)
                    {
                        switch (feedBack.FeedbackType)
                        {
                        case FeedbackTypes.Error:
                            if (this.Logger != null)
                            {
                                this.Logger.WriteFailed(feedBack.Message);
                                if (feedBack.InvolvedObjectsByRole != null)
                                {
                                    this.Logger.WriteFailed("Involved Objects : ");
                                    foreach (var fco in feedBack.InvolvedObjectsByRole)
                                    {
                                        if (fco != null)
                                        {
                                            // TODO: turn object references to valid objects using Traceability map
                                            this.Logger.WriteFailed("[ {0} ]", fco.ToMgaHyperLink(this.Traceability));
                                        }
                                        else
                                        {
                                            this.Logger.WriteError("[ Could not get fco from InvolvedObjectsByRole for this error. (fco was null) ]");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                GMEConsole.Error.WriteLine(feedBack.Message);
                            }

                            passed = false;
                            break;

                        case FeedbackTypes.Warning:
                            if (this.Logger != null)
                            {
                                this.Logger.WriteWarning(feedBack.Message);
                                if (feedBack.InvolvedObjectsByRole != null)
                                {
                                    this.Logger.WriteWarning("Involved Objects : ");
                                    foreach (var fco in feedBack.InvolvedObjectsByRole)
                                    {
                                        if (fco != null)
                                        {
                                            // TODO: turn object references to valid objects using Traceability map
                                            this.Logger.WriteWarning("[ {0} ]", fco.ToMgaHyperLink(this.Traceability));
                                        }
                                        else
                                        {
                                            this.Logger.WriteError("[ Could not get fco from InvolvedObjectsByRole for this error. (fco was null) ]");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                GMEConsole.Warning.WriteLine(feedBack.Message);
                            }
                            passed = false;
                            break;
                        }

                        //var sb = new StringBuilder();
                        //sb.AppendLine(feedBack.Message);
                        if (this.Logger == null)
                        {
                            if (feedBack.InvolvedObjectsByRole != null && feedBack.InvolvedObjectsByRole.Any())
                            {
                                //sb.AppendLine("- Involved objects: ");

                                GMEConsole.Out.WriteLine("[ Involved objects: ]");
                            }

                            foreach (var fco in feedBack.InvolvedObjectsByRole)
                            {
                                if (fco != null)
                                {
                                    GMEConsole.Out.WriteLine("[ {0} ]", fco.ToMgaHyperLink(this.Traceability));
                                }
                                else
                                {
                                    GMEConsole.Out.WriteLine("[ Could not get fco from InvolvedObjectsByRole for this error. (fco was null) ]");
                                }
                            }
                        }
                    }
                }
            }

            if (passed && rule.ValidContext.Any(context => _allChildrenCache.ContainsKey(context)))
            {
                if (this.Logger != null)
                {
                    this.Logger.WriteSuccess("{0} : {1}", rule.Name, rule.Description);
                }
                else
                {
                    GMEConsole.Info.WriteLine("PASSED: {0} : {1}", rule.Name, rule.Description);
                }
            }
        }