Esempio n. 1
0
    private static string FindLableIfNotEnglish(OptionMetadata optionMetadata, string defaultName)
    {
        string value = null;
        var    defaultNameIsInEnglish = IsLabelOK(defaultName);

        if (defaultNameIsInEnglish)
        {
            value = defaultName;
        }
        else
        {
            var localizedLabels = optionMetadata.Label.LocalizedLabels.FirstOrDefault();

            if (localizedLabels != null)
            {
                if (!string.IsNullOrWhiteSpace(localizedLabels.Label))
                {
                    value = localizedLabels.Label.RemoveDiacritics(); //ReplaceLanguageChar(localizedLabels.Label, localizedLabels.LanguageCode);
                }
                else
                {
                    value = defaultName;
                }
            }
        }

        return(GetValidCSharpName(value));
    }
Esempio n. 2
0
        private OptionSetMetadata BuildOptionSet()
        {
            OptionSetMetadata optionset = new OptionSetMetadata()
            {
                Name          = Name,
                DisplayName   = new Label(DisplayName, CrmContext.Language),
                Description   = new Label(Description ?? string.Empty, CrmContext.Language),
                OptionSetType = OptionSetType.Picklist
            };

            if (Customizable.HasValue)
            {
                optionset.IsCustomizable = new BooleanManagedProperty(Customizable.Value);
            }

            foreach (var item in Values)
            {
                OptionMetadata option = new OptionMetadata(new Label(item.DisplayName, CrmContext.Language), item.Value)
                {
                    Description = new Label(item.Description ?? string.Empty, CrmContext.Language)
                };
                optionset.Options.Add(option);
            }
            return(optionset);
        }
        private string RetrieveOptionsetText(int optionsetValue, string attributeName, string entityName)
        {
            var optionsetText            = string.Empty;
            var retrieveAttributeRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName     = entityName,
                LogicalName           = attributeName,
                RetrieveAsIfPublished = true
            };
            var            retrieveAttributeResponse = (RetrieveAttributeResponse)Service.Execute(retrieveAttributeRequest);
            var            optionSets     = retrieveAttributeResponse.AttributeMetadata;
            OptionMetadata optionMetaData = null;

            if (optionSets is PicklistAttributeMetadata)
            {
                optionMetaData = ((PicklistAttributeMetadata)optionSets).OptionSet.Options.FirstOrDefault(x => x.Value == optionsetValue);
            }
            else if (optionSets is StatusAttributeMetadata)
            {
                optionMetaData = ((StatusAttributeMetadata)optionSets).OptionSet.Options.FirstOrDefault(x => x.Value == optionsetValue);
            }
            else if (optionSets is StateAttributeMetadata)
            {
                optionMetaData = ((StateAttributeMetadata)optionSets).OptionSet.Options.FirstOrDefault(x => x.Value == optionsetValue);
            }
            if (optionMetaData != null)
            {
                optionsetText = optionMetaData.Label.UserLocalizedLabel.Label;
            }
            return(optionsetText);
        }
        /// <summary>
        /// Gets an option set value from a single or multi-selection option set.
        /// </summary>
        /// <param name="value">The value to convert to an option set value.</param>
        private OptionSetValue GetOptionSetValue(object value)
        {
            int optionSetValue = 0;

            if (value is string)
            {
                bool success = int.TryParse(value.ToString(), out optionSetValue);

                if (!success)
                {
                    OptionMetadata optionMetadata = ((EnumAttributeMetadata)AttributeMetadata).OptionSet.Options.FirstOrDefault(option => option.Label.UserLocalizedLabel.Label.ToLower() == value.ToString().ToLower());

                    if (optionMetadata != default(OptionMetadata))
                    {
                        optionSetValue = (int)optionMetadata.Value;
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("'{1}' is not a valid option set value", AttributeMetadata.DisplayName.UserLocalizedLabel.Label, value.ToString()));
                    }
                }
            }
            else
            {
                optionSetValue = System.Convert.ToInt32(value);
            }

            return(new OptionSetValue(optionSetValue));
        }
Esempio n. 5
0
        /// <inheritdoc />
        public string GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
        {
            string value = _defaultService.GetNameForOption(optionSetMetadata, optionMetadata, services);

            value = ModifyPublisher(value);
            return(value);
        }
