Exemple #1
0
 protected string GetCustomLabel(AssociatedMenuConfiguration menuConfiguration)
 {
     if (menuConfiguration.Behavior.HasValue &&
         menuConfiguration.Behavior == AssociatedMenuBehavior.UseLabel)
     {
         return(XrmService.GetLabelDisplay(menuConfiguration.Label));
     }
     return(null);
 }
Exemple #2
0
 protected static int GetDisplayOrder(AssociatedMenuConfiguration menuConfiguration)
 {
     if (!menuConfiguration.Order.HasValue)
     {
         return(0);
     }
     else
     {
         return(menuConfiguration.Order.Value);
     }
 }
Exemple #3
0
 protected static bool GetIsDisplayRelated(AssociatedMenuConfiguration menuConfiguration)
 {
     if (!menuConfiguration.Behavior.HasValue ||
         menuConfiguration.Behavior == AssociatedMenuBehavior.DoNotDisplay)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #4
0
 protected static bool GetIsCustomLabel(AssociatedMenuConfiguration menuConfiguration)
 {
     if (!menuConfiguration.Behavior.HasValue ||
         menuConfiguration.Behavior != AssociatedMenuBehavior.UseLabel)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
 public AssociatedMenuConfigurationInfo(AssociatedMenuConfiguration configuration)
 {
     this.configuration = configuration;
 }
        /// <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);
        }
        private void AddAssociatedMenuConfigurationDifference(FormatTextTableHandler table, string name, AssociatedMenuConfiguration config1, AssociatedMenuConfiguration config2)
        {
            if (config1 != null && config2 == null)
            {
                table.AddLineIfNotEqual(name, "not null", "null");
            }
            else if (config1 == null && config2 != null)
            {
                table.AddLineIfNotEqual(name, "null", "not null");
            }
            else if (config1 != null && config2 != null)
            {
                if (config1.Label != null && config2.Label == null)
                {
                    table.AddLineIfNotEqual(name + ".Label", "not null", "null");
                }
                else if (config1.Label == null && config2.Label != null)
                {
                    table.AddLineIfNotEqual(name + ".Label", "null", "not null");
                }
                else if (config1.Label != null && config2.Label != null)
                {
                    var isDifferentLabel = LabelComparer.GetDifference(config1.Label, config2.Label);

                    if (!isDifferentLabel.IsEmpty)
                    {
                        table.AddLine(name + ".Label");

                        if (isDifferentLabel.LabelsOnlyIn1.Count > 0)
                        {
                            table.AddLine(string.Format("Labels ONLY in {0}: {1}", _connectionName1, isDifferentLabel.LabelsOnlyIn1.Count));
                            table.AddLine("LanguageCode", "Value");
                            isDifferentLabel.LabelsOnlyIn1.ForEach(e => table.AddLine(e.Locale, e.Value));
                        }

                        if (isDifferentLabel.LabelsOnlyIn2.Count > 0)
                        {
                            table.AddLine(string.Format("Labels ONLY in {0}: {1}", _connectionName2, isDifferentLabel.LabelsOnlyIn2.Count));
                            table.AddLine("LanguageCode", "Value");
                            isDifferentLabel.LabelsOnlyIn2.ForEach(e => table.AddLine(e.Locale, e.Value));
                        }

                        if (isDifferentLabel.LabelDifference.Count > 0)
                        {
                            table.AddLine(string.Format("Labels DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentLabel.LabelDifference.Count));
                            table.AddLine("LanguageCode", "Organization", "Value");
                            isDifferentLabel.LabelDifference.ForEach(e => table.AddLine(e.Locale, e.Value1, e.Value2));
                        }
                    }
                }
            }
        }
Exemple #8
0
        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 AssociatedMenuConfigurationInfo(AssociatedMenuConfiguration configuration)
 {
     this.configuration = configuration;
 }