diff --git a/.codacy.yml b/.codacy.yml new file mode 100644 index 000000000..dbc0982f7 --- /dev/null +++ b/.codacy.yml @@ -0,0 +1,10 @@ +--- +exclude_paths: + - '**/Examples/**' + - '**/UnitTests/**' + - '**/Editor/**' + - '**/PlayModeTests/**' + - '**/netstandard2.0/**' + - '**/Plugins/**' + - '**/Scripts/PubnubExample.*' + \ No newline at end of file diff --git a/.pubnub.yml b/.pubnub.yml index f54fab43a..389419140 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,15 @@ name: c-sharp -version: "4.3.0.0" +version: "4.4.0.0" schema: 1 scm: github.com/pubnub/c-sharp changelog: + - version: 4.4.0.0 + date: December 19, 2019 + changes: + - type: Improvement + text: Refactored code related to TMS GetToken and GetTokens + - type: Improvement + text: Refactored code to retrieve assembly version - version: 4.3.0.0 date: December 12, 2019 changes: @@ -458,7 +465,7 @@ features: - QUERY-PARAM supported-platforms: - - version: Pubnub 'C#' 4.3.0.0 + version: Pubnub 'C#' 4.4.0.0 platforms: - Windows 10 and up - Windows Server 2008 and up @@ -468,7 +475,7 @@ supported-platforms: - .Net Framework 4.5 - .Net Framework 4.6.1+ - - version: PubnubPCL 'C#' 4.3.0.0 + version: PubnubPCL 'C#' 4.4.0.0 platforms: - Xamarin.Android - Xamarin.iOS @@ -486,7 +493,7 @@ supported-platforms: - .Net Standard 2.0 - .Net Core - - version: PubnubUWP 'C#' 4.3.0.0 + version: PubnubUWP 'C#' 4.4.0.0 platforms: - Windows Phone 10 - Universal Windows Apps diff --git a/src/Api/PubnubApi/Builder/UriUtil.cs b/src/Api/PubnubApi/Builder/UriUtil.cs index 584fec7f0..70746d188 100644 --- a/src/Api/PubnubApi/Builder/UriUtil.cs +++ b/src/Api/PubnubApi/Builder/UriUtil.cs @@ -95,7 +95,6 @@ public static string EncodeUriComponent(string s, PNOperationType type, bool ign return encodedUri; } - private static bool IsOperationTypeForPercent2fEncode(PNOperationType type) { bool ret; @@ -138,16 +137,6 @@ private static bool IsUnsafeToEncode(char ch, bool ignoreComma, bool ignoreColon return " ~`!@#$%^&*()+=[]\\{}|;':\",/<>?".IndexOf(ch) >= 0; } } - - private static bool IsUnsafeToEscapeForPamSign(char ch) - { -#if NET35 || NET40 - return "*()':!~".ToLowerInvariant().IndexOf(ch) >= 0; -#else - return "*()':!".ToLowerInvariant().IndexOf(ch) >= 0; -#endif - } - private static char ToHex(int ch) { return (char)(ch < 10 ? '0' + ch : 'A' + ch - 10); @@ -207,7 +196,5 @@ private static int ConvertToUtf32(String s, int index) // Not a high-surrogate or low-surrogate. Genereate the UTF32 value for the BMP characters. return (int)s[index]; } - - } } diff --git a/src/Api/PubnubApi/EndPoint/TokenManager.cs b/src/Api/PubnubApi/EndPoint/TokenManager.cs index 7ca5c9237..667e119db 100644 --- a/src/Api/PubnubApi/EndPoint/TokenManager.cs +++ b/src/Api/PubnubApi/EndPoint/TokenManager.cs @@ -4,13 +4,11 @@ using System.Text; using System.Text.RegularExpressions; using PubnubApi.CBOR; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; using System.Collections; using System.Reflection; -using Newtonsoft.Json.Linq; - +#if DEBUG && NET461 +#endif +using Newtonsoft.Json; namespace PubnubApi.EndPoint { @@ -20,13 +18,12 @@ public class TokenManager : IDisposable private readonly IJsonPluggableLibrary jsonLib; private readonly IPubnubLog pubnubLog; private readonly string pubnubInstanceId; - private static ConcurrentDictionary> dicToken + private static ConcurrentDictionary> dicToken { get; set; - } = new ConcurrentDictionary>(); + } = new ConcurrentDictionary>(); -#if DEBUG && NET461 internal class TokenManagerConverter : JsonConverter { public override bool CanConvert(Type objectType) @@ -37,8 +34,13 @@ public override bool CanConvert(Type objectType) private static bool TypeImplementsGenericInterface(Type concreteType, Type interfaceType) { +#if NET35 || NET40 return concreteType.GetInterfaces() .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == interfaceType); +#else + return concreteType.GetInterfaces() + .Any(i => i.GetTypeInfo().IsGenericType && i.GetGenericTypeDefinition() == interfaceType); +#endif } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) @@ -66,31 +68,6 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist throw new NotImplementedException(); } } -#endif - - internal class TokenKey - { - [JsonProperty("ResourceType ")] - public string ResourceType { get; set; } - - [JsonProperty("ResourceId ")] - public string ResourceId { get; set; } - - [JsonProperty("PatternFlag ")] - public int PatternFlag { get; set; } - - public override bool Equals(object obj) - { - TokenKey currentKey = obj as TokenKey; - if (currentKey == null) - { - return false; - } - return currentKey.ResourceType == this.ResourceType && currentKey.ResourceId == this.ResourceId && currentKey.PatternFlag == this.PatternFlag; - } - - public override int GetHashCode() => ResourceType.GetHashCode() ^ PatternFlag.GetHashCode() ^ ResourceId.GetHashCode(); - } public TokenManager(PNConfiguration config, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubLog log, string instanceId) { @@ -100,7 +77,7 @@ public TokenManager(PNConfiguration config, IJsonPluggableLibrary jsonPluggableL this.pubnubInstanceId = instanceId; if (!dicToken.ContainsKey(instanceId)) { - dicToken.GetOrAdd(instanceId, new ConcurrentDictionary()); + dicToken.GetOrAdd(instanceId, new ConcurrentDictionary()); } } @@ -331,12 +308,12 @@ public void SetToken(string token) PNGrantToken tokenObj = ParseToken(token); if (tokenObj != null) { - #region "Non-Pattern Resources" +#region "Non-Pattern Resources" if (tokenObj.Channels != null && tokenObj.Channels.Count > 0) { foreach(KeyValuePair kvp in tokenObj.Channels) { - TokenKey key = new TokenKey { ResourceType = "channel", ResourceId = kvp.Key, PatternFlag = 0 }; + PNTokenKey key = new PNTokenKey { ResourceType = "channel", ResourceId = kvp.Key, PatternFlag = 0 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } @@ -344,7 +321,7 @@ public void SetToken(string token) { foreach (KeyValuePair kvp in tokenObj.ChannelGroups) { - TokenKey key = new TokenKey { ResourceType = "group", ResourceId = kvp.Key, PatternFlag = 0 }; + PNTokenKey key = new PNTokenKey { ResourceType = "group", ResourceId = kvp.Key, PatternFlag = 0 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } @@ -352,7 +329,7 @@ public void SetToken(string token) { foreach (KeyValuePair kvp in tokenObj.Users) { - TokenKey key = new TokenKey { ResourceType = "user", ResourceId = kvp.Key, PatternFlag = 0 }; + PNTokenKey key = new PNTokenKey { ResourceType = "user", ResourceId = kvp.Key, PatternFlag = 0 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } @@ -360,17 +337,17 @@ public void SetToken(string token) { foreach (KeyValuePair kvp in tokenObj.Spaces) { - TokenKey key = new TokenKey { ResourceType = "space", ResourceId = kvp.Key, PatternFlag = 0 }; + PNTokenKey key = new PNTokenKey { ResourceType = "space", ResourceId = kvp.Key, PatternFlag = 0 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } - #endregion - #region "Pattern Resources" +#endregion +#region "Pattern Resources" if (tokenObj.ChannelPatterns != null && tokenObj.ChannelPatterns.Count > 0) { foreach (KeyValuePair kvp in tokenObj.ChannelPatterns) { - TokenKey key = new TokenKey { ResourceType = "channel", ResourceId = kvp.Key, PatternFlag = 1 }; + PNTokenKey key = new PNTokenKey { ResourceType = "channel", ResourceId = kvp.Key, PatternFlag = 1 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } @@ -378,7 +355,7 @@ public void SetToken(string token) { foreach (KeyValuePair kvp in tokenObj.GroupPatterns) { - TokenKey key = new TokenKey { ResourceType = "group", ResourceId = kvp.Key, PatternFlag = 1 }; + PNTokenKey key = new PNTokenKey { ResourceType = "group", ResourceId = kvp.Key, PatternFlag = 1 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } @@ -386,7 +363,7 @@ public void SetToken(string token) { foreach (KeyValuePair kvp in tokenObj.UserPatterns) { - TokenKey key = new TokenKey { ResourceType = "user", ResourceId = kvp.Key, PatternFlag = 1 }; + PNTokenKey key = new PNTokenKey { ResourceType = "user", ResourceId = kvp.Key, PatternFlag = 1 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } @@ -394,13 +371,13 @@ public void SetToken(string token) { foreach (KeyValuePair kvp in tokenObj.SpacePatterns) { - TokenKey key = new TokenKey { ResourceType = "space", ResourceId = kvp.Key, PatternFlag = 1 }; + PNTokenKey key = new PNTokenKey { ResourceType = "space", ResourceId = kvp.Key, PatternFlag = 1 }; dicToken[pubnubInstanceId].AddOrUpdate(key, token, (oldVal, newVal) => token); } } - #endregion +#endregion } -#if DEBUG && NET461 +#if DEBUG System.Diagnostics.Debug.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(dicToken, new TokenManagerConverter())); #endif } @@ -409,7 +386,7 @@ public string GetToken(string resourceType, string resourceId) { string resultToken = ""; - TokenKey key = new TokenKey { ResourceType = resourceType, ResourceId = resourceId, PatternFlag = 0 }; + PNTokenKey key = new PNTokenKey { ResourceType = resourceType, ResourceId = resourceId, PatternFlag = 0 }; if (!string.IsNullOrEmpty(pubnubInstanceId) && dicToken[pubnubInstanceId].ContainsKey(key)) { resultToken = dicToken[pubnubInstanceId][key]; @@ -431,7 +408,7 @@ public string GetToken(string resourceType, string resourceId, bool pattern) List tokenKeyPatternList = dicToken[pubnubInstanceId].Keys.Where(k => patterFlag == k.PatternFlag && resourceType == k.ResourceType && Regex.IsMatch(resourceId, k.ResourceId)).Select(k => k.ResourceId).ToList(); string targetResourceId = (tokenKeyPatternList != null && tokenKeyPatternList.Count > 0) ? tokenKeyPatternList[0] : ""; - TokenKey key = new TokenKey { ResourceType = resourceType, ResourceId = targetResourceId, PatternFlag = patterFlag }; + PNTokenKey key = new PNTokenKey { ResourceType = resourceType, ResourceId = targetResourceId, PatternFlag = patterFlag }; if (!string.IsNullOrEmpty(pubnubInstanceId) && dicToken[pubnubInstanceId].ContainsKey(key)) { resultToken = dicToken[pubnubInstanceId][key]; @@ -452,13 +429,26 @@ public string GetToken(string resourceType, string resourceId, bool pattern) return resultToken; } - public List GetAllTokens() + public Dictionary GetAllTokens() + { + Dictionary tokenList = null; + + if (!string.IsNullOrEmpty(pubnubInstanceId) && dicToken != null && dicToken.ContainsKey(pubnubInstanceId)) + { + ConcurrentDictionary currentInstanceTokens = dicToken[pubnubInstanceId]; + tokenList = new Dictionary(currentInstanceTokens); + } + + return tokenList; + } + + public Dictionary GetTokensByResource(string resourceType) { - List tokenList = null; + Dictionary tokenList = null; if (!string.IsNullOrEmpty(pubnubInstanceId) && dicToken != null && dicToken.ContainsKey(pubnubInstanceId)) { - tokenList = dicToken[pubnubInstanceId].Values.Distinct().ToList(); + tokenList = dicToken[pubnubInstanceId].Where(tk=> tk.Key.ResourceType == resourceType).ToDictionary(kvp=> kvp.Key, kvp=> kvp.Value); } return tokenList; @@ -496,7 +486,7 @@ internal void Destroy() } - #region IDisposable Support +#region IDisposable Support private bool disposedValue; protected virtual void DisposeInternal(bool disposing) @@ -517,7 +507,7 @@ void IDisposable.Dispose() { DisposeInternal(true); } - #endregion +#endregion } } diff --git a/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs b/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs index cdf99146b..eb873bd42 100644 --- a/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs +++ b/src/Api/PubnubApi/Interface/IJsonPluggableLibrary.cs @@ -10,6 +10,8 @@ public interface IJsonPluggableLibrary string SerializeToJsonString(object objectToSerialize); + string SerializeDictionaryOfTokenKey(Dictionary objectToSerialize); + List DeserializeToListOfObject(string jsonString); object DeserializeToObject(string jsonString); @@ -25,5 +27,6 @@ public interface IJsonPluggableLibrary object[] ConvertToObjectArray(object localContainer); void PopulateObject(string value, object target); + } } diff --git a/src/Api/PubnubApi/Model/Consumer/PNTokenKey.cs b/src/Api/PubnubApi/Model/Consumer/PNTokenKey.cs new file mode 100644 index 000000000..deed08fd1 --- /dev/null +++ b/src/Api/PubnubApi/Model/Consumer/PNTokenKey.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace PubnubApi +{ + public class PNTokenKey + { + [JsonProperty("ResourceType ")] + public string ResourceType { get; set; } + + [JsonProperty("ResourceId ")] + public string ResourceId { get; set; } + + [JsonProperty("PatternFlag ")] + public int PatternFlag { get; set; } + + public override bool Equals(object obj) + { + PNTokenKey currentKey = obj as PNTokenKey; + if (currentKey == null) + { + return false; + } + return currentKey.ResourceType == this.ResourceType && currentKey.ResourceId == this.ResourceId && currentKey.PatternFlag == this.PatternFlag; + } + + public override int GetHashCode() => ResourceType.GetHashCode() ^ PatternFlag.GetHashCode() ^ ResourceId.GetHashCode(); + } +} diff --git a/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs b/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs index a88b22bfd..d686248ae 100644 --- a/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs +++ b/src/Api/PubnubApi/NewtonsoftJsonDotNet.cs @@ -135,6 +135,16 @@ public string SerializeToJsonString(object objectToSerialize) return JsonConvert.SerializeObject(objectToSerialize); } + /// + /// Use this to serialize Dictionary + /// + /// + /// + public string SerializeDictionaryOfTokenKey(Dictionary objectToSerialize) + { + return JsonConvert.SerializeObject(objectToSerialize, new EndPoint.TokenManager.TokenManagerConverter()); + } + public List DeserializeToListOfObject(string jsonString) { List result = JsonConvert.DeserializeObject>(jsonString); diff --git a/src/Api/PubnubApi/Properties/AssemblyInfo.cs b/src/Api/PubnubApi/Properties/AssemblyInfo.cs index 4bd4b859f..a99e2515f 100644 --- a/src/Api/PubnubApi/Properties/AssemblyInfo.cs +++ b/src/Api/PubnubApi/Properties/AssemblyInfo.cs @@ -11,8 +11,8 @@ [assembly: AssemblyProduct("Pubnub C# SDK")] [assembly: AssemblyCopyright("Copyright © 2019")] [assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.3.0.0")] -[assembly: AssemblyFileVersion("4.3.0.0")] +[assembly: AssemblyVersion("4.4.0.0")] +[assembly: AssemblyFileVersion("4.4.0.0")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. diff --git a/src/Api/PubnubApi/Pubnub.cs b/src/Api/PubnubApi/Pubnub.cs index 3101ab8cb..f46f66e9b 100644 --- a/src/Api/PubnubApi/Pubnub.cs +++ b/src/Api/PubnubApi/Pubnub.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Threading; using PubnubApi; +using System.Reflection; namespace PubnubApi { @@ -16,14 +17,21 @@ public class Pubnub private EndPoint.ListenerManager listenerManager; private readonly EndPoint.TelemetryManager telemetryManager; private readonly EndPoint.TokenManager tokenManager; - - private readonly string instanceId; - - private static string sdkVersion = string.Format("{0}CSharp4.3.0.0", PNPlatform.Get()); - private object savedSubscribeOperation; private readonly string savedSdkVerion; + static Pubnub() + { +#if NET35 || NET40 + var assemblyVersion = typeof(Pubnub).Assembly.GetName().Version; +#else + var assembly = typeof(Pubnub).GetTypeInfo().Assembly; + var assemblyName = new AssemblyName(assembly.FullName); + string assemblyVersion = assemblyName.Version.ToString(); +#endif + Version = string.Format("{0}CSharp{1}", PNPlatform.Get(), assemblyVersion); + } + #region "PubNub API Channel Methods" public EndPoint.SubscribeOperation Subscribe() @@ -274,9 +282,9 @@ public EndPoint.GetMessageActionsOperation GetMessageActions() return getMessageActionsOperation; } - #endregion +#endregion - #region "PubNub API Channel Group Methods" +#region "PubNub API Channel Group Methods" public EndPoint.AddChannelsToChannelGroupOperation AddChannelsToChannelGroup() { @@ -331,9 +339,9 @@ public bool RemoveListener(SubscribeCallback listener) } return ret; } - #endregion +#endregion - #region "PubNub API Other Methods" +#region "PubNub API Other Methods" public void TerminateCurrentSubscriberRequest() { EndPoint.OtherOperation endpoint = new EndPoint.OtherOperation(pubnubConfig, jsonPluggableLibrary, pubnubUnitTest, pubnubLog, null, tokenManager, this); @@ -429,9 +437,9 @@ public void SetTokens(string[] tokens) } } - public List GetTokens() + public Dictionary GetTokens() { - List result = null; + Dictionary result = null; if (tokenManager != null) { result = tokenManager.GetAllTokens(); @@ -439,7 +447,7 @@ public List GetTokens() return result; } - internal string GetToken(string resourceType, string resourceId) + public string GetToken(string resourceType, string resourceId) { string result = ""; if (tokenManager != null) @@ -449,6 +457,16 @@ internal string GetToken(string resourceType, string resourceId) return result; } + public Dictionary GetTokensByResource(string resourceType) + { + Dictionary result = null; + if (tokenManager != null) + { + result = tokenManager.GetTokensByResource(resourceType); + } + return result; + } + public void ClearTokens() { if (tokenManager != null) @@ -553,9 +571,9 @@ public string Encrypt(string inputString, string cipherKey) return pc.Encrypt(inputString); } - #endregion +#endregion - #region "Properties" +#region "Properties" public IPubnubUnitTest PubnubUnitTest { get @@ -567,11 +585,11 @@ public IPubnubUnitTest PubnubUnitTest pubnubUnitTest = value; if (pubnubUnitTest != null) { - sdkVersion = pubnubUnitTest.SdkVersion; + Version = pubnubUnitTest.SdkVersion; } else { - sdkVersion = savedSdkVerion; + Version = savedSdkVerion; } } } @@ -592,23 +610,11 @@ public IJsonPluggableLibrary JsonPluggableLibrary } } - public static string Version - { - get - { - return sdkVersion; - } - } + public static string Version { get; private set; } - public string InstanceId - { - get - { - return instanceId; - } - } + public string InstanceId { get; private set; } #endregion @@ -616,8 +622,8 @@ public string InstanceId public Pubnub(PNConfiguration config) { - savedSdkVerion = sdkVersion; - instanceId = Guid.NewGuid().ToString(); + savedSdkVerion = Version; + InstanceId = Guid.NewGuid().ToString(); pubnubConfig = config; if (config != null) { @@ -673,6 +679,6 @@ private void CheckRequiredConfigValues() } } - #endregion +#endregion } } \ No newline at end of file diff --git a/src/Api/PubnubApi/PubnubApi.csproj b/src/Api/PubnubApi/PubnubApi.csproj index 3d62db720..b3a5ace53 100644 --- a/src/Api/PubnubApi/PubnubApi.csproj +++ b/src/Api/PubnubApi/PubnubApi.csproj @@ -14,7 +14,7 @@ Pubnub - 4.3.0.0 + 4.4.0.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub diff --git a/src/Api/PubnubApiPCL/Properties/AssemblyInfo.cs b/src/Api/PubnubApiPCL/Properties/AssemblyInfo.cs deleted file mode 100644 index 851ea70dd..000000000 --- a/src/Api/PubnubApiPCL/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -//[assembly: AssemblyConfiguration("")] -[assembly: AssemblyTitle("Pubnub C# SDK")] -//[assembly: AssemblyDescription("")] -//[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("PubNub")] -[assembly: AssemblyProduct("Pubnub C# SDK")] -[assembly: AssemblyCopyright("Copyright © 2019")] - -[assembly: AssemblyTrademark("")] -[assembly: AssemblyVersion("4.3.0.0")] -[assembly: AssemblyFileVersion("4.3.0.0")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -//[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -//[assembly: Guid("b23455af-6376-482c-bbed-74c3744d6aa6")] diff --git a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj index 789dc6c95..bd5635530 100644 --- a/src/Api/PubnubApiPCL/PubnubApiPCL.csproj +++ b/src/Api/PubnubApiPCL/PubnubApiPCL.csproj @@ -14,7 +14,7 @@ PubnubPCL - 4.3.0.0 + 4.4.0.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -338,6 +338,7 @@ Refactored code for PAM Signature. Model\Consumer\PNTimeResult.cs + Model\Consumer\Presence\PNGetStateResult.cs @@ -493,6 +494,7 @@ Refactored code for PAM Signature. PNConfiguration.cs + Proxy\PubnubProxy.cs @@ -536,7 +538,6 @@ Refactored code for PAM Signature. Timer.cs - @@ -592,9 +593,15 @@ Refactored code for PAM Signature. None + + None + None + + None + None @@ -616,6 +623,12 @@ Refactored code for PAM Signature. None + + None + + + None + @@ -771,6 +784,7 @@ Refactored code for PAM Signature. + diff --git a/src/Api/PubnubApiUWP/Properties/AssemblyInfo.cs b/src/Api/PubnubApiUWP/Properties/AssemblyInfo.cs deleted file mode 100644 index 9dc908a85..000000000 --- a/src/Api/PubnubApiUWP/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Pubnub C# SDK")] -//[assembly: AssemblyDescription("")] -//[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("PubNub")] -[assembly: AssemblyProduct("Pubnub C# SDK")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.3.0.0")] -[assembly: AssemblyFileVersion("4.3.0.0")] -//[assembly: ComVisible(false)] \ No newline at end of file diff --git a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj index 55d35c588..6f33bffdd 100644 --- a/src/Api/PubnubApiUWP/PubnubApiUWP.csproj +++ b/src/Api/PubnubApiUWP/PubnubApiUWP.csproj @@ -15,7 +15,7 @@ PubnubUWP - 4.3.0.0 + 4.4.0.0 PubNub C# .NET - Web Data Push API Pandu Masabathula PubNub @@ -446,6 +446,7 @@ Refactored code for PAM Signature. Model\Consumer\PNTimeResult.cs + Model\Consumer\Presence\PNGetStateResult.cs @@ -601,6 +602,7 @@ Refactored code for PAM Signature. PNConfiguration.cs + Proxy\PubnubProxy.cs @@ -644,7 +646,6 @@ Refactored code for PAM Signature. Timer.cs - diff --git a/src/Examples/PubnubApi.ConsoleExample/PubnubApi.ConsoleExample.csproj b/src/Examples/PubnubApi.ConsoleExample/PubnubApi.ConsoleExample.csproj index 33a7a3c95..e097a3291 100644 --- a/src/Examples/PubnubApi.ConsoleExample/PubnubApi.ConsoleExample.csproj +++ b/src/Examples/PubnubApi.ConsoleExample/PubnubApi.ConsoleExample.csproj @@ -45,8 +45,8 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\Pubnub.4.3.0\lib\net461\Pubnub.dll + + ..\..\packages\Pubnub.4.4.0\lib\net461\Pubnub.dll diff --git a/src/Examples/PubnubApi.ConsoleExample/packages.config b/src/Examples/PubnubApi.ConsoleExample/packages.config index 35f98be7b..8d7a0513d 100644 --- a/src/Examples/PubnubApi.ConsoleExample/packages.config +++ b/src/Examples/PubnubApi.ConsoleExample/packages.config @@ -2,7 +2,7 @@ - + diff --git a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs index 3aeb19a81..a1dc44421 100644 --- a/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs +++ b/src/UnitTests/PubnubApi.Tests/EncryptionTests.cs @@ -187,14 +187,82 @@ public void GetTokenByResourceTypeAndIdTest() Pubnub pubnub = new Pubnub(config); pubnub.SetToken(token); - List tokensList = pubnub.GetTokens(); - - actual = tokensList[0]; - - //if (pnGrant != null) - //{ - // actual = Newtonsoft.Json.JsonConvert.SerializeObject(pnGrant); - //} + actual = pubnub.GetToken("space", "public"); + + pubnub.ClearTokens(); + + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine("Exception = " + ex.ToString()); + } + Assert.AreEqual(actual, expected); + } + + [Test] + public void GetTokenByResourceTypeTest() + { + string expected = "p0F2AkF0Gl2BkWVDdHRsGGRDcmVzpERjaGFuoENncnCgQ3VzcqBDc3BjoENwYXSkRGNoYW6gQ2dycKBDdXNyo2ZeZW1wLSoDZl5tZ3ItKhgbYl4kAUNzcGOjaV5wdWJsaWMtKgNqXnByaXZhdGUtKhgbYl4kAURtZXRhoENzaWdYIBzbsFygBNyhETvsHwgDJm79KaCNk7nNwG8P0ra4UBoh"; + string actual = ""; + string token = "p0F2AkF0Gl2BkWVDdHRsGGRDcmVzpERjaGFuoENncnCgQ3VzcqBDc3BjoENwYXSkRGNoYW6gQ2dycKBDdXNyo2ZeZW1wLSoDZl5tZ3ItKhgbYl4kAUNzcGOjaV5wdWJsaWMtKgNqXnByaXZhdGUtKhgbYl4kAURtZXRhoENzaWdYIBzbsFygBNyhETvsHwgDJm79KaCNk7nNwG8P0ra4UBoh"; + try + { + PNConfiguration config = new PNConfiguration + { + SubscribeKey = PubnubCommon.SubscribeKey, + PublishKey = PubnubCommon.PublishKey, + }; + Pubnub pubnub = new Pubnub(config); + pubnub.SetToken(token); + + Dictionary tokensList = pubnub.GetTokensByResource("user"); + if (tokensList != null && tokensList.Count > 0) + { + Debug.WriteLine(pubnub.JsonPluggableLibrary.SerializeDictionaryOfTokenKey(tokensList)); + foreach (KeyValuePair kvp in tokensList) + { + actual = kvp.Value; + break; + } + } + + pubnub.ClearTokens(); + + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine("Exception = " + ex.ToString()); + } + Assert.AreEqual(actual, expected); + } + + [Test] + public void GetAllTokensTest() + { + string expected = "p0F2AkF0Gl2BkWVDdHRsGGRDcmVzpERjaGFuoENncnCgQ3VzcqBDc3BjoENwYXSkRGNoYW6gQ2dycKBDdXNyo2ZeZW1wLSoDZl5tZ3ItKhgbYl4kAUNzcGOjaV5wdWJsaWMtKgNqXnByaXZhdGUtKhgbYl4kAURtZXRhoENzaWdYIBzbsFygBNyhETvsHwgDJm79KaCNk7nNwG8P0ra4UBoh"; + string actual = ""; + string token = "p0F2AkF0Gl2BkWVDdHRsGGRDcmVzpERjaGFuoENncnCgQ3VzcqBDc3BjoENwYXSkRGNoYW6gQ2dycKBDdXNyo2ZeZW1wLSoDZl5tZ3ItKhgbYl4kAUNzcGOjaV5wdWJsaWMtKgNqXnByaXZhdGUtKhgbYl4kAURtZXRhoENzaWdYIBzbsFygBNyhETvsHwgDJm79KaCNk7nNwG8P0ra4UBoh"; + try + { + PNConfiguration config = new PNConfiguration + { + SubscribeKey = PubnubCommon.SubscribeKey, + PublishKey = PubnubCommon.PublishKey, + }; + Pubnub pubnub = new Pubnub(config); + pubnub.SetToken(token); + + Dictionary tokensDic = pubnub.GetTokens(); + if (tokensDic != null && tokensDic.Count > 0) + { + Debug.WriteLine(pubnub.JsonPluggableLibrary.SerializeDictionaryOfTokenKey(tokensDic)); + foreach (KeyValuePair kvp in tokensDic) + { + actual = kvp.Value; + break; + } + } + pubnub.ClearTokens(); }