Пример #1
0
        private static string UpdateCasingForCustomGlobalOptionSets(string name, OptionSetMetadataBase optionSetMetadata)
        {
            var preferredEndings = new [] { "StateCode", "Status", "State" };
            var displayName      = optionSetMetadata.DisplayName?.GetLocalOrDefaultText() ?? string.Empty;

            if (string.IsNullOrWhiteSpace(displayName))
            {
                return(CamelCaseClassNames
                    ? CamelCaser.Case(name, preferredEndings)
                    : name);
            }

            displayName = displayName.RemoveDiacritics().Replace(" ", ""); // Remove spaces
            if (name.EndsWith(displayName.ToLower()))
            {
                name = name.Replace(displayName.ToLower(), displayName);
            }
            else if (name.Contains(displayName.ToLower()) && name.IndexOf(displayName.ToLower(), StringComparison.Ordinal) == name.LastIndexOf(displayName.ToLower(), StringComparison.Ordinal))
            {
                // Name only contains the display name, and only once, but also contains other characters.  Capitalize the Display Name, and the next character
                // as long as more than one character exists: given HelloWorld, helloworldstatus => HelloWorldStatus but helloworlds => HelloWorlds
                // May need to check for plural instead... s/es/ies
                var index = name.IndexOf(displayName.ToLower(), StringComparison.Ordinal) + displayName.Length;
                name = name.Replace(displayName.ToLower(), displayName);
                if (index < name.Length - 1)
                {
                    name = name.Substring(0, index) + char.ToUpper(name[index]) + name.Substring(index + 1, name.Length - index - 1);
                }
            }
            return(CamelCaseClassNames
                ? CamelCaser.Case(name, preferredEndings)
                : name);
        }
Пример #2
0
        public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            // Should we output a enum optionset or just plain OptionSetValue?
            var enums  = Config.GetConfig("picklistEnums") == "true" && (optionSetMetadata.IsGlobal != true);
            var states = Config.GetConfig("stateEnums") == "true";

            var optionsetValues = optionSetMetadata as OptionSetMetadata;

            if (optionsetValues != null)
            {
                // check if there are any invalid names
                foreach (var option in optionsetValues.Options)
                {
                    string optionSetName = Regex.Replace(option.Label.UserLocalizedLabel.Label, "[^a-zA-Z0-9]", string.Empty);
                    if ((optionSetName.Length > 0) && !char.IsLetter(optionSetName, 0))
                    {
                        option.Label.UserLocalizedLabel.Label = "Number_" + optionSetName;
                    }
                    else if (optionSetName.Length == 0)
                    {
                        option.Label.UserLocalizedLabel.Label = "empty";
                    }

                    // Set all languages to the user localised version
                    foreach (var label in option.Label.LocalizedLabels)
                    {
                        label.Label = option.Label.UserLocalizedLabel.Label;
                    }
                }

                // check if the names are unique in optionset values
                var duplicateNames = optionsetValues.Options.GroupBy(x => x.Label.UserLocalizedLabel.Label).Where(g => g.Count() > 1).Select(y => y.Key).ToList();
                duplicateNames.ForEach(delegate(string duplicate){
                    var option = optionsetValues.Options.Where(x => x.Label.UserLocalizedLabel.Label == duplicate).First();
                    option.Label.UserLocalizedLabel.Label += option.Value.ToString();
                    // Also set the other labels
                    foreach (var label in option.Label.LocalizedLabels)
                    {
                        label.Label = option.Label.UserLocalizedLabel.Label;
                    }
                });
            }

            var optionType = (OptionSetType)optionSetMetadata.OptionSetType.Value;

            switch (optionType)
            {
            case OptionSetType.State:
                return(states);

            case OptionSetType.Status:
                return(states);

            case OptionSetType.Picklist:
                return(enums);

            default:
                return(false);
            }
        }
Пример #3
0
    bool ICodeWriterFilterService.GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
    {
        if (optionSetMetadata.IsGlobal.HasValue && optionSetMetadata.IsGlobal.Value)
        {
            if (!GeneratedOptionSets.ContainsKey(optionSetMetadata.Name))
            {
                if (!config.GlobalOptionSets.Contains(optionSetMetadata.Name))
                {
                    return(false);
                }
                GeneratedOptionSets[optionSetMetadata.Name] = true;
                return(true);
            }
        }
        else
        {
            if (currentEntity == null)
            {
                return(false);
            }

            return(true);
        }
        return(false);
    }
        private void HandleDuplicateNames(OptionSetMetadataBase optionSetMetadata)
        {
            var nonBooleanOptionSet = optionSetMetadata as OptionSetMetadata;

            if (nonBooleanOptionSet == null)
            {
                return;
            }

            foreach (var option in nonBooleanOptionSet.Options.ToList())
            {
                bool addValue = false;
                foreach (var otherOption in nonBooleanOptionSet.Options.Where(o =>
                                                                              option != o &&
                                                                              GetValidCSharpName(o) == GetValidCSharpName(option)).ToList())
                {
                    // options have identical text values, Remove if the int values are the same, add int to name if they are different
                    if (option.Value == otherOption.Value)
                    {
                        nonBooleanOptionSet.Options.Remove(otherOption);
                    }
                    else
                    {
                        otherOption.Label.UserLocalizedLabel.Label = string.Format("{0}_{1}", otherOption.Label.GetLocalOrDefaultText(), otherOption.Value);
                        addValue = true;
                    }
                }

                if (addValue)
                {
                    option.Label.UserLocalizedLabel.Label = string.Format("{0}_{1}", option.Label.GetLocalOrDefaultText(), option.Value);
                }
            }
        }
        public OptionSetIntellisenseData(EnumAttributeMetadata enumAttributeMetadata)
        {
            this.IsStateCode  = enumAttributeMetadata is StateAttributeMetadata;
            this.IsStatusCode = enumAttributeMetadata is StatusAttributeMetadata;

            this.OptionSetMetadata = enumAttributeMetadata.OptionSet;
        }