Esempio n. 6
0
        private ComboBoxItem CreateComboBoxItem(OptionMetadata item, bool value)
        {
            StringBuilder name = new StringBuilder();

            name.Append(value);

            var label       = CreateFileHandler.GetLocalizedLabel(item.Label);
            var description = CreateFileHandler.GetLocalizedLabel(item.Description);

            if (!string.IsNullOrEmpty(label))
            {
                name.AppendFormat(" - {0}", label);
            }
            else if (!string.IsNullOrEmpty(description))
            {
                name.AppendFormat(" - {0}", description);
            }

            var newItem = new ComboBoxItem()
            {
                Content = name.ToString(),
                Tag     = value,
            };

            cmBValue.Items.Add(newItem);

            return(newItem);
        }
Esempio n. 7
0
        private static string Transliterate(OptionMetadata optionMetadata, string englishName)
        {
            var localizedLabels = optionMetadata.Label.LocalizedLabels;

            if (LanguageCodeOverride < 0 || LanguageCodeOverride == English)
            {
                if (IsLabelPopulated(englishName))
                {
                    return(englishName.RemoveDiacritics());
                }
            }
            else
            {
                var overrideLabel = localizedLabels.FirstOrDefault(l => l.LanguageCode == LanguageCodeOverride && IsLabelPopulated(l.Label));
                if (overrideLabel != null)
                {
                    return(TransliterationService.HasCode(LanguageCodeOverride)
                        ? TransliterationService.Transliterate(overrideLabel)
                        : overrideLabel.Label.RemoveDiacritics());
                }
            }

            var localizedLabel = localizedLabels.FirstOrDefault(x => TransliterationService.HasCode(x.LanguageCode) && IsLabelPopulated(x.Label));

            return(localizedLabel == null?
                   localizedLabels.FirstOrDefault(x => IsLabelPopulated(x.Label))?.Label?.RemoveDiacritics() ?? string.Empty:
                   TransliterationService.Transliterate(localizedLabel));
        }
Esempio n. 8
0
 public bool GenerateOption(
     OptionMetadata option
     , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
     )
 {
     return(true);
 }
Esempio n. 9
0
        public OptionMetadata[] GetOptionSet(string entityName, string fieldName)
        {
            OptionMetadata[]         optionMetadatas;
            IOrganizationService     orgService       = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService);
            RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName     = entityName,
                LogicalName           = fieldName,
                RetrieveAsIfPublished = false
            };

            RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)orgService.Execute(attributeRequest);

            if (attributeResponse.AttributeMetadata.AttributeType == Microsoft.Xrm.Sdk.Metadata.AttributeTypeCode.Boolean)
            {
                BooleanAttributeMetadata boolenAttributeMetadata = (BooleanAttributeMetadata)attributeResponse.AttributeMetadata;
                BooleanOptionSetMetadata boolenOptionSetMetadata = boolenAttributeMetadata.OptionSet;

                OptionMetadata[] options = new OptionMetadata[2];
                options[0]      = boolenOptionSetMetadata.TrueOption;
                options[1]      = boolenOptionSetMetadata.FalseOption;
                optionMetadatas = options;
            }
            else
            {
                EnumAttributeMetadata picklistAttributeMetadata = (EnumAttributeMetadata)attributeResponse.AttributeMetadata;
                OptionSetMetadata     optionSetMetadata         = picklistAttributeMetadata.OptionSet;
                OptionMetadata[]      optionList = optionSetMetadata.Options.ToArray();
                optionMetadatas = optionList;
            }


            return(optionMetadatas);
        }
Esempio n. 10
0
        private static string AppendState(OptionMetadata option, string name)
        {
            var statusOption = (StatusOptionMetadata)option;

            name += "_" + (statusOption.State == 0 ? "Active" : "Inactive");
            return(name);
        }
        private string RetrieveBooleanLabel(bool optionsetValue, string attributeName, string entityName)
        {
            var optionsetText            = string.Empty;
            var retrieveAttributeRequest = new RetrieveAttributeRequest
            {
                EntityLogicalName     = entityName,
                LogicalName           = attributeName,
                RetrieveAsIfPublished = true
            };
            var            retrieveAttributeResponse = (RetrieveAttributeResponse)Service.Execute(retrieveAttributeRequest);
            var            optionSets     = retrieveAttributeResponse.AttributeMetadata;
            OptionMetadata optionMetaData = null;

            if (optionSets is BooleanAttributeMetadata)
            {
                optionMetaData = optionsetValue
                    ? ((BooleanAttributeMetadata)optionSets).OptionSet.TrueOption
                    : ((BooleanAttributeMetadata)optionSets).OptionSet.FalseOption;
            }
            if (optionMetaData != null)
            {
                optionsetText = optionMetaData.Label.UserLocalizedLabel.Label;
            }
            return(optionsetText);
        }
        async Task <bool> ICodeWriterFilterService.GenerateOptionAsync(OptionMetadata option, IServiceProvider services)
        {
            await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name);

            await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name);

            return(true);
        }
