Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GraphEncoder.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
4using Waher.Content;
8
10{
15 {
19 public GraphEncoder()
20 {
21 }
22
26 public string[] ContentTypes => contentTypes;
27
28 private static readonly string[] contentTypes = new string[] { ImageCodec.ContentTypePng };
29
33 public string[] FileExtensions => new string[] { ImageCodec.FileExtensionPng };
34
42 public bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
43 {
44 if ((Object is Graph || Object is PixelInformation) &&
46 {
47 Grade = Grade.Ok;
48 return true;
49 }
50 else
51 {
52 Grade = Grade.NotAtAll;
53 return false;
54 }
55 }
56
65 public Task<ContentResponse> EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
66 {
67 if (!(Object is PixelInformation Pixels))
68 {
69 if (Object is Graph G)
70 Pixels = G.CreatePixels();
71 else
72 return Task.FromResult(new ContentResponse(new ArgumentException("Object not PixelInformation or Graph.", nameof(Object))));
73 }
74
75 return Task.FromResult(new ContentResponse(ImageCodec.ContentTypePng, Object, Pixels.EncodeAsPng()));
76 }
77
84 public bool TryGetContentType(string FileExtension, out string ContentType)
85 {
86 if (string.Compare(FileExtension, ImageCodec.FileExtensionPng, true) == 0)
87 {
88 ContentType = ImageCodec.ContentTypePng;
89 return true;
90 }
91 else
92 {
93 ContentType = string.Empty;
94 return false;
95 }
96 }
97
104 public bool TryGetFileExtension(string ContentType, out string FileExtension)
105 {
106 switch (ContentType.ToLower())
107 {
109 FileExtension = ImageCodec.FileExtensionPng;
110 return true;
111
112 default:
113 FileExtension = string.Empty;
114 return false;
115 }
116 }
117
118 }
119}
Contains information about a response to a content request.
Image encoder/decoder.
Definition: ImageCodec.cs:14
const string FileExtensionPng
png
Definition: ImageCodec.cs:75
const string ContentTypePng
image/png
Definition: ImageCodec.cs:30
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Encodes graphs as images
Definition: GraphEncoder.cs:15
string[] FileExtensions
Supported file extensions.
Definition: GraphEncoder.cs:33
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Definition: GraphEncoder.cs:84
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Definition: GraphEncoder.cs:42
GraphEncoder()
Encodes graphs as images
Definition: GraphEncoder.cs:19
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
Definition: GraphEncoder.cs:65
string[] ContentTypes
Supported content types.
Definition: GraphEncoder.cs:26
Base class for graphs.
Definition: Graph.cs:88
Contains pixel information
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7