private void WalkDictionary(List <BodyLineItem> data, DataType type, int level,
                                    Action <BodyLineItem> opening = null,
                                    Action <BodyLineItem> closing = null)
        {
            var dictionaryOpening = new BodyLineItem
            {
                Name           = type.Name,
                LongNamespace  = type.LongNamespace,
                ShortNamespace = type.ShortNamespace,
                Comments       = type.Comments.TransformMarkdownInline(),
                Whitespace     = Whitespace.Repeat(level),
                IsOpening      = true,
                IsDictionary   = true
            };

            if (opening != null)
            {
                opening(dictionaryOpening);
            }

            data.Add(dictionaryOpening);

            WalkGraph(data, type.DictionaryEntry.ValueType, level + 1,
                      x =>
            {
                x.Name = type.DictionaryEntry.KeyName ??
                         _configuration.DefaultDictionaryKeyName;
                x.IsDictionaryEntry = true;
                if (type.DictionaryEntry.ValueComments != null)
                {
                    x.Comments = type.DictionaryEntry.ValueComments.TransformMarkdownInline();
                }
                x.DictionaryKey = new Key
                {
                    TypeName = type.DictionaryEntry.KeyType.Name,
                    Options  = WalkOptions(type.DictionaryEntry.KeyType),
                    Comments = type.DictionaryEntry.KeyComments.TransformMarkdownInline()
                };
            },
                      x =>
            {
                x.Name = _configuration.DefaultDictionaryKeyName;
                x.IsDictionaryEntry = true;
            });

            var dictionaryClosing = new BodyLineItem
            {
                Name         = type.Name,
                Whitespace   = Whitespace.Repeat(level),
                IsClosing    = true,
                IsDictionary = true
            };

            if (closing != null)
            {
                closing(dictionaryClosing);
            }

            data.Add(dictionaryClosing);
        }
        private void WalkSimpleType(
            List<BodyLineItem> description, 
            DataType type, int level,
            Action<BodyLineItem> opening)
        {
            var data = new BodyLineItem
            {
                Name = type.Name,
                TypeName = type.Name,
                Comments = type.Comments.TransformMarkdownInline(),
                Whitespace = Whitespace.Repeat(level),
                IsSimpleType = true
            };

            switch (type.Name)
            {
                case Xml.UnsignedLongType:
                case Xml.LongType:
                case Xml.UnsignedIntType:
                case Xml.IntType:
                case Xml.UnsignedShortType:
                case Xml.ShortType:
                case Xml.ByteType:
                case Xml.UnsignedByteType:
                    data.IsNumeric = true;
                    data.SampleValue = _configuration.SampleIntegerValue.ToSampleValueString(_configuration);
                    break;
                case Xml.FloatType:
                case Xml.DoubleType:
                case Xml.DecimalType: 
                    data.IsNumeric = true;
                    data.SampleValue = _configuration.SampleRealValue.ToSampleValueString(_configuration);
                    break;
                case Xml.BooleanType: 
                    data.IsBoolean = true;
                    data.SampleValue = _configuration.SampleBoolValue.ToString().ToLower();
                    break;
                case Xml.DateTimeType: 
                    data.IsDateTime = true;
                    data.SampleValue = _configuration.SampleDateTimeValue.ToSampleValueString(_configuration);
                   break;
                case Xml.DurationType: 
                    data.IsDuration = true;
                    data.SampleValue = _configuration.SampleTimeSpanValue.ToSampleValueString(_configuration);
                    break;
                case Xml.UuidType: 
                    data.IsGuid = true;
                    data.SampleValue = _configuration.SampleGuidValue.ToSampleValueString(_configuration);
                    break;
                default: 
                    data.IsString = true;
                    data.SampleValue = _configuration.SampleStringValue; 
                    break;
            }

            data.Options = WalkOptions(type, x => data.SampleValue = x.Options.First().Value);

            if (opening != null) opening(data);
            description.Add(data);
        }
        private void WalkArray(List <BodyLineItem> data, DataType type, int level,
                               Action <BodyLineItem> opening = null,
                               Action <BodyLineItem> closing = null)
        {
            var arrayOpening = new BodyLineItem
            {
                Name           = type.Name,
                LongNamespace  = type.LongNamespace,
                ShortNamespace = type.ShortNamespace,
                Comments       = type.Comments.TransformMarkdownInline(),
                Whitespace     = Whitespace.Repeat(level),
                IsOpening      = true,
                IsArray        = true
            };

            if (opening != null)
            {
                opening(arrayOpening);
            }

            data.Add(arrayOpening);

            WalkGraph(data, type.ArrayItem.Type, level + 1,
                      x =>
            {
                if (type.ArrayItem != null)
                {
                    if (type.ArrayItem.Name != null)
                    {
                        x.Name = type.ArrayItem.Name;
                    }
                    if (type.ArrayItem.Comments != null)
                    {
                        x.Comments = type.ArrayItem.Comments.TransformMarkdownInline();
                    }
                }
            },
                      x =>
            {
                if (type.ArrayItem != null && type.ArrayItem.Name != null)
                {
                    x.Name = type.ArrayItem.Name;
                }
            });

            var arrayClosing = new BodyLineItem
            {
                Name       = type.Name,
                Whitespace = Whitespace.Repeat(level),
                IsClosing  = true,
                IsArray    = true
            };

            if (closing != null)
            {
                closing(arrayClosing);
            }

            data.Add(arrayClosing);
        }
