From 1e2617738159d930f4f11ded51518365a8dcfeac Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 28 Nov 2017 18:29:38 -0500 Subject: [PATCH] Compatibility changes for Xamarin --- TGS.Interface/ChatSetupInfo.cs | 25 ++++++++-------- TGS.Interface/RemoteLoginInfo.cs | 15 +++++----- TGS.Interface/ServerInterface.cs | 46 +++++++++++++++++++++++------- TGS.Interface/TGS.Interface.csproj | 5 +++- TGS.Interface/packages.config | 4 +++ Tools/PostCIBuild.ps1 | 1 + 6 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 TGS.Interface/packages.config diff --git a/TGS.Interface/ChatSetupInfo.cs b/TGS.Interface/ChatSetupInfo.cs index 6a1c346d2b..6809b85dd3 100644 --- a/TGS.Interface/ChatSetupInfo.cs +++ b/TGS.Interface/ChatSetupInfo.cs @@ -1,7 +1,8 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Runtime.Serialization; -using System.Web.Script.Serialization; +using System.Runtime.Serialization.Formatters.Binary; namespace TGS.Interface { @@ -131,8 +132,8 @@ namespace TGS.Interface /// public List AdminList { - get { return new JavaScriptSerializer().Deserialize>(DataFields[AdminListIndex]); } - set { DataFields[AdminListIndex] = new JavaScriptSerializer().Serialize(value); } + get { return JsonConvert.DeserializeObject>(DataFields[AdminListIndex]); } + set { DataFields[AdminListIndex] = JsonConvert.SerializeObject(value); } } /// /// If AdminList corresponds to a Provider specific recognization method @@ -147,11 +148,11 @@ namespace TGS.Interface /// public List AdminChannels { - get { return new JavaScriptSerializer().Deserialize>(DataFields[AdminChannelIndex]); } + get { return JsonConvert.DeserializeObject>(DataFields[AdminChannelIndex]); } set { SanitizeChannelNames(value); - DataFields[AdminChannelIndex] = new JavaScriptSerializer().Serialize(value); + DataFields[AdminChannelIndex] = JsonConvert.SerializeObject(value); } } /// @@ -159,11 +160,11 @@ namespace TGS.Interface /// public List DevChannels { - get { return new JavaScriptSerializer().Deserialize>(DataFields[DevChannelIndex]); } + get { return JsonConvert.DeserializeObject>(DataFields[DevChannelIndex]); } set { SanitizeChannelNames(value); - DataFields[DevChannelIndex] = new JavaScriptSerializer().Serialize(value); + DataFields[DevChannelIndex] = JsonConvert.SerializeObject(value); } } /// @@ -171,11 +172,11 @@ namespace TGS.Interface /// public List WatchdogChannels { - get { return new JavaScriptSerializer().Deserialize>(DataFields[WDChannelIndex]); } + get { return JsonConvert.DeserializeObject>(DataFields[WDChannelIndex]); } set { SanitizeChannelNames(value); - DataFields[WDChannelIndex] = new JavaScriptSerializer().Serialize(value); + DataFields[WDChannelIndex] = JsonConvert.SerializeObject(value); } } /// @@ -183,11 +184,11 @@ namespace TGS.Interface /// public List GameChannels { - get { return new JavaScriptSerializer().Deserialize>(DataFields[GameChannelIndex]); } + get { return JsonConvert.DeserializeObject>(DataFields[GameChannelIndex]); } set { SanitizeChannelNames(value); - DataFields[GameChannelIndex] = new JavaScriptSerializer().Serialize(value); + DataFields[GameChannelIndex] = JsonConvert.SerializeObject(value); } } /// diff --git a/TGS.Interface/RemoteLoginInfo.cs b/TGS.Interface/RemoteLoginInfo.cs index abdd76c4ee..891a31bd42 100644 --- a/TGS.Interface/RemoteLoginInfo.cs +++ b/TGS.Interface/RemoteLoginInfo.cs @@ -1,6 +1,6 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; -using System.Web.Script.Serialization; namespace TGS.Interface { @@ -33,7 +33,7 @@ namespace TGS.Interface /// /// Check if the has been initialized with a /// - [ScriptIgnore] + [JsonIgnore] public bool HasPassword { get { return !String.IsNullOrWhiteSpace(Password); } } /// @@ -76,7 +76,7 @@ namespace TGS.Interface /// The result of a call to public RemoteLoginInfo(string json) { - var dic = new JavaScriptSerializer().Deserialize>(json); + var dic = JsonConvert.DeserializeObject>(json); var ip = (string)dic[nameof(IP)]; if (String.IsNullOrWhiteSpace(ip)) throw new InvalidOperationException("ip must be set!"); @@ -119,15 +119,14 @@ namespace TGS.Interface public string ToJSON() { //serialize it to a dic first so we can store the entropy - var serializer = new JavaScriptSerializer(); - var raw = serializer.Serialize(this); - var dic = serializer.Deserialize>(raw); + var raw = JsonConvert.SerializeObject(this); + var dic = JsonConvert.DeserializeObject>(raw); if (HasPassword) { dic.Add(nameof(Password), Helpers.EncryptData(Password, out string entropy)); dic.Add(String.Format(EntropyFormatter, nameof(Password)), entropy); } - return serializer.Serialize(dic); + return JsonConvert.SerializeObject(dic); } } } diff --git a/TGS.Interface/ServerInterface.cs b/TGS.Interface/ServerInterface.cs index de77d54432..0c358d0ba5 100644 --- a/TGS.Interface/ServerInterface.cs +++ b/TGS.Interface/ServerInterface.cs @@ -368,29 +368,53 @@ namespace TGS.Interface /// Directly creates a for without caching. This should be eventually closed by the caller /// /// The component of the channel to be created + /// The instance to connect to, if any /// The correct - /// Thrown if isn't a valid component ChannelFactory CreateChannel(string instanceName) { var accessPath = instanceName == null ? MasterInterfaceName : String.Format("{0}/{1}", InstanceInterfaceName, instanceName); - - var InterfaceName = typeof(T).Name; if (!IsRemoteConnection) - { - var res2 = new ChannelFactory( - new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", accessPath, InterfaceName))); //10 megs - res2.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; - return res2; - } + return CreateLocalChannel(instanceName, accessPath); + return CreateRemoteChannel(instanceName, accessPath); + } + //NOTE: This needs to be kept seperate from CreateRemoteChannel because not all our client implementations have NetNamedPipeBinding and attempting to call this function on those platforms will throw an exception + + /// + /// Directly creates a for on a local connection without caching. This should be eventually closed by the caller + /// + /// The component of the channel to be created + /// The instance to connect to, if any + /// The URL of the interface to connect to + /// The correct + ChannelFactory CreateLocalChannel(string instanceName, string accessPath) + { + var interfaceName = typeof(T).Name; + var res2 = new ChannelFactory( + new NetNamedPipeBinding { SendTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = TransferLimitLocal }, new EndpointAddress(String.Format("net.pipe://localhost/{0}/{1}", accessPath, interfaceName))); //10 megs + res2.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; + return res2; + } + + /// + /// Directly creates a for on a remote connection without caching. This should be eventually closed by the caller + /// + /// The component of the channel to be created + /// The instance to connect to, if any + /// The URL of the interface to connect to + /// The correct + ChannelFactory CreateRemoteChannel(string instanceName, string accessPath) + { //okay we're going over var binding = new BasicHttpsBinding() { SendTimeout = new TimeSpan(0, 0, 40), MaxReceivedMessageSize = TransferLimitRemote }; - var requireAuth = InterfaceName != typeof(ITGConnectivity).Name; - var url = String.Format("https://{0}:{1}/{2}/{3}", LoginInfo.IP, LoginInfo.Port, accessPath, InterfaceName); + + var interfaceName = typeof(T).Name; + var requireAuth = interfaceName != typeof(ITGConnectivity).Name; + var url = String.Format("https://{0}:{1}/{2}/{3}", LoginInfo.IP, LoginInfo.Port, accessPath, interfaceName); var address = new EndpointAddress(url); var res = new ChannelFactory(binding, address); if (requireAuth) diff --git a/TGS.Interface/TGS.Interface.csproj b/TGS.Interface/TGS.Interface.csproj index bb494f14b9..a1b6f3d248 100644 --- a/TGS.Interface/TGS.Interface.csproj +++ b/TGS.Interface/TGS.Interface.csproj @@ -40,11 +40,13 @@ false + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + - @@ -77,6 +79,7 @@ + diff --git a/TGS.Interface/packages.config b/TGS.Interface/packages.config new file mode 100644 index 0000000000..810e559c04 --- /dev/null +++ b/TGS.Interface/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Tools/PostCIBuild.ps1 b/Tools/PostCIBuild.ps1 index d548a8e2b0..f875c61386 100644 --- a/Tools/PostCIBuild.ps1 +++ b/Tools/PostCIBuild.ps1 @@ -33,6 +33,7 @@ Copy-Item "$bf\TGS.CommandLine\bin\Release\TGCommandLine.exe" "$src2\TGCommandLi Copy-Item "$bf\TGS.ControlPanel\bin\Release\TGControlPanel.exe" "$src2\TGControlPanel.exe" Copy-Item "$bf\TGS.ControlPanel\bin\Release\Octokit.dll" "$src2\Octokit.dll" Copy-Item "$bf\TGS.Interface\bin\Release\TGServiceInterface.dll" "$src2\TGServiceInterface.dll" +Copy-Item "$bf\TGS.Interface\bin\Release\Newtonsoft.Json.dll" "$src2\Newtonsoft.Json.dll" $dest2 = "$bf\TGS3-Client-v$version.zip"