private PubNub(PNConfiguration pnConfiguration, GameObject gameObjectRef, IJsonLibrary jsonLibrary) { this.jsonLibrary = jsonLibrary; this.gameObj = gameObjectRef; this.PNConfig = pnConfiguration; PubNubUnityInitializationAfterCleanup(); }
void LocateJsonWrapperClasses() { m_knownJsonLibraryWrappers = new List <IJsonLibrary>(); var assembly = System.Reflection.Assembly.GetAssembly(typeof(IJsonLibrary)); foreach (var t in assembly.GetExportedTypes()) { if (!t.IsAbstract) { var interfaces = new List <System.Type>(t.GetInterfaces()); if (interfaces.Contains(typeof(IJsonLibrary))) { IJsonLibrary wrapper = System.Activator.CreateInstance(t) as IJsonLibrary; if (wrapper != null) { m_knownJsonLibraryWrappers.Add(wrapper); } } } } UnityEngine.Debug.Log(string.Format("Found {0} json library wrappers", m_knownJsonLibraryWrappers.Count)); }
IEnumerator DoBenchmark() { yield return(null); // Attempt to find a wrapper matching the selection name IJsonLibrary wrapper = null; foreach (var w in m_knownJsonLibraryWrappers) { System.Type t = w.GetType(); if (t.ToString() == Lib) { wrapper = w; break; } } if (wrapper != null) { yield return(null); LastLibName.text = Lib; LastActionName.text = Action.ToString(); long sum = 0; long samples = long.Parse(NumSamplesToRun.text); string notes = string.Empty; // Gets overwritten, only last notes are shown long avg = 0; #if !UNITY_EDITOR long memoryAllocatedDuringAction = 0; #endif if (samples > 0) { for (int i = 0; i < samples; i++) { Stopwatch timer = new Stopwatch(); #if !UNITY_EDITOR System.GC.Collect(); UnityEngine.Scripting.GarbageCollector.GCMode = UnityEngine.Scripting.GarbageCollector.Mode.Disabled; long totalGCBeforeAction = System.GC.GetTotalMemory(true); #endif if (Action == JsonAction.Deserialize) { notes = string.Format("Json being used is {0} char long", m_jsonText.Length); notes += wrapper.Deserialize(timer); } else if (Action == JsonAction.Serialize) { notes = string.Format("Class being serialized has {0} complex elements", m_holder.junkList.Length); notes += wrapper.Serialize(timer); } if (!timer.IsRunning) { throw new System.Exception("Stopwatch timer was not started by wrapper"); } timer.Stop(); sum += timer.ElapsedMilliseconds; #if !UNITY_EDITOR memoryAllocatedDuringAction += System.GC.GetTotalMemory(true) - totalGCBeforeAction; UnityEngine.Scripting.GarbageCollector.GCMode = UnityEngine.Scripting.GarbageCollector.Mode.Enabled; #endif //UnityEngine.Debug.Log(string.Format("----> {0} using {1} took {2}", Action, Lib, timer.ElapsedMilliseconds)); yield return(null); } avg = (sum / samples); } notes += "\n" + samples.ToString() + " samples taken"; #if !UNITY_EDITOR notes += "\n" + (memoryAllocatedDuringAction / samples * 1e-6).ToString("F2") + " mb GC allocated"; #endif Notes.text = notes; LastTimeValue.text = avg.ToString(); } else { UnityEngine.Debug.Log(string.Format("Unable to find suitable IJsonWrapper to match selection {0}", Lib)); } Action = JsonAction.None; m_working = -1; }
public PubNubUnityBase(PNConfiguration pnConfiguration, GameObject gameObjectRef, IJsonLibrary jsonLibrary) { PNConfig = pnConfiguration; PNLog = new PNLoggingMethod(PNConfig.LogVerbosity); #if (UNITY_IOS) Version = string.Format("PubNub-CSharp-UnityIOS/{0}", build); #elif (UNITY_STANDALONE_WIN) Version = string.Format("PubNub-CSharp-UnityWin/{0}", build); #elif (UNITY_STANDALONE_OSX) Version = string.Format("PubNub-CSharp-UnityOSX/{0}", build); #elif (UNITY_ANDROID) Version = string.Format("PubNub-CSharp-UnityAndroid/{0}", build); #elif (UNITY_STANDALONE_LINUX) Version = string.Format("PubNub-CSharp-UnityLinux/{0}", build); #elif (UNITY_WEBPLAYER) Version = string.Format("PubNub-CSharp-UnityWeb/{0}", build); #elif (UNITY_WEBGL) Version = string.Format("PubNub-CSharp-UnityWebGL/{0}", build); #else Version = string.Format("PubNub-CSharp-Unity/{0}", build); #endif #if (ENABLE_PUBNUB_LOGGING) this.PNLog.WriteToLog(Version, PNLoggingMethod.LevelInfo); #endif if (gameObjectRef == null) { #if (ENABLE_PUBNUB_LOGGING) this.PNLog.WriteToLog("Initilizing new GameObject", PNLoggingMethod.LevelInfo); #endif GameObjectRef = new GameObject("PubnubGameObject"); localGobj = true; } else { #if (ENABLE_PUBNUB_LOGGING) this.PNLog.WriteToLog("Reusing already initialized GameObject", PNLoggingMethod.LevelInfo); #endif GameObjectRef = gameObjectRef; localGobj = false; } publishMessageCounter = new Counter(); QManager = GameObjectRef.AddComponent <QueueManager> (); latency = GameObjectRef.AddComponent <PNLatencyManager> (); QManager.NoOfConcurrentRequests = PNConfig.ConcurrentNonSubscribeWorkers; }
public PubNubUnity(PNConfiguration pnConfiguration, GameObject gameObjectRef, IJsonLibrary jsonLibrary) : base(pnConfiguration, gameObjectRef, jsonLibrary) { #if (ENABLE_PUBNUB_LOGGING) base.PNLog.WriteToLog(string.Format("Init with UUID {0}", base.PNConfig.UUID), PNLoggingMethod.LevelInfo); #endif SubscriptionInstance = new Subscription(this); SubWorker = new SubscriptionWorker <SubscribeEnvelope>(this); base.QManager.PubNubInstance = this; //TODO test PNConfig.UUIDChanged += (sender, e) => { if (SubWorker != null) { SubWorker.UUIDChanged = true; SubWorker.BounceRequest(); } }; PNConfig.FilterExpressionChanged += (sender, e) => { if (SubWorker != null) { SubWorker.BounceRequest(); } }; }
public static List <object> DeserializeAndAddToResult(string jsonString, string multiChannel, IJsonLibrary jsonPluggableLibrary, bool addChannel) { Dictionary <string, object> dictionary = jsonPluggableLibrary.DeserializeToDictionaryOfObject(jsonString); List <object> result = new List <object> (); result.Add(dictionary); if (addChannel) { result.Add(multiChannel); } return(result); }
public static string JsonEncodePublishMsg(object originalMessage, string cipherKey, IJsonLibrary jsonPluggableLibrary, PNLoggingMethod pnLog) { string message = jsonPluggableLibrary.SerializeToJsonString(originalMessage); if (!string.IsNullOrEmpty(cipherKey) && (cipherKey.Length > 0)) { PubnubCrypto aes = new PubnubCrypto(cipherKey, pnLog); string encryptMessage = aes.Encrypt(message); message = jsonPluggableLibrary.SerializeToJsonString(encryptMessage); } return(message); }