public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; EntitiesToSkip = Config.GetHashSet("EntitiesToSkip", new HashSet<string>()); EntityPrefixesToSkip = Config.GetList("EntityPrefixesToSkip", new List<string>()); GenerateEntityRelationships = ConfigHelper.GetAppSettingOrDefault("GenerateEntityRelationships", true); }
public FilteringService(ICodeWriterFilterService defaultService) { this.DefaultService = defaultService; entities = new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:Entities") ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); allAttributes = new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:AllAttributes") ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); entityAttributes = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allAttributes)) { entityAttributes.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:Attributes:" + entity) ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))); } all1NRelationships = new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:All1NRelationships") ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); entity1NRelationships = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(all1NRelationships)) { entity1NRelationships.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:1NRelationships:" + entity) ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))); } allN1Relationships = new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:AllN1Relationships") ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); entityN1Relationships = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allN1Relationships)) { entityN1Relationships.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:N1Relationships:" + entity) ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))); } allNNRelationships = new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:AllNNRelationships") ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); entityNNRelationships = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allNNRelationships)) { entityNNRelationships.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable("AlbanianXrm.EarlyBound:NNRelationships:" + entity) ?? "").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))); } }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; EntitiesToSkip = Config.GetHashSet("EntitiesToSkip", new HashSet <string>()); EntityPrefixesToSkip = Config.GetList("EntityPrefixesToSkip", new List <string>()); GenerateEntityRelationships = ConfigHelper.GetAppSettingOrDefault("GenerateEntityRelationships", true); }
public static EntityMetadata AddManyToMany( this EntityMetadata entityMetadata, ICodeWriterFilterService filterService, params ManyToManyRelationshipMetadata[] manyToManyRelationshipMetadata ) { foreach (var many2Many in manyToManyRelationshipMetadata) { many2Many.Set(x => x.RelationshipType, RelationshipType.ManyToManyRelationship); if (many2Many.Entity1LogicalName == null) { many2Many.Entity1IntersectAttribute = entityMetadata.PrimaryIdAttribute; many2Many.Entity1LogicalName = entityMetadata.LogicalName; } else { many2Many.Entity2IntersectAttribute = entityMetadata.PrimaryIdAttribute; many2Many.Entity2LogicalName = entityMetadata.LogicalName; } if (filterService != null) { filterService.GenerateRelationship(many2Many, Arg.Any <EntityMetadata>(), Arg.Any <IServiceProvider>()) .Returns(true); } } var existing = entityMetadata.ManyToManyRelationships ?? Array.Empty <ManyToManyRelationshipMetadata>(); entityMetadata.Set(x => x.ManyToManyRelationships, existing.Union(manyToManyRelationshipMetadata).ToArray()); return(entityMetadata); }
public SolutionFilter(ICodeWriterFilterService defaultService) { this.defaultService = defaultService; var uniqueSolutionName = Parameters.GetParameter("solution"); var service = new OrganizationServiceFactory().Create(); solutionEntities = getSolutionEntities(uniqueSolutionName, service); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; Approver = new WhitelistBlacklistLogic(Config.GetHashSet("EntitiesWhitelist", new HashSet <string>()), Config.GetList("EntityPrefixesWhitelist", new List <string>()), Config.GetHashSet("EntitiesToSkip", new HashSet <string>()), Config.GetList("EntityPrefixesToSkip", new List <string>())); GenerateEntityRelationships = ConfigHelper.GetAppSettingOrDefault("GenerateEntityRelationships", true); }
public CodeWriterFilter(ICodeWriterFilterService defaultService) { DefaultService = defaultService; EntityPrefixToSkip = new List <string> { "msdyn_", "pvs_", "ball_", "adx_" }; EntitiesToGenerate = new HashSet <string> { "account", "contact", "crmp_sap_accountdetail" }; }
public CodeFilteringService(ICodeWriterFilterService defaultService, IDictionary <string, string> parameters) { _defaultService = defaultService; this.Debug(); foreach (var param in parameters) { $"Key:{param.Key} Value:{param.Value}".Debug(); } }
/// <summary> /// constructor /// </summary> /// <param name="defaultService">default implementation</param> public CodeWriterFilter(ICodeWriterFilterService defaultService) { if (System.Environment.GetCommandLineArgs()?.Where(r => r == "/debug").Any() == true) { Console.WriteLine("Please attach debugger to crmsvcutil.exe process"); Console.WriteLine("Press [Enter] when ready"); Console.ReadLine(); Console.WriteLine("Continues..."); } this._defaultService = defaultService; }
public BasicFilteringService(ICodeWriterFilterService defaultService) { this.DefaultService = defaultService; try { _xldoc = XDocument.Load(FilterXml); } catch (Exception ex) { throw new Exception("Could not find filter.xml" + ex.ToString()); } }
public void CustomizeCodeDom(CodeCompileUnit codeCompileUnit, IServiceProvider services) { if (codeCompileUnit == null) { throw new ArgumentNullException(nameof(codeCompileUnit)); } if (services == null) { throw new ArgumentNullException(nameof(services)); } Console.WriteLine(string.Empty); Console.WriteLine("Generating code is in progress."); ReferencedOptionSetNames = new List <string>(); ICodeWriterFilterService codeWriterFilterService = (ICodeWriterFilterService)services.GetService(typeof(ICodeWriterFilterService)); IMetadataProviderService metadataProviderService = (IMetadataProviderService)services.GetService(typeof(IMetadataProviderService)); IOrganizationMetadata organizationMetadata = metadataProviderService.LoadMetadata(); // ServiceHelper.IntersectionEntityList = organizationMetadata.Entities.Where(x => x.IsIntersect == true).ToList(); foreach (CodeNamespace codeNamespace in codeCompileUnit.Namespaces) { foreach (EntityInfo entityInfo in ServiceHelper.EntityList) { EntityMetadata entityMetadata = entityInfo.EntityMetadata; CodeTypeDeclaration codeTypeDeclaration = codeNamespace .Types .OfType <CodeTypeDeclaration>() .FirstOrDefault(codeType => codeType.Name.ToUpperInvariant() == entityMetadata.SchemaName.ToUpperInvariant()); GenerateMultiSelectOptionSets(codeNamespace, codeTypeDeclaration, entityMetadata); GenerateOptionSets(codeNamespace, codeTypeDeclaration, entityMetadata); GenerateSetterForReadOnlyFields(codeTypeDeclaration, entityMetadata); } } ExcludeNonReferencedGlobalOptionSets(codeCompileUnit, organizationMetadata); GenerateFieldStructures(codeCompileUnit); GenerateCodeFiles(codeCompileUnit); CleanupNamespaces(codeCompileUnit); Console.WriteLine("Generating code completed successfully."); }
internal CodeGenerationServiceProvider( ITypeMappingService typeMappingService , ICodeGenerationService codeGenerationService , ICodeWriterFilterService codeFilterService , IMetadataProviderService metadataProviderService , INamingService namingService ) { this.TypeMappingService = typeMappingService; this.CodeGenerationService = codeGenerationService; this.CodeWriterFilterService = codeFilterService; this.MetadataProviderService = metadataProviderService; this.NamingService = namingService; }
public FilteringService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; GeneratedOptionSets = new Dictionary <String, bool>(); try { _xldoc = XDocument.Load(FilterXml); } catch (Exception ex) { throw new Exception("Could not find filter.xml" + ex.ToString()); } }
public void Initialise() { Builder = Model.UsingModule <DynamicsModule>(); typeof(SolutionHelper) .NullStaticField(nameof(SolutionHelper.organisationMetadata)) .NullStaticField(nameof(SolutionHelper.solutionEntities)); SolutionHelper.organisationService = Substitute.For <IOrganizationService>(); serviceProvider = Substitute.For <IServiceProvider>(); filterService = Substitute.For <ICodeWriterFilterService>(); serviceProvider.GetService(typeof(ICodeWriterFilterService)).Returns(filterService); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; if (string.IsNullOrWhiteSpace(OptionSetEntityFilter) || !GenerateOnlyReferencedOptionSets) { EntityFilterService = DefaultService; } else { var t = Type.GetType(OptionSetEntityFilter); EntityFilterService = (ICodeWriterFilterService)Activator.CreateInstance(t, DefaultService); } GeneratedOptionSets = new HashSet <string>(); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; if (string.IsNullOrWhiteSpace(OptionSetEntityFilter) || !GenerateOnlyReferencedOptionSets) { EntityFilterService = DefaultService; } else { var t = Type.GetType(OptionSetEntityFilter); if (t == null) { throw new Exception("Unable to determine OptionSetEntityFilter Type"); } EntityFilterService = (ICodeWriterFilterService)Activator.CreateInstance(t, DefaultService); } GeneratedOptionSets = new HashSet <string>(); }
public static EntityMetadata AddAttribute( this EntityMetadata entityMetadata, ICodeWriterFilterService filterService, params AttributeMetadata[] attributes ) { foreach (var att in attributes) { att.Set(x => x.EntityLogicalName, entityMetadata.LogicalName); if (filterService != null) { filterService.GenerateAttribute(att, Arg.Any <IServiceProvider>()) .Returns(true); } } var existing = entityMetadata.Attributes ?? Array.Empty <AttributeMetadata>(); entityMetadata.Set(x => x.Attributes, existing.Union(attributes).ToArray()); return(entityMetadata); }
public static EntityMetadata AddOneToMany( this EntityMetadata entityMetadata, ICodeWriterFilterService filterService, params OneToManyRelationshipMetadata[] oneToManyRelationshipMetadata ) { foreach (var one2Many in oneToManyRelationshipMetadata) { one2Many.Set(x => x.RelationshipType, RelationshipType.OneToManyRelationship); one2Many.ReferencedAttribute = entityMetadata.PrimaryIdAttribute; one2Many.ReferencedEntity = entityMetadata.LogicalName; if (filterService != null) { filterService.GenerateRelationship(one2Many, Arg.Is <EntityMetadata>(x => x.LogicalName == one2Many.ReferencingEntity), Arg.Any <IServiceProvider>()) .Returns(true); } } var existing = entityMetadata.OneToManyRelationships ?? Array.Empty <OneToManyRelationshipMetadata>(); entityMetadata.Set(x => x.OneToManyRelationships, existing.Union(oneToManyRelationshipMetadata).ToArray()); return(entityMetadata); }
public FilteringService(ICodeWriterFilterService defaultService) { #if DEBUG if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(Constants.ENVIRONMENT_ATTACHDEBUGGER))) { System.Diagnostics.Debugger.Launch(); } #endif this.DefaultService = defaultService; entities = new HashSet <string>((Environment.GetEnvironmentVariable(Constants.ENVIRONMENT_ENTITIES) ?? "").Split(",")); allAttributes = new HashSet <string>((Environment.GetEnvironmentVariable(Constants.ENVIRONMENT_ALL_ATTRIBUTES) ?? "").Split(",")); entityAttributes = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allAttributes)) { entityAttributes.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable(string.Format(CultureInfo.InvariantCulture, Constants.ENVIRONMENT_ENTITY_ATTRIBUTES, entity)) ?? "").Split(","))); } allRelationships = new HashSet <string>((Environment.GetEnvironmentVariable(Constants.ENVIRONMENT_ALL_RELATIONSHIPS) ?? "").Split(",")); entity1NRelationships = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allRelationships)) { entity1NRelationships.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable(string.Format(CultureInfo.InvariantCulture, Constants.ENVIRONMENT_RELATIONSHIPS1N, entity)) ?? "").Split(","))); } entityN1Relationships = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allRelationships)) { entityN1Relationships.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable(string.Format(CultureInfo.InvariantCulture, Constants.ENVIRONMENT_RELATIONSHIPSN1, entity)) ?? "").Split(","))); } entityNNRelationships = new Dictionary <string, HashSet <string> >(); foreach (var entity in entities.Except(allRelationships)) { entityNNRelationships.Add(entity, new HashSet <string>((Environment.GetEnvironmentVariable(string.Format(CultureInfo.InvariantCulture, Constants.ENVIRONMENT_RELATIONSHIPSNN, entity)) ?? "").Split(","))); } }
public static EntityMetadata AddManyToOne( this EntityMetadata entityMetadata, ICodeWriterFilterService filterService, params OneToManyRelationshipMetadata[] manyToOneRelationshipMetadata ) { foreach (var many2One in manyToOneRelationshipMetadata) { many2One.Set(x => x.RelationshipType, RelationshipType.OneToManyRelationship); many2One.ReferencingEntity = entityMetadata.LogicalName; if (filterService != null) { filterService.GenerateRelationship(many2One, Arg.Is <EntityMetadata>(x => x.LogicalName == many2One.ReferencedEntity), Arg.Any <IServiceProvider>()) .Returns(true); } } ; var existing = entityMetadata.ManyToOneRelationships ?? Array.Empty <OneToManyRelationshipMetadata>(); entityMetadata.Set(x => x.ManyToOneRelationships, existing.Union(manyToOneRelationshipMetadata).ToArray()); return(entityMetadata); }
public CompositeFilterService(ICodeWriterFilterService defaultService, IServiceExtensionsConfiguration configuration) : base(defaultService, configuration) { InitializeFilters(); }
public CompositeFilterService(ICodeWriterFilterService defaultService) : base(defaultService) { InitializeFilters(); }
public EntityFilter(ICodeWriterFilterService defaultService) { this.defaultService = defaultService; this.LoadFilter(); }
public FilterOptionSetEnums(ICodeWriterFilterService defaultService) { DefaultService = defaultService; GeneratedOptionSets = new HashSet<string>(); InvalidCSharpNamePrefix = ConfigHelper.GetAppSettingOrDefault("InvalidCSharpNamePrefix", "_"); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; }
public FilteringService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { Console.WriteLine("Initializing CodeWriterFilterService."); ActivityList = ServiceHelper.ActivityLogicalNames(); DefaultService = defaultService; EntityBlackList = new List <string>(); EntityWhiteList = new List <string>(); FieldBlackList = new List <string>(); OptionList = new List <string>(); OptionSetList = new List <string>(); RelationshipList = new List <string>(); if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.EntityBlackList)) { string[] entities = Properties.Settings.Default.EntityBlackList.Split(",".ToCharArray()); if (entities.Length > 0) { EntityBlackList = entities.ToList(); } } if (!Properties.Settings.Default.GenerateAllEntities) { XElement xmlDocument = XElement.Load(Properties.Settings.Default.EntityWhiteListFilename); XElement entitiesElement = xmlDocument.Element("entities"); if (entitiesElement == null) { throw new InvalidProgramException("Entities XML file is missing the 'entities' element."); } if (entitiesElement.Elements("entity").ToList().Count == 0) { throw new InvalidProgramException("Entities XML file does not contain any entities."); } bool entityWhiteListContainsActivity = false; foreach (XElement entityElement in entitiesElement.Elements("entity")) { string entityName = Regex.Replace(entityElement.Value, @"[^a-zA-Z0-9_]", string.Empty).ToLowerInvariant(); if (!string.IsNullOrWhiteSpace(entityName)) { EntityWhiteList.Add(entityName); } if (ActivityList.Contains(entityName)) { entityWhiteListContainsActivity = true; } } if (entityWhiteListContainsActivity) { if (!EntityWhiteList.Contains(ServiceHelper.ActivityPartyLogicalName)) { EntityWhiteList.Add(ServiceHelper.ActivityPartyLogicalName); } if (!EntityWhiteList.Contains(ServiceHelper.ActivityPointerLogicalName)) { EntityWhiteList.Add(ServiceHelper.ActivityPointerLogicalName); } } } if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.GlobalFieldBlackList)) { string[] fields = Properties.Settings.Default.GlobalFieldBlackList.Split(",".ToCharArray()); if (fields.Length > 0) { FieldBlackList = fields.ToList(); } } // Debugging: Uncomment the below lines of code - run the generate batch file, set the break points and // attach the debugger on CrmSvcUtil.exe process. Then press enter to start your debugging. //Console.WriteLine("CodeWriterFilterService attach debugger and press enter."); //Console.ReadLine(); Console.WriteLine("CodeWriterFilterService initialized successfully."); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; EntitiesToSkip = ConfigHelper.GetHashSet("EntitiesToSkip"); GenerateEntityRelationships = ConfigHelper.GetAppSettingOrDefault("GenerateEntityRelationships", true); }
public BasicFilteringService(ICodeWriterFilterService defaultService) { this.DefaultService = defaultService; }
public FilterOptionSetEnums(ICodeWriterFilterService defaultService) { DefaultService = defaultService; GeneratedOptionSets = new HashSet<string>(); }
public FilteringService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; GeneratedOptionSets = new Dictionary<String, bool>(); }
/// <summary> /// Initializes a new instance of the <see cref="EntityFilteringService" /> class. /// </summary> /// <param name="defaultService"><see cref="ICodeWriterFilterService" /> instance.</param> public EntityFilteringService(ICodeWriterFilterService defaultService) { this.DefaultService = defaultService; this._collection = FilterItemCollection.CreateInstance(); }
public FilteringService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; GeneratedOptionSets = new Dictionary <String, bool>(); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; EnumFilter = new FilterOptionSetEnums(defaultService); EntitiesToSkip = ConfigHelper.GetHashSet("EntitiesToSkip"); }
private static void TestFileCreation(ServiceFactory factory, ICustomizeCodeDomService customizeDom, ICodeGenerationService codeGen, ICodeWriterFilterService filter) { if (!Debugger.IsAttached && !ConfigHelper.GetAppSettingOrDefault("TestFileCreation", false)) { return; } using (var tmp = TempDir.Create()) { var fileName = Path.Combine(tmp.Name, Guid.NewGuid() + ".txt"); try { //factory.Add<ICustomizeCodeDomService>(new CustomizeCodeDomService(new Dictionary<string, string> //{ // { "url", @"https://allegient.api.crm.dynamics.com/XRMServices/2011/Organization.svc"}, // { "namespace", @"Test.Xrm.Entities"}, // { "out", fileName }, // {"servicecontextname", "CrmContext"}, // {"codecustomization", "DLaB.CrmSvcUtilExtensions.Entity.CustomizeCodeDomService,DLaB.CrmSvcUtilExtensions"}, // {"codegenerationservice", "DLaB.CrmSvcUtilExtensions.Entity.CustomCodeGenerationService,DLaB.CrmSvcUtilExtensions" }, // {"codewriterfilter", "DLaB.CrmSvcUtilExtensions.Entity.CodeWriterFilterService,DLaB.CrmSvcUtilExtensions"}, // {"metadataproviderservice:", "DLaB.CrmSvcUtilExtensions.Entity.MetadataProviderService,DLaB.CrmSvcUtilExtensions"}, // {"namingservice", "DLaB.CrmSvcUtilExtensions.NamingService,DLaB.CrmSvcUtilExtensions"}, // {"username", "*****@*****.**"}, // {"password", "*********"} //})); factory.Add(customizeDom); factory.Add(codeGen); factory.Add(filter); factory.Add <INamingService>(new NamingService(factory.GetService <INamingService>())); factory.GetService <ICodeGenerationService>().Write(factory.GetMetadata(), "CS", fileName, "DLaB.CrmSvcUtilExtensions.UnitTest", factory.ServiceProvider); } catch (Exception ex) { // Line for adding a debug breakpoint var message = ex.Message; if (message != null) { throw; } } } }
public TestMetadata(ICodeWriterFilterService filterService) { this.filterService = filterService; AddRange(SetupEntities()); }
public CodeWriterFilterService(ICodeWriterFilterService defaultService) { DefaultService = defaultService; GeneratedOptionSets = new HashSet <string>(); }