Пример #6
0
    public String GetNameForOptionSet(
        EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata,
        IServiceProvider services)
    {
        if (optionSetMetadata.IsGlobal.HasValue && !optionSetMetadata.IsGlobal.Value)
        {
            var attribute =
                (from a in entityMetadata.Attributes
                 where a.AttributeType == AttributeTypeCode.Picklist &&
                 ((EnumAttributeMetadata)a).OptionSet.MetadataId
                 == optionSetMetadata.MetadataId
                 select a).FirstOrDefault();

            if (attribute != null)
            {
                return(String.Format("{0}_{1}",
                                     DefaultNamingService.GetNameForEntity(entityMetadata, services),
                                     DefaultNamingService.GetNameForAttribute(
                                         entityMetadata, attribute, services)));
            }
        }

        return(DefaultNamingService.GetNameForOptionSet(
                   entityMetadata, optionSetMetadata, services));
    }
Пример #7
0
    private String EnsureUniqueOptionName(OptionSetMetadataBase metadata, String name)
    {
        if (OptionNames.ContainsKey(metadata))
        {
            if (OptionNames[metadata].ContainsKey(name))
            {
                ++OptionNames[metadata][name];

                var newName = String.Format("{0}_{1}",
                                            name, OptionNames[metadata][name]);

                Trace.TraceInformation(String.Format(
                                           "The {0} OptionSet already contained a definition for {1}. Changed to {2}",
                                           metadata.Name, name, newName));

                return(EnsureUniqueOptionName(metadata, newName));
            }
        }
        else
        {
            OptionNames[metadata] = new Dictionary <string, int>();
        }

        OptionNames[metadata][name] = 1;

        return(name);
    }
Пример #8
0
        /// <summary>
        /// Provide a new implementation for finding a name for an OptionSet. If the
        /// OptionSet is not global, we want the name to be the concatenation of the Entity's
        /// name and the Attribute's name.  Otherwise, we can use the default implementation.
        /// </summary>
        public String GetNameForOptionSet(
            EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata,
            IServiceProvider services)
        {
            // Ensure that the OptionSet is not global before using the custom
            // implementation.
            if (optionSetMetadata.IsGlobal.HasValue && !optionSetMetadata.IsGlobal.Value)
            {
                // Find the attribute which uses the specified OptionSet.
                var attribute =
                    (from a in entityMetadata.Attributes
                     where a.AttributeType == AttributeTypeCode.Picklist
                     && ((EnumAttributeMetadata)a).OptionSet.MetadataId
                         == optionSetMetadata.MetadataId
                     select a).FirstOrDefault();

                // Check for null, since statuscode attributes on custom entities are not
                // global, but their optionsets are not included in the attribute
                // metadata of the entity, either.
                if (attribute != null)
                {
                    // Concatenate the name of the entity and the name of the attribute
                    // together to form the OptionSet name.
                    return String.Format("{0}{1}",
                        DefaultNamingService.GetNameForEntity(entityMetadata, services),
                        DefaultNamingService.GetNameForAttribute(
                            entityMetadata, attribute, services));
                }
            }

            return DefaultNamingService.GetNameForOptionSet(
                entityMetadata, optionSetMetadata, services);
        }
        private static Dictionary <int, string> GetOptionsetValuesFromMetadata(OptionSetMetadataBase optionSets)
        {
            var optionsetValues = new Dictionary <int, string>();

            if (optionSets is OptionSetMetadata options)
            {
                foreach (OptionMetadata option in options.Options)
                {
                    int?value = option.Value;
                    option.Label.LocalizedLabels.ToList().ForEach(lab => optionsetValues.Add(value.Value, lab.Label));
                }
            }

            if (optionSets is BooleanOptionSetMetadata boolOptions)
            {
                var    trueOption  = boolOptions.TrueOption;
                var    falseOption = boolOptions.FalseOption;
                var    dictionary1 = optionsetValues;
                int?   nullable    = trueOption.Value;
                int    key1        = nullable.Value;
                string label1      = trueOption.Label.LocalizedLabels[0].Label;
                dictionary1.Add(key1, label1);
                Dictionary <int, string> dictionary2 = optionsetValues;
                nullable = falseOption.Value;
                int    key2   = nullable.Value;
                string label2 = falseOption.Label.LocalizedLabels[0].Label;
                dictionary2.Add(key2, label2);
            }
            return(optionsetValues);
        }
Пример #10
0
        /// <summary>
        /// Checks to make sure that the name does not already exist for the OptionSet
        /// to be generated.
        /// </summary>
        private String EnsureUniqueOptionName(OptionSetMetadataBase metadata, String name)
        {
            if (OptionNames.ContainsKey(metadata))
            {
                if (OptionNames[metadata].ContainsKey(name))
                {
                    // Increment the number of times that an option with this name has
                    // been found.
                    ++OptionNames[metadata][name];

                    // Append the number to the name to create a new, unique name.
                    var newName = String.Format("{0}_{1}",
                                                name, OptionNames[metadata][name]);

                    Trace.TraceInformation(String.Format(
                                               "The {0} OptionSet already contained a definition for {1}. Changed to {2}",
                                               metadata.Name, name, newName));

                    // Call this function again to make sure that our new name is unique.
                    return(EnsureUniqueOptionName(metadata, newName));
                }
            }
            else
            {
                // This is the first time this OptionSet has been encountered. Add it to
                // the dictionary.
                OptionNames[metadata] = new Dictionary <string, int>();
            }

            // This is the first time this name has been encountered. Begin keeping track
            // of the times we've run across it.
            OptionNames[metadata][name] = 1;

            return(name);
        }
Пример #11
0
        /// <inheritdoc />
        public string GetNameForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
        {
            string value = _defaultService.GetNameForOption(optionSetMetadata, optionMetadata, services);

            value = ModifyPublisher(value);
            return(value);
        }
