aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-11-03 19:59:50 -0400
committerGitHub <noreply@github.com>2016-11-03 19:59:50 -0400
commitc53745548ac2130f4cfbbe0d7a2804c36c8ae4eb (patch)
tree6ee298ebb5470c4f3bcbef8d814a0354901469c4 /Emby.Common.Implementations
parent338b04a0c58729ec70aed89924ea6bd12422872b (diff)
parent405a5f69c5967b4d919b5fe91396f12cb83e8aa8 (diff)
Merge pull request #2267 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations')
-rw-r--r--Emby.Common.Implementations/BaseApplicationHost.cs2
-rw-r--r--Emby.Common.Implementations/Cryptography/CryptographyProvider.cs17
-rw-r--r--Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs20
-rw-r--r--Emby.Common.Implementations/Reflection/AssemblyInfo.cs18
-rw-r--r--Emby.Common.Implementations/TextEncoding/TextEncoding.cs48
-rw-r--r--Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs22
-rw-r--r--Emby.Common.Implementations/project.json28
7 files changed, 137 insertions, 18 deletions
diff --git a/Emby.Common.Implementations/BaseApplicationHost.cs b/Emby.Common.Implementations/BaseApplicationHost.cs
index 897557efd..e1f7ef08a 100644
--- a/Emby.Common.Implementations/BaseApplicationHost.cs
+++ b/Emby.Common.Implementations/BaseApplicationHost.cs
@@ -549,6 +549,8 @@ return null;
TimerFactory = new TimerFactory();
RegisterSingleInstance(TimerFactory);
+ RegisterSingleInstance(CryptographyProvider);
+
return Task.FromResult(true);
}
diff --git a/Emby.Common.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Common.Implementations/Cryptography/CryptographyProvider.cs
index 5ece28dc6..7b8d95b96 100644
--- a/Emby.Common.Implementations/Cryptography/CryptographyProvider.cs
+++ b/Emby.Common.Implementations/Cryptography/CryptographyProvider.cs
@@ -19,6 +19,15 @@ namespace Emby.Common.Implementations.Cryptography
return provider.ComputeHash(Encoding.Unicode.GetBytes(str));
}
}
+
+ public byte[] GetSHA1Bytes(byte[] bytes)
+ {
+ using (var provider = SHA1.Create())
+ {
+ return provider.ComputeHash(bytes);
+ }
+ }
+
public byte[] GetMD5Bytes(Stream str)
{
using (var provider = MD5.Create())
@@ -26,5 +35,13 @@ namespace Emby.Common.Implementations.Cryptography
return provider.ComputeHash(str);
}
}
+
+ public byte[] GetMD5Bytes(byte[] bytes)
+ {
+ using (var provider = MD5.Create())
+ {
+ return provider.ComputeHash(bytes);
+ }
+ }
}
}
diff --git a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs
index 4c034fa6a..85fcb556f 100644
--- a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -169,9 +169,23 @@ namespace Emby.Common.Implementations.HttpClientManager
AddRequestHeaders(httpWebRequest, options);
#if NET46
- httpWebRequest.AutomaticDecompression = options.EnableHttpCompression ?
- (options.DecompressionMethod ?? DecompressionMethods.Deflate) :
- DecompressionMethods.None;
+ if (options.EnableHttpCompression)
+ {
+ if (options.DecompressionMethod.HasValue)
+ {
+ httpWebRequest.AutomaticDecompression = options.DecompressionMethod.Value == CompressionMethod.Gzip
+ ? DecompressionMethods.GZip
+ : DecompressionMethods.Deflate;
+ }
+ else
+ {
+ httpWebRequest.AutomaticDecompression = DecompressionMethods.Deflate;
+ }
+ }
+ else
+ {
+ httpWebRequest.AutomaticDecompression = DecompressionMethods.None;
+ }
#endif
}
diff --git a/Emby.Common.Implementations/Reflection/AssemblyInfo.cs b/Emby.Common.Implementations/Reflection/AssemblyInfo.cs
new file mode 100644
index 000000000..820856da5
--- /dev/null
+++ b/Emby.Common.Implementations/Reflection/AssemblyInfo.cs
@@ -0,0 +1,18 @@
+using System;
+using System.IO;
+using MediaBrowser.Model.Reflection;
+using System.Reflection;
+
+namespace Emby.Common.Implementations.Reflection
+{
+ public class AssemblyInfo : IAssemblyInfo
+ {
+ public Stream GetManifestResourceStream(Type type, string resource)
+ {
+#if NET46
+ return type.Assembly.GetManifestResourceStream(resource);
+#endif
+ return type.GetTypeInfo().Assembly.GetManifestResourceStream(resource);
+ }
+ }
+}
diff --git a/Emby.Common.Implementations/TextEncoding/TextEncoding.cs b/Emby.Common.Implementations/TextEncoding/TextEncoding.cs
new file mode 100644
index 000000000..35b869e43
--- /dev/null
+++ b/Emby.Common.Implementations/TextEncoding/TextEncoding.cs
@@ -0,0 +1,48 @@
+using System.Text;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.TextEncoding;
+
+namespace Emby.Common.Implementations.TextEncoding
+{
+ public class TextEncoding : IEncoding
+ {
+ private readonly IFileSystem _fileSystem;
+
+ public TextEncoding(IFileSystem fileSystem)
+ {
+ _fileSystem = fileSystem;
+ }
+
+ public byte[] GetASCIIBytes(string text)
+ {
+ return Encoding.ASCII.GetBytes(text);
+ }
+
+ public string GetASCIIString(byte[] bytes, int startIndex, int length)
+ {
+ return Encoding.ASCII.GetString(bytes, 0, bytes.Length);
+ }
+
+ public Encoding GetFileEncoding(string srcFile)
+ {
+ // *** Detect byte order mark if any - otherwise assume default
+ var buffer = new byte[5];
+
+ using (var file = _fileSystem.OpenRead(srcFile))
+ {
+ file.Read(buffer, 0, 5);
+ }
+
+ if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
+ return Encoding.UTF8;
+ if (buffer[0] == 0xfe && buffer[1] == 0xff)
+ return Encoding.Unicode;
+ if (buffer[0] == 0 && buffer[1] == 0 && buffer[2] == 0xfe && buffer[3] == 0xff)
+ return Encoding.UTF32;
+ if (buffer[0] == 0x2b && buffer[1] == 0x2f && buffer[2] == 0x76)
+ return Encoding.UTF7;
+
+ return null;
+ }
+ }
+}
diff --git a/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs b/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs
new file mode 100644
index 000000000..806290cf4
--- /dev/null
+++ b/Emby.Common.Implementations/Xml/XmlReaderSettingsFactory.cs
@@ -0,0 +1,22 @@
+using System.Xml;
+using MediaBrowser.Model.Xml;
+
+namespace Emby.Common.Implementations.Xml
+{
+ public class XmlReaderSettingsFactory : IXmlReaderSettingsFactory
+ {
+ public XmlReaderSettings Create(bool enableValidation)
+ {
+ var settings = new XmlReaderSettings();
+
+ if (!enableValidation)
+ {
+#if NET46
+ settings.ValidationType = ValidationType.None;
+#endif
+ }
+
+ return settings;
+ }
+ }
+}
diff --git a/Emby.Common.Implementations/project.json b/Emby.Common.Implementations/project.json
index a65b86345..dc96f5726 100644
--- a/Emby.Common.Implementations/project.json
+++ b/Emby.Common.Implementations/project.json
@@ -23,27 +23,20 @@
"System.Xml.Serialization": "4.0.0.0"
},
"dependencies": {
- "MediaBrowser.Common": {
- "target": "project"
- },
+ "SimpleInjector": "3.2.4",
+ "NLog": "4.4.0-betaV15",
"MediaBrowser.Model": {
"target": "project"
},
- "SimpleInjector": "3.2.4",
- "NLog": "4.4.0-betaV15"
- }
+ "MediaBrowser.Common": {
+ "target": "project"
+ } }
},
"netstandard1.6": {
"imports": "dnxcore50",
"dependencies": {
"NETStandard.Library": "1.6.0",
- "MediaBrowser.Common": {
- "target": "project"
- },
- "MediaBrowser.Model": {
- "target": "project"
- },
- "System.IO.FileSystem.DriveInfo": "4.0.0",
+ "System.IO.FileSystem.DriveInfo": "4.0.0",
"System.Diagnostics.Process": "4.1.0",
"System.Threading.Timer": "4.0.1",
"System.Net.Requests": "4.0.11",
@@ -58,8 +51,13 @@
"System.Reflection.Primitives": "4.0.1",
"System.Runtime.Loader": "4.0.0",
"SimpleInjector": "3.2.4",
- "NLog": "4.4.0-betaV15"
- }
+ "NLog": "4.4.0-betaV15",
+ "MediaBrowser.Model": {
+ "target": "project"
+ },
+ "MediaBrowser.Common": {
+ "target": "project"
+ } }
}
}
}