private async Task GenerateOptionSetEnums(IEnumerable <AttributeMetadata> attributeList, OptionSetMetadata optionSet) { var options = CreateFileHandler.GetOptionItems(attributeList.First().EntityLogicalName, attributeList.First().LogicalName, optionSet, this._listStringMap); if (!options.Any()) { return; } WriteLine(); WriteLine("// Attribute:"); foreach (var attr in attributeList.OrderBy(a => a.LogicalName)) { WriteLine("// " + _tabSpacer + attr.LogicalName); } if (optionSet.IsGlobal.GetValueOrDefault() && this._config.WithDependentComponents) { var coll = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); var desc = await _descriptorHandler.GetDescriptionDependentAsync(coll); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); if (split.Any()) { WriteSummaryStrings(split); } } bool ignore = attributeList.Any(a => IgnoreAttribute(_entityMetadata.LogicalName, a.LogicalName)); if (ignore) { foreach (var attr in attributeList.OrderBy(a => a.LogicalName)) { WriteLine("//var {0}Enum", attr.LogicalName); } return; } var enumName = string.Empty; if (optionSet.IsGlobal.GetValueOrDefault()) { enumName = optionSet.Name; } else { enumName = attributeList.First().LogicalName; } WriteLine(string.Format("'{0}Enum':", enumName) + " {"); WriteLine(); // Формируем значения foreach (var item in options) { WriteLine(item.MakeStringJS()); } WriteLine("},"); }
private async Task GenerateOptionSetEnums(string tempNamespace, OptionSetMetadata optionSet) { var dependent = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); string entityname = null; string attributename = null; List <StringMap> listStringmap = null; if (dependent.Any(e => e.DependentComponentType.Value == (int)ComponentType.Attribute)) { var attr = dependent.FirstOrDefault(e => e.DependentComponentType.Value == (int)ComponentType.Attribute); var attributeMetadata = _descriptor.MetadataSource.GetAttributeMetadata(attr.DependentComponentObjectId.Value); if (attributeMetadata != null) { entityname = attributeMetadata.EntityLogicalName; attributename = attributeMetadata.LogicalName; listStringmap = await _repositoryStringMap.GetListAsync(entityname); } } var options = CreateFileHandler.GetOptionItems(entityname, attributename, optionSet, listStringmap); if (!options.Any()) { return; } WriteLine(); if (this._withDependentComponents) { var desc = await _descriptorHandler.GetDescriptionDependentAsync(dependent); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in split) { WriteLine("// {0}", item); } } string objectName = string.Format("{0}{1}Enum", tempNamespace, optionSet.Name); if (CreateFileHandler.IgnoreGlobalOptionSet(optionSet.Name)) { WriteLine("// {0}", objectName); return; } WriteLine(string.Format("{0} =", objectName) + " {"); WriteLine(); // Формируем значения foreach (var item in options) { WriteLine(item.MakeStringJS()); } WriteLine("};"); }
private async Task GenerateOptionSetEnums(OptionSetMetadata optionSet) { var dependent = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value); string entityname = null; string attributename = null; List <StringMap> listStringmap = null; if (dependent.Any(e => e.DependentComponentType.Value == (int)ComponentType.Attribute)) { var attr = dependent.FirstOrDefault(e => e.DependentComponentType.Value == (int)ComponentType.Attribute); var attributeMetadata = _descriptor.MetadataSource.GetAttributeMetadata(attr.DependentComponentObjectId.Value); if (attributeMetadata != null) { entityname = attributeMetadata.EntityLogicalName; attributename = attributeMetadata.LogicalName; listStringmap = await _repositoryStringMap.GetListAsync(entityname); } } WriteLine(); List <string> headers = new List <string>(); string temp = string.Format("OptionSet Name: {0} IsCustomOptionSet: {1}", optionSet.Name, optionSet.IsCustomOptionSet); if (this._config.WithManagedInfo) { temp += string.Format(" IsManaged: {0}", optionSet.IsManaged); } headers.Add(temp); if (this._config.WithDependentComponents) { var desc = await _descriptorHandler.GetDescriptionDependentAsync(dependent); var split = desc.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); if (split.Any()) { headers.Add(string.Empty); foreach (var item in split) { headers.Add(item); } } } WriteSummary(optionSet.DisplayName, optionSet.Description, null, headers); var options = CreateFileHandler.GetOptionItems(entityname, attributename, optionSet, listStringmap); { bool ignore = CreateFileHandler.IgnoreGlobalOptionSet(optionSet.Name) || !options.Any(); if (!ignore) { if (this._config.AddDescriptionAttribute) { string description = CreateFileHandler.GetLocalizedLabel(optionSet.DisplayName); if (string.IsNullOrEmpty(description)) { description = CreateFileHandler.GetLocalizedLabel(optionSet.Description); } if (!string.IsNullOrEmpty(description)) { WriteLine("[System.ComponentModel.DescriptionAttribute(\"{0}\")]", description); } } if (this._config.OptionSetExportType == OptionSetExportType.Enums && _config.AddTypeConverterAttributeForEnums && !string.IsNullOrEmpty(_config.TypeConverterName)) { WriteLine("[System.ComponentModel.TypeConverterAttribute(\"{0}\")]", _config.TypeConverterName); } } StringBuilder str = new StringBuilder(); if (ignore) { str.Append("// "); } if (this._config.OptionSetExportType == OptionSetExportType.Enums) { str.AppendFormat("public enum {0}", optionSet.Name); } else { str.AppendFormat("public static partial class {0}", optionSet.Name); } WriteLine(str.ToString()); if (ignore) { return; } } WriteLine("{"); bool first = true; // Формируем значения foreach (var item in options) { if (first) { first = false; } else { WriteLine(); } List <string> header = new List <string>() { item.Value.ToString() }; if (item.DisplayOrder.HasValue) { header.Add(string.Format("DisplayOrder: {0}", item.DisplayOrder.Value)); } WriteSummary(item.Label, item.Description, header, null); if (this._config.AddDescriptionAttribute) { string description = CreateFileHandler.GetLocalizedLabel(item.Label); if (string.IsNullOrEmpty(description)) { description = CreateFileHandler.GetLocalizedLabel(item.Description); } if (!string.IsNullOrEmpty(description)) { WriteLine("[System.ComponentModel.DescriptionAttribute(\"{0}\")]", description); } } var str = item.MakeStrings(); if (this._config.OptionSetExportType == OptionSetExportType.Enums) { WriteLine("[System.Runtime.Serialization.EnumMemberAttribute()]"); WriteLine(str + ","); } else { WriteLine("public {0} int {1};", _fieldHeader, str); } } WriteLine("}"); }