Esempio n. 13
0
 public static string GetOptionSetText(this OptionMetadata optionMeta)
 {
     if (optionMeta != null && optionMeta.Label != null && optionMeta.Label.UserLocalizedLabel != null)
     {
         return(optionMeta.Label.UserLocalizedLabel.Label);
     }
     return(string.Empty);
 }
Esempio n. 14
0
 public static string GetOptionSetText(this OptionMetadata optionMeta)
 {
     _ = optionMeta ?? throw new ArgumentNullException(nameof(optionMeta));
     if (optionMeta.Label != null && optionMeta.Label.UserLocalizedLabel != null)
     {
         return(optionMeta.Label.UserLocalizedLabel.Label);
     }
     return(string.Empty);
 }
        public void BeginOption(OptionSetMetadataBase optionSet, OptionMetadata option)
        {
            var alphaRegex = new Regex("[^a-zA-Z0-9_]");

            var label = option.Label.LocalizedLabels.FirstOrDefault(l => l.LanguageCode == 1033);
            var name = string.Format("{0}_{1}", optionSet.Name, label == null ? option.Value.ToString() : alphaRegex.Replace(label.Label, "_"));

            _hWriter.WriteLine(TemplateResources.H_Option_Begin
                .SaneReplace(OPTION_NAME, name, ObjectiveCWordProvider.Instance)
                .SaneReplace(OPTION_VALUE, option.Value.ToString(), ObjectiveCWordProvider.Instance));
        }
Esempio n. 16
0
        private static ObjectCollectionItem <OptionMetadata> CreateOptionMetadataItem(string label, int?value, string color = "#0000ff", string description = null)
        {
            var option = new OptionMetadata
            {
                Value       = value.GetValueOrDefault(),
                Label       = new XrmLabel(label, 1033),
                Color       = color,
                Description = description == null ? null : new Microsoft.Xrm.Sdk.Label(description, 1033)
            };

            return(new ObjectCollectionItem <OptionMetadata>(label, value.HasValue ? option : null));
        }
Esempio n. 17
0
        private static FilterOption ToFilterOption(OptionMetadata optionMetadata, IEnumerable <string> selected)
        {
            var id = string.Empty + optionMetadata.Value;

            return(new FilterOption
            {
                Id = id,
                Type = "dynamic",
                Label = optionMetadata.Label.GetLocalizedLabelString(),
                Checked = selected.Contains(id)
            });
        }
        public void Can_generate()
        {
            var openOption = new OptionMetadata(1)
            {
                Label = new Label {
                    UserLocalizedLabel = new LocalizedLabel("Open", 1033)
                }
            };

            var releaseOption = new OptionMetadata(2)
            {
                Label = new Label {
                    UserLocalizedLabel = new LocalizedLabel("Release", 1033)
                }
            };

            var open1Option = new OptionMetadata(3)
            {
                Label = new Label {
                    UserLocalizedLabel = new LocalizedLabel("Open", 1033)
                }
            };

            var release2Option = new OptionMetadata(4)
            {
                Label = new Label {
                    UserLocalizedLabel = new LocalizedLabel("Release", 1033)
                }
            };

            var release3Option = new OptionMetadata(5)
            {
                Label = new Label {
                    UserLocalizedLabel = new LocalizedLabel("Release", 1033)
                }
            };

            var optionSet = new OptionSetMetadata();

            optionSet.Options.AddRange(openOption, releaseOption, open1Option, release2Option, release3Option);

            var picklistMetadata = new PicklistAttributeMetadata
            {
                SchemaName = "xts_status",
                OptionSet  = optionSet
            };

            var generator = new OptionsGenerator(picklistMetadata, Template.Options);
            var result    = generator.Generate();

            _output.WriteLine(result);
            Assert.Equal(ExpectedTemplate.Options, result);
        }