Пример #12
0
        public override string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            string returnValue  = string.Empty;
            string defaultValue = base.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);

            foreach (var namer in _namers)
            {
                Trace.Debug($"Executing naming rule {nameof(GetNameForOptionSet)} using {namer.GetType().FullName}");

                returnValue = namer.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);
            }

            if (string.IsNullOrEmpty(returnValue))
            {
                returnValue = defaultValue;
            }

            var cacheItem = DynamicsMetadataCache.OptionSets.GetOrParse(optionSetMetadata);

            if (cacheItem != null)
            {
                cacheItem.GeneratedTypeName = returnValue;
            }

            DynamicsMetadataCache.OptionSets.Set(cacheItem);

            return(returnValue);
        }
Пример #13
0
        /// <summary>
        /// Provide a new implementation for finding a name for an OptionSet. If the
        /// OptionSet is not global, we want the name to be the concatenation of the Entity's
        /// name and the Attribute's name.  Otherwise, we can use the default implementation.
        /// </summary>
        public String GetNameForOptionSet(
            EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata,
            IServiceProvider services)
        {
            // Ensure that the OptionSet is not global before using the custom
            // implementation.
            if (optionSetMetadata.IsGlobal.HasValue && !optionSetMetadata.IsGlobal.Value)
            {
                // Find the attribute which uses the specified OptionSet.
                var attribute =
                    (from a in entityMetadata.Attributes
                     where a.AttributeType == AttributeTypeCode.Picklist &&
                     ((EnumAttributeMetadata)a).OptionSet.MetadataId
                     == optionSetMetadata.MetadataId
                     select a).FirstOrDefault();

                // Check for null, since statuscode attributes on custom entities are not
                // global, but their optionsets are not included in the attribute
                // metadata of the entity, either.
                if (attribute != null)
                {
                    // Concatenate the name of the entity and the name of the attribute
                    // together to form the OptionSet name.
                    return(String.Format("{0}{1}",
                                         DefaultNamingService.GetNameForEntity(entityMetadata, services),
                                         DefaultNamingService.GetNameForAttribute(
                                             entityMetadata, attribute, services)));
                }
            }

            return(DefaultNamingService.GetNameForOptionSet(
                       entityMetadata, optionSetMetadata, services));
        }
        private static bool IsNewOptionSetValue(OptionSetMetadataBase optionSet, int?lookupValue)
        {
            bool isNew = true;

            if (!lookupValue.HasValue)
            {
                return(true);
            }

            if (optionSet is OptionSetMetadata picklistOptionSet)
            {
                if (picklistOptionSet.Options.Any(o => o.Value.Value.Equals(lookupValue.Value)))
                {
                    // Existing; Do update
                    isNew = false;
                }
            }
            else if (optionSet is BooleanOptionSetMetadata booleanOptionSet)
            {
                if (booleanOptionSet.TrueOption.Value.Equals(lookupValue.Value) || booleanOptionSet.FalseOption.Value.Equals(lookupValue.Value))
                {
                    // Existing; Do update
                    isNew = false;
                }
            }

            return(isNew);
        }
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been marked for
        /// generation.
        /// </summary>
        public bool GenerateOptionSet(
            OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
#if SKIP_STATE_OPTIONSETS
            // Only skip the state optionsets if the user of the extension wishes to.
            if (optionSetMetadata.OptionSetType == OptionSetType.State)
            {
                return(false);
            }
#endif

            if (optionSetMetadata.IsGlobal.HasValue && optionSetMetadata.IsGlobal.Value)
            {
                if (!GeneratedOptionSets.ContainsKey(optionSetMetadata.Name))
                {
                    GeneratedOptionSets[optionSetMetadata.Name] = true;
                    return(true);
                }
            }
            else
            {
                return(true);
            }
            return(false);
        }
        public override bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            bool whitelist, blacklist = false;

            whitelist = _whitelistFilters.Any(filter => filter.GenerateOptionSet(optionSetMetadata, services));

            if (whitelist)
            {
                Trace.TraceInformation($"Whitelist: {optionSetMetadata.Name} is on the whitelist and will be generated.");
            }
            else
            {
                if (Configuration.Filtering.HasWhitelist && Configuration.Filtering.Whitelist.Filter == WhitelistFilter.Exclusive)
                {
                    return(false);
                }

                blacklist = _blacklistFilters.Any(filter => filter.GenerateOptionSet(optionSetMetadata, services));

                if (!blacklist)
                {
                    Trace.TraceInformation($"Blacklist: {optionSetMetadata.Name} is on the blacklist and will not be generated.");
                }
            }

            return(whitelist || blacklist);
        }
        private void UpdateEntityOptionSet()
        {
            AttributeMetadata attribute = _repository.GetAttribute(Entity, Attribute);

            // Can be new or update
            OptionSetMetadataBase attributeOptionSet = null;

            if (attribute is BooleanAttributeMetadata booleanAttribute)
            {
                attributeOptionSet = booleanAttribute.OptionSet;
            }
            else if (attribute is PicklistAttributeMetadata picklistAttribute)
            {
                attributeOptionSet = picklistAttribute.OptionSet;
            }

            if (IsNewOptionSetValue(attributeOptionSet, Value))
            {
                _repository.AddOptionSetValue(Entity, Attribute, DisplayName, Value, Description);
            }
            else
            {
                _repository.UpdateOptionSetValue(Entity, Attribute, Value.Value, DisplayName, Description);
            }
        }
Пример #18
0
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been marked for
        /// generation.
        /// </summary>
        public bool GenerateOptionSet(
            OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            #if SKIP_STATE_OPTIONSETS 
                // Only skip the state optionsets if the user of the extension wishes to.
                if (optionSetMetadata.OptionSetType == OptionSetType.State)
                {
                    return false;
                }
            #endif

            if (optionSetMetadata.IsGlobal.HasValue && optionSetMetadata.IsGlobal.Value)
            {
                if (!GeneratedOptionSets.ContainsKey(optionSetMetadata.Name))
                {
                    GeneratedOptionSets[optionSetMetadata.Name] = true;
                    return true;
                }
            }
            else
            {
                return true;
            }
            return false;
        }
