/// <summary>
        /// The get repository.
        /// </summary>
        /// <param name="serviceLocator">
        /// The service locator.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// The <see cref="IRepository{T}"/>.
        /// </returns>
        public static IRepository <T> GetRepository <T>([NotNull] this IHaveServiceLocator serviceLocator)
            where T : IEntity
        {
            CodeContracts.VerifyNotNull(serviceLocator, "serviceLocator");

            return(serviceLocator.Get <IRepository <T> >());
        }
        /// <summary>
        /// The run startup services.
        /// </summary>
        /// <param name="serviceLocator">
        /// The instance that has a service locator.
        /// </param>
        public static void RunStartupServices([NotNull] this IHaveServiceLocator serviceLocator)
        {
            CodeContracts.VerifyNotNull(serviceLocator, "serviceLocator");

            var startupServices = serviceLocator.Get <IEnumerable <IStartupService> >();

            // run critical first...
            startupServices.Where(s => s.HasInterface <ICriticalStartupService>()).OrderByDescending(i => i.Priority)
            .ForEach(service => service.Run());

            // run secondary...
            startupServices.Where(s => !s.HasInterface <ICriticalStartupService>()).OrderByDescending(i => i.Priority)
            .ForEach(service => service.Run());
        }
示例#3
0
        /// <summary>
        /// The send verification email.
        /// </summary>
        /// <param name="haveServiceLocator">
        /// The have service locator.
        /// </param>
        /// <param name="user"></param>
        public static void SendVerificationEmail(
            [NotNull] this IHaveServiceLocator haveServiceLocator, [NotNull] MembershipUser user, [NotNull] string email, int?userID, string newUsername = null)
        {
            CodeContracts.VerifyNotNull(email, "email");
            CodeContracts.VerifyNotNull(user, "user");
            CodeContracts.VerifyNotNull(haveServiceLocator, "haveServiceLocator");

            string hashinput = DateTime.UtcNow + email + Security.CreatePassword(20);
            string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

            // save verification record...
            haveServiceLocator.GetRepository <CheckEmail>().Save(userID, hash, user.Email);

            var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

            string subject = haveServiceLocator.Get <ILocalization>().GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", haveServiceLocator.Get <YafBoardSettings>().Name);

            verifyEmail.TemplateParams["{link}"]      = YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash);
            verifyEmail.TemplateParams["{key}"]       = hash;
            verifyEmail.TemplateParams["{forumname}"] = haveServiceLocator.Get <YafBoardSettings>().Name;
            verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

            verifyEmail.SendEmail(new MailAddress(email, newUsername ?? user.UserName), subject, true);
        }