/// <summary>
 /// Add a message to end of queue.
 /// </summary>
 /// <param name="aMessage">The message to add to the end.</param>
 internal void Add(IQUMessage aMessage)
 {
     if (this.m_first == null)
       {
     this.m_first = aMessage;
       }
       if (this.m_last != null)
       {
     this.m_last.Next = aMessage;
       }
       this.m_last = aMessage;
       // update queue property so the IQUMessage will call onMessageChanged
       aMessage.Queue = this;
       // queue has changed.
       this.m_dirtyJSON = true;
       this.m_dirtyStored = true;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a message to the pending message list if the %SDK is initialized; else the message gets destroyed.
 /// </summary>
 /// <param name="aMessage">Message to add.</param>
 private void AddMessage(IQUMessage aMessage)
 {
     // only add if %IQU %SDK has been initialized.
       if (this.Initialized)
       {
     this.m_pendingMessages.Add(aMessage);
       }
       else
       {
     // message was not added, destroy the instance
     aMessage.Destroy();
       }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a message from an event and it to the pending queue.
 /// </summary>
 /// <param name="anEvent">Event to create message for.</param>
 private void AddEvent(IDictionary<string, object> anEvent)
 {
     IQUMessage message = new IQUMessage(this.m_ids, anEvent);
       this.AddMessage(message);
 }
 /// <summary>
 /// Clears the references to the messages, but don't destroy the messages
 /// themselves.
 /// <p>
 /// After this method the queue will be empty.
 /// </p>
 /// </summary>
 internal void reset()
 {
     this.m_first = null;
       this.m_last = null;
       this.m_cachedJSONString = null;
       this.m_dirtyJSON = false;
       this.m_dirtyStored = false;
 }
 /// <summary>
 /// Prepend a queue before the current queue. This will move the items from
 /// aQueue to this queue.
 /// <p>
 /// After this call, aQueue will be empty.
 /// </p>
 /// 
 /// @param aQueue
 ///            
 /// @param aChangeQueue
 ///            
 /// </summary>
 /// <param name="aQueue">The queue to prepend before this queue.</param>
 /// <param name="aChangeQueue"> When <code>true</code> change the queue
 /// property in every message to this queue.</param>
 internal void Prepend(IQUMessageQueue aQueue, bool aChangeQueue)
 {
     if (!aQueue.IsEmpty())
       {
     // if this queue is empty, copy cached JSON string and dirty state;
     // else reset it.
     if (this.m_first == null)
     {
       this.m_cachedJSONString = aQueue.m_cachedJSONString;
       this.m_dirtyJSON = aQueue.m_dirtyJSON;
       this.m_dirtyStored = aQueue.m_dirtyStored;
     }
     else
     {
       this.m_cachedJSONString = null;
       this.m_dirtyJSON = true;
       this.m_dirtyStored = true;
     }
     // get first and last
     IQUMessage first = aQueue.m_first;
     IQUMessage last = aQueue.m_last;
     // this queue is empty?
     if (this.m_last == null)
     {
       // yes, just copy last
       this.m_last = last;
     }
     else
     {
       // add the first message in the chain to the chain in aQueue
       last.Next = this.m_first;
     }
     // chain starts now with the first message in the chain of aQueue
     this.m_first = first;
     // update queue property?
     if (aChangeQueue)
     {
       for (IQUMessage message = first; message != null; message = message.Next)
       {
     message.Queue = this;
       }
     }
     // aQueue is now empty
     aQueue.reset();
       }
 }
 /// <summary>
 /// Loads the messages from persistent storage.
 /// </summary>
 internal void Load()
 {
     this.Clear(false);
       try
       {
     #if UNITY_WEBPLAYER
     // exit if there is no stored data
     if (!IQUSDK.Instance.LocalStorage.HasKey(IQUMessageQueue.FileName))
     {
       return;
     }
     MemoryStream stream = new MemoryStream(IQUSDK.Instance.LocalStorage.GetBytes(IQUMessageQueue.FileName)));
     #else
     // exit if there is no file
     string fileName = Application.persistentDataPath + "/" + IQUMessageQueue.FileName;
     if (!File.Exists(fileName))
     {
       return;
     }
     FileStream stream = new FileStream(fileName, FileMode.Open);
     #endif
     BinaryReader reader = new BinaryReader(stream);
     int version = reader.ReadInt32();
     // correct version?
     if (version == IQUMessageQueue.FileVersion)
     {
       // get number of stored messages and load the messages
       int count = reader.ReadInt32();
       for (int index = 0; index < count; index++)
       {
     IQUMessage message = new IQUMessage();
     message.Load(reader);
     this.Add(message);
       }
       reader.Close();
       stream.Close();
       IQUSDK.Instance.AddLog("[Queue] loaded " + count + " messages.");
     }
     else
     {
       // unsupported version, close and delete storage (no longer usefull)
       reader.Close();
       stream.Close();
       this.DeleteStorage();
     }
     // no need to store the just loaded messages
     this.m_dirtyStored = false;
       }
       catch (Exception error)
       {
     IQUSDK.Instance.AddLog("[Queue][Error] while loading: " + error.Message);
       }
 }
 /// <summary>
 /// This handler is called by IQUMessage when the contents changes.
 /// </summary>
 /// <param name="aMessage">Message with changed content</param>
 internal void HandleMessageChanged(IQUMessage aMessage)
 {
     this.m_dirtyJSON = true;
       this.m_dirtyStored = true;
 }
 /// <summary>
 /// Removes references and resources.
 /// </summary>
 internal void Destroy()
 {
     this.m_next = null;
       this.m_queue = null;
       if (this.m_ids != null)
       {
     this.m_ids.Destroy();
     this.m_ids = null;
       }
 }