Пример #19
0
        internal static string GetOptionSetName(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata)
        {
            string metadataName = TransformMetadataName(optionSetMetadata?.DisplayName?.UserLocalizedLabel?.Label);

            if (optionSetMetadata.OptionSetType == OptionSetType.Boolean)
            {
                return(null);
            }
            else if (optionSetMetadata.IsGlobal.GetValueOrDefault())
            {
                return(string.IsNullOrWhiteSpace(metadataName) ? null : Properties.Settings.Default.GlobalOptionSetPrefix + metadataName);
            }
            else if (entityMetadata == null)
            {
                return(string.IsNullOrWhiteSpace(metadataName) ? null : metadataName);
            }
            else if (optionSetMetadata.Name.EndsWith(StateCodeLogicalName, StringComparison.Ordinal))
            {
                return(entityMetadata.SchemaName + Properties.Settings.Default.StateCodeSuffix);
            }
            else if (optionSetMetadata.Name.EndsWith(Properties.Settings.Default.StateCodeSuffix, StringComparison.Ordinal))
            {
                return(optionSetMetadata.Name);
            }
            else if (optionSetMetadata.Name.EndsWith(Properties.Settings.Default.StatusReasonSuffix, StringComparison.Ordinal))
            {
                return(optionSetMetadata.Name);
            }
            else
            {
                return(string.IsNullOrWhiteSpace(metadataName) ? null : entityMetadata.SchemaName + metadataName);
            }
        }
Пример #20
0
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            switch (this.ParameterSetName)
            {
            case SetOptionSetParameterSet:
                if (DisplayName != null || Description != null || Customizable.HasValue)
                {
                    OptionSetMetadataBase internalOptionSet = BuildOptionSet();
                    _repository.UpdateOptionSet(internalOptionSet);
                    if (PassThru)
                    {
                        WriteObject(_repository.GetOptionSet(Name));
                    }
                }
                break;

            case SetOptionSetByInputObjectParameterSet:
                _repository.UpdateOptionSet(InputObject);
                if (PassThru)
                {
                    WriteObject(_repository.GetOptionSet(InputObject.MetadataId.Value));
                }
                break;

            default:
                break;
            }
        }
        async Task <bool> ICodeWriterFilterService.GenerateOptionSetAsync(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name);

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

            return(optionSetMetadata.OptionSetType != null && optionSetMetadata.OptionSetType.Value == OptionSetType.State);
        }
        /// <inheritdoc />
        public override string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            string value = base.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);

            value = ModifyPublisher(value);

            return(value);
        }
Пример #23
0
 public OptionSetComponent(CrmComponent c, OptionSetMetadataBase osmdb)
 {
     this.osmdb    = osmdb;
     Id            = osmdb.MetadataId;
     ComponentType = c.ComponentType;
     Name          = osmdb.Name;
     DisplayName   = osmdb.DisplayName?.UserLocalizedLabel?.Label;
 }
        public void BeginOptionSet(OptionSetMetadataBase optionSet)
        {
            _writer = new StreamWriter(string.Format("{0}.java", optionSet.Name));
            _writer.WriteLine(TemplateResources.Java_File_Begin.Replace(FILE_NAME, optionSet.Name));

            _writer.WriteLine(TemplateResources.Java_OptionSet_Begin.Replace(OPTIONSET_NAME, optionSet.Name));
            _optionToObjectCases = new StringBuilder();
        }
Пример #25
0
 internal OrganizationMetadata(EntityMetadata[] entities, OptionSetMetadataBase[] optionSets, SdkMessages messages)
 {
     Trace.TraceInformation("Entering {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     _entities = entities;
     _optionSets = optionSets;
     _sdkMessages = messages;
     Trace.TraceInformation("Exiting {0}", new object[] {MethodBase.GetCurrentMethod().Name});
 }
Пример #26
0
 public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     if (EnumFilter.GenerateOptionSet(optionSetMetadata, services))
     {
         OptionSetMetadata.Add(optionSetMetadata.MetadataId.GetValueOrDefault(), optionSetMetadata);
     }
     return(DefaultService.GenerateOptionSet(optionSetMetadata, services));
 }
 public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     if (EnumFilter.GenerateOptionSet(optionSetMetadata, services))
     {
         OptionSetMetadata.Add(optionSetMetadata.MetadataId.GetValueOrDefault(), optionSetMetadata);
     }
     return DefaultService.GenerateOptionSet(optionSetMetadata, services);
 }
Пример #28
0
 /// <summary>
 /// Gets the option set label.
 /// </summary>
 /// <param name="optionSet">The option set.</param>
 /// <returns></returns>
 private static string GetOptionSetLabel(OptionSetMetadataBase optionSet)
 {
     if (optionSet.DisplayName != null && optionSet.DisplayName.UserLocalizedLabel != null && optionSet.DisplayName.UserLocalizedLabel.Label != null)
     {
         return(optionSet.DisplayName.UserLocalizedLabel.Label);
     }
     return(optionSet.Name);
 }