Esempio n. 4
0
        public void SetUp()
        {
            var graph = Behavior.BuildGraph();

            graph.AddAction<PostHandler>();
            var chain = graph.GetAction<PostHandler>().ParentChain();

            var secondAction = new ActionCall(typeof(Handlers.Widgets.PostHandler), ReflectionHelper.GetMethod<Handlers.Widgets.PostHandler>(x => x.Execute_Id(null)));

            chain.AddToEnd(secondAction);

            var spec = BuildSpec<PostHandler>(graph);

            var endpoint = spec.Modules[0].Resources[0].Endpoints[0];
            _request = endpoint.Request.Body.Description[0];
            _response = endpoint.Response.Body.Description[0];
        }
        private void WalkComplexType(List<BodyLineItem> data, DataType type, int level,
            Action<BodyLineItem> opening = null,
            Action<BodyLineItem> closing = null)
        {
            var complexOpening = new BodyLineItem
            {
                Name = type.Name,
                LongNamespace = type.LongNamespace,
                ShortNamespace = type.ShortNamespace,
                Comments = type.Comments.TransformMarkdownInline(),
                Whitespace = Whitespace.Repeat(level),
                IsOpening = true,
                IsComplexType = true
            };

            if (opening != null) opening(complexOpening);

            data.Add(complexOpening);

            foreach (var member in type.Members)
            {
                var lastMember = member == type.Members.Last();

                WalkGraph(data, member.Type, level + 1, 
                    x => {
                        x.Name = member.Name;
                        x.Comments = member.Comments.TransformMarkdownInline();
                        x.DefaultValue = member.DefaultValue;
                        if (member.SampleValue != null) x.SampleValue = 
                            member.SampleValue.ToSampleValueString(_configuration);
                        x.IsMember = true;
                        if (lastMember) x.IsLastMember = true;
                        if (!member.Type.IsSimple) x.IsOpening = true;
                        if (member.Required) x.Required = true;
                        if (member.Optional) x.Optional = true;

                        if (member.Deprecated)
                        {
                            x.IsDeprecated = true;
                            x.DeprecationMessage = member.DeprecationMessage;
                        }
                    }, 
                    x => {
                        x.Name = member.Name;
                        x.IsMember = true;
                        if (lastMember) x.IsLastMember = true;
                    });
            }

            var complexClosing = new BodyLineItem
            {
                Name = type.Name,
                Whitespace = Whitespace.Repeat(level),
                IsClosing = true,
                IsComplexType = true
            };

            if (closing != null) closing(complexClosing);

            data.Add(complexClosing);
        }
        private void WalkDictionary(List<BodyLineItem> data, DataType type, int level,
            Action<BodyLineItem> opening = null,
            Action<BodyLineItem> closing = null)
        {
            var dictionaryOpening = new BodyLineItem
            {
                Name = type.Name,
                LongNamespace = type.LongNamespace,
                ShortNamespace = type.ShortNamespace,
                Comments = type.Comments.TransformMarkdownInline(),
                Whitespace = Whitespace.Repeat(level),
                IsOpening = true,
                IsDictionary = true
            };

            if (opening != null) opening(dictionaryOpening);

            data.Add(dictionaryOpening);

            WalkGraph(data, type.DictionaryEntry.ValueType, level + 1,
                x =>
                {
                    x.Name = type.DictionaryEntry.KeyName ?? 
                        _configuration.DefaultDictionaryKeyName;
                    x.IsDictionaryEntry = true;
                    if (type.DictionaryEntry.ValueComments != null)
                        x.Comments = type.DictionaryEntry.ValueComments.TransformMarkdownInline();
                    x.DictionaryKey = new Key
                    {
                        TypeName = type.DictionaryEntry.KeyType.Name,
                        Options = WalkOptions(type.DictionaryEntry.KeyType),
                        Comments = type.DictionaryEntry.KeyComments.TransformMarkdownInline()
                    };
                },
                x =>
                {
                    x.Name = _configuration.DefaultDictionaryKeyName;
                    x.IsDictionaryEntry = true;
                });

            var dictionaryClosing = new BodyLineItem
            {
                Name = type.Name,
                Whitespace = Whitespace.Repeat(level),
                IsClosing = true,
                IsDictionary = true
            };

            if (closing != null) closing(dictionaryClosing);

            data.Add(dictionaryClosing);
        }
        private void WalkArray(List<BodyLineItem> data, DataType type, int level,
            Action<BodyLineItem> opening = null,
            Action<BodyLineItem> closing = null)
        {
            var arrayOpening = new BodyLineItem
            {
                Name = type.Name,
                LongNamespace = type.LongNamespace,
                ShortNamespace = type.ShortNamespace,
                Comments = type.Comments.TransformMarkdownInline(),
                Whitespace = Whitespace.Repeat(level),
                IsOpening = true,
                IsArray = true
            };

            if (opening != null) opening(arrayOpening);

            data.Add(arrayOpening);

            WalkGraph(data, type.ArrayItem.Type, level + 1,
                x =>
                {
                    if (type.ArrayItem != null)
                    {
                        if (type.ArrayItem.Name != null)
                            x.Name = type.ArrayItem.Name;
                        if (type.ArrayItem.Comments != null)
                            x.Comments = type.ArrayItem.Comments.TransformMarkdownInline();
                    }
                },
                x =>
                {
                    if (type.ArrayItem != null && type.ArrayItem.Name != null)
                            x.Name = type.ArrayItem.Name;
                });

            var arrayClosing = new BodyLineItem
            {
                Name = type.Name,
                Whitespace = Whitespace.Repeat(level),
                IsClosing = true,
                IsArray = true
            };

            if (closing != null) closing(arrayClosing);

            data.Add(arrayClosing);
        }
        private void WalkSimpleType(
            List <BodyLineItem> description,
            DataType type, int level,
            Action <BodyLineItem> opening)
        {
            var data = new BodyLineItem
            {
                Name         = type.Name,
                TypeName     = type.Name,
                Comments     = type.Comments.TransformMarkdownInline(),
                Whitespace   = Whitespace.Repeat(level),
                IsSimpleType = true
            };

            switch (type.Name)
            {
            case Xml.UnsignedLongType:
            case Xml.LongType:
            case Xml.UnsignedIntType:
            case Xml.IntType:
            case Xml.UnsignedShortType:
            case Xml.ShortType:
            case Xml.ByteType:
            case Xml.UnsignedByteType:
                data.IsNumeric   = true;
                data.SampleValue = _configuration.SampleIntegerValue.ToSampleValueString(_configuration);
                break;

            case Xml.FloatType:
            case Xml.DoubleType:
            case Xml.DecimalType:
                data.IsNumeric   = true;
                data.SampleValue = _configuration.SampleRealValue.ToSampleValueString(_configuration);
                break;

            case Xml.BooleanType:
                data.IsBoolean   = true;
                data.SampleValue = _configuration.SampleBoolValue.ToString().ToLower();
                break;

            case Xml.DateTimeType:
                data.IsDateTime  = true;
                data.SampleValue = _configuration.SampleDateTimeValue.ToSampleValueString(_configuration);
                break;

            case Xml.DurationType:
                data.IsDuration  = true;
                data.SampleValue = _configuration.SampleTimeSpanValue.ToSampleValueString(_configuration);
                break;

            case Xml.UuidType:
                data.IsGuid      = true;
                data.SampleValue = _configuration.SampleGuidValue.ToSampleValueString(_configuration);
                break;

            default:
                data.IsString    = true;
                data.SampleValue = _configuration.SampleStringValue;
                break;
            }

            data.Options = WalkOptions(type, x => data.SampleValue = x.Options.First().Value);

            if (opening != null)
            {
                opening(data);
            }
            description.Add(data);
        }
        private void WalkComplexType(List <BodyLineItem> data, DataType type, int level,
                                     Action <BodyLineItem> opening = null,
                                     Action <BodyLineItem> closing = null)
        {
            var complexOpening = new BodyLineItem
            {
                Name           = type.Name,
                LongNamespace  = type.LongNamespace,
                ShortNamespace = type.ShortNamespace,
                Comments       = type.Comments.TransformMarkdownInline(),
                Whitespace     = Whitespace.Repeat(level),
                IsOpening      = true,
                IsComplexType  = true
            };

            if (opening != null)
            {
                opening(complexOpening);
            }

            data.Add(complexOpening);

            foreach (var member in type.Members)
            {
                var lastMember = member == type.Members.Last();

                WalkGraph(data, member.Type, level + 1,
                          x => {
                    x.Name         = member.Name;
                    x.Comments     = member.Comments.TransformMarkdownInline();
                    x.DefaultValue = member.DefaultValue;
                    if (member.SampleValue != null)
                    {
                        x.SampleValue =
                            member.SampleValue.ToSampleValueString(_configuration);
                    }
                    x.IsMember = true;
                    if (lastMember)
                    {
                        x.IsLastMember = true;
                    }
                    if (!member.Type.IsSimple)
                    {
                        x.IsOpening = true;
                    }
                    if (member.Required)
                    {
                        x.Required = true;
                    }
                    if (member.Optional)
                    {
                        x.Optional = true;
                    }

                    if (member.Deprecated)
                    {
                        x.IsDeprecated       = true;
                        x.DeprecationMessage = member.DeprecationMessage;
                    }
                },
                          x => {
                    x.Name     = member.Name;
                    x.IsMember = true;
                    if (lastMember)
                    {
                        x.IsLastMember = true;
                    }
                });
            }

            var complexClosing = new BodyLineItem
            {
                Name          = type.Name,
                Whitespace    = Whitespace.Repeat(level),
                IsClosing     = true,
                IsComplexType = true
            };

            if (closing != null)
            {
                closing(complexClosing);
            }

            data.Add(complexClosing);
        }