示例#1
0
        private void ProcessDummySavingField(pavelkh_advancedmultiselectitemsetconfiguration itemSetConfig)
        {
            var pluginContext = this.PluginContext;
            var target        = pluginContext.InputTarget;
            var createNew     = itemSetConfig.pavelkh_CreateNewDummySavingAttribute ?? false;

            if (!createNew)
            {
                var parentCtx             = pluginContext.ExecContext.ParentContext;
                var checkIfCreateRequired = parentCtx != null &&
                                            parentCtx.MessageName == MessageName.pavelkh_ItemSetConfigurationImport.ToString();
                if (checkIfCreateRequired)
                {
                    var attributeMetadata = (StringAttributeMetadata)MetadataUtils.GetAttributeMetadata(
                        pluginContext.Service,
                        itemSetConfig.pavelkh_EntityName,
                        itemSetConfig.pavelkh_DummySavingField,
                        new[] { "LogicalName" });
                    if (attributeMetadata == null)
                    {
                        createNew = true;
                        itemSetConfig.pavelkh_NewDummySavingField = itemSetConfig.pavelkh_DummySavingField;
                    }
                }
            }

            if (createNew)
            {
                var attrSchemaName = itemSetConfig.pavelkh_NewDummySavingField;
                var incorrectNewAttributeParams = string.IsNullOrWhiteSpace(attrSchemaName) ||
                                                  string.IsNullOrWhiteSpace(itemSetConfig.pavelkh_NewDummySavingFieldDisplayName) ||
                                                  itemSetConfig.pavelkh_NewDummySavingAttributeLength == null;
                if (incorrectNewAttributeParams)
                {
                    throw new InvalidPluginExecutionException("You would like to create a new Dummy Saving Attribute, but didn't specify all required info for the new attribute correctly.");
                }

                var prefixes      = ItemSetConfigurationActionManager.GetPrefixList(pluginContext.OrgCtxAsSystemUser);
                var prefixIsValid = prefixes.Any(r => attrSchemaName.StartsWith(r));
                if (!prefixIsValid)
                {
                    throw new InvalidPluginExecutionException(
                              $"You would like to create a new Dummy Saving Attribute. 'New Attribute Schema Name' should start with one of the following prefix: {string.Join(", ", prefixes)}.");
                }

                this.CreateNewDummySavingAttribute(itemSetConfig);
                target.pavelkh_DummySavingField = itemSetConfig.pavelkh_NewDummySavingField.ToLowerInvariant();
            }
            else
            {
                this.ValidateDummySavingFieldAttributeName(itemSetConfig);
            }

            target.pavelkh_CreateNewDummySavingAttribute  = false;
            target.pavelkh_NewDummySavingField            = null;
            target.pavelkh_NewDummySavingFieldDisplayName = null;
            target.pavelkh_NewDummySavingAttributeLength  = null;
        }
示例#2
0
        private void SetDummyAttributeProperties(ItemSetConfig itemSetConfig)
        {
            var pluginContext     = this.PluginContext;
            var attributeMetadata = (StringAttributeMetadata)MetadataUtils.GetAttributeMetadata(
                pluginContext.Service,
                itemSetConfig.EntityName,
                itemSetConfig.DummySavingAttributeName,
                new[] { "SchemaName", "DisplayName", "MaxLength" });

            if (attributeMetadata == null)
            {
                throw new InvalidPluginExecutionException($"Attribute {itemSetConfig.DummySavingAttributeName} of {itemSetConfig.EntityName} is not found in the system.");
            }

            itemSetConfig.DummySavingAttributeDisplayName = attributeMetadata.DisplayName?.LocalizedLabels.FirstOrDefault()?.Label;
            itemSetConfig.DummySavingAttributeSchemaName  = attributeMetadata.SchemaName;
            itemSetConfig.DummySavingAttributeLength      = attributeMetadata.MaxLength;
        }