This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+using System; | |
+using System.Collections.Generic; | |
+using System.Linq; | |
+using System.Text; | |
+using System.Web.Http; | |
+using WebApiContrib.CollectionJson; | |
+using WebApiContrib.Formatting.CollectionJson; | |
+using WebApiContrib.Formatting.CollectionJson.Infrastructure; | |
+using WebApiContrib.Formatting.CollectionJson.Models; | |
+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CollectionJsonContent : HttpContent | |
{ | |
private readonly ReadDocument _readDocument; | |
private readonly JsonSerializer _serializer; | |
public CollectionJsonContent(Collection collection) | |
{ | |
_serializer = JsonSerializer.Create(new JsonSerializerSettings | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TokenValidationHandler : DelegatingHandler | |
{ | |
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | |
{ | |
const string errorMessage = "Unauthorized access"; | |
const HttpStatusCode code = HttpStatusCode.Unauthorized; | |
var authValue = request.Headers.Authorization; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ImageContent : HttpContent | |
{ | |
private Image _image; | |
public ImageContent(Image image, MediaTypeHeaderValue mediatype) | |
{ | |
_image = image; | |
Headers.ContentType = mediatype; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FileContent : HttpContent | |
{ | |
private const int DefaultBufferSize = 1024 * 64; | |
private readonly string _fileName; | |
private readonly FileInfo _fileInfo; | |
public FileContent(string fileName, MediaTypeHeaderValue contentType = null) | |
{ | |
Headers.ContentType = contentType ?? new MediaTypeHeaderValue("application/octet-stream"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EmbeddedContent : HttpContent | |
{ | |
private readonly Stream _Stream; | |
public EmbeddedContent(Type locatorType, string filename, MediaTypeHeaderValue contentType = null) | |
{ | |
Headers.ContentType = contentType ?? new MediaTypeHeaderValue("application/octet-stream"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > | |
<xsl:output method="xml" indent="yes" /> | |
<xsl:template match="/ | @* | node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="* | @* | node()" /> | |
</xsl:copy> | |
</xsl:template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var webApiconfig = new HttpConfiguration(); | |
webApiconfig.Routes.MapHttpRoute("test","Test",new {controller="Test"}); | |
app.UseWebApi(webApiconfig); | |
// Turn cross domain on | |
var config = new HubConfiguration { EnableCrossDomain = true }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JsonStringController : ApiController | |
{ | |
public HttpResponseMessage Post([FromBody]string jsonBody) | |
{ | |
var myobject = Newtonsoft.Json.JsonConvert.DeserializeObject<MyObject>(jsonBody) | |
return new HttpResponseMessage(HttpStatusCode.Created); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IDisposable CreateHttpListenerServer(Uri baseAddress, Func<IDictionary<string, object>, Task> appFunc) | |
{ | |
var props = new Dictionary<string, object>(); | |
var address = Address.Create(); | |
address.Host = baseAddress.Host; | |
address.Port = baseAddress.Port.ToString(); | |
address.Scheme = baseAddress.Scheme; | |
address.Path = baseAddress.AbsolutePath; |