Ejemplo n.º 1
0
        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("};");
        }
Ejemplo n.º 2
0
        private async Task <string> CreateFile(string entityName, string filePath, bool allComponents)
        {
            StringBuilder content = new StringBuilder();

            var metedata = _descriptor.MetadataSource.GetEntityMetadata(entityName);

            foreach (var currentAttribute in metedata.Attributes.OrderBy(attr => attr.LogicalName))
            {
                if (currentAttribute.AttributeOf == null)
                {
                    string name = string.Format("{0}.{1}", entityName, currentAttribute.LogicalName);

                    var coll = await _dependencyRepository.GetDependentComponentsAsync((int)ComponentType.Attribute, currentAttribute.MetadataId.Value);

                    if (!allComponents)
                    {
                        coll = coll.Where(ent =>
                        {
                            var val = ent.DependentComponentType.Value;

                            return(val == (int)ComponentType.Workflow ||
                                   val == (int)ComponentType.SdkMessageProcessingStep ||
                                   val == (int)ComponentType.SdkMessageProcessingStepImage
                                   );

                            //return val == (int)ComponentType.SDKMessageProcessingStepImage
                            //    ;
                        }
                                          ).ToList();
                    }

                    var desc = await _descriptorHandler.GetDescriptionDependentAsync(coll);

                    if (!string.IsNullOrEmpty(desc))
                    {
                        if (content.Length > 0)
                        {
                            content
                            .AppendLine()
                            .AppendLine()
                            .AppendLine(new string('-', 100))
                            .AppendLine()
                            .AppendLine();
                        }

                        content.AppendFormat("Attribute {0} Dependent Components:", name).AppendLine();
                        content.Append(desc);
                    }
                }
            }

            string message = string.Empty;

            if (content.Length > 0)
            {
                File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false));

                message = string.Format("For entity '{0}' created file with attributes dependent components: {1}", entityName, filePath);
            }
            else
            {
                message = string.Format("No information about attributes dependent components for entity '{0}'.", entityName);
            }

            return(message);
        }
Ejemplo n.º 3
0
        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("}");
        }
        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("},");
        }
Ejemplo n.º 5
0
        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 = GetOptionItems(entityname, attributename, optionSet, listStringmap);

            if (!options.Any())
            {
                return;
            }

            WriteLine();
            WriteLine();

            List <string> headers = new List <string>();

            string temp = string.Format("OptionSet Name: {0}      IsCustomOptionSet: {1}", optionSet.Name, optionSet.IsCustomOptionSet);

            headers.Add(temp);

            if (this._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);

            string objectName = string.Format("{0}{1}Enum", tempNamespace, optionSet.Name);

            if (IgnoreGlobalOptionSet(optionSet.Name))
            {
                WriteLine("// {0}", objectName);
                return;
            }

            WriteLine(string.Format("{0} =", objectName) + " {");

            WriteLine();

            bool first = true;

            // Формируем значения
            foreach (var item in options.OrderBy(o => o.Value))
            {
                WriteCommaIfNotFirstLine(ref first);

                Write(item.MakeStringJS());
            }

            WriteLine();
            Write("};");
        }