Пример #29
0
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been generated.
        /// This could get called for the same Global Option Set multiple times because it's on multiple Entities
        /// </summary>
        public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            PopulateUsedEntityGlobalOptionSetOnInitialCall(services);

            // Skip the state optionsets unless the XrmClient is used
            if (!Entity.CustomizeCodeDomService.UseXrmClient && optionSetMetadata.OptionSetType == OptionSetType.State)
            {
                return(false);
            }

            if (optionSetMetadata.IsGlobal.GetValueOrDefault() &&
                GenerateOnlyReferencedOptionSets &&
                !UsedEntityGlobalOptionSets.Contains(optionSetMetadata.Name.ToLower()))
            {
                return(false);
            }


            if (!IsOptionSetGenerated(optionSetMetadata.Name))
            {
                return(false);
            }

            bool generate = false;

            if (optionSetMetadata.IsGlobal.GetValueOrDefault())
            {
                if (!GeneratedOptionSets.Contains(optionSetMetadata.Name))
                {
                    GeneratedOptionSets.Add(optionSetMetadata.Name);
                    generate = true;
                }
            }
            else
            {
                generate = true;
            }

            // Remove Dups
            var metadataOptionSet = optionSetMetadata as OptionSetMetadata;

            if (generate && metadataOptionSet != null)
            {
                var namingService = new NamingService((INamingService)services.GetService(typeof(INamingService)));
                var names         = new HashSet <string>();
                foreach (var option in metadataOptionSet.Options.ToList())
                {
                    var name = namingService.GetNameForOption(optionSetMetadata, option, services);
                    if (names.Contains(name))
                    {
                        metadataOptionSet.Options.Remove(option);
                    }
                    names.Add(name);
                }
            }

            return(generate);
        }
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been generated.  
        /// This could get called for the same Global Option Set multiple times because it's on multiple Entites
        /// </summary>
        public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {

#if SKIP_STATE_OPTIONSETS
            // Only skip the state optionsets if the user of the extension wishes to.
            if (optionSetMetadata.OptionSetType == OptionSetType.State)
            {
                return false;
            }
#endif
            if (Skip(optionSetMetadata.Name))
            {
                return false;
            }

            bool generate = false;

            if (optionSetMetadata.IsGlobal.GetValueOrDefault())
            {
                if (!GeneratedOptionSets.Contains(optionSetMetadata.Name))
                {
                    GeneratedOptionSets.Add(optionSetMetadata.Name);
                    generate = true;
                }
            }
            else
            {
                generate = true;
            }

            if (generate && optionSetMetadata.Name != null)
            {
                string name = optionSetMetadata.Name;
                if (name.ToLower().EndsWith("set"))
                {
                    optionSetMetadata.Name = name + "Enum";
                }
            }

            // Remove Dups
            var metadataOptionSet = optionSetMetadata as OptionSetMetadata;
            if (generate && metadataOptionSet != null)
            {
                var namingService = new NamingService((INamingService)services.GetService(typeof(INamingService)));
                var names = new HashSet<string>();
                foreach (var option in metadataOptionSet.Options.ToList())
                {
                    var name = namingService.GetNameForOption(optionSetMetadata, option, services);
                    if (names.Contains(name))
                    {
                        metadataOptionSet.Options.Remove(option);
                    }
                    names.Add(name);
                }
            }

            return generate;
        }
Пример #31
0
        public static void AddMetadataAttributesForSet(CodeTypeDeclaration type, OptionSetMetadataBase osMetadata)
        {
            if (!AddOptionSetMetadataAttribute)
            {
                return;
            }

            Trace.TraceInformation("Adding MetadataAttributes for {0}", type.Name);
            var options           = osMetadata.GetOptions();
            var metadataByValue   = options.ToDictionary(k => k.Value);
            var orderIndexByValue = new Dictionary <int, int>();

            for (var i = 0; i < options.Count; i++)
            {
                if (options[i].Value is int intValue)
                {
                    orderIndexByValue.Add(intValue, i);
                }
                else
                {
                    Trace.TraceInformation("Unable to find orderIndexByValue for {0}", type.Name);
                }
            }

            for (var i = 0; i < type.Members.Count; i++)
            {
                var value = type.Members[i] as CodeMemberField;
                if (value != null &&
                    value.InitExpression is CodePrimitiveExpression primitive &&
                    primitive.Value is int intValue &&
                    metadataByValue.TryGetValue(intValue, out var metadata))
                {
                    var attribute = new CodeAttributeDeclaration("OptionSetMetadataAttribute",
                                                                 new CodeAttributeArgument(new CodePrimitiveExpression(metadata.Label.GetLocalOrDefaultText())),
                                                                 new CodeAttributeArgument(new CodePrimitiveExpression(orderIndexByValue[intValue]))
                                                                 );
                    var optionalArs = new Stack <string>(new []
                    {
                        metadata.Color,
                        metadata.Description.GetLocalOrDefaultText(),
                        metadata.ExternalValue
                    });

                    while (optionalArs.Count > 0 && string.IsNullOrWhiteSpace(optionalArs.Peek()))
                    {
                        optionalArs.Pop();
                    }

                    if (optionalArs.Count > 0)
                    {
                        attribute.Arguments.AddRange(
                            optionalArs.Select(v => new CodeAttributeArgument(new CodePrimitiveExpression(v)))
                            .Reverse().ToArray()
                            );
                    }

                    value.CustomAttributes.Add(attribute);
                }
Пример #32
0
        public static string GetGlobalOptionSetName(this OptionSetMetadataBase optionSetMetadata)
        {
            if (optionSetMetadata == null)
            {
                return(null);
            }

            return(optionSetMetadata.IsGlobal.HasValue && optionSetMetadata.IsGlobal.Value ? optionSetMetadata.Name : null);
        }
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been generated.
        /// This could get called for the same Global Option Set multiple times because it's on multiple Entites
        /// </summary>
        public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
#if SKIP_STATE_OPTIONSETS
            // Only skip the state optionsets if the user of the extension wishes to.
            if (optionSetMetadata.OptionSetType == OptionSetType.State)
            {
                return(false);
            }
#endif
            if (Skip(optionSetMetadata.Name))
            {
                return(false);
            }

            bool generate = false;

            if (optionSetMetadata.IsGlobal.GetValueOrDefault())
            {
                if (!GeneratedOptionSets.Contains(optionSetMetadata.Name))
                {
                    GeneratedOptionSets.Add(optionSetMetadata.Name);
                    generate = true;
                }
            }
            else
            {
                generate = true;
            }

            if (generate && optionSetMetadata.Name != null)
            {
                string name = optionSetMetadata.Name;
                if (name.ToLower().EndsWith("set"))
                {
                    optionSetMetadata.Name = name + "Enum";
                }
            }

            // Remove Dups
            var metadataOptionSet = optionSetMetadata as OptionSetMetadata;
            if (generate && metadataOptionSet != null)
            {
                var namingService = new NamingService((INamingService)services.GetService(typeof(INamingService)));
                var names         = new HashSet <string>();
                foreach (var option in metadataOptionSet.Options.ToList())
                {
                    var name = namingService.GetNameForOption(optionSetMetadata, option, services);
                    if (names.Contains(name))
                    {
                        metadataOptionSet.Options.Remove(option);
                    }
                    names.Add(name);
                }
            }

            return(generate);
        }
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been generated.
        /// This could get called for the same Global Option Set multiple times because it's on multiple Entities
        /// </summary>
        public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            PopulateUsedEntityGlobalOptionSetOnInitialCall(services);

            // Skip the state optionSets
            if (optionSetMetadata.OptionSetType == OptionSetType.State)
            {
                return(false);
            }

            if (optionSetMetadata.IsGlobal.GetValueOrDefault() &&
                GenerateOnlyReferencedOptionSets &&
                !UsedEntityGlobalOptionSets.Contains(optionSetMetadata.Name.ToLower()))
            {
                return(false);
            }


            if (!Approver.IsAllowed(optionSetMetadata.Name.ToLower()))
            {
                return(false);
            }

            var generate = false;

            if (optionSetMetadata.IsGlobal.GetValueOrDefault())
            {
                if (!GeneratedOptionSets.Contains(optionSetMetadata.Name))
                {
                    GeneratedOptionSets.Add(optionSetMetadata.Name);
                    generate = true;
                }
            }
            else
            {
                generate = true;
            }

            // Remove Dups
            if (generate && optionSetMetadata is OptionSetMetadata metadataOptionSet)
            {
                var namingService = new NamingService((INamingService)services.GetService(typeof(INamingService)));
                var names         = new HashSet <string>();
                foreach (var option in metadataOptionSet.Options.ToList())
                {
                    var name = namingService.GetNameForOption(optionSetMetadata, option, services);
                    if (names.Contains(name))
                    {
                        metadataOptionSet.Options.Remove(option);
                    }
                    names.Add(name);
                }
            }

            return(generate);
        }
        public void EndOptionSet(OptionSetMetadataBase optionSet)
        {
            _writer.WriteLine(TemplateResources.Java_OptionSet_End
                .Replace(OPTIONSET_NAME, optionSet.Name)
                .Replace(OPTIONSET_TO_OBJECT_CASES, _optionToObjectCases.ToString()));

            _optionToObjectCases = null;
            _writer.Flush();
            _writer.Close();
        }