Esempio n. 19
0
        /// <summary>
        /// Handles building the name for an Option of an OptionSet.
        /// </summary>
        public string GetNameForOption(OptionSetMetadataBase optionSetMetadata,
                                       OptionMetadata optionMetadata, IServiceProvider services)
        {
            var name = DefaultNamingService.GetNameForOption(optionSetMetadata,
                                                             optionMetadata, services);

            Trace.TraceInformation(String.Format("The name of this option is {0}",
                                                 name));
            name = EnsureValidIdentifier(name);
            name = EnsureUniqueOptionName(optionSetMetadata, name);
            return(name);
        }
 /// <summary>
 /// Convert a given voteQuestion to a ViewModel
 /// </summary>
 public static ViewModels.OptionMetadata ToViewModel(this OptionMetadata optionMetadata)
 {
     ViewModels.OptionMetadata result = null;
     if (optionMetadata != null)
     {
         result       = new ViewModels.OptionMetadata();
         result.value = (int)optionMetadata.Value;
         result.label = optionMetadata.Label.LocalizedLabels.FirstOrDefault().Label;
         // Description is not set as there is no data
     }
     return(result);
 }
        public string GetOptionSetLabelByValue(string entityName, string attributeName, int value)
        {
            var            optionMetadataCollection = GetOptionsSetByAttribute(entityName, attributeName);
            OptionMetadata option = optionMetadataCollection.SingleOrDefault(o => o.Value == value);
            string         label  = string.Empty;

            if (option != null)
            {
                label = option.Label.UserLocalizedLabel.Label;
            }
            return(label);
        }
        private string GetValidCSharpName(OptionMetadata optionMetadata)
        {
            string label = optionMetadata.Label.GetLocalOrDefaultText(string.Empty);

            //remove spaces and special characters
            label = Regex.Replace(label, @"[^a-zA-Z0-9_]", string.Empty);
            if (label.Length > 0 && !char.IsLetter(label, 0))
            {
                label = InvalidCSharpNamePrefix + label;
            }
            return(label);
        }
        /// <summary>
        /// Gets the option set text
        /// </summary>
        /// <param name="service">The organization service</param>
        /// <param name="entityLogicalName">The logical name of the entity</param>
        /// <param name="logicalName">The logical name of the attribute</param>
        /// <param name="optionSetValue">The option set value</param>
        /// <returns>The option set text</returns>
        public static string GetOptionSetText(IOrganizationService service, string entityLogicalName, string logicalName, int optionSetValue)
        {
            var            picklistAttributeMetadata = (PicklistAttributeMetadata)MetadataManager.GetAttributeMetadata(service, entityLogicalName, logicalName);
            OptionMetadata optionMetadata            = picklistAttributeMetadata.OptionSet.Options.FirstOrDefault(om => om.Value == optionSetValue);

            if (optionMetadata != null)
            {
                return(optionMetadata.Label.UserLocalizedLabel.Label);
            }

            return(null);
        }
Esempio n. 24
0
        public string GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
        {
            var optionName = optionMetadata.DisplayName();

            optionName = EnsureValidIdentifier(optionName);

            var optionSet = optionSetMetadata as OptionSetMetadata;
            var matches   = optionSet.Options.Where(x => EnsureValidIdentifier(x.DisplayName()) == optionName);

            optionName = MakeUnique(optionName, matches, x => x.Value, optionMetadata.Value);

            return(optionName);
        }
        public override bool GenerateOption(OptionMetadata optionMetadata, IServiceProvider services)
        {
            bool whitelist, blacklist = false;

            whitelist = _whitelistFilters.Any(filter => filter.GenerateOption(optionMetadata, services));

            if (!whitelist)
            {
                blacklist = _blacklistFilters.Any(filter => filter.GenerateOption(optionMetadata, services));
            }

            return(whitelist || blacklist);
        }
        private static MapperEnumItem MapBoolOption(OptionMetadata option)
        {
            var results = new MapperEnumItem()
            {
                Attribute = new CrmPicklistAttribute()
                {
                    DisplayName = option.Label.UserLocalizedLabel.Label,
                    Value       = (int)option.Value
                },
                Name = Naming.GetProperVariableName(option.Label.UserLocalizedLabel.Label)
            };

            return(results);
        }
