public static void AlterConnegInput(this BehaviorChain chain, Action <ConnegInputNode> configure)
        {
            var node = chain.ConnegInputNode();

            if (node != null)
            {
                configure(node);
            }
        }
Beispiel #2
0
        public static void MakeAsymmetricJson(this BehaviorChain chain)
        {
            chain.RemoveConneg();
            chain.ApplyConneg();

            chain.ConnegInputNode().UseFormatter <JsonFormatter>();

            chain.AlterConnegOutput(x => x.JsonOnly());
        }
        public static bool IsAsymmetricJson(this BehaviorChain chain)
        {
            if (chain.ConnegInputNode() == null && chain.ConnegOutputNode() == null)
            {
                return(false);
            }

            if (chain.ActionOutputType() != null)
            {
                var output = chain.ConnegOutputNode();
                if (output.SelectedFormatterTypes.Count() != 1)
                {
                    return(false);
                }

                if (output.SelectedFormatterTypes.Single() != typeof(JsonFormatter))
                {
                    return(false);
                }
            }

            if (chain.InputType() != null)
            {
                var input = chain.ConnegInputNode();

                if (!input.AllowHttpFormPosts)
                {
                    return(false);
                }

                if (input.SelectedFormatterTypes.Count() != 1)
                {
                    return(false);
                }

                if (input.SelectedFormatterTypes.Single() != typeof(JsonFormatter))
                {
                    return(false);
                }
            }

            return(true);
        }
        // This should not do anything if there are conneg nodes
        public static void ApplyConneg(this BehaviorChain chain)
        {
            var inputType = chain.InputType();

            if (chain.ConnegInputNode() == null && inputType != null)
            {
                var inputNode = new ConnegInputNode(inputType);
                var action    = chain.FirstCall();
                action.AddBefore(inputNode);
            }

            var actionOutputType = chain.ActionOutputType();

            if (chain.ConnegOutputNode() == null && actionOutputType != null && actionOutputType != typeof(void) && actionOutputType != typeof(HttpStatusCode))
            {
                var outputNode = new ConnegOutputNode(actionOutputType);
                var action     = chain.Last(x => x is ActionCall);
                action.AddAfter(outputNode);
            }
        }