Esempio n. 1
0
        private List <ValidationResult> Validate([NotNull] IThreatEventScenario scenario)
        {
            var result = new List <ValidationResult>();

            var risk = scenario.GetRisk();

            if (risk != null)
            {
                if (risk.InDepth)
                {
                    if (risk.LossEventFrequency == null)
                    {
                        result.Add(new ValidationResult(Resources.UndefinedLEF, true));
                    }
                    else
                    {
                        if (!risk.LossEventFrequency.IsValid)
                        {
                            result.Add(new ValidationResult(Resources.InvalidLEF, true));
                        }
                    }

                    if (risk.LossMagnitude == null)
                    {
                        result.Add(new ValidationResult(Resources.UndefinedLM, true));
                    }
                    else
                    {
                        if (risk.LossMagnitude.SecondaryLossEventFrequency == null)
                        {
                            result.Add(new ValidationResult(Resources.NullSLEF, true));
                        }
                        else if (!risk.LossMagnitude.SecondaryLossEventFrequency.IsValid)
                        {
                            result.Add(new ValidationResult(Resources.InvalidSLEF, true));
                        }

                        if (risk.LossMagnitude.PrimaryLosses == null)
                        {
                            result.Add(new ValidationResult(Resources.InvalidPL, true));
                        }
                        else
                        {
                            var found = false;
                            if (risk.LossMagnitude.PrimaryLosses.Any(
                                    x => x.Form == LossForm.Productivity && x.IsValid))
                            {
                                found = true;
                            }
                            else
                            {
                                result.Add(new ValidationResult(
                                               string.Format(Resources.InvalidPrimaryLoss,
                                                             LossForm.Productivity.GetEnumLabel()),
                                               false));
                            }
                            if (risk.LossMagnitude.PrimaryLosses.Any(
                                    x => x.Form == LossForm.Replacement && x.IsValid))
                            {
                                found = true;
                            }
                            else
                            {
                                result.Add(new ValidationResult(
                                               string.Format(Resources.InvalidPrimaryLoss,
                                                             LossForm.Replacement.GetEnumLabel()),
                                               false));
                            }
                            if (risk.LossMagnitude.PrimaryLosses.Any(
                                    x => x.Form == LossForm.Response && x.IsValid))
                            {
                                found = true;
                            }
                            else
                            {
                                result.Add(new ValidationResult(
                                               string.Format(Resources.InvalidPrimaryLoss, LossForm.Response.GetEnumLabel()),
                                               false));
                            }

                            if (!found)
                            {
                                result.Add(new ValidationResult(Resources.NoPrimaryLoss, true));
                            }
                        }

                        if (risk.LossMagnitude.SecondaryLosses == null)
                        {
                            result.Add(new ValidationResult(Resources.InvalidSL, true));
                        }
                        else
                        {
                            var found = false;
                            if (risk.LossMagnitude.SecondaryLosses.Any(
                                    x => x.Form == LossForm.CompetitiveAdvantage && x.IsValid))
                            {
                                found = true;
                            }
                            else
                            {
                                result.Add(new ValidationResult(
                                               string.Format(Resources.InvalidSecondaryLoss,
                                                             LossForm.CompetitiveAdvantage.GetEnumLabel()), false));
                            }
                            if (risk.LossMagnitude.SecondaryLosses.Any(
                                    x => x.Form == LossForm.FinesJudgements && x.IsValid))
                            {
                                found = true;
                            }
                            else
                            {
                                result.Add(new ValidationResult(
                                               string.Format(Resources.InvalidSecondaryLoss,
                                                             LossForm.FinesJudgements.GetEnumLabel()),
                                               false));
                            }
                            if (risk.LossMagnitude.SecondaryLosses.Any(
                                    x => x.Form == LossForm.Reputation && x.IsValid))
                            {
                                found = true;
                            }
                            else
                            {
                                result.Add(new ValidationResult(
                                               string.Format(Resources.InvalidSecondaryLoss,
                                                             LossForm.Reputation.GetEnumLabel()),
                                               false));
                            }

                            if (!found)
                            {
                                result.Add(new ValidationResult(Resources.NoSecondaryLoss, true));
                            }
                        }
                    }
                }
                else
                {
                    if (!risk.IsValid)
                    {
                        result.Add(new ValidationResult(Resources.InvalidRisk, true));
                    }
                }
            }
            else
            {
                result.Add(new ValidationResult(Resources.NullRisk, true));
            }

            return(result);
        }
