public static DaoDbType GetContextDatabaseType(string logicalName) { if (contextDatabaseTypes.ContainsKey(logicalName)) { return(contextDatabaseTypes[logicalName]); } string type = typeof(DaoContext).Name; string property = DefaultConfiguration.GetProperty(type + "." + logicalName, "DaoDbType"); if (string.IsNullOrEmpty(property)) { CascadeConfiguration.ThrowException(type + "." + logicalName, "DaoDbType"); } return((DaoDbType)Enum.Parse(typeof(DaoDbType), property, true)); }
private bool CascadeCompare(CascadeConfiguration cascadeConfiguration, CascadeSelection selection) { if (selection == null) { return(true); } if (selection.assign && HasCascadeBehaviour(cascadeConfiguration.Assign)) { return(true); } if (selection.delete && HasCascadeBehaviour(cascadeConfiguration.Delete)) { return(true); } if (selection.merge && HasCascadeBehaviour(cascadeConfiguration.Merge)) { return(true); } if (selection.reparent && HasCascadeBehaviour(cascadeConfiguration.Reparent)) { return(true); } if (selection.share && HasCascadeBehaviour(cascadeConfiguration.Share)) { return(true); } if (selection.unshare && HasCascadeBehaviour(cascadeConfiguration.Unshare)) { return(true); } #if !(XRM_MOCKUP_2011 || XRM_MOCKUP_2013 || XRM_MOCKUP_2015 || XRM_MOCKUP_2016) if (selection.rollup && HasCascadeBehaviour(cascadeConfiguration.RollupView)) { return(true); } #endif return(false); }
protected override void ExecuteCmdlet() { base.ExecuteCmdlet(); CascadeConfiguration config = new CascadeConfiguration(); if (Assign.HasValue) { config.Assign = ToCrmEnum(Assign.Value); } if (Delete.HasValue) { config.Delete = ToCrmEnum(Delete.Value); } if (Merge.HasValue) { config.Merge = ToCrmEnum(Merge.Value); } if (Reparent.HasValue) { config.Reparent = ToCrmEnum(Reparent.Value); } if (Share.HasValue) { config.Share = ToCrmEnum(Share.Value); } if (Unshare.HasValue) { config.Unshare = ToCrmEnum(Unshare.Value); } OneToManyRelationshipMetadata relationship = new OneToManyRelationshipMetadata() { SchemaName = Relationship, CascadeConfiguration = config }; _repository.UpdateRelationship(relationship); }
/// <summary> /// Create the LookupField in CDS /// </summary> /// <param name="entity"> /// Uses: Entity.CollectionName /// </param> /// <param name="field"> /// Uses: LookupField.SchemaName, .LookupToEntity, .LookupToField /// </param> public void CreateLookupField(JToken field) { var entitySchemaName = JSONUtil.GetText(field, "entity"); var displayName = JSONUtil.GetText(field, "displayname"); var fieldSchemaName = JSONUtil.GetText(field, "schemaname"); var targetentity = JSONUtil.GetText(field, "target-entity"); var targetfield = JSONUtil.GetText(field, "target-field"); var relationshipname = JSONUtil.GetText(field, "relname"); var em = this._cdsConnection.GetEntityMetadata(entitySchemaName); CreateOneToManyRequest req = new CreateOneToManyRequest(); // define the general lookup metadata var la = new LookupAttributeMetadata(); la.Description = new Label("", 1033); la.DisplayName = new Label(displayName, 1033); la.LogicalName = fieldSchemaName; la.SchemaName = fieldSchemaName; la.RequiredLevel = new AttributeRequiredLevelManagedProperty( AttributeRequiredLevel.Recommended); req.Lookup = la; // define the 1:N relationship var rel = new OneToManyRelationshipMetadata(); // 1:N associated menu config var amc = new AssociatedMenuConfiguration(); amc.Behavior = AssociatedMenuBehavior.UseCollectionName; amc.Group = AssociatedMenuGroup.Details; amc.Label = em.DisplayCollectionName; amc.Order = 10000; rel.AssociatedMenuConfiguration = amc; // 1:N cascade behavior config var cc = new CascadeConfiguration(); cc.Assign = CascadeType.NoCascade; cc.Delete = CascadeType.RemoveLink; cc.Merge = CascadeType.NoCascade; cc.Reparent = CascadeType.NoCascade; cc.Share = CascadeType.NoCascade; cc.Unshare = CascadeType.NoCascade; rel.CascadeConfiguration = cc; // 1:N entity reference rel.ReferencedEntity = targetentity; rel.ReferencedAttribute = targetfield; rel.ReferencingEntity = entitySchemaName; if (relationshipname == null) { relationshipname = this.GetNextRelationshipName(em, field); } rel.SchemaName = relationshipname; req.OneToManyRelationship = rel; this._cdsConnection.Execute(req); }
public CascadeConfigurationInfo(CascadeConfiguration configuration) { this.configuration = configuration; }
private AttributeMetadata CreateLookupAttribute(ExcelWorksheet sheet, int rowIndex, int startCell, AttributeMetadata fakeAmd, ProcessResult info, bool isCreate) { var amc = new AssociatedMenuConfiguration { Order = sheet.GetValue <int>(rowIndex, startCell + 6), Group = new AssociatedMenuGroup?() }; switch (sheet.GetValue <string>(rowIndex, startCell + 5)) { case "Details": amc.Group = AssociatedMenuGroup.Details; break; case "Sales": amc.Group = AssociatedMenuGroup.Sales; break; case "Service": amc.Group = AssociatedMenuGroup.Service; break; case "Marketing": amc.Group = AssociatedMenuGroup.Marketing; break; } switch (sheet.GetValue <string>(rowIndex, startCell + 3)) { case "Do not display": amc.Behavior = AssociatedMenuBehavior.DoNotDisplay; break; case "Custom label": amc.Behavior = AssociatedMenuBehavior.UseLabel; if (!string.IsNullOrEmpty(sheet.GetValue <string>(rowIndex, startCell + 4))) { amc.Label = new Label(sheet.GetValue <string>(rowIndex, startCell + 4), settings.LanguageCode); } else { throw new Exception("If display behavior is \"Custom Label\", the label must be specified"); } break; default: amc.Behavior = AssociatedMenuBehavior.UseCollectionName; break; } var cc = new CascadeConfiguration(); switch (sheet.GetValue <string>(rowIndex, startCell + 7)) { case "Parental": cc.Assign = CascadeType.Cascade; cc.Delete = CascadeType.Cascade; cc.Merge = CascadeType.Cascade; cc.Reparent = CascadeType.Cascade; cc.RollupView = CascadeType.NoCascade; cc.Share = CascadeType.Cascade; cc.Unshare = CascadeType.Cascade; break; case "Referential, restrict delete": cc.Assign = CascadeType.NoCascade; cc.Delete = CascadeType.Restrict; cc.Merge = CascadeType.NoCascade; cc.Reparent = CascadeType.NoCascade; cc.RollupView = CascadeType.NoCascade; cc.Share = CascadeType.NoCascade; cc.Unshare = CascadeType.NoCascade; break; case "Custom": cc.RollupView = CascadeType.NoCascade; cc.Assign = GetCascade(sheet.GetValue <string>(rowIndex, startCell + 8)); cc.Share = GetCascade(sheet.GetValue <string>(rowIndex, startCell + 9)); cc.Unshare = GetCascade(sheet.GetValue <string>(rowIndex, startCell + 10)); cc.Reparent = GetCascade(sheet.GetValue <string>(rowIndex, startCell + 11)); cc.Delete = GetCascade(sheet.GetValue <string>(rowIndex, startCell + 12)); cc.Merge = GetCascade(sheet.GetValue <string>(rowIndex, startCell + 13)); break; default: cc.Assign = CascadeType.NoCascade; cc.Delete = CascadeType.RemoveLink; cc.Merge = CascadeType.NoCascade; cc.Reparent = CascadeType.NoCascade; cc.RollupView = CascadeType.NoCascade; cc.Share = CascadeType.NoCascade; cc.Unshare = CascadeType.NoCascade; break; } var lookup = new LookupAttributeMetadata { DisplayName = fakeAmd.DisplayName, SchemaName = fakeAmd.SchemaName, LogicalName = fakeAmd.LogicalName, IsValidForAdvancedFind = fakeAmd.IsValidForAdvancedFind, RequiredLevel = fakeAmd.RequiredLevel, IsSecured = fakeAmd.IsSecured, IsAuditEnabled = fakeAmd.IsAuditEnabled, Targets = new[] { sheet.GetValue <string>(rowIndex, startCell).ToLower() } }; if (settings.AddLookupSuffix && !lookup.SchemaName.ToLower().EndsWith("id")) { lookup.SchemaName = $"{lookup.SchemaName}Id"; lookup.LogicalName = lookup.SchemaName.ToLower(); } if (fakeAmd.Description != null) { lookup.Description = fakeAmd.Description; } var relationship = new OneToManyRelationshipMetadata { IsValidForAdvancedFind = sheet.GetValue <string>(rowIndex, startCell + 1) == "Yes", SchemaName = $"{settings.Solution.Prefix}{info.Entity}_{sheet.GetValue<string>(rowIndex, startCell)}_{lookup.SchemaName}", AssociatedMenuConfiguration = amc, CascadeConfiguration = cc, IsHierarchical = sheet.GetValue <string>(rowIndex, startCell + 2) == "Yes", ReferencedEntity = sheet.GetValue <string>(rowIndex, startCell), ReferencingEntity = info.Entity, SecurityTypes = SecurityTypes.Append, }; if (isCreate) { service.Execute(new CreateOneToManyRequest { OneToManyRelationship = relationship, Lookup = lookup, SolutionUniqueName = settings.Solution.UniqueName }); info.IsCreate = true; return(null); } service.Execute(new UpdateRelationshipRequest { Relationship = relationship, SolutionUniqueName = settings.Solution.UniqueName, MergeLabels = true }); return(lookup); }
public CascadeConfigurationInfo(CascadeConfiguration configuration) { this.configuration = configuration; }