Esempio n. 27
0
        private static string Transliterate(OptionMetadata optionMetadata, string defaultName)
        {
            var defaultNameIsInEnglish = IsLabelPopulated(defaultName);

            if (defaultNameIsInEnglish)
            {
                return(defaultName);
            }
            var localizedLabels = optionMetadata.Label.LocalizedLabels;

            var localizedLabel = localizedLabels.FirstOrDefault(x => TransliterationService.HasCode(x.LanguageCode));

            return(localizedLabel == null?
                   localizedLabels.FirstOrDefault(x => IsLabelPopulated(x.Label))?.Label?.RemoveDiacritics() :
                       TransliterationService.Transliterate(localizedLabel.LanguageCode, localizedLabel.Label));
        }
Esempio n. 28
0
        public CRMPicklist CRMGetStateStatus(CRMPicklist picklist)
        {
            OrganizationServiceProxy _serviceProxy;

            using (_serviceProxy = GetCRMConnection())
            {
                try
                {
                    RetrieveAttributeRequest retrieveAttributeStateRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName       = "statecode",
                    };
                    RetrieveAttributeResponse retrieveAttributeStateResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeStateRequest);

                    RetrieveAttributeRequest retrieveAttributeStatusRequest = new RetrieveAttributeRequest
                    {
                        EntityLogicalName = picklist.EntityLogicalName,
                        LogicalName       = "statuscode"
                    };
                    RetrieveAttributeResponse retrieveAttributeStatusResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(retrieveAttributeStatusRequest);

                    StateAttributeMetadata  state  = (StateAttributeMetadata)retrieveAttributeStateResponse.AttributeMetadata;
                    StatusAttributeMetadata status = (StatusAttributeMetadata)retrieveAttributeStatusResponse.AttributeMetadata;


                    List <CRMPicklistOption> options = new List <CRMPicklistOption>();
                    foreach (StatusOptionMetadata o in status.OptionSet.Options)
                    {
                        OptionMetadata s = state.OptionSet.Options.Where(p => p.Value.Value == o.State.Value).First();

                        CRMPicklistOption option = new CRMPicklistOption();
                        option.PicklistValue       = o.Value.HasValue ? o.Value.Value : 0;
                        option.PicklistLabel       = o.Label.UserLocalizedLabel.Label;
                        option.PicklistParentLabel = s.Label.UserLocalizedLabel.Label.ToString();
                        option.PicklistParentValue = s.Value.HasValue ? s.Value.Value : 0;
                        options.Add(option);
                    }
                    picklist.Picklist = options;
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return(picklist);
        }
        private IOrganizationService SetupIOrganisationService(Entity recordContext, int optionSetValue)
        {
            StubIOrganizationService stubIOrganisationService = new StubIOrganizationService();

            stubIOrganisationService.RetrieveStringGuidColumnSet = (entityLogicalName, recordId, columnSet)
                                                                   =>
            {
                if (entityLogicalName == "dxtools_payment")
                {
                    return(recordContext);
                }
                else
                {
                    return(null);
                }
            };

            stubIOrganisationService.ExecuteOrganizationRequest = (request)
                                                                  =>
            {
                if (request.RequestName == "RetrieveAttribute")
                {
                    RetrieveAttributeResponse response = new RetrieveAttributeResponse();
                    return(response);
                }
                else
                {
                    return(null);
                }
            };

            Microsoft.Xrm.Sdk.Messages.Fakes.ShimRetrieveAttributeResponse.AllInstances.AttributeMetadataGet = (i)
                                                                                                               =>
            {
                OptionMetadataCollection optionMetadataCollection = new OptionMetadataCollection();
                OptionMetadata           optionMetadata           = new OptionMetadata(new Label(), optionSetValue);
                optionMetadata.Label.UserLocalizedLabel = new LocalizedLabel("IN", 1033);
                optionMetadataCollection.Add(optionMetadata);

                PicklistAttributeMetadata picklistAttributeMetadata = new PicklistAttributeMetadata();
                picklistAttributeMetadata.OptionSet = new OptionSetMetadata(optionMetadataCollection);
                return(picklistAttributeMetadata);
            };

            return(stubIOrganisationService);
        }