Пример #36
0
        /// <summary>
        /// Provide a new implementation for finding a name for an OptionSet. If the
        /// OptionSet is not global, we want the name to be the concatenation of the Entity's
        /// name and the Attribute's name.  Otherwise, we can use the default implementation.
        /// </summary>
        public string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            var name = GetPossiblyConflictedNameForOptionSet(entityMetadata, optionSetMetadata, services);

            while (EntityNames.Contains(name))
            {
                name += "_Enum";
            }
            return(OptionSetNames.TryGetValue(name.ToLower(), out var overriden) ? overriden : name);
        }
        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));
        }
        protected override bool?GenerateOptionSet(OptionSetMetadataBase optionSetMetadata)
        {
            var filters = FilterConfiguration.Filters.GetFilters(FilterMember.Attribute);

            if (filters?.Length == 0)
            {
                return(null);
            }

            return(DoesMatchSettings(optionSetMetadata.Name, "optionSet", filters));
        }
        /// <summary>
        /// Does not mark the OptionSet for generation if it has already been marked for
        /// generation.  This could get called for the same Global Option Set multiple times because it's on multiple Entites
        /// </summary>
        public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
#if SKIP_STATE_OPTIONSETS
            // Only skip the state optionsets if the user of the extension wishes to.
            if (optionSetMetadata.OptionSetType == OptionSetType.State)
            {
                return false;
            }
#endif

            bool generate = false;

            if (optionSetMetadata.IsGlobal.GetValueOrDefault())
            {
                if (!GeneratedOptionSets.Contains(optionSetMetadata.Name))
                {
                    GeneratedOptionSets.Add(optionSetMetadata.Name);
                    generate = true;
                }
            }
            else
            {
                generate = true;
            }

            if (generate && optionSetMetadata.Name != null)
            {
                string name = optionSetMetadata.Name;
                if (name.ToLower().EndsWith("set"))
                {
                    optionSetMetadata.Name = name + "Enum";
                }
            }

            if (generate)
            {
                HandleDuplicateNames(optionSetMetadata);
            }

            return generate;
        }
        /// <summary>
        /// Provide a new implementation for finding a name for an OptionSet. If the
        /// OptionSet is not global, we want the name to be the concatenation of the Entity's
        /// name and the Attribute's name.  Otherwise, we can use the default implementation.
        /// </summary>
        public string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        {
            if (UseDeprecatedOptionSetNaming)
            {
                return DefaultService.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);
            }
            // Ensure that the OptionSet is not global before using the custom implementation.
            if (optionSetMetadata.IsGlobal.HasValue && !optionSetMetadata.IsGlobal.Value)
            {
                // Find the attribute which uses the specified OptionSet.
                var attribute =
                    (from a in entityMetadata.Attributes
                     where a.AttributeType == AttributeTypeCode.Picklist &&
                        ((EnumAttributeMetadata)a).OptionSet.MetadataId == optionSetMetadata.MetadataId
                     select a).FirstOrDefault();

                // Check for null, since statuscode attributes on custom entities are not global, 
                // but their optionsets are not included in the attribute metadata of the entity, either.
                if (attribute == null)
                {
                    if (optionSetMetadata.OptionSetType.GetValueOrDefault() == OptionSetType.Status && DefaultService.GetNameForOptionSet(entityMetadata, optionSetMetadata, services).EndsWith("statuscode"))
                    {
                        return string.Format(LocalOptionSetFormat, GetNameForEntity(entityMetadata, services), "StatusCode");
                    }
                }
                else
                {
                    // Concatenate the name of the entity and the name of the attribute
                    // together to form the OptionSet name.
                    return string.Format(LocalOptionSetFormat, GetNameForEntity(entityMetadata, services),
                           GetNameForAttribute(entityMetadata, attribute, services));
                }
            }
            var name = DefaultService.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);
            name = UpdateCasingForGlobalOptionSets(name, optionSetMetadata);
            return name;
        }
 public void BeginOptionSet(OptionSetMetadataBase optionSet)
 {
     _hWriter.WriteLine(TemplateResources.H_OptionSet_Begin);
 }
 public void EndOptionSet(OptionSetMetadataBase optionSet)
 {
     _hWriter.WriteLine(TemplateResources.H_OptionSet_End
         .SaneReplace(OPTIONSET_NAME, optionSet.Name, ObjectiveCWordProvider.Instance));
 }
 public void EndOption(OptionSetMetadataBase optionSet, OptionMetadata option) { }
