elsa-core/src/modules/Elsa.Http/ContentWriters/XmlContentFactory.cs
Sipke Schoorstra 225a99f39d
Bulk Import + Export of Workflow Definitions and Instances (#4643)
* Implement bulk export of workflow definitions

* Update Import endpoint with support for file uploads

* Update Import endpoint to return imported workflow count

* Implement workflow instance (bulk) export

* Implement workflow state, bookmark, workflow + activity execution export

* Remove globally imported usings
2023-11-22 14:31:48 +01:00

33 lines
918 B
C#

using System.Net.Mime;
using System.Text;
using System.Xml.Serialization;
namespace Elsa.Http.ContentWriters;
/// <summary>
/// Creates a <see cref="HttpContent"/> object for XML types.
/// </summary>
public class XmlContentFactory : IHttpContentFactory
{
/// <inheritdoc />
public IEnumerable<string> SupportedContentTypes => new[]
{
MediaTypeNames.Application.Xml,
MediaTypeNames.Text.Xml,
MediaTypeNames.Application.Soap,
};
/// <inheritdoc />
public HttpContent CreateHttpContent(object content, string contentType)
{
var text = content as string ?? Serialize(content);
return new StringContent(text, Encoding.UTF8, contentType);
}
private string Serialize(object value)
{
using var writer = new StringWriter();
new XmlSerializer(value.GetType()).Serialize(writer, value);
return writer.ToString();
}
}