Esempio n. 1
0
        public void success_test()
        {
            var reader = new Mock <IList>();
            var output = Required.NotNull(reader.Object, nameof(reader.Object));

            Assert.IsNotNull(output);
        }
Esempio n. 2
0
        public void type_test()
        {
            var reader = new Mock <IList>();
            var output = Required.NotNull(reader.Object, nameof(reader.Object));

            Assert.AreSame(output, reader.Object);
        }
Esempio n. 3
0
 public Device(ICommandLineParser parser, IDeviceReader deviceReader, IDeviceSorter deviceSorter, IDeviceChanger deviceChanger)
 {
     //TODO OWN Factory pls
     CmdParser = Required.NotNull(parser, nameof(parser));
     _reader   = Required.NotNull(deviceReader, nameof(deviceReader));
     _sorter   = Required.NotNull(deviceSorter, nameof(deviceSorter));
     _changer  = Required.NotNull(deviceChanger, nameof(deviceChanger));
     init_modules();
 }
        public void Send(Email email)
        {
            Required.NotNull(email, "Email");
            Required.NotNullOrEmpty(email.To, string.Empty, "To");
            Required.NotNullOrEmpty(email.From, string.Empty, "From");
            Required.NotNullOrEmpty(email.Subject, string.Empty, "Subject");
            Required.NotNullOrEmpty(email.Body, string.Empty, "Body");

            email.CreateDate = DateTime.Now;
            email.Attempts   = 0;

            _servicesRepository.Add(email);
            _servicesRepository.Save();
        }
Esempio n. 5
0
 public void set_parser(ICommandLineParser parser)
 {
     _parser = Required.NotNull(parser, nameof(parser));
 }
Esempio n. 6
0
 public DeviceChanger(IConsole console)
 {
     _Console = Required.NotNull(console, nameof(console));
 }
Esempio n. 7
0
 public MenuView(string[] args, int level, List <MethodsHolder> mh, string start_path) : base(args, level)
 {
     _methods = Required.NotNull(mh, nameof(mh));
     _path    = Required.NotNull(start_path, nameof(start_path));
     render();
 }
Esempio n. 8
0
 public void exception_test()
 {
     Assert.ThrowsException <ArgumentNullException>(() => Required.NotNull <string>(null, "name"));
 }