Пример #44
0
        /// <summary>
        /// Checks to make sure that the name does not already exist for the OptionSet
        /// to be generated.
        /// </summary>
        private String EnsureUniqueOptionName(OptionSetMetadataBase metadata, String name)
        {
            if (OptionNames.ContainsKey(metadata))
            {
                if (OptionNames[metadata].ContainsKey(name))
                {
                    // Increment the number of times that an option with this name has
                    // been found.
                    ++OptionNames[metadata][name];

                    // Append the number to the name to create a new, unique name.
                    var newName = String.Format("{0}_{1}",
                        name, OptionNames[metadata][name]);

                    Trace.TraceInformation(String.Format(
                        "The {0} OptionSet already contained a definition for {1}. Changed to {2}",
                        metadata.Name, name, newName));

                    // Call this function again to make sure that our new name is unique.
                    return EnsureUniqueOptionName(metadata, newName);
                }
            }
            else
            {
                // This is the first time this OptionSet has been encountered. Add it to
                // the dictionary.
                OptionNames[metadata] = new Dictionary<string, int>();
            }

            // This is the first time this name has been encountered. Begin keeping track
            // of the times we've run across it.
            OptionNames[metadata][name] = 1;

            return name;
        }
Пример #45
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;
 }
Пример #46
0
 static CodeTypeDeclarationCollection BuildOptionSets(OptionSetMetadataBase[] optionSetMetadata, ServiceProvider serviceProvider)
 {
     Trace.TraceInformation("Entering {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     var declarations = new CodeTypeDeclarationCollection();
     foreach (var base2 in optionSetMetadata)
     {
         if ((serviceProvider.CodeFilterService.GenerateOptionSet(base2, serviceProvider) && base2.IsGlobal.HasValue) && base2.IsGlobal.Value)
         {
             var declaration = BuildOptionSet(null, base2, serviceProvider);
             if (declaration != null)
             {
                 declarations.Add(declaration);
             }
             else
             {
                 Trace.TraceInformation("Skipping OptionSet {0} of type {1} from being generated.", new object[] {base2.Name, base2.GetType()});
             }
         }
         else
         {
             Trace.TraceInformation("Skipping OptionSet {0} from being generated.", new object[] {base2.Name});
         }
     }
     Trace.TraceInformation("Exiting {0}", new object[] {MethodBase.GetCurrentMethod().Name});
     return declarations;
 }
Пример #47
0
 string INamingService.GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     if (_knowNames.ContainsKey(optionSetMetadata.MetadataId.Value.ToString()))
     {
         return _knowNames[optionSetMetadata.MetadataId.Value.ToString()];
     }
     string str;
     if ((optionSetMetadata.OptionSetType.Value) == OptionSetType.State)
     {
         str = CreateValidTypeName(entityMetadata.SchemaName + "State");
     }
     else
     {
         str = CreateValidTypeName(optionSetMetadata.Name);
     }
     _knowNames.Add(optionSetMetadata.MetadataId.Value.ToString(), str);
     return str;
 }
Пример #48
0
 CodeGenerationType ICodeGenerationService.GetTypeForOption(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services)
 {
     return CodeGenerationType.Field;
 }
Пример #49
0
 CodeGenerationType ICodeGenerationService.GetTypeForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     return CodeGenerationType.Enum;
 }
 private string UpdateCasingForGlobalOptionSets(string name, OptionSetMetadataBase optionSetMetadata)
 {
     switch (name.ToLower())
     {
         case "budgetstatus":
             return "BudgetStatus";
         case "componentstate":
             return "ComponentState";
         case "componenttype":
             return "ComponentType";
         case "connectionrole_category":
             return "ConnectionRole_Category";
         case "convertrule_channelactivity":
             return "ConvertRule_ChannelActivity";
         case "dependencytype":
             return "DependencyType";
         case "emailserverprofile_authenticationprotocol":
             return "EmailServerProfile_AuthenticationProtocol";
         case "field_security_permission_type":
             return "Field_Security_Permission_Type";
         case "goal_fiscalperiod":
             return "Goal_FiscalPeriod";
         case "goal_fiscalyear":
             return "Goal_FiscalYear";
         case "incident_caseorigincode":
             return "Incident_CaseOriginCode";
         case "initialcommunication":
             return "InitialCommunication";
         case "lead_salesstage":
             return "Lead_SalesStage";
         case "metric_goaltype":
             return "Metric_GoalType";
         case "need":
             return "Need";
         case "opportunity_salesstage":
             return "Opportunity_SalesStage";
         case "principalsyncattributemapping_syncdirection":
             return "PrincipalSyncAttributeMapping_SyncDirection";
         case "processstage_category":
             return "Processstage_Category";
         case "purchaseprocess":
             return "PurchaseProcess";
         case "purchasetimeframe":
             return "PurchaseTimeFrame";
         case "qooi_pricingerrorcode":
             return "Qooi_PricingErrorCode";
         case "qooiproduct_producttype":
             return "QooiProduct_ProductType";
         case "qooiproduct_propertiesconfigurationstatus":
             return "QooiProduct_PropertiesConfigurationStatus";
         case "recurrencerule_monthofyear":
             return "RecurrenceRule_MonthOfYear";
         case "servicestage":
             return "ServiceStage";
         case "sharepoint_validationstatus":
             return "SharePoint_ValidationStatus";
         case "sharepoint_validationstatusreason":
             return "SharePoint_ValidationStatusReason";
         case "sharepointdocumentlocation_locationtype":
             return "SharePointDocumentLocation_LocationType";
         case "socialactivity_postmessagetype":
             return "SocialActivity_PostMessageType";
         case "socialprofile_community":
             return "SocialProfile_Community";
         case "syncattributemapping_syncdirection":
             return "SyncAttributeMapping_SyncDirection";
         case "workflow_runas":
             return "Workflow_RunAs";
         case "workflow_stage":
             return "Workflow_Stage";
         case "workflowlog_objecttypecode":
             return "WorkflowLog_ObjectTypeCode";
         default:
             return UpdateCasingForCustomGlobalOptionSets(name, optionSetMetadata);
     }
 }
 public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     return false;
 }
