private void SendEmailsForEvents()
        {
            try
            {
                if (!_configuration.SendEmails)
                {
                    return;
                }

                var eventSubs = _methodInfo.GetCustomAttributes <EventNotification>();
                foreach (var sub in eventSubs)
                {
                    var currentTestVersions = ReportTestHelper.GetTestsFromFolder(_test.AttachmentsPath);
                    var subscription        = _configuration.EventDurationSubscriptions.FirstOrDefault(x => x.Name.Equals(sub.Name));
                    if (currentTestVersions.Count > 1)
                    {
                        var previousTest = currentTestVersions
                                           .OrderByDescending(x => x.DateTimeFinish)
                                           .Skip(1)
                                           .First(x => x.Events.Any(e => e.Name.Equals(sub.EventName)));
                        var previuosEvent = previousTest.Events.First(x => x.Name.Equals(sub.EventName));
                        var currentEvent  = _test.Events.First(x => x.Name.Equals(sub.EventName));

                        if (currentEvent.Duration - previuosEvent.Duration > sub.MaxDifference)
                        {
                            if (subscription != null)
                            {
                                ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                       _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                       true, sub.EventName, previuosEvent);
                            }
                            else if (sub.FullPath != null)
                            {
                                subscription = ReportXMLHelper.Load <EventDurationSubscription>(sub.FullPath);
                                ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                       _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                       true, sub.EventName, previuosEvent);
                            }
                            else if (sub.Targets.Any())
                            {
                                ReportEmailHelper.Send(_configuration.SendFromList, sub.Targets,
                                                       _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                       true, sub.EventName, previuosEvent);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in SendEmailsForEvents");
            }
        }
        private void SendEmails(bool isSuccess)
        {
            try
            {
                if (!_configuration.SendEmails)
                {
                    return;
                }

                var subs = _methodInfo.GetCustomAttributes <Notification>();
                foreach (var sub in subs)
                {
                    var sendCondition = (sub.UnsuccessfulOnly && !isSuccess) || (!sub.UnsuccessfulOnly);
                    if (!sendCondition)
                    {
                        continue;
                    }

                    var subscription = _configuration.Subsciptions.FirstOrDefault(x => x.Name.Equals(sub.Name));
                    if (subscription != null)
                    {
                        ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                               _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                    }
                    else if (sub.FullPath != null)
                    {
                        subscription = ReportXMLHelper.Load <Subsciption>(sub.FullPath);
                        ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                               _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                    }
                    else if (sub.Targets.Any())
                    {
                        ReportEmailHelper.Send(_configuration.SendFromList, sub.Targets,
                                               _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                    }
                }

                /*
                 * var singleSubs = _methodInfo.GetCustomAttributes<SingleTestSubscriptionAttribute>();
                 * foreach (var singleSub in singleSubs)
                 * {
                 *  var sendCondition = (singleSub.UnsuccessfulOnly && !isSuccess) || (!singleSub.UnsuccessfulOnly);
                 *  if (!sendCondition) continue;
                 *
                 *  var singleTestSubscription =
                 *      _configuration.SingleTestSubscriptions.FirstOrDefault(x => x.TestGuid.Equals(_test.Guid));
                 *  if (singleTestSubscription != null)
                 *  {
                 *      ReportEmailHelper.Send(_configuration.SendFromList, singleTestSubscription.TargetEmails,
                 *          _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                 *  }
                 *  else if (singleSub.FullPath != null)
                 *  {
                 *      var singleSubFromXml = ReportXMLHelper.Load<SingleTestSubscription>(singleSub.FullPath);
                 *      ReportEmailHelper.Send(_configuration.SendFromList, singleSubFromXml.TargetEmails,
                 *          _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                 *  }
                 *  else if (singleSub.Targets.Any())
                 *  {
                 *      ReportEmailHelper.Send(_configuration.SendFromList, singleSub.Targets,
                 *          _test, _screenshotsPath, _configuration.AddLinksInsideEmail);
                 *  }
                 * }
                 */
                var eventSubs = _methodInfo.GetCustomAttributes <EventNotification>();
                foreach (var sub in eventSubs)
                {
                    var currentTestVersions = ReportTestHelper.GetTestsFromFolder(_test.AttachmentsPath);

                    if (currentTestVersions.Count <= 1)
                    {
                        continue;
                    }

                    var previousTest = currentTestVersions
                                       .OrderByDescending(x => x.DateTimeFinish)
                                       .Skip(1)
                                       .First(x => x.Events.Any(e => e.Name.Equals(sub.EventName)));
                    var previuosEvent = previousTest.Events.First(x => x.Name.Equals(sub.EventName));
                    var currentEvent  = _test.Events.First(x => x.Name.Equals(sub.EventName));

                    if (Math.Abs(currentEvent.Duration - previuosEvent.Duration) > sub.MaxDifference)
                    {
                        var subscription = _configuration.EventDurationSubscriptions.FirstOrDefault(x => x.Name.Equals(sub.Name));
                        if (subscription != null)
                        {
                            ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                   _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                   true, sub.EventName, previuosEvent);
                        }
                        else if (sub.FullPath != null)
                        {
                            subscription = ReportXMLHelper.Load <EventDurationSubscription>(sub.FullPath);
                            ReportEmailHelper.Send(_configuration.SendFromList, subscription.TargetEmails,
                                                   _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                   true, sub.EventName, previuosEvent);
                        }
                        else if (sub.Targets.Any())
                        {
                            ReportEmailHelper.Send(_configuration.SendFromList, sub.Targets,
                                                   _test, _screenshotsPath, _configuration.AddLinksInsideEmail,
                                                   true, sub.EventName, previuosEvent);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                InternalLogs.Exception(ex, "Exception in SendEmail");
            }
        }