Esempio n. 30
0
        public string GetOptionSetValue(string Entity, string Attribute, int Value)
        {
            if (!_optionSetValues.Any(x => (x.Item1 == Entity && x.Item2 == Attribute && x.Item3 == Value)))
            {
                RetrieveAttributeRequest rar = new RetrieveAttributeRequest()
                {
                    EntityLogicalName     = Entity,
                    LogicalName           = Attribute,
                    RetrieveAsIfPublished = true
                };
                RetrieveAttributeResponse rarr = (RetrieveAttributeResponse)OrganizationService.Execute(rar);

                OptionMetadata op = null;
                if (rarr.AttributeMetadata.GetType().Name == "PicklistAttributeMetadata")
                {
                    if (((PicklistAttributeMetadata)rarr.AttributeMetadata).OptionSet.Options.Count > 0)
                    {
                        op = ((PicklistAttributeMetadata)rarr.AttributeMetadata).OptionSet.Options.First(x => x.Value == Value);
                    }
                }

                if (rarr.AttributeMetadata.GetType().Name == "StateAttributeMetadata")
                {
                    op = ((StateAttributeMetadata)rarr.AttributeMetadata).OptionSet.Options.First(x => x.Value == Value);
                }

                if (rarr.AttributeMetadata.GetType().Name == "StatusAttributeMetadata")
                {
                    op = ((StatusAttributeMetadata)rarr.AttributeMetadata).OptionSet.Options.First(x => x.Value == Value);
                }

                if (op != null)
                {
                    _optionSetValues.Add(new Tuple <string, string, int, string>(Entity, Attribute, Value, op.Label.LocalizedLabels[0].Label));
                }
                else
                {
                    _optionSetValues.Add(new Tuple <string, string, int, string>(Entity, Attribute, Value, "UNKNOWN"));
                }
            }

            Tuple <string, string, int, string> record = _optionSetValues.Find(x => (x.Item1 == Entity && x.Item2 == Attribute && x.Item3 == Value));

            return(string.Format("({0}) {1}", record.Item3, record.Item4));
        }
Esempio n. 31
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            PicklistAttributeMetadata attribute = new PicklistAttributeMetadata();

            if (DefaultValue.HasValue)
            {
                attribute.DefaultFormValue = DefaultValue;
            }

            switch (this.ParameterSetName)
            {
            case AddOptionSetNewParameterSet:
                attribute.OptionSet = new OptionSetMetadata()
                {
                    IsGlobal = false
                };
                foreach (PSOptionSetValue item in Values)
                {
                    OptionMetadata option = new OptionMetadata(new Label(item.DisplayName, CrmContext.Language), item.Value);
                    attribute.OptionSet.Options.Add(option);
                }
                break;

            case AddOptionSetExistingParameterSet:
                MetadataRepository repository = new MetadataRepository();
                OptionSetMetadata  optionset  = repository.GetOptionSet(OptionSet) as OptionSetMetadata;
                if (optionset != null && optionset.IsGlobal.GetValueOrDefault())
                {
                    attribute.OptionSet = optionset;
                    attribute.OptionSet.Options.Clear();
                }
                else
                {
                    throw new Exception($"No global optionset found with name: {OptionSet}");
                }
                break;

            default:
                break;
            }

            WriteAttribute(attribute);
        }
Esempio n. 32
0
        public void GetPicklistOptionCountTest_Test()
        {
            //ARRANGE - set up everything our test needs

            //first - set up a mock service to act like the CRM organization service
            var serviceMock = new Mock<IOrganizationService>();
            IOrganizationService service = serviceMock.Object;

            PicklistAttributeMetadata retrievedPicklistAttributeMetadata = new PicklistAttributeMetadata();
            OptionMetadata femaleOption = new OptionMetadata(new Label("Female", 1033), 43);
            femaleOption.Label.UserLocalizedLabel = new LocalizedLabel("Female", 1033);
            femaleOption.Label.UserLocalizedLabel.Label = "Female";
            OptionMetadata maleOption = new OptionMetadata(new Label("Male", 1033), 400);
            maleOption.Label.UserLocalizedLabel = new LocalizedLabel("Male", 400);
            maleOption.Label.UserLocalizedLabel.Label = "Male";
            OptionSetMetadata genderOptionSet = new OptionSetMetadata
            {
                Name = "gendercode",
                DisplayName = new Label("Gender", 1033),
                IsGlobal = true,
                OptionSetType = OptionSetType.Picklist,
                Options = { femaleOption, maleOption }
            };

            retrievedPicklistAttributeMetadata.OptionSet = genderOptionSet;
            RetrieveAttributeResponseWrapper picklistWrapper = new RetrieveAttributeResponseWrapper(new RetrieveAttributeResponse());
            picklistWrapper.AttributeMetadata = retrievedPicklistAttributeMetadata;

            serviceMock.Setup(t => t.Execute(It.Is<RetrieveAttributeRequest>(r => r.LogicalName == "gendercode"))).Returns(picklistWrapper);

            //ACT
            int returnedCount = Sample03.GetPicklistOptionCount("ANYENTITYMATCHES", "gendercode", service);

            //ASSERT
            Assert.AreEqual(2, returnedCount);
        }
