Moved more stuff into Abstractions
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public abstract class AbstractSerializationService
|
||||
{
|
||||
/// <summary>
|
||||
/// A sequence of <see cref="IFormatter" /> registered with this serialization service.
|
||||
/// </summary>
|
||||
public IEnumerable<IFormatter> Formatters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and deserializes the <see cref="Stream" /> <paramref
|
||||
/// name="input" /> to an object graph.
|
||||
/// </summary>
|
||||
/// <param name="input"> </param>
|
||||
/// <param name="outputType"> </param>
|
||||
/// <param name="intent"> </param>
|
||||
/// <returns> </returns>
|
||||
public abstract object FromStream(Stream input, Type outputType, string intent = null);
|
||||
|
||||
/// <summary>
|
||||
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and serializes the <paramref
|
||||
/// name="input" /> object graph to an <see cref="IStreamedResult" /> .
|
||||
/// </summary>
|
||||
/// <param name="input"> </param>
|
||||
/// <param name="intent"> </param>
|
||||
/// <returns> </returns>
|
||||
public abstract IStreamedResult ToStream(object input, string intent = null);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public class Formatter : IFormatter
|
||||
{
|
||||
#region Implementation of IFormatter
|
||||
|
||||
public string Intent
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public ISerializer Serializer
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public interface IFormatter
|
||||
{
|
||||
string Intent { get; }
|
||||
|
||||
ISerializer Serializer { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public interface ISerializer
|
||||
{
|
||||
object FromStream(Stream input, Type outputType);
|
||||
|
||||
IStreamedResult ToStream(object input);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public interface IStreamedResult
|
||||
{
|
||||
Stream ResultStream { get; }
|
||||
bool Success { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public class SerializationService : AbstractSerializationService
|
||||
{
|
||||
private readonly ISerializer _serializer;
|
||||
|
||||
public SerializationService(ISerializer serializer)
|
||||
{
|
||||
_serializer = serializer;
|
||||
}
|
||||
|
||||
#region Overrides of AbstractSerializationService
|
||||
|
||||
/// <summary>
|
||||
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and deserializes the <see cref="Stream" /> <paramref
|
||||
/// name="input" /> to an object graph.
|
||||
/// </summary>
|
||||
/// <param name="input"> </param>
|
||||
/// <param name="outputType"> </param>
|
||||
/// <param name="intent"> </param>
|
||||
/// <returns> </returns>
|
||||
public override object FromStream(Stream input, Type outputType, string intent = null)
|
||||
{
|
||||
if (input.CanSeek && input.Position > 0) input.Seek(0, SeekOrigin.Begin);
|
||||
return _serializer.FromStream(input, outputType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds an <see cref="IFormatter" /> with a matching <paramref name="intent" /> , and serializes the <paramref
|
||||
/// name="input" /> object graph to an <see cref="IStreamedResult" /> .
|
||||
/// </summary>
|
||||
/// <param name="input"> </param>
|
||||
/// <param name="intent"> </param>
|
||||
/// <returns> </returns>
|
||||
public override IStreamedResult ToStream(object input, string intent = null)
|
||||
{
|
||||
return _serializer.ToStream(input);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public static class StreamResultExtensions
|
||||
{
|
||||
public static string ToJsonString(this Stream stream)
|
||||
{
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
stream.Position = 0;
|
||||
stream.Read(bytes, 0, (int)stream.Length);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
|
||||
public static XDocument ToXDoc(this Stream stream)
|
||||
{
|
||||
return XDocument.Load(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Umbraco.Core.Serialization
|
||||
{
|
||||
public class StreamedResult : IStreamedResult
|
||||
{
|
||||
internal StreamedResult(Stream stream, bool success)
|
||||
{
|
||||
ResultStream = stream;
|
||||
Success = success;
|
||||
}
|
||||
|
||||
#region Implementation of IStreamedResult
|
||||
|
||||
public Stream ResultStream { get; protected set; }
|
||||
|
||||
public bool Success { get; protected set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user