Пример #52
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;
 }
Пример #53
0
 IOrganizationMetadata CreateOrganizationMetadata(EntityMetadata[] entityMetadata, OptionSetMetadataBase[] optionSetMetadata, SdkMessages messages)
 {
     return new OrganizationMetadata(entityMetadata, optionSetMetadata, messages);
 }
Пример #54
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;
 }
Пример #55
0
 bool ICodeWriterFilterService.GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     return this.DefaultService.GenerateOptionSet(optionSetMetadata, services);
 }
        private void HandleDuplicateNames(OptionSetMetadataBase optionSetMetadata)
        {
            var nonBooleanOptionSet = optionSetMetadata as OptionSetMetadata;
            if (nonBooleanOptionSet == null) { return; }

            foreach (var option in nonBooleanOptionSet.Options.ToList())
            {
                bool addValue = false;
                foreach (var otherOption in nonBooleanOptionSet.Options.Where(o =>
                    option != o &&
                    GetValidCSharpName(o) == GetValidCSharpName(option)).ToList())
                {
                    // options have identical text values, Remove if the int values are the same, add int to name if they are different
                    if (option.Value == otherOption.Value)
                    {
                        nonBooleanOptionSet.Options.Remove(otherOption);
                    }
                    else
                    {
                        otherOption.Label.UserLocalizedLabel.Label = string.Format("{0}_{1}", otherOption.Label.GetLocalOrDefaultText(), otherOption.Value);
                        addValue = true;
                    }
                }

                if (addValue)
                {
                    option.Label.UserLocalizedLabel.Label = string.Format("{0}_{1}", option.Label.GetLocalOrDefaultText(), option.Value);
                }
            }
        }
 /// <summary>
 /// Generates attributes.
 /// </summary>
 /// <param name="optionSetMetadata"><see cref="OptionSetMetadataBase" /> instance.</param>
 /// <param name="services"><see cref="IServiceProvider" /> instance.</param>
 /// <returns>Returns <c>True</c>, if successfully generated; otherwise returns <c>False</c>.</returns>
 public bool GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     return this.DefaultService.GenerateOptionSet(optionSetMetadata, services);
 }
Пример #58
0
        static CodeTypeDeclaration BuildOptionSet(EntityMetadata entity, OptionSetMetadataBase optionSet, ServiceProvider serviceProvider)
        {
            Trace.TraceInformation("Entering {0}", new object[] {MethodBase.GetCurrentMethod().Name});
            var declaration = Enum(serviceProvider.NamingService.GetNameForOptionSet(entity, optionSet, serviceProvider), new[] {Attribute(typeof (DataContractAttribute))});
            var metadata = optionSet as OptionSetMetadata;
            if (metadata == null)
            {
                return null;
            }
            foreach (var metadata2 in metadata.Options)
            {

                if (Char.IsDigit(serviceProvider.NamingService.GetNameForOption(optionSet, metadata2, serviceProvider).First()))
                {
                    Trace.TraceInformation("Skipping {0}.Option {1} from being generated because it starts with a number.", new object[] { optionSet.Name, metadata2.Value.Value });
                    return null;
                }

                if (serviceProvider.CodeFilterService.GenerateOption(metadata2, serviceProvider))
                {
                    declaration.Members.Add(BuildOption(optionSet, metadata2, serviceProvider));
                }
                else
                {
                    Trace.TraceInformation("Skipping {0}.Option {1} from being generated.", new object[] {optionSet.Name, metadata2.Value.Value});
                }
            }
            Trace.TraceInformation("Exiting {0}: OptionSet Enumeration {1} defined", new object[] {MethodBase.GetCurrentMethod().Name, declaration.Name});
            return declaration;
        }
 public string GetNameForOptionSet(EntityMetadata entityMetadata, OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
 {
     return DefaultService.GetNameForOptionSet(entityMetadata, optionSetMetadata, services);
 }
Пример #60
0
        CodeTypeReference BuildCodeTypeReferenceForOptionSet(string attributeName, EntityMetadata entityMetadata, OptionSetMetadataBase attributeOptionSet, IServiceProvider services)
        {
            var service = (ICodeWriterFilterService) services.GetService(typeof (ICodeWriterFilterService));
            var service2 = (INamingService) services.GetService(typeof (INamingService));
            var service3 = (ICodeGenerationService) services.GetService(typeof (ICodeGenerationService));
            if (service.GenerateOptionSet(attributeOptionSet, services))
            {
                var typeName = service2.GetNameForOptionSet(entityMetadata, attributeOptionSet, services);
                var type = service3.GetTypeForOptionSet(entityMetadata, attributeOptionSet, services);
                switch (type)
                {
                    case CodeGenerationType.Class:
                        return TypeRef(typeName);

                    case CodeGenerationType.Enum:
                    case CodeGenerationType.Struct:
                        return TypeRef(typeof (Nullable<>), TypeRef(typeName));
                }
                Trace.TraceWarning("Cannot map type for atttribute {0} with OptionSet type {1} which has CodeGenerationType {2}", new object[] {attributeName, attributeOptionSet.Name, type});
            }
            return TypeRef(typeof (object));
        }