Esempio n. 33
0
 CodeGenerationType ICodeGenerationService.GetTypeForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
 {
     return CodeGenerationType.Field;
 }
Esempio n. 34
0
 /// <summary>
 /// Handles building the name for an Option of an OptionSet.
 /// </summary>
 public string GetNameForOption(OptionSetMetadataBase optionSetMetadata,
     OptionMetadata optionMetadata, IServiceProvider services)
 {
     var name = DefaultNamingService.GetNameForOption(optionSetMetadata,
         optionMetadata, services);
     Trace.TraceInformation(String.Format("The name of this option is {0}",
         name));
     name = EnsureValidIdentifier(name);
     name = EnsureUniqueOptionName(optionSetMetadata, name);
     return name;
 }
 public void EndOption(OptionSetMetadataBase optionSet, OptionMetadata option)
 {
     Each(cg => cg.EndOption(optionSet, option));
 }
 /// <summary>
 /// Fix to handle invalid C# naming conventions for optionSets
 /// </summary>
 /// <param name="optionMetadata"></param>
 private void HandleInvalidCSharpName(OptionMetadata optionMetadata)
 {
     optionMetadata.Label = new Label(GetValidCSharpName(optionMetadata), 1033);
 }
 private string GetValidCSharpName(OptionMetadata optionMetadata)
 {
     string label = optionMetadata.Label.GetLocalOrDefaultText(string.Empty);
     //remove spaces and special characters
     label = Regex.Replace(label, @"[^a-zA-Z0-9_]", string.Empty);
     if (label.Length > 0 && !char.IsLetter(label, 0))
     {
         label = InvalidCSharpNamePrefix + label;
     }
     return label;
 }
Esempio n. 38
0
 private static string GetOptionLabel(OptionMetadata option)
 {
     return option.Label.LocalizedLabels[0].Label;
 }
        public bool GenerateOption(OptionMetadata optionMetadata, IServiceProvider services)
        {
            HandleInvalidCSharpName(optionMetadata);

            return DefaultService.GenerateOption(optionMetadata, services);
        }
        public void BeginOption(OptionSetMetadataBase optionSet, OptionMetadata option)
        {
            var optionSetMetadata = optionSet as OptionSetMetadata;
            if(optionSetMetadata == null) throw new NotImplementedException("Unsupported option set type.");

            bool isLast = optionSetMetadata.Options.IndexOf(option) == optionSetMetadata.Options.Count - 1;
            string separator = isLast ? ";" : ",";

            string label = Regex.Replace(option.Label.LocalizedLabels.FirstOrDefault().Label, @"\'|\s|:|&|-|,|\(|\)|\.|\/|>|%|\+|{|}", "");

            _writer.WriteLine(TemplateResources.Java_Option_Begin
                .Replace(OPTION_NAME, label)
                .Replace(OPTION_VALUE, option.Value.ToString())
                .Replace(OPTION_SEPARATOR, separator));

            _optionToObjectCases.AppendLine(TemplateResources.Java_Option_ToObjectCase
                .Replace(OPTION_NAME, label)
                .Replace(OPTION_VALUE, option.Value.ToString()));
        }
        private static string Transliterate(OptionMetadata optionMetadata, string defaultName)
        {
            var defaultNameIsInEnglish = IsLabelPopulated(defaultName);
            if (defaultNameIsInEnglish)
            {
                return defaultName;
            }
            var localizedLabels = optionMetadata.Label.LocalizedLabels;

            var localizedLabel = localizedLabels.FirstOrDefault(x => TransliterationService.HasCode(x.LanguageCode) && IsLabelPopulated(x.Label));

            return localizedLabel == null ?
                localizedLabels.FirstOrDefault(x => IsLabelPopulated(x.Label))?.Label?.RemoveDiacritics() ?? string.Empty : 
                TransliterationService.Transliterate(localizedLabel.LanguageCode, localizedLabel.Label);
        }
 private OptionMetadataCollection GetOptionMetadataCollection(AttributeTemplate attributeTemplate)
 {
     var optionMetadataCollection = new OptionMetadataCollection();
     if (attributeTemplate.OptionSetList != null)
     {
         foreach (var optionMetadataTemplate in attributeTemplate.OptionSetList)
         {
             var optionMetadata = new OptionMetadata
             {
                 Description = GetLabelWithLocalized(optionMetadataTemplate.Description),
                 Label = GetLabelWithLocalized(optionMetadataTemplate.Label),
                 Value = optionMetadataTemplate.Value
             };
             optionMetadataCollection.Add(optionMetadata);
         }
     }
     return optionMetadataCollection;
 }
 public void BeginOption(OptionSetMetadataBase optionSet, OptionMetadata option)
 {
     Each(cg => cg.BeginOption(optionSet, option));
 }
 public void EndOption(OptionSetMetadataBase optionSet, OptionMetadata option) { }
        public string GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
        {
            var defaultName = DefaultService.GetNameForOption(optionSetMetadata, optionMetadata, services);

            defaultName = Transliterate(optionMetadata, defaultName);

            var newName = GetValidCSharpName(defaultName);
            newName = AppendValueForDuplicateOptionSetValueNames(optionSetMetadata, newName, optionMetadata.Value.GetValueOrDefault(), services);

            Trace.TraceInformation(newName == defaultName
                ? $"The name of this option is {defaultName}"
                : $"The name of this option was {defaultName} but has been changed to {newName}");

            return newName;
        }
 public string GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
 {
     return DefaultService.GetNameForOption(optionSetMetadata, optionMetadata, services);
 }
