public override CodeCompileUnit CreateCodeCompileUnit() { if (!CanImplementRoleStore) { return(null); } var unit = new CodeCompileUnit(); var ns = new CodeNamespace(Namespace); var type = new CodeTypeDeclaration(TypeName); type.IsPartial = true; CodeDomProducer.AddSignature(type); Helpers.AddGeneratedCodeAttribute(type, CodeDomProducer.ProductionFlags); ns.Types.Add(type); unit.Namespaces.Add(ns); ImplementIRoleStore(type); ImplementIRoleClaimStore(type); ImplementIQueryableRoleStore(type); ImplementIDisposableInterface(type); FinalizeMethods(type); return(unit); }
public override void Initialize(Project project, Producer producer) { base.Initialize(project, producer); _codeDomProducer = project.Producers.GetProducerInstance <CodeDomProducer>(); if (_codeDomProducer == null) { return; } if (string.IsNullOrWhiteSpace(EditorTargetDirectory)) { EditorTargetDirectory = _codeDomProducer.EditorTargetDirectory; } _codeDomProducer.CodeDomProduction += CodeDomProducer_CodeDomProduction; Entity userEntity = ProjectUtilities.FindByEntityType(project, EntityType.User); if (userEntity != null) { _identityUser = new IdentityUser(userEntity); } Entity roleEntity = ProjectUtilities.FindByEntityType(project, EntityType.Role); if (roleEntity != null) { _identityRole = new IdentityRole(roleEntity); } Entity loginEntity = ProjectUtilities.FindByEntityType(project, EntityType.Login); if (loginEntity != null) { _identityLogin = new IdentityLogin(loginEntity); } Entity claimEntity = ProjectUtilities.FindByEntityType(project, EntityType.Claim); if (claimEntity != null) { _identityClaim = new IdentityClaim(claimEntity); } if (_identityUser != null) { _userStoreProducer = new UserStoreProducer(_codeDomProducer, this, _identityUser, _identityRole, _identityLogin, _identityClaim); } if (_identityRole != null) { _roleStoreProducer = new RoleStoreProducer(_codeDomProducer, this, _identityRole); } }
public XmlDocument Run(IDictionary context) { if (context == null || !context.Contains("Project")) { // we are probably called for meta data inspection, so we send back the descriptor xml return(_descriptor); } Project = (Project)context["Project"]; _codeDomProducer = Project.Producers.GetProducerInstance <CodeDomProducer>(); if (_codeDomProducer != null) { _codeDomProducer.CodeDomProduction += CodeDomProducer_CodeDomProduction; } return(_descriptor); }
public XmlDocument Run(IDictionary context) { if (context == null || !context.Contains("Project")) { // we are probably called for meta data inspection, so we send back the descriptor xml return _descriptor; } Project = (Project)context["Project"]; _codeDomProducer = Project.Producers.GetProducerInstance<CodeDomProducer>(); if (_codeDomProducer != null) { _codeDomProducer.CodeDomProduction += CodeDomProducer_CodeDomProduction; } return _descriptor; }
public override void Initialize(Project project, Producer producer) { base.Initialize(project, producer); _codeDomProducer = project.Producers.GetProducerInstance<CodeDomProducer>(); if (_codeDomProducer == null) return; if (string.IsNullOrWhiteSpace(EditorTargetDirectory)) { EditorTargetDirectory = _codeDomProducer.EditorTargetDirectory; } _codeDomProducer.CodeDomProduction += CodeDomProducer_CodeDomProduction; Entity userEntity = ProjectUtilities.FindByEntityType(project, EntityType.User); if (userEntity != null) { _identityUser = new IdentityUser(userEntity); } Entity roleEntity = ProjectUtilities.FindByEntityType(project, EntityType.Role); if (roleEntity != null) { _identityRole = new IdentityRole(roleEntity); } Entity loginEntity = ProjectUtilities.FindByEntityType(project, EntityType.Login); if (loginEntity != null) { _identityLogin = new IdentityLogin(loginEntity); } Entity claimEntity = ProjectUtilities.FindByEntityType(project, EntityType.Claim); if (claimEntity != null) { _identityClaim = new IdentityClaim(claimEntity); } if (_identityUser != null) { _userStoreProducer = new UserStoreProducer(_codeDomProducer, this, _identityUser, _identityRole, _identityLogin, _identityClaim); } if (_identityRole != null) { _roleStoreProducer = new RoleStoreProducer(_codeDomProducer, this, _identityRole); } }
public virtual string Produce(bool addFile) { Hashtable dic = new Hashtable(); dic.Add("Project", CodeDomProducer.Project); dic.Add("Producer", CodeDomProducer); dic.Add("TemplateProducer", this); string productionTargetPath = CodeDomProducer.GetProductionTargetPath(ProductionNode, FinalizeTargetPath(), IsWebType, false); string tempPath = (CodeDomProducer.TargetProductionOptions & TargetProductionOptions.CreateTempFile) == TargetProductionOptions.None ? null : productionTargetPath + ".tmp"; dic.Add("TargetPath", productionTargetPath); dic.Add("TempTargetPath", tempPath); if (!RaiseProducing(dic)) { return(null); } try { if (tempPath == null) { BaseProducer.CreateFileDirectory(productionTargetPath, CodeDomProducer); BaseProducer.PathUnprotect(productionTargetPath, CodeDomProducer); } else { BaseProducer.CreateFileDirectory(tempPath, CodeDomProducer); } bool append = false; if (File.Exists(productionTargetPath) && CodeDomProducer.IsGeneratedFile(productionTargetPath)) { if (tempPath != null) { IOUtilities.PathOverwrite(productionTargetPath, tempPath, true); } append = true; } string target = tempPath ?? productionTargetPath; try { var unit = CreateCodeCompileUnit(); if (unit == null) { return(null); } IOUtilities.WrapSharingViolations(() => { using (StreamWriter streamWriter = new StreamWriter(target, append, CodeDomProducer.OutputEncoding)) { IndentedTextWriter indentedTextWriter = ((CodeDomProducer.ProductionFlags & ProductionFlags.RemoveDates) != ProductionFlags.RemoveDates ? new IndentedTextWriter(streamWriter) : new NoDiffIndentedTextWriter(streamWriter)); CodeDomProducer.CodeDomProvider.GenerateCodeFromCompileUnit(unit, indentedTextWriter, CodeDomProducer.CodeGeneratorOptions); } }); } catch (Exception ex) { CodeFluentRuntimeException violationException = IOUtilities.GetSharingViolationException(target, ex); if (violationException != null) { throw violationException; } throw; } if (File.Exists(tempPath ?? productionTargetPath)) { CodeDomProducer.RaiseProduction(this, ProductionEventArgs.CreateFileWriteEvent(productionTargetPath, GetType().FullName)); if (tempPath != null) { BaseProducer.FileOverwrite(tempPath, productionTargetPath, CodeDomProducer, false); } CodeDomProducer.AddToGeneratedFiles(productionTargetPath); } } finally { if (tempPath != null && File.Exists(tempPath)) { File.Delete(tempPath); } } RaiseProduced(); if (addFile) { CodeDomProducer.AddFileName(productionTargetPath); } return(productionTargetPath); }