コード例 #1
0
        public static void MakeSymmetricJson(this BehaviorChain chain)
        {
            chain.RemoveConneg();
            chain.ApplyConneg();

            chain.AlterConnegInput(x => x.JsonOnly());
            chain.AlterConnegOutput(x => x.JsonOnly());
        }
コード例 #2
0
        public static void MakeAsymmetricJson(this BehaviorChain chain)
        {
            chain.RemoveConneg();
            chain.ApplyConneg();

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

            chain.AlterConnegOutput(x => x.JsonOnly());
        }
コード例 #3
0
        // SAMPLE: conneg-manipulation
        public static void MessWithConneg(BehaviorChain chain)
        {
            // Remove all readers
            chain.Input.ClearAll();

            // Accept 'application/x-www-form-urlencoded' with model binding
            chain.Input.AllowHttpFormPosts = true;

            // Add basic Json reading
            chain.Input.AddFormatter <JsonFormatter>();

            // Query whether or not the chain uses the basic Json reading
            bool readsJson = chain.Input.UsesFormatter <JsonFormatter>();

            // Add a completely custom Reader
            var specialReader = chain.Input
                                .AddReader <SpecialContentMediaReader>();

            // Reorder the special reader to move it to the first
            // as the default
            specialReader.MoveToFront();

            // Add a new Reader as the last reader
            chain.Input.Readers.AddToEnd(new ModelBind(chain.InputType()));

            // Are there any Readers?
            chain.HasReaders();

            // Is there any output?
            chain.HasOutput();


            // Add the default Conneg policies to this chain
            // model binding, json, or xml in and json or xml out
            chain.ApplyConneg();

            // Manipulate an existing writer
            var writer = chain.Output.Writers.First();

            manipulateWriter(writer);

            // Remove all writers
            chain.Output.ClearAll();

            // Add the HtmlStringWriter
            chain.Output.AddHtml();

            // Add basic Json output
            chain.OutputJson();

            // Add basic Xml output
            chain.OutputXml();
        }
コード例 #4
0
 public static void OutputXml(this BehaviorChain chain)
 {
     chain.ApplyConneg();
     chain.ConnegOutputNode().UseFormatter <XmlFormatter>();
 }