3using System.Reflection;
4using System.Security.Cryptography.X509Certificates;
6using System.Threading.Tasks;
23 public static readonly Encoding
ISO_8859_1 = Encoding.GetEncoding(
"ISO-8859-1");
25 private static string[] canEncodeContentTypes =
null;
26 private static string[] canEncodeFileExtensions =
null;
27 private static string[] canDecodeContentTypes =
null;
28 private static string[] canDecodeFileExtensions =
null;
29 private static string[] canGetUriSchemes =
null;
30 private static string[] canPostToUriSchemes =
null;
31 private static string[] canPutToUriSchemes =
null;
32 private static string[] canDeleteToUriSchemes =
null;
33 private static string[] canHeadUriSchemes =
null;
34 private static string[] canQueryUriSchemes =
null;
44 private readonly
static Dictionary<string, KeyValuePair<Grade, IContentDecoder>> decoderByContentType =
45 new Dictionary<string, KeyValuePair<Grade, IContentDecoder>>(StringComparer.CurrentCultureIgnoreCase);
46 private readonly
static Dictionary<string, KeyValuePair<Grade, IContentEncoder>> encodersByType =
47 new Dictionary<string, KeyValuePair<Grade, IContentEncoder>>();
48 private readonly
static Dictionary<string, string> contentTypeByFileExtensions =
new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
49 private readonly
static Dictionary<string, string> fileExtensionsByContentType =
new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);
50 private readonly
static Dictionary<string, IContentConverter> convertersByStep =
new Dictionary<string, IContentConverter>(StringComparer.CurrentCultureIgnoreCase);
51 private readonly
static Dictionary<string, ChunkedList<IContentConverter>> convertersByFrom =
new Dictionary<string, ChunkedList<IContentConverter>>();
52 private readonly
static Dictionary<string, IContentGetter[]> gettersByScheme =
new Dictionary<string, IContentGetter[]>(StringComparer.CurrentCultureIgnoreCase);
53 private readonly
static Dictionary<string, IContentPoster[]> postersByScheme =
new Dictionary<string, IContentPoster[]>(StringComparer.CurrentCultureIgnoreCase);
54 private readonly
static Dictionary<string, IContentPutter[]> puttersByScheme =
new Dictionary<string, IContentPutter[]>(StringComparer.CurrentCultureIgnoreCase);
55 private readonly
static Dictionary<string, IContentDeleter[]> deletersByScheme =
new Dictionary<string, IContentDeleter[]>(StringComparer.CurrentCultureIgnoreCase);
56 private readonly
static Dictionary<string, IContentHeader[]> headersByScheme =
new Dictionary<string, IContentHeader[]>(StringComparer.CurrentCultureIgnoreCase);
57 private readonly
static Dictionary<string, IContentQuery[]> queriesByScheme =
new Dictionary<string, IContentQuery[]>(StringComparer.CurrentCultureIgnoreCase);
58 private static int defaultTimeout = 60000;
59 private static bool defaultTimeoutLocked =
false;
63 Types.OnInvalidated += Types_OnInvalidated;
66 private static void Types_OnInvalidated(
object Sender, EventArgs e)
68 canEncodeContentTypes =
null;
69 canEncodeFileExtensions =
null;
70 canDecodeContentTypes =
null;
71 canDecodeFileExtensions =
null;
72 canGetUriSchemes =
null;
82 lock (decoderByContentType)
84 decoderByContentType.Clear();
89 encodersByType.Clear();
92 lock (contentTypeByFileExtensions)
94 contentTypeByFileExtensions.Clear();
97 lock (fileExtensionsByContentType)
99 fileExtensionsByContentType.Clear();
102 lock (convertersByStep)
104 convertersByStep.Clear();
105 convertersByFrom.Clear();
108 lock (gettersByScheme)
110 gettersByScheme.Clear();
113 lock (headersByScheme)
115 headersByScheme.Clear();
118 lock (postersByScheme)
120 postersByScheme.Clear();
123 lock (puttersByScheme)
125 puttersByScheme.Clear();
128 lock (deletersByScheme)
130 deletersByScheme.Clear();
134 #region Default Timeout
151 throw new ArgumentException(
"Timeout must be a positive number of milliseconds.", nameof(Timeout));
153 if (defaultTimeoutLocked && defaultTimeout != Timeout)
154 throw new InvalidOperationException(
"Default timeout is locked and cannot be changed.");
156 defaultTimeout = Timeout;
157 defaultTimeoutLocked |= Lock;
171 if (canEncodeContentTypes is
null)
173 SortedDictionary<string, bool> ContentTypes =
new SortedDictionary<string, bool>();
178 ContentTypes[ContentType] =
true;
181 string[]
Types =
new string[ContentTypes.Count];
182 ContentTypes.Keys.CopyTo(
Types, 0);
184 canEncodeContentTypes =
Types;
187 return canEncodeContentTypes;
198 if (canEncodeFileExtensions is
null)
200 SortedDictionary<string, bool> FileExtensions =
new SortedDictionary<string, bool>();
205 FileExtensions[FileExtension] =
true;
208 string[]
Types =
new string[FileExtensions.Count];
209 FileExtensions.Keys.CopyTo(
Types, 0);
211 canEncodeFileExtensions =
Types;
214 return canEncodeFileExtensions;
225 if (encoders is
null)
231 foreach (Type T
in EncoderTypes)
268 if (!(AcceptedContentTypes is
null) &&
269 AcceptedContentTypes.Length == 1 &&
270 AcceptedContentTypes[0] ==
"*")
272 AcceptedContentTypes = Array.Empty<
string>();
273 Key = Object.GetType().FullName;
275 else if (AcceptedContentTypes is
null || AcceptedContentTypes.Length == 0)
276 Key = Object.GetType().FullName;
279 StringBuilder sb =
new StringBuilder();
281 sb.Append(Object.GetType().FullName);
283 foreach (
string Accepted
in AcceptedContentTypes)
292 lock (encodersByType)
294 if (encodersByType.TryGetValue(Key, out KeyValuePair<Grade, IContentEncoder> P))
299 if (!(Encoder is
null))
317 if (Encoder2.
Encodes(Object, out
Grade Grade2, AcceptedContentTypes) && Grade2 >
Grade)
324 lock (encodersByType)
326 encodersByType[Key] =
new KeyValuePair<Grade, IContentEncoder>(
Grade, Encoder);
329 if (!(Encoder is
null))
348 [Obsolete(
"Use the EncodeAsync method for more efficient processing of content including asynchronous processing elements in parallel environments.")]
351 return EncodeAsync(Object, Encoding, AcceptedContentTypes).Result;
361 public static Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
363 return EncodeAsync(Object, Encoding,
null, AcceptedContentTypes);
374 public static Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
378 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"No encoder found to encode objects of type " + (Object?.GetType()?.FullName) +
".", nameof(Object))));
380 return Encoder.EncodeAsync(Object, Encoding, Progress);
388 public static bool IsAccepted(
string ContentType, params
string[] AcceptedContentTypes)
390 if (AcceptedContentTypes.Length == 0)
393 return Array.IndexOf(AcceptedContentTypes, ContentType) >= 0;
401 public static bool IsAccepted(
string[] ContentTypes, params
string[] AcceptedContentTypes)
403 return IsAccepted(ContentTypes, out
string _, AcceptedContentTypes);
412 public static bool IsAccepted(
string[] ContentTypes, out
string ContentType, params
string[] AcceptedContentTypes)
414 if (ContentTypes.Length == 0)
420 if ((AcceptedContentTypes?.Length ?? 0) == 0)
422 ContentType = ContentTypes[0];
426 foreach (
string ContentType2
in ContentTypes)
428 if (
IsAccepted(ContentType2, AcceptedContentTypes))
430 ContentType = ContentType2;
450 if (canDecodeContentTypes is
null)
452 SortedDictionary<string, bool> ContentTypes =
new SortedDictionary<string, bool>();
457 ContentTypes[ContentType] =
true;
460 string[]
Types =
new string[ContentTypes.Count];
461 ContentTypes.Keys.CopyTo(
Types, 0);
463 canDecodeContentTypes =
Types;
466 return canDecodeContentTypes;
477 if (canDecodeFileExtensions is
null)
479 SortedDictionary<string, bool> FileExtensions =
new SortedDictionary<string, bool>();
484 FileExtensions[FileExtension] =
true;
487 string[]
Types =
new string[FileExtensions.Count];
488 FileExtensions.Keys.CopyTo(
Types, 0);
490 canDecodeFileExtensions =
Types;
493 return canDecodeFileExtensions;
504 if (decoders is
null)
510 foreach (Type T
in DecoderTypes)
544 lock (decoderByContentType)
546 if (decoderByContentType.TryGetValue(ContentType, out KeyValuePair<Grade, IContentDecoder> P))
551 return !(Decoder is
null);
567 lock (decoderByContentType)
569 decoderByContentType[ContentType] =
new KeyValuePair<Grade, IContentDecoder>(
Grade, Decoder);
572 return !(Decoder is
null);
584 [Obsolete(
"Use the DecoceAsync method for more efficient processing of content including asynchronous processing elements in parallel environments.")]
585 public static ContentResponse Decode(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
587 return DecodeAsync(ContentType, Data, Encoding, Fields, BaseUri).Result;
599 public static Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
601 return DecodeAsync(ContentType, Data, Encoding, Fields, BaseUri,
null);
614 public static Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
615 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
617 if (
string.IsNullOrEmpty(ContentType))
619 if ((Data?.Length ?? 0) == 0)
628 return Decoder.DecodeAsync(ContentType, Data, Encoding, Fields, BaseUri, Progress);
643 [Obsolete(
"Use the DecoceAsync method for more efficient processing of content including asynchronous processing elements in parallel environments.")]
646 return DecodeAsync(ContentType, Data, BaseUri).Result;
656 public static Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Uri BaseUri)
658 return DecodeAsync(ContentType, Data, BaseUri,
null);
669 public static Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Uri BaseUri,
673 out KeyValuePair<string, string>[] Fields);
675 return DecodeAsync(ContentType, Data, Encoding, Fields, BaseUri, Progress);
690 out KeyValuePair<string, string>[] Fields)
696 i = ContentType.IndexOf(
';');
700 ContentType = ContentType.Substring(0, i).TrimEnd();
702 foreach (KeyValuePair<string, string> Field
in Fields)
704 if (
string.Compare(Field.Key,
"CHARSET",
true) == 0)
712 Fields = Array.Empty<KeyValuePair<string, string>>();
724 if (
string.IsNullOrEmpty(CharacterSet))
728 switch (CharacterSet.ToUpper())
732 return Encoding.ASCII;
736 return Encoding.Unicode;
739 return Encoding.BigEndianUnicode;
743 return Encoding.UTF32;
745 case "UNICODE-1-1-UTF-7":
747 return Encoding.UTF7;
750 return Encoding.UTF8;
753 return Encoding.GetEncoding(CharacterSet);
759 #region File extensions
784 FileExtension = FileExtension.ToLower();
785 if (FileExtension.StartsWith(
"."))
786 FileExtension = FileExtension.Substring(1);
788 lock (contentTypeByFileExtensions)
790 if (contentTypeByFileExtensions.TryGetValue(FileExtension, out ContentType))
798 lock (contentTypeByFileExtensions)
800 contentTypeByFileExtensions[FileExtension] = ContentType;
811 lock (contentTypeByFileExtensions)
813 contentTypeByFileExtensions[FileExtension] = ContentType;
833 return FileExtension;
846 ContentType = ContentType.ToLower();
848 lock (fileExtensionsByContentType)
850 if (fileExtensionsByContentType.TryGetValue(ContentType, out FileExtension))
858 lock (fileExtensionsByContentType)
860 fileExtensionsByContentType[ContentType] = FileExtension;
871 lock (fileExtensionsByContentType)
873 fileExtensionsByContentType[ContentType] = FileExtension;
885 #region Content Conversion
895 if (converters is
null)
915 lock (convertersByStep)
917 if (converters is
null)
920 string PathKey = FromContentType +
" -> " + ToContentType;
921 if (convertersByStep.TryGetValue(PathKey, out Converter))
922 return !(Converter is
null);
932 Step =
new ConversionStep()
934 From = FromContentType,
944 Dictionary<string, ConversionStep> Possibilities =
new Dictionary<string, ConversionStep>();
945 ConversionStep Best =
null;
947 int BestDistance =
int.MaxValue;
952 while (Queue.HasFirstItem)
954 Step = Queue.RemoveFirst();
956 StepDistance = Step.Distance + 1;
957 StepGrade = Step.Converter.ConversionGrade;
958 if (Step.TotalGrade < StepGrade)
959 StepGrade = Step.TotalGrade;
961 foreach (
string To
in Step.Converter.ToContentTypes)
963 if (
string.Compare(To, ToContentType,
true) == 0 || To ==
"*")
965 if (StepGrade > BestGrade || StepGrade == BestGrade && StepDistance < BestDistance)
968 BestGrade = StepGrade;
969 BestDistance = StepDistance;
974 if (Possibilities.TryGetValue(To, out ConversionStep NextStep) && NextStep.TotalGrade >= StepGrade && NextStep.Distance <= StepDistance)
977 if (!convertersByFrom.TryGetValue(To, out
Converters))
983 NextStep =
new ConversionStep()
987 TotalGrade = StepGrade,
989 Distance = StepDistance
994 Possibilities[To] = NextStep;
1004 if (!(Best is
null))
1008 while (!(Best is
null))
1010 List.
Insert(0,
new KeyValuePair<string, IContentConverter>(Best.From, Best.Converter));
1014 Converter =
new ConversionSequence(FromContentType, ToContentType, BestGrade, List.
ToArray());
1015 convertersByStep[PathKey] = Converter;
1020 convertersByStep[PathKey] =
null;
1027 private class ConversionStep
1030 public Grade TotalGrade;
1031 public ConversionStep Prev;
1033 public int Distance;
1036 private static void FindConverters()
1042 convertersByStep.Clear();
1043 convertersByFrom.Clear();
1045 lock (convertersByStep)
1047 foreach (Type T
in ConverterTypes)
1069 convertersByFrom[From] = List;
1072 List.Add(Converter);
1077 convertersByStep[From +
" -> " + To] = Converter;
1093 lock (convertersByStep)
1095 if (converters is
null)
1107 #region Getting resources
1116 if (canGetUriSchemes is
null)
1118 SortedDictionary<string, bool> UriSchemes =
new SortedDictionary<string, bool>();
1122 foreach (
string Scheme
in Getter.UriSchemes)
1123 UriSchemes[Scheme] =
true;
1126 string[] Schemes =
new string[UriSchemes.Count];
1127 UriSchemes.Keys.CopyTo(Schemes, 0);
1129 canGetUriSchemes = Schemes;
1132 return canGetUriSchemes;
1143 if (getters is
null)
1150 private static void BuildGetters()
1154 Dictionary<string, ChunkedList<IContentGetter>> ByScheme =
new Dictionary<string, ChunkedList<IContentGetter>>();
1157 foreach (Type T
in GetterTypes)
1174 foreach (
string Schema
in Getter.UriSchemes)
1179 ByScheme[Schema] = List;
1186 lock (gettersByScheme)
1189 gettersByScheme[P.Key] = P.Value.ToArray();
1211 if (getters is
null)
1216 lock (gettersByScheme)
1218 if (Uri is
null || !gettersByScheme.TryGetValue(Uri.Scheme, out
Getters))
1238 return !(Getter is
null);
1247 public static Task<ContentResponse>
GetAsync(Uri Uri, params KeyValuePair<string, string>[]
Headers)
1259 public static Task<ContentResponse>
GetAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
1272 public static Task<ContentResponse>
GetAsync(Uri Uri, X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
1273 params KeyValuePair<string, string>[]
Headers)
1276 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (GET): " + Uri.Scheme, nameof(Uri))));
1278 return Getter.GetAsync(Uri, Certificate, RemoteCertificateValidator,
Headers);
1288 public static Task<ContentResponse>
GetAsync(Uri Uri,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1301 public static Task<ContentResponse>
GetAsync(Uri Uri, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1315 public static Task<ContentResponse>
GetAsync(Uri Uri, X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
1316 int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1319 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (GET): " + Uri.Scheme, nameof(Uri))));
1321 return Getter.GetAsync(Uri, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
1354 public static Task<ContentStreamResponse>
GetTempStreamAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
1381 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
1384 return Task.FromResult(
new ContentStreamResponse(
new ArgumentException(
"URI Scheme not recognized (GET): " + Uri.Scheme, nameof(Uri))));
1386 return Getter.GetTempStreamAsync(Uri, Certificate, RemoteCertificateValidator,
Headers);
1399 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
TemporaryStream Destination, params KeyValuePair<string, string>[]
Headers)
1402 return Task.FromResult(
new ContentStreamResponse(
new ArgumentException(
"URI Scheme not recognized (GET): " + Uri.Scheme, nameof(Uri))));
1404 return Getter.GetTempStreamAsync(Uri, Certificate, RemoteCertificateValidator, Destination,
Headers);
1440 public static Task<ContentStreamResponse>
GetTempStreamAsync(Uri Uri, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1454 public static Task<ContentStreamResponse>
GetTempStreamAsync(Uri Uri, X509Certificate Certificate,
int TimeoutMs,
1470 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1473 return Task.FromResult(
new ContentStreamResponse(
new ArgumentException(
"URI Scheme not recognized (GET): " + Uri.Scheme, nameof(Uri))));
1475 return Getter.GetTempStreamAsync(Uri, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
1489 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs,
TemporaryStream Destination,
1490 params KeyValuePair<string, string>[]
Headers)
1493 return Task.FromResult(
new ContentStreamResponse(
new ArgumentException(
"URI Scheme not recognized (GET): " + Uri.Scheme, nameof(Uri))));
1495 return Getter.GetTempStreamAsync(Uri, Certificate, RemoteCertificateValidator, TimeoutMs, Destination,
Headers);
1500 #region Posting to resources
1509 if (canPostToUriSchemes is
null)
1511 SortedDictionary<string, bool> UriSchemes =
new SortedDictionary<string, bool>();
1516 UriSchemes[Scheme] =
true;
1519 string[] Schemes =
new string[UriSchemes.Count];
1520 UriSchemes.Keys.CopyTo(Schemes, 0);
1522 canPostToUriSchemes = Schemes;
1525 return canPostToUriSchemes;
1536 if (posters is
null)
1543 private static void BuildPosters()
1547 Dictionary<string, ChunkedList<IContentPoster>> ByScheme =
new Dictionary<string, ChunkedList<IContentPoster>>();
1550 foreach (Type T
in PosterTypes)
1567 foreach (
string Schema
in Poster.UriSchemes)
1572 ByScheme[Schema] = List;
1579 lock (postersByScheme)
1582 postersByScheme[P.Key] = P.Value.ToArray();
1604 if (posters is
null)
1609 lock (postersByScheme)
1611 if (Uri is
null || !postersByScheme.TryGetValue(Uri.Scheme, out
Posters))
1631 return !(Poster is
null);
1641 public static Task<ContentResponse>
PostAsync(Uri Uri,
object Data, params KeyValuePair<string, string>[]
Headers)
1654 public static Task<ContentResponse>
PostAsync(Uri Uri,
object Data, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
1668 public static Task<ContentResponse>
PostAsync(Uri Uri,
object Data, X509Certificate Certificate,
1669 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
1672 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (POST): " + Uri.Scheme, nameof(Uri))));
1674 return Poster.PostAsync(Uri, Data, Certificate, RemoteCertificateValidator,
Headers);
1685 public static Task<ContentResponse>
PostAsync(Uri Uri,
object Data,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1699 public static Task<ContentResponse>
PostAsync(Uri Uri,
object Data, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1714 public static Task<ContentResponse>
PostAsync(Uri Uri,
object Data, X509Certificate Certificate,
1715 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1718 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (POST): " + Uri.Scheme, nameof(Uri))));
1720 return Poster.PostAsync(Uri, Data, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
1731 public static Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType, params KeyValuePair<string, string>[]
Headers)
1745 public static Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
1746 X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
1748 return PostAsync(Uri, EncodedData, ContentType, Certificate,
null,
Headers);
1761 public static Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
1762 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
1765 return Task.FromResult(
new ContentBinaryResponse(
new ArgumentException(
"URI Scheme not recognized (POST): " + Uri.Scheme, nameof(Uri))));
1767 return Poster.PostAsync(Uri, EncodedData, ContentType, Certificate, RemoteCertificateValidator,
Headers);
1779 public static Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1781 return PostAsync(Uri, EncodedData, ContentType,
null,
null, TimeoutMs,
Headers);
1794 public static Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
1795 X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
1797 return PostAsync(Uri, EncodedData, ContentType, Certificate,
null, TimeoutMs,
Headers);
1811 public static Task<ContentBinaryResponse>
PostAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
1812 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs,
1813 params KeyValuePair<string, string>[]
Headers)
1816 return Task.FromResult(
new ContentBinaryResponse(
new ArgumentException(
"URI Scheme not recognized (POST): " + Uri.Scheme, nameof(Uri))));
1818 return Poster.PostAsync(Uri, EncodedData, ContentType, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
1823 #region Putting to resources
1832 if (canPutToUriSchemes is
null)
1834 SortedDictionary<string, bool> UriSchemes =
new SortedDictionary<string, bool>();
1839 UriSchemes[Scheme] =
true;
1842 string[] Schemes =
new string[UriSchemes.Count];
1843 UriSchemes.Keys.CopyTo(Schemes, 0);
1845 canPutToUriSchemes = Schemes;
1848 return canPutToUriSchemes;
1859 if (putters is
null)
1866 private static void BuildPutters()
1870 Dictionary<string, ChunkedList<IContentPutter>> ByScheme =
new Dictionary<string, ChunkedList<IContentPutter>>();
1873 foreach (Type T
in PutterTypes)
1890 foreach (
string Schema
in Putter.UriSchemes)
1895 ByScheme[Schema] = List;
1902 lock (puttersByScheme)
1905 puttersByScheme[P.Key] = P.Value.ToArray();
1927 if (putters is
null)
1932 lock (puttersByScheme)
1934 if (Uri is
null || !puttersByScheme.TryGetValue(Uri.Scheme, out
Putters))
1954 return !(Putter is
null);
1964 public static Task<ContentResponse>
PutAsync(Uri Uri,
object Data, params KeyValuePair<string, string>[]
Headers)
1977 public static Task<ContentResponse>
PutAsync(Uri Uri,
object Data, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
1991 public static Task<ContentResponse>
PutAsync(Uri Uri,
object Data, X509Certificate Certificate,
1992 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
1995 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
1997 return Putter.PutAsync(Uri, Data, Certificate, RemoteCertificateValidator,
Headers);
2008 public static Task<ContentResponse>
PutAsync(Uri Uri,
object Data,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2022 public static Task<ContentResponse>
PutAsync(Uri Uri,
object Data, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2037 public static Task<ContentResponse>
PutAsync(Uri Uri,
object Data, X509Certificate Certificate,
2038 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2041 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2043 return Putter.PutAsync(Uri, Data, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
2054 public static Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType, params KeyValuePair<string, string>[]
Headers)
2068 public static Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
2070 return PutAsync(Uri, EncodedData, ContentType, Certificate,
null,
Headers);
2083 public static Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
2084 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
2087 return Task.FromResult(
new ContentBinaryResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2089 return Putter.PutAsync(Uri, EncodedData, ContentType, Certificate, RemoteCertificateValidator,
Headers);
2101 public static Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2103 return PutAsync(Uri, EncodedData, ContentType,
null,
null, TimeoutMs,
Headers);
2116 public static Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2118 return PutAsync(Uri, EncodedData, ContentType, Certificate,
null, TimeoutMs,
Headers);
2132 public static Task<ContentBinaryResponse>
PutAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
2133 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2136 return Task.FromResult(
new ContentBinaryResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2138 return Putter.PutAsync(Uri, EncodedData, ContentType, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
2143 #region Deleting to resources
2152 if (canDeleteToUriSchemes is
null)
2154 SortedDictionary<string, bool> UriSchemes =
new SortedDictionary<string, bool>();
2158 foreach (
string Scheme
in Deleter.
UriSchemes)
2159 UriSchemes[Scheme] =
true;
2162 string[] Schemes =
new string[UriSchemes.Count];
2163 UriSchemes.Keys.CopyTo(Schemes, 0);
2165 canDeleteToUriSchemes = Schemes;
2168 return canDeleteToUriSchemes;
2179 if (deleters is
null)
2186 private static void BuildDeleters()
2190 Dictionary<string, ChunkedList<IContentDeleter>> ByScheme =
new Dictionary<string, ChunkedList<IContentDeleter>>();
2193 foreach (Type T
in DeleterTypes)
2210 foreach (
string Schema
in Deleter.UriSchemes)
2215 ByScheme[Schema] = List;
2222 lock (deletersByScheme)
2225 deletersByScheme[P.Key] = P.Value.ToArray();
2247 if (deleters is
null)
2252 lock (deletersByScheme)
2254 if (Uri is
null || !deletersByScheme.TryGetValue(Uri.Scheme, out
Deleters))
2274 return !(Deleter is
null);
2295 public static Task<ContentResponse>
DeleteAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
2308 public static Task<ContentResponse>
DeleteAsync(Uri Uri, X509Certificate Certificate,
2309 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
2312 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (DELETE): " + Uri.Scheme, nameof(Uri))));
2314 return Deleter.DeleteAsync(Uri, Certificate, RemoteCertificateValidator,
Headers);
2324 public static Task<ContentResponse>
DeleteAsync(Uri Uri,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2337 public static Task<ContentResponse>
DeleteAsync(Uri Uri, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2351 public static Task<ContentResponse>
DeleteAsync(Uri Uri, X509Certificate Certificate,
2352 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs,
2353 params KeyValuePair<string, string>[]
Headers)
2356 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (DELETE): " + Uri.Scheme, nameof(Uri))));
2358 return Deleter.DeleteAsync(Uri, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
2363 #region Getting headers of resources
2372 if (canHeadUriSchemes is
null)
2374 SortedDictionary<string, bool> UriSchemes =
new SortedDictionary<string, bool>();
2378 foreach (
string Scheme
in Header.UriSchemes)
2379 UriSchemes[Scheme] =
true;
2382 string[] Schemes =
new string[UriSchemes.Count];
2383 UriSchemes.Keys.CopyTo(Schemes, 0);
2385 canHeadUriSchemes = Schemes;
2388 return canHeadUriSchemes;
2399 if (headers is
null)
2406 private static void BuildHeaders()
2410 Dictionary<string, ChunkedList<IContentHeader>> ByScheme =
new Dictionary<string, ChunkedList<IContentHeader>>();
2413 foreach (Type T
in HeaderTypes)
2430 foreach (
string Schema
in Header.UriSchemes)
2435 ByScheme[Schema] = List;
2442 lock (headersByScheme)
2445 headersByScheme[P.Key] = P.Value.ToArray();
2467 if (headers is
null)
2472 lock (headersByScheme)
2474 if (Uri is
null || !headersByScheme.TryGetValue(Uri.Scheme, out
Headers))
2494 return !(Header is
null);
2503 public static Task<ContentResponse>
HeadAsync(Uri Uri, params KeyValuePair<string, string>[]
Headers)
2515 public static Task<ContentResponse>
HeadAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
2528 public static Task<ContentResponse>
HeadAsync(Uri Uri, X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
2529 params KeyValuePair<string, string>[]
Headers)
2532 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (HEAD): " + Uri.Scheme, nameof(Uri))));
2534 return Header.HeadAsync(Uri, Certificate, RemoteCertificateValidator,
Headers);
2544 public static Task<ContentResponse>
HeadAsync(Uri Uri,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2557 public static Task<ContentResponse>
HeadAsync(Uri Uri, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2571 public static Task<ContentResponse>
HeadAsync(Uri Uri, X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
2572 int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2575 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (HEAD): " + Uri.Scheme, nameof(Uri))));
2577 return Header.HeadAsync(Uri, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
2582 #region Querying resources
2591 if (canQueryUriSchemes is
null)
2593 SortedDictionary<string, bool> UriSchemes =
new SortedDictionary<string, bool>();
2598 UriSchemes[Scheme] =
true;
2601 string[] Schemes =
new string[UriSchemes.Count];
2602 UriSchemes.Keys.CopyTo(Schemes, 0);
2604 canQueryUriSchemes = Schemes;
2607 return canQueryUriSchemes;
2618 if (queries is
null)
2625 private static void BuildQueries()
2629 Dictionary<string, ChunkedList<IContentQuery>> ByScheme =
new Dictionary<string, ChunkedList<IContentQuery>>();
2632 foreach (Type T
in QueryTypes)
2649 foreach (
string Schema
in Query.UriSchemes)
2654 ByScheme[Schema] = List;
2661 lock (queriesByScheme)
2664 queriesByScheme[P.Key] = P.Value.ToArray();
2686 if (queries is
null)
2691 lock (queriesByScheme)
2693 if (Uri is
null || !queriesByScheme.TryGetValue(Uri.Scheme, out
Queries))
2713 return !(Query is
null);
2723 public static Task<ContentResponse>
QueryAsync(Uri Uri,
object Data, params KeyValuePair<string, string>[]
Headers)
2736 public static Task<ContentResponse>
QueryAsync(Uri Uri,
object Data, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
2750 public static Task<ContentResponse>
QueryAsync(Uri Uri,
object Data, X509Certificate Certificate,
2751 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
2754 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2756 return Query.QueryAsync(Uri, Data, Certificate, RemoteCertificateValidator,
Headers);
2767 public static Task<ContentResponse>
QueryAsync(Uri Uri,
object Data,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2781 public static Task<ContentResponse>
QueryAsync(Uri Uri,
object Data, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2796 public static Task<ContentResponse>
QueryAsync(Uri Uri,
object Data, X509Certificate Certificate,
2797 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2800 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2802 return Query.QueryAsync(Uri, Data, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
2813 public static Task<ContentBinaryResponse>
QueryAsync(Uri Uri,
byte[] EncodedData,
string ContentType, params KeyValuePair<string, string>[]
Headers)
2827 public static Task<ContentBinaryResponse>
QueryAsync(Uri Uri,
byte[] EncodedData,
string ContentType, X509Certificate Certificate, params KeyValuePair<string, string>[]
Headers)
2842 public static Task<ContentBinaryResponse>
QueryAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
2843 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, params KeyValuePair<string, string>[]
Headers)
2846 return Task.FromResult(
new ContentBinaryResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2848 return Query.QueryAsync(Uri, EncodedData, ContentType, Certificate, RemoteCertificateValidator,
Headers);
2860 public static Task<ContentBinaryResponse>
QueryAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2862 return QueryAsync(Uri, EncodedData, ContentType,
null,
null, TimeoutMs,
Headers);
2875 public static Task<ContentBinaryResponse>
QueryAsync(Uri Uri,
byte[] EncodedData,
string ContentType, X509Certificate Certificate,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2877 return QueryAsync(Uri, EncodedData, ContentType, Certificate,
null, TimeoutMs,
Headers);
2891 public static Task<ContentBinaryResponse>
QueryAsync(Uri Uri,
byte[] EncodedData,
string ContentType,
2892 X509Certificate Certificate, EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator,
int TimeoutMs, params KeyValuePair<string, string>[]
Headers)
2895 return Task.FromResult(
new ContentBinaryResponse(
new ArgumentException(
"URI Scheme not recognized (PUT): " + Uri.Scheme, nameof(Uri))));
2897 return Query.QueryAsync(Uri, EncodedData, ContentType, Certificate, RemoteCertificateValidator, TimeoutMs,
Headers);
2902 #region Local domains
2910 public static bool IsLocalDomain(
string DomainOrHost,
bool IncludeAlternativeDomains)
2912 if (DomainOrHost ==
"localhost")
2918 return e.IsLocal ??
false;
const string DefaultContentType
text/plain
Encodes custom-encoded objects
Helps with parsing of commong data types.
static KeyValuePair< string, string >[] ParseFieldValues(string Value)
Parses a set of comma or semicolon-separated field values, optionaly delimited by ' or " characters.
Contains information about a binary response to a content request.
Contains information about a response to a content request.
Contains information about a stream response to a content request.
Static class managing encoding and decoding of internet content.
static string[] CanDecodeContentTypes
Internet content types that can be decoded.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
static ContentResponse Encode(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
static Task< ContentResponse > HeadAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Heads a resource, given its URI.
static Task< ContentResponse > PutAsync(Uri Uri, object Data, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > GetAsync(Uri Uri, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
static Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static IContentConverter[] GetConverters(string FromContentType)
Gets available converters that can convert content from a given type.
static EventHandler< LocalDomainEventArgs > LocalDomainCheck
Event raised when a local domain is to be checked.
static Task< ContentBinaryResponse > QueryAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static IContentHeader[] Headers
Available Internet Content Header-retrievers.
static Task< ContentResponse > QueryAsync(Uri Uri, object Data, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static ContentResponse Decode(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
static bool CanPost(Uri Uri, out Grade Grade, out IContentPoster Poster)
If a resource can be posted to, given its URI.
static Task< ContentResponse > HeadAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Heads a resource, given its URI.
static Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > QueryAsync(Uri Uri, object Data, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static string GetFileExtension(string ContentType)
Gets the file extension of an item, given its content type. It uses the TryGetFileExtension to see if...
static Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > QueryAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > HeadAsync(Uri Uri, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Heads a resource, given its URI.
static Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static bool CanGet(Uri Uri, out Grade Grade, out IContentGetter Getter)
If a resource can be gotten, given its URI.
static Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Uri BaseUri)
Decodes an object.
static IContentQuery[] Queries
Available Internet Content Queries.
static Task< ContentResponse > GetAsync(Uri Uri, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
static int DefaultTimeout
Default timeout of internet access methods, in milliseconds.
static IContentDecoder[] Decoders
Available Internet Content Decoders.
static bool Encodes(object Object, out Grade Grade, out IContentEncoder Encoder, params string[] AcceptedContentTypes)
If a given object can be encoded.
static void SetDefaultTimeout(int Timeout, bool Lock)
Sets the default timeout of internet access methods, in milliseconds.
static string[] CanPutToUriSchemes
Internet URI Schemes that can be put to.
static Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
static string[] CanDeleteToUriSchemes
Internet URI Schemes that can be deleted to.
static Task< ContentResponse > DeleteAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > PutAsync(Uri Uri, object Data, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static string GetContentType(string FileExtension)
Gets the content type of an item, given its file extension. It uses the TryGetContentType to see if a...
static IContentEncoder[] Encoders
Available Internet Content Encoders.
static Task< ContentBinaryResponse > QueryAsync(Uri Uri, byte[] EncodedData, string ContentType, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
static Task< ContentResponse > QueryAsync(Uri Uri, object Data, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > QueryAsync(Uri Uri, object Data, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentBinaryResponse > QueryAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static bool CanConvert(string FromContentType, string ToContentType, out IContentConverter Converter)
Checks if it is possible to convert content from one type to another.
static Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentBinaryResponse > QueryAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
static bool CanQuery(Uri Uri, out Grade Grade, out IContentQuery Query)
If a resource can be queried, given its URI.
static Task< ContentResponse > DeleteAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
static IContentPutter[] Putters
Available Internet Content Putters.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static string[] CanHeadUriSchemes
Internet URI Schemes where it is possible to get headers.
static Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static IContentGetter[] Getters
Available Internet Content Getters.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > HeadAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Heads a resource, given its URI.
static Task< ContentResponse > GetAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
static IContentDeleter[] Deleters
Available Internet Content Deleters.
static string[] CanEncodeContentTypes
Internet content types that can be encoded.
static readonly Encoding ISO_8859_1
ISO-8859-1 character encoding.
static bool Decodes(string ContentType, out Grade Grade, out IContentDecoder Decoder)
If an object with a given content type can be decoded.
static Task< ContentResponse > GetAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
static IContentPoster[] Posters
Available Internet Content Posters.
static ContentResponse Decode(string ContentType, byte[] Data, Uri BaseUri)
Decodes an object.
static Task< ContentResponse > PutAsync(Uri Uri, object Data, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > GetAsync(Uri Uri, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static bool IsAccepted(string[] ContentTypes, out string ContentType, params string[] AcceptedContentTypes)
Checks if at least one content type in a set of content types is acceptable.
static Task< ContentResponse > HeadAsync(Uri Uri, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Heads a resource, given its URI.
static Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static string[] CanDecodeFileExtensions
File extensions that can be decoded.
static Task< ContentResponse > HeadAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Heads a resource, given its URI.
static bool CanPut(Uri Uri, out Grade Grade, out IContentPutter Putter)
If a resource can be put to, given its URI.
static string[] CanPostToUriSchemes
Internet URI Schemes that can be posted to.
static Task< ContentResponse > DeleteAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > PostAsync(Uri Uri, object Data, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > DeleteAsync(Uri Uri, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
static bool CanHead(Uri Uri, out Grade Grade, out IContentHeader Header)
If the headers of a resource can be gotten, given its URI.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, int TimeoutMs, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > PutAsync(Uri Uri, object Data, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static bool IsLocalDomain(string DomainOrHost, bool IncludeAlternativeDomains)
Checks if a domain or nost name is local.
static string[] CanGetUriSchemes
Internet URI Schemes that can be gotten.
static Task< ContentResponse > DeleteAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static IContentConverter[] Converters
Available Internet Content Converters.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, int TimeoutMs, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentBinaryResponse > PostAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentBinaryResponse > PutAsync(Uri Uri, byte[] EncodedData, string ContentType, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Task< ContentResponse > PostAsync(Uri Uri, object Data, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static bool ParseContentType(ref string ContentType, out Encoding Encoding, out KeyValuePair< string, string >[] Fields)
Parses a Content-Type, providing the base Content-Type, character encoding, if any,...
static Task< ContentResponse > QueryAsync(Uri Uri, object Data, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
static bool IsAccepted(string[] ContentTypes, params string[] AcceptedContentTypes)
Checks if at least one content type in a set of content types is acceptable.
static bool CanDelete(Uri Uri, out Grade Grade, out IContentDeleter Deleter)
If a resource can be deleted to, given its URI.
static Task< ContentBinaryResponse > QueryAsync(Uri Uri, byte[] EncodedData, string ContentType, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static string[] CanQueryToUriSchemes
Internet URI Schemes that can be queried.
static Task< ContentResponse > PutAsync(Uri Uri, object Data, X509Certificate Certificate, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static string[] CanEncodeFileExtensions
File extensions that can be encoded.
static Task< ContentResponse > DeleteAsync(Uri Uri, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > PutAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Puts to a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentBinaryResponse > QueryAsync(Uri Uri, byte[] EncodedData, string ContentType, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Queries a resource, using a Uniform Resource Identifier (or Locator).
static Task< ContentResponse > GetAsync(Uri Uri, params KeyValuePair< string, string >[] Headers)
Gets a resource, given its URI.
static bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
static Task< ContentStreamResponse > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, TemporaryStream Destination, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, given its URI.
static Encoding GetEncoding(string CharacterSet)
Gets a character encoding from its name.
static bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its content type.
Local domain check event arguments.
A chunked list is a linked list of chunks of objects of type T .
void Insert(int Index, T Item)
Inserts an item to the list at the specified index.
T[] ToArray()
Returns an array containing all elements of the collection.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object[] NoParameters
Contains an empty array of parameter values.
static Type[] GetTypesImplementingInterface(string InterfaceFullName)
Gets all types implementing a given interface.
static ConstructorInfo GetDefaultConstructor(Type Type)
Gets the default constructor of a type, if one exists.
Manages a temporary stream. Contents is kept in-memory, if below a memory threshold,...
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 ConversionGrade
How well the content is converted.
string[] FromContentTypes
Converts content from these content types.
string[] ToContentTypes
Converts content to these content types. Return an array of "*" to signify content can be converted t...
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
Basic interface for Internet Content deleters. A class implementing this interface and having a defau...
string[] UriSchemes
Supported URI schemes.
bool CanDelete(Uri Uri, out Grade Grade)
If the deleter is able to delete to a resource, given its URI.
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Basic interface for Internet Content getters. A class implementing this interface and having a defaul...
bool CanGet(Uri Uri, out Grade Grade)
If the getter is able to get a resource, given its URI.
Basic interface for Internet Content posters. A class implementing this interface and having a defaul...
string[] UriSchemes
Supported URI schemes.
bool CanPost(Uri Uri, out Grade Grade)
If the poster is able to post to a resource, given its URI.
Basic interface for Internet Content putters. A class implementing this interface and having a defaul...
string[] UriSchemes
Supported URI schemes.
bool CanPut(Uri Uri, out Grade Grade)
If the putter is able to put to a resource, given its URI.
Basic interface for Internet Content query handlers. A class implementing this interface and having a...
string[] UriSchemes
Supported URI schemes.
bool CanQuery(Uri Uri, out Grade Grade)
If the query handler is able to query a resource, given its URI.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
string[] ContentTypes
Supported content types.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
string[] FileExtensions
Supported file extensions.