Esempio n. 47
0
 string INamingService.GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
 {
     if (_knowNames.ContainsKey(optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture)))
     {
         return _knowNames[optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture)];
     }
     var invariantName = string.Empty;
     var metadata = optionMetadata as StateOptionMetadata;
     if (metadata != null)
     {
         invariantName = metadata.InvariantName;
     }
     else
     {
         foreach (var label in optionMetadata.Label.LocalizedLabels)
         {
             if (label.LanguageCode == 0x409)
             {
                 invariantName = label.Label;
             }
         }
     }
     if (string.IsNullOrEmpty(invariantName))
     {
         invariantName = string.Format(CultureInfo.InvariantCulture, "UnknownLabel{0}", new object[] {optionMetadata.Value.Value});
     }
     invariantName = CreateValidName(invariantName);
     _knowNames.Add(optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture), invariantName);
     return invariantName;
 }
 public bool GenerateOption(OptionMetadata optionMetadata, IServiceProvider services)
 {
     return DefaultService.GenerateOption(optionMetadata, services);
 }
Esempio n. 49
0
 bool ICodeWriterFilterService.GenerateOption(OptionMetadata optionMetadata, IServiceProvider services)
 {
     return this.DefaultService.GenerateOption(optionMetadata, services);
 }
Esempio n. 50
0
 bool ICodeWriterFilterService.GenerateOption(OptionMetadata option, IServiceProvider services)
 {
     return true;
 }
Esempio n. 51
0
 static CodeTypeMember BuildOption(OptionSetMetadataBase optionSet, OptionMetadata option, ServiceProvider serviceProvider)
 {
     Trace.TraceInformation("Entering {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     var field = Field(serviceProvider.NamingService.GetNameForOption(optionSet, option, serviceProvider), typeof (int), option.Value.Value, new[] {Attribute(typeof (EnumMemberAttribute))});
     Trace.TraceInformation("Exiting {0}: {1}.Option {2} defined", new object[] {MethodBase.GetCurrentMethod().Name, optionSet.Name, field.Name});
     return field;
 }
 public bool GenerateOption(OptionMetadata optionMetadata, IServiceProvider services)
 {
     return false;
 }
Esempio n. 53
0
 public OptionMetadataInfo(OptionMetadata amd)
 {
     this.amd = amd;
 }
 private static string AppendState(OptionMetadata option, string name)
 {
     var statusOption = (StatusOptionMetadata) option;
     name += "_" + (statusOption.State == 0 ? "Active" : "Inactive");
     return name;
 }