/// <summary> /// Handles the configuration of Type Converters factories for the TypeConverterFactories node /// </summary> private void HandleCollectionHandlers() { SectionHandler handler = new SectionHandler(reader, "CollectionHandlers"); handler.AddMethod(new MethodMap("add", "type", new MethodDelegate(AddCollectionHandler))); handler.Process(); }
private void DoRead(SectionHandler h) { for (int no = 1;; ++no) { string line = sr.ReadLine(); if (line == null) { break; } line = line.Trim(); string[] tokens = SplitString(line); try { if (tokens.Length == 0) { continue; } if (!h(tokens)) { break; } } catch (Exception e) { string msg = string.Format("File format error: {0} \"{1}\"", no, line); throw new Exception(msg, e); } } }
/// <summary> /// Get runtime object. /// </summary> /// <returns>Runtime object.</returns> protected internal virtual object GetRuntimeObject() { if (SectionHandler != null) { try { XmlReader reader = new XmlTextReader(new StringReader(RawXml)); DoDeserializeSection(reader); if (!String.IsNullOrEmpty(SectionInformation.Source)) { RawXml = File.ReadAllText(SectionInformation.Source); SectionInformation.SetRawXml(RawXml); } } catch { } XmlDocument doc = new XmlDocument(); doc.LoadXml(RawXml); return(SectionHandler.Create(GenContext, doc.DocumentElement)); } return(this); }
private void RegisterConfiguredModule(ContainerBuilder builder, SectionHandler configurationSection, ModuleElement moduleElement) { try { var moduleType = this.LoadType(moduleElement.Type, configurationSection.DefaultAssembly); IModule module = null; IEnumerable <Parameter> parameters = moduleElement.Parameters.ToParameters().Select(p => new LazyParameter(p)); IEnumerable <Parameter> properties = moduleElement.Properties.ToParameters().Select(p => new LazyParameter(p)); using (var moduleActivator = new ReflectionActivator( moduleType, new DefaultConstructorFinder(), new MostParametersConstructorSelector(), parameters, properties)) { module = (IModule)moduleActivator.ActivateInstance(new ContainerBuilder().Build(), Enumerable.Empty <Parameter>()); } builder.RegisterModule(module); } catch (Exception) { // log it throw; } }
/// <summary> /// Handles the configuration of Type Converters for the TypeConverters node /// </summary> private void HandleTypeConverters() { SectionHandler handler = new SectionHandler(reader, "TypeConverters"); handler.AddMethod(new MethodMap("add", "type property converter", new MethodDelegate(AddTypeConverter))); handler.Process(); }
private void HandleIgnoreProperties() { SectionHandler handler = new SectionHandler(reader, "IgnoreProperties"); handler.AddMethod(new MethodMap("add", "type property", new MethodDelegate(AddIgnoreProperty))); handler.Process(); }
/// <summary> /// Handles the "TypeBindings" tag of the config /// </summary> private void HandleTypeBindings() { SectionHandler handler = new SectionHandler(reader, "TypeBindings"); handler.AddMethod(new MethodMap("add", "alias type", new MethodDelegate(AddTypeBinding))); handler.AddMethod(new MethodMap("remove", "alias type", new MethodDelegate(RemoveTypeBinding))); handler.AddMethod(new MethodMap("clear", "", delegate(string t, string[] v) { context.TypeAliases.Clear(); })); handler.Process(); }
public async Task Unauthorized_User_Is_Not_Authorized() { AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext(); SectionHandler sut = CreateHandler(); await sut.HandleAsync(authHandlerContext); Assert.IsFalse(authHandlerContext.HasSucceeded); }
public async Task User_Without_Section_Access_Is_Not_Authorized() { AuthorizationHandlerContext authHandlerContext = CreateAuthorizationHandlerContext(); SectionHandler sut = CreateHandler(userIsAuthorized: true); await sut.HandleAsync(authHandlerContext); Assert.IsFalse(authHandlerContext.HasSucceeded); }
protected internal virtual object GetRuntimeObject() { if (SectionHandler != null) { ConfigurationSection parentSection = sectionInformation != null?sectionInformation.GetParentSection() : null; object parent = parentSection != null?parentSection.GetRuntimeObject() : null; if (RawXml == null) { return(parent); } try { // This code requires some re-thinking... XmlReader reader = new ConfigXmlTextReader( new StringReader(RawXml), Configuration.FilePath); DoDeserializeSection(reader); if (!String.IsNullOrEmpty(SectionInformation.ConfigSource)) { string fileDir = SectionInformation.ConfigFilePath; if (!String.IsNullOrEmpty(fileDir)) { fileDir = Path.GetDirectoryName(fileDir); } else { fileDir = String.Empty; } string path = Path.Combine(fileDir, SectionInformation.ConfigSource); if (File.Exists(path)) { RawXml = File.ReadAllText(path); SectionInformation.SetRawXml(RawXml); } } } catch { // ignore, it can fail - we deserialize only in order to get // the configSource attribute } XmlDocument doc = new ConfigurationXmlDocument(); doc.LoadXml(RawXml); return(SectionHandler.Create(parent, ConfigContext, doc.DocumentElement)); } return(this); }
public void TestGetConfigNullSection() { var handler = new SectionHandler(); var section = new XmlDocument(); object result = handler.Create(null, null, section); Assert.NotNull(result); Assert.True(result is CacheConfig[]); var caches = result as CacheConfig[]; Assert.Equal(0, caches.Length); }
public async Task <HttpResponseMessage> SaveSharedProjectAsync(SharedProjectsDto sharedProjectsDto) { var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault(); var urlBrand = "generac"; if (clientURL.ToLower().Contains("pramac")) { urlBrand = "pramac"; } if (String.IsNullOrEmpty(sharedProjectsDto.Language) || sharedProjectsDto.Language != "en" || sharedProjectsDto.Language != "en") { sharedProjectsDto.Language = "en"; } var result = _userDashboard.SaveSharedProject(sharedProjectsDto, UserID, UserName); //var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault(); var callbackURL = $"{clientURL}/project/{sharedProjectsDto.ProjectID}"; var emaildata = new SendGridEmailData { template_id = SectionHandler.GetSectionValue($"{sharedProjectsDto.Language.ToLower()}/emailTemplates/projectShared", "TemplateID", ""), personalizations = new List <Personalization>() { new Personalization { to = new List <To>() { new To { email = sharedProjectsDto.RecipientEmail, name = sharedProjectsDto.RecipientEmail } }, substitutions = new Dictionary <string, string>() { { "%SharerLoginID%", UserName }, { "%ProjectName%", result.SharedProjectName }, { "%ProjectComments%", sharedProjectsDto.Notes }, { "%ProjectLink%", callbackURL }, { "%CompanyName%", EmailHelper.CompanyName(sharedProjectsDto.Language, urlBrand) }, { "%CompanyAddress%", EmailHelper.CompanyAddress(sharedProjectsDto.Language, urlBrand) } } } } }; var emailResponse = EmailHelper.SendGridAsyncWithTemplate(emaildata); return(CreateHttpResponse(() => { return Request.CreateResponse(result); })); }
private async Task <string> SendEmailConfirmationTokenAsync(ApplicationUser user, string language) { var code = UserManager.GenerateEmailConfirmationToken(user.Id); var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault(); var callbackURL = $"{clientURL}/confirmEmail?userId={user.Id}&code={code}"; var urlBrand = "generac"; if (clientURL.ToLower().Contains("pramac")) { urlBrand = "pramac"; } if (String.IsNullOrEmpty(language) || language != "en" || language != "en") { language = "en"; } var emaildata = new SendGridEmailData { template_id = SectionHandler.GetSectionValue($"{language.ToLower()}/emailTemplates/confirmEmail", "TemplateID", ""), personalizations = new List <Personalization>() { new Personalization { to = new List <To>() { new To { email = user.Email, name = user.FirstName + " " + user.LastName } }, substitutions = new Dictionary <string, string>() { { "%FirstName%", user.FirstName }, { "%LastName%", user.LastName }, { "%EmailConfirmationLink%", callbackURL }, { "%CompanyName%", EmailHelper.CompanyName(language, urlBrand) }, { "%CompanyAddress%", EmailHelper.CompanyAddress(language, urlBrand) } } } } }; var responseCode = await EmailHelper.SendGridAsyncWithTemplate(emaildata); return(callbackURL); }
protected override void RegisterConfiguredModules(ContainerBuilder builder, SectionHandler configurationSection) { if (builder == null) { throw new ArgumentNullException("builder"); } if (configurationSection == null) { throw new ArgumentNullException("configurationSection"); } foreach (ModuleElement moduleElement in configurationSection.Modules) { this.RegisterConfiguredModule(builder, configurationSection, moduleElement); } }
public void TestGetConfigFromFile() { const string xmlSimple = "<rediscache><cache region=\"foo\" expiration=\"500\" priority=\"4\" /></rediscache>"; var handler = new SectionHandler(); XmlNode section = GetConfigurationSection(xmlSimple); object result = handler.Create(null, null, section); Assert.NotNull(result); Assert.True(result is CacheConfig[]); var caches = result as CacheConfig[]; Assert.Equal(1, caches.Length); Assert.Equal(new Dictionary <string, string>() { { "expiration", "500" }, { "priority", "4" } }, caches[0].Properties); }
public async Task <HttpResponseMessage> GrantEditAccess(SolutionRequestDto solutionRequestDto) { var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault(); var urlBrand = "generac"; if (clientURL.ToLower().Contains("pramac")) { urlBrand = "pramac"; } if (String.IsNullOrEmpty(solutionRequestDto.Language) || solutionRequestDto.Language != "en" || solutionRequestDto.Language != "en") { solutionRequestDto.Language = "en"; } var result = _projectSolutionProcessor.GrantEditAccess(solutionRequestDto, UserID, UserName); //var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault(); var callbackURL = $"{clientURL}/project/{solutionRequestDto.ProjectID}/solution/{solutionRequestDto.SolutionID}"; var projectOwnerUserDetails = GetUserDetailsByUserName(result.RecipientEmail); var shareeUserDetails = GetUserDetailsByUserName(UserName); var emaildata = new SendGridEmailData { template_id = SectionHandler.GetSectionValue($"{solutionRequestDto.Language.ToLower()}/emailTemplates/grantEditAccess", "TemplateID", ""), personalizations = new List <Personalization>() { new Personalization { to = new List <To>() { new To { email = result.RecipientEmail, name = projectOwnerUserDetails.FirstName + " " + projectOwnerUserDetails.LastName } }, substitutions = new Dictionary <string, string>() { { "%FirstName%", projectOwnerUserDetails.FirstName }, { "%LastName%", projectOwnerUserDetails.LastName }, { "%ShareeFirstName%", shareeUserDetails.LastName }, { "%ShareeLastName%", shareeUserDetails.LastName }, { "%ShareeEmail%", shareeUserDetails.Email }, { "%SolutionName%", result.SolutionName }, { "%ProjectName%", result.ProjectName }, { "%SolutionComments%", result.SolutionComments }, { "%SolutionLink%", callbackURL }, { "%CompanyName%", EmailHelper.CompanyName(solutionRequestDto.Language, urlBrand) }, { "%CompanyAddress%", EmailHelper.CompanyAddress(solutionRequestDto.Language, urlBrand) } } } } }; var emailResponse = await EmailHelper.SendGridAsyncWithTemplate(emaildata); return(CreateHttpResponse(() => { return Request.CreateResponse(result); })); }
public async Task <HttpResponseMessage> ForgotPassword(ForgotPasswordDto model) { try { if (model == null || !ModelState.IsValid) { var errorResponse = new { ErrorCode = -1, ErrorDescription = "Model State is invalid." }; return(Request.CreateResponse(HttpStatusCode.OK, errorResponse)); } var user = await UserManager.FindByEmailAsync(model.EmailAddress); if (user == null) { var errorResponse = new { ErrorCode = -1, ErrorDescription = "forgotPassword.ForgotPasswordEmailNotFoundError" }; return(Request.CreateResponse(HttpStatusCode.OK, errorResponse)); } else if (!(await UserManager.IsEmailConfirmedAsync(user.Id))) { var errorResponse = new { ErrorCode = -1, ErrorDescription = "forgotPassword.ForgotPasswordTechnicalError" }; return(Request.CreateResponse(HttpStatusCode.OK, errorResponse)); } var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); //var clientURL = Request.GetOwinContext().Request.Uri.GetLeftPart(UriPartial.Authority); var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault(); var callbackURL = $"{clientURL}/resetPassword?userId={user.Id}&code={code}"; var urlBrand = "generac"; if (clientURL.ToLower().Contains("pramac")) { urlBrand = "pramac"; } if (String.IsNullOrEmpty(model.Language) || model.Language != "en" || model.Language != "en") { model.Language = "en"; } var emaildata = new SendGridEmailData { template_id = SectionHandler.GetSectionValue($"{model.Language.ToLower()}/emailTemplates/resetPassword", "TemplateID", ""), personalizations = new List <Personalization>() { new Personalization { to = new List <To>() { new To { email = user.Email, name = user.FirstName + " " + user.LastName } }, substitutions = new Dictionary <string, string>() { { "%FirstName%", user.FirstName }, { "%LastName%", user.LastName }, { "%LoginID%", user.Email }, { "%PasswordResetLink%", callbackURL }, { "%CompanyName%", EmailHelper.CompanyName(model.Language, urlBrand) }, { "%CompanyAddress%", EmailHelper.CompanyAddress(model.Language, urlBrand) } } } } }; await EmailHelper.SendGridAsyncWithTemplate(emaildata); var successResponse = new { ErrorCode = 0, Message = "Password Reset Email sent successfully." }; _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Info, "Forgot Password", "Forgot Password", "Forgot Password", "Forgot Password Success for " + model.EmailAddress); return(Request.CreateResponse(HttpStatusCode.OK, successResponse)); } catch (Exception ex) { var errorResponse = new { ErrorCode = -1, ErrorDescription = "Exception occured in User registration" }; _traceMessageProcessor.WriteTrace(TraceMessaging.EventSource, TraceLevel.Error, "Forgot Password", "Forgot Password", "Forgot Password Failed for " + model.EmailAddress, ex.Message); return(Request.CreateResponse(HttpStatusCode.OK, errorResponse)); } }