本文整理汇总了C#中IFormatterLogger类的典型用法代码示例。如果您正苦于以下问题:C# IFormatterLogger类的具体用法?C# IFormatterLogger怎么用?C# IFormatterLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IFormatterLogger类属于命名空间,在下文中一共展示了IFormatterLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeSerialize
private object DeSerialize(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
{
HttpContentHeaders contentHeaders = content == null ? null : content.Headers;
// If content length is 0 then return default value for this type
if (contentHeaders != null && contentHeaders.ContentLength == 0)
{
return GetDefaultValueForType(type);
}
// Get the character encoding for the content
Encoding effectiveEncoding = SelectCharacterEncoding(contentHeaders);
try
{
using (var reader = new StreamReader(readStream, effectiveEncoding, false, 512, true))
{
var deserialize = TypedDeserializers.GetTyped(type);
return deserialize(reader, _jilOptions);
}
}
catch (Exception e)
{
if (formatterLogger == null)
{
throw;
}
formatterLogger.LogError(String.Empty, e);
return GetDefaultValueForType(type);
}
}
示例2: ReadFromStreamAsync
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
return Task.Factory.StartNew(() =>
{
MemoryStream stream = new MemoryStream();
readStream.CopyTo(stream);
IEnumerable<string> xContentHeader;
var success = content.Headers.TryGetValues("X-Content-Type", out xContentHeader);
if (!success)
{
throw Error.BadRequest("POST to binary must provide a Content-Type header");
}
string contentType = xContentHeader.FirstOrDefault();
Binary binary = new Binary();
binary.Content = stream.ToArray();
binary.ContentType = contentType;
//ResourceEntry entry = ResourceEntry.Create(binary);
//entry.Tags = content.Headers.GetFhirTags();
return (object)binary;
});
}
示例3: ReadFromStreamAsync
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
{
var task = Task<object>.Factory.StartNew(() =>
{
var ser = JsonNetExtensions.GetJsonSerializer();
using (var sr = new StreamReader(readStream))
{
using (var jreader = new JsonTextReader(sr))
{
ser.Converters.Add(new IsoDateTimeConverter());
return ser.Deserialize(jreader, type);
}
}
/*
var sr = new StreamReader(stream);
var jreader = new JsonTextReader(sr);
var ser = new JsonSerializer();
ser.Converters.Add(new IsoDateTimeConverter());
object val = ser.Deserialize(jreader, type);
return val;*/
});
return task;
}
示例4: ReadFromStreamAsync
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
return Task.Factory.StartNew(() =>
{
return (object)null;
});
}
示例5: ReadFromStreamAsync
/// <inheritdoc />
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
if (type == null)
{
throw Error.ArgumentNull("type");
}
if (readStream == null)
{
throw Error.ArgumentNull("readStream");
}
if (type == typeof(DBNull) && content != null && content.Headers != null && content.Headers.ContentLength == 0)
{
// Lower-level Json.Net deserialization can convert null to DBNull.Value. However this formatter treats
// DBNull.Value like null and serializes no content. Json.Net code won't be invoked at all (for read or
// write). Override BaseJsonMediaTypeFormatter.ReadFromStream()'s call to GetDefaultValueForType()
// (which would return null in this case) and instead return expected DBNull.Value. Special case exists
// primarily for parity with JsonMediaTypeFormatter.
return Task.FromResult((object)DBNull.Value);
}
else
{
return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);
}
}
示例6: ReadFromStreamAsync
public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger)
{
var tcs = new TaskCompletionSource<object>();
if (content.Headers != null && content.Headers.ContentLength == 0) return null;
try
{
var serializer = MessagePackSerializer.Get(type, sContext);
object result;
using (var unpacker = Unpacker.Create(stream))
{
unpacker.Read();
result = serializer.UnpackFrom(unpacker);
}
tcs.SetResult(result);
}
catch (Exception e)
{
if (formatterLogger == null) throw;
formatterLogger.LogError(String.Empty, e.Message);
tcs.SetResult(GetDefaultValueForType(type));
}
return tcs.Task;
}
示例7: ReadFromStreamAsync
public override async Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
MultipartMemoryStreamProvider multipartMemoryStreamProvider = await content.ReadAsMultipartAsync();
Collection<HttpContent> contents = multipartMemoryStreamProvider.Contents;
ImageSet imageSet = await contents.FirstOrDefault<HttpContent>((HttpContent c) => c.Headers.ContentDisposition.Name.NormalizeName() == "imageset").ReadAsAsync<ImageSet>();
ImageSet images = imageSet;
Collection<HttpContent> httpContents = multipartMemoryStreamProvider.Contents;
List<HttpContent> list = (
from c in httpContents
where c.Headers.ContentDisposition.Name.NormalizeName().Matches("image\\d+")
select c).ToList<HttpContent>();
images.Images = new List<Image>();
foreach (HttpContent httpContent in list)
{
List<Image> images1 = images.Images;
Image image = new Image();
Image image1 = image;
image1.ImageData = await httpContent.ReadAsByteArrayAsync();
image.MimeType = httpContent.Headers.ContentType.MediaType;
image.FileName = httpContent.Headers.ContentDisposition.FileName.NormalizeName();
images1.Add(image);
images1 = null;
image1 = null;
image = null;
}
return images;
}
示例8: ReadFromStreamAsync
public async override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
if (!content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var Parts = await content.ReadAsMultipartAsync();
var FileContent = Parts.Contents.First(x =>
SupportedMediaTypes.Contains(x.Headers.ContentType));
var DataString = "";
foreach (var Part in Parts.Contents.Where(x => x.Headers.ContentDisposition.DispositionType == "form-data"
&& x.Headers.ContentDisposition.Name == "\"data\""))
{
var Data = await Part.ReadAsStringAsync();
DataString = Data;
}
string FileName = FileContent.Headers.ContentDisposition.FileName;
string MediaType = FileContent.Headers.ContentType.MediaType;
using (var Imgstream = await FileContent.ReadAsStreamAsync())
{
return new GenericContent { ContentType = MediaType, Body = ReadToEnd(Imgstream) };
}
}
示例9: ReadFromStreamAsync
public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger logger)
{
var trades = new Trades();
var symbol = _symbol;
using (var reader = new StreamReader(stream))
{
var line = reader.ReadLine();
var seperator = ",".ToCharArray();
while (null != (line = reader.ReadLine()))
{
if (!line.Contains("502 Bad Gateway"))
{
var parts = line.Split(seperator);
var unixtime = parts[0].Parse();
var price = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
var quantity = decimal.Parse(parts[2], CultureInfo.InvariantCulture);
var datetime = Epoch.AddSeconds(unixtime);
trades.Add(symbol, datetime, price, quantity);
}
else throw new Exception("Bad Gateway");
}
}
var tcs = new TaskCompletionSource<object>();
tcs.SetResult(trades);
return tcs.Task;
}
示例10: ReadFromStreamArgs
public ReadFromStreamArgs(Type type, Stream stream, HttpContent content, IFormatterLogger logger)
{
Type = type;
Stream = stream;
Content = content;
Logger = logger;
}
示例11: ReadFromStream
public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) {
HttpContentHeaders contentHeaders = content == null ? null : content.Headers;
// If content length is 0 then return default value for this type
if (contentHeaders != null && contentHeaders.ContentLength == null) {
return GetDefaultValueForType(type);
}
try {
using (readStream) {
using (var reader = XmlReader.Create(readStream)) {
var formatter = new Atom10ItemFormatter();
formatter.ReadFrom(reader);
var command = Activator.CreateInstance(type);
((IPublicationCommand)command).ReadSyndicationItem(formatter.Item);
return command;
}
}
}
catch (Exception e) {
if (formatterLogger == null) {
throw;
}
formatterLogger.LogError(String.Empty, e);
return GetDefaultValueForType(type);
}
}
示例12: ReadFromStreamAsync
//private readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//public XmlFormatter()
//{
// SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml"));
// SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));
//}
public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
{
var task = new TaskCompletionSource<object>();
var serializer = new XmlSerializer(type);
using (var ms = new MemoryStream())
{
readStream.CopyTo(ms);
//ms.Seek(0, SeekOrigin.Begin);
//Log.IfDebugFormat("Content Length: {0}", ms.Length);
//Log.IfDebugFormat("Content: {0}", new StreamReader(ms).ReadToEnd());
//var result = XmlSchemaValidator.Instance().Validate(ms, type);
//if (!string.IsNullOrWhiteSpace(result))
//task.SetResult(result);
//else
{
ms.Seek(0, SeekOrigin.Begin);
var obj = serializer.Deserialize(ms);
task.SetResult(obj);
}
}
return task.Task;
}
示例13: ReadFromStreamAsync
public async override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger)
{
try
{
if (!content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var provider = await content.ReadAsMultipartAsync();
var mediacontent = provider.Contents.First(x =>
SupportedMediaTypes.Contains(x.Headers.ContentType));
string fileName = mediacontent.Headers.ContentDisposition.FileName;
string mediaType = mediacontent.Headers.ContentType.MediaType;
var imagebuffer = await mediacontent.ReadAsByteArrayAsync();
return new ImageMediaModels(fileName, mediaType, imagebuffer);
}
catch (Exception Ex)
{
string Err = "Unable to upload the image ";
Log.LogError("{0}, Error: {1}", Err, Ex.Message);
throw;
}
}
示例14: ReadFromStreamAsync
public override Task<object> ReadFromStreamAsync(Type type, System.IO.Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
return Task<object>.Factory.StartNew(() =>
{
var reader = new StreamReader(readStream);
var text = reader.ReadToEnd();
var regex = new Regex("<wav>[a-zA-Z0-9]*.wav</wav>");
var wavLink = regex.Match(text).Value.Replace("<wav>", "").Replace("</wav>", "");
if(string.IsNullOrEmpty(wavLink))
{
wavLink = "{wav}";
}
//<dt>:
regex = new Regex("<dt>:[a-zA-Z0-9 '.s\"\\(\\):]*<");
var def = regex.Match(text).Value.Replace("<dt>:", "").Replace("<", "");
if(string.IsNullOrEmpty(def))
{
def = "{def}";
}
return wavLink + ";" +def;
});
}
示例15: ReadFromStream
private object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
{
var root = GetRootFieldName(type);
var contentHeaders = content == null ? null : content.Headers;
// If content length is 0 then return default value for this type
if (contentHeaders != null && contentHeaders.ContentLength == 0)
return GetDefaultValueForType(type);
// Get the character encoding for the content
var effectiveEncoding = SelectCharacterEncoding(contentHeaders);
try
{
using (var reader = (new StreamReader(readStream, effectiveEncoding)))
{
var json = reader.ReadToEnd();
var serializer = new EmberJsonSerializer();
var deserialized = serializer.Deserialize(json, root);
return deserialized.ToObject(type);
}
}
catch (Exception e)
{
if (formatterLogger == null)
{
throw;
}
formatterLogger.LogError(String.Empty, e);
return GetDefaultValueForType(type);
}
}