Esempio n. 9
0
        public SaveSurveyResponseResponse SaveSurveyResponse(ref SurveyResponse surveyResponse)
        {
            Required.NotNull(surveyResponse, "surveyResponse");

            var response = new SaveSurveyResponseResponse();

            try
            {
                ClearResponseCache(surveyResponse);

                // Get user's survey and apply response
                var survey = GetSurvey(new SurveyRequest
                {
                    SurveyName      = surveyResponse.SurveyName,
                    UserID          = surveyResponse.UserID,
                    ApplyResponse   = true,
                    ResponseToApply = surveyResponse
                });

                // Grab any questions that have errors (rule engine adds items to Question's Error collection)
                var questionsWithErrors = survey.Questions.Where(q => q.Errors.Any()).ToList();

                if (questionsWithErrors.Any())
                {
                    response.Success = false;
                    response.Message = "Validation Failed";
                    response.Result  = questionsWithErrors.Select(q => new SurveyQuestionError()
                    {
                        SurveyQuestionID = q.SurveyQuestionID,
                        ErrorMessage     = q.Errors[0].ErrorMessage
                    }).ToList();
                }
                else
                {
                    var existingResponse = GetSurveyResponse(new SurveyResponseRequest()
                    {
                        SurveyName     = surveyResponse.SurveyName,
                        UserID         = surveyResponse.UserID,
                        IncludeAnswers = true
                    });

                    surveyResponse.CurrentScore    = survey.Status.Score;
                    surveyResponse.PercentComplete = survey.Status.PercentComplete;

                    // If survey is complete, ensure corresponding fields have values
                    if (survey.Status.State == SurveyState.Complete && (survey.IsAutoCompleteEnabled || surveyResponse.ApplyAsComplete))
                    {
                        if (existingResponse != null)
                        {
                            surveyResponse.CompleteDate    = existingResponse.CompleteDate ?? DateTime.Now;
                            surveyResponse.CompleteDateUtc = existingResponse.CompleteDateUtc ?? DateTime.UtcNow;
                            surveyResponse.CompleteUserID  = existingResponse.CompleteUserID ?? surveyResponse.ModifyUserID;
                        }
                        else
                        {
                            surveyResponse.CompleteDate    = DateTime.Now;
                            surveyResponse.CompleteDateUtc = DateTime.UtcNow;
                            surveyResponse.CompleteUserID  = surveyResponse.ModifyUserID;
                        }
                    }
                    else
                    {
                        surveyResponse.CompleteDate    = null;
                        surveyResponse.CompleteDateUtc = null;
                        surveyResponse.CompleteUserID  = null;
                    }

                    // Ensure answers have audit info
                    foreach (var answer in surveyResponse.Answers)
                    {
                        answer.CreateUserID  = surveyResponse.ModifyUserID;
                        answer.CreateDate    = surveyResponse.ModifyDate;
                        answer.CreateDateUtc = surveyResponse.ModifyDateUtc;
                    }

                    // Create or Update
                    if (existingResponse == null)
                    {
                        surveyResponse.CreateUserID  = surveyResponse.ModifyUserID;
                        surveyResponse.CreateDate    = surveyResponse.ModifyDate;
                        surveyResponse.CreateDateUtc = surveyResponse.ModifyDateUtc;

                        CreateSurveyResponse(ref surveyResponse);
                    }
                    else
                    {
                        surveyResponse.SurveyResponseID = existingResponse.SurveyResponseID;
                        surveyResponse.CreateUserID     = existingResponse.ModifyUserID;
                        surveyResponse.CreateDate       = existingResponse.ModifyDate;
                        surveyResponse.CreateDateUtc    = existingResponse.ModifyDateUtc;

                        _surveyRepository.UpdateSurveyResponse(surveyResponse);
                    }

                    SaveSurveyResponseHistory(surveyResponse.SurveyResponseID, surveyResponse.ModifyUserID, survey.Status.Pages);

                    response.Success = true;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.FullMessage();

                _logger.Log(ex);
            }

            return(response);
        }
Esempio n. 10
0
        public void Send(Email email)
        {
            Required.NotNull(email, "Email");
            Required.NotNullOrEmpty(email.To, string.Empty, "To");
            Required.NotNullOrEmpty(email.From, string.Empty, "From");
            Required.NotNullOrEmpty(email.Subject, string.Empty, "Subject");
            Required.NotNullOrEmpty(email.Body, string.Empty, "Body");

            var mailMessage = new MailMessage();
            var smtpClient  = new SmtpClient();

            try
            {
                if (!string.IsNullOrEmpty(email.From))
                {
                    mailMessage.From = new MailAddress(email.From);
                }

                if (!string.IsNullOrEmpty(email.To))
                {
                    email.To.Split(';', ',').ForEach(address => { if (!string.IsNullOrEmpty(address))
                                                                  {
                                                                      mailMessage.To.Add(address);
                                                                  }
                                                     });
                }

                if (!string.IsNullOrEmpty(email.Cc))
                {
                    email.Cc.Split(';', ',').ForEach(address => { if (!string.IsNullOrEmpty(address))
                                                                  {
                                                                      mailMessage.CC.Add(address);
                                                                  }
                                                     });
                }

                if (!string.IsNullOrEmpty(email.Bcc))
                {
                    email.Bcc.Split(';', ',').ForEach(address => { if (!string.IsNullOrEmpty(address))
                                                                   {
                                                                       mailMessage.Bcc.Add(address);
                                                                   }
                                                      });
                }

                var re = new Regex(REGEX_HTML,
                                   RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase |
                                   RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);

                mailMessage.Subject    = email.Subject;
                mailMessage.Body       = email.Body;
                mailMessage.IsBodyHtml = re.IsMatch(email.Body);

                smtpClient.Send(mailMessage);

                Log(email, "Email successfully sent.");
            }
            catch (Exception ex)
            {
                var message = "Email send failed.";

                if (ex is SmtpFailedRecipientException)
                {
                    message += string.Format("  Recipient: {0}.", (ex as SmtpFailedRecipientException).FailedRecipient);
                }

                Log(email, message, ex);
            }
        }