Esempio n. 2
0
        public bool Simulate([NotNull] IThreatEventScenario scenario, out IEnumerable <ValidationResult> validationResults)
        {
            var result = false;

            _frequencyArrays.Clear();
            _magnitudeArrays.Clear();

            var results = Validate(scenario);

            validationResults = results;
            if (!(results?.Any(x => x.IsBlockingError) ?? false))
            {
                var risk = scenario.GetRisk();
                if (risk.InDepth && risk.LossEventFrequency.IsValid && risk.LossMagnitude.SecondaryLossEventFrequency.IsValid)
                {
                    var primaryFrequency = GetSamples(risk.LossEventFrequency.FrequencyMin,
                                                      risk.LossEventFrequency.FrequencyMostLikely,
                                                      risk.LossEventFrequency.FrequencyMax,
                                                      risk.LossEventFrequency.FrequencyConfidence);
                    if (primaryFrequency != null)
                    {
                        var secondaryPercentage = GetSamples(risk.LossMagnitude.SecondaryLossEventFrequency.Minimum,
                                                             risk.LossMagnitude.SecondaryLossEventFrequency.MostLikely,
                                                             risk.LossMagnitude.SecondaryLossEventFrequency.Maximum,
                                                             risk.LossMagnitude.SecondaryLossEventFrequency.Confidence);
                        if (secondaryPercentage != null)
                        {
                            var primaryMagnitude = GetPrimaryLossMagnitudeSamples(risk);
                            if (primaryMagnitude != null)
                            {
                                var secondaryMagnitude = GetSecondaryLossMagnitudeSamples(risk);
                                if (secondaryMagnitude != null)
                                {
                                    _frequencyArrays.Add(primaryFrequency);
                                    var secondaryFrequency = new double[SamplesCount];
                                    for (var i = 0; i < SamplesCount; i++)
                                    {
                                        secondaryFrequency[i] =
                                            primaryFrequency[i] * secondaryPercentage[i] / 100.0;
                                    }
                                    _frequencyArrays.Add(secondaryFrequency);
                                    _magnitudeArrays.Add(primaryMagnitude);
                                    _magnitudeArrays.Add(secondaryMagnitude);
                                    result = true;
                                }
                                else
                                {
                                    results?.Add(new ValidationResult("Secondary Magnitude does not define a valid distribution", true));
                                }
                            }
                            else
                            {
                                results?.Add(new ValidationResult("Primary Magnitude does not define a valid distribution", true));
                            }
                        }
                        else
                        {
                            results?.Add(new ValidationResult(Resources.InvalidSLEFDistribution, true));
                        }
                    }
                    else
                    {
                        results?.Add(new ValidationResult(Resources.InvalidLEFDistribution, true));
                    }
                }
                else
                {
                    var frequency = GetSamples(risk.FrequencyMin, risk.FrequencyMostLikely,
                                               risk.FrequencyMax, risk.FrequencyConfidence);
                    var magnitude = GetSamples(risk.MagnitudeMin, risk.MagnitudeMostLikely,
                                               risk.MagnitudeMax, risk.MagnitudeConfidence);
                    if (frequency != null && magnitude != null)
                    {
                        _frequencyArrays.Add(frequency);
                        _magnitudeArrays.Add(magnitude);
                        result = true;
                    }
                }
            }

            return(result);
        }