An item is a message (parameters) and the category (GA service) the message should be sent to
Exemple #1
0
    /// <summary>
    /// If we already have the same message item in the queue we simply increase the message count instead of adding a duplicate.
    /// </summary>
    /// <param name='queue'>
    /// Queue.
    /// </param>
    /// <param name='item'>
    /// Item.
    /// </param>
    private static void StackQueue(List <GA_Submit.Item> queue, GA_Submit.Item item)
    {
        bool stacked = false;

        for (int i = 0; i < queue.Count; i++)
        {
            if (!stacked && queue[i].Type == GA_Submit.CategoryType.GA_Log && item.Type == GA_Submit.CategoryType.GA_Log &&
                queue[i].Parameters.ContainsKey(GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.EventID]) &&
                item.Parameters.ContainsKey(GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.EventID]) &&
                queue[i].Parameters[GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.EventID]].Equals(item.Parameters[GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.EventID]]) &&
                queue[i].Parameters.ContainsKey(GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Message]) &&
                item.Parameters.ContainsKey(GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Message]) &&
                queue[i].Parameters[GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Message]].Equals(item.Parameters[GA_ServerFieldTypes.Fields[GA_ServerFieldTypes.FieldType.Message]]))
            {
                stacked  = true;
                queue[i] = new GA_Submit.Item {
                    AddTime = queue[i].AddTime, Parameters = queue[i].Parameters, Type = queue[i].Type, Count = Mathf.Max(2, queue[i].Count + 1)
                };
            }
        }
        if (!stacked)
        {
            queue.Add(item);
        }
    }
Exemple #2
0
    /// <summary>
    /// Add a new message to the submit queue. If we are in the middle of a queue submit we add the message to the temporary queue instead
    /// </summary>
    /// <param name="parameters">
    /// The message is a dictionary of parameters <see cref="Dictionary<System.String, System.Object>"/>
    /// </param>
    /// <param name="type">
    /// The GA service to send the message to (see GA_Submit) <see cref="GA_Submit.CategoryType"/>
    /// </param>
    /// <param name="stack">
    /// If true any identical messages in the queue will be merged/stacked as a single message, to save server load
    /// </param>
    public static void AddItem(Hashtable parameters, GA_Submit.CategoryType type, bool stack)
    {
        //No reason to add any more items if we have stopped submitting data or we are not supposed to submit in the first place
        if (_endsubmit || (Application.isEditor && !GA.SettingsGA.RunInEditorPlayMode))
        {
            return;
        }

        GA_Submit.Item item = new GA_Submit.Item
        {
            Type       = type,
            Parameters = parameters,
            AddTime    = Time.time
        };

                #if !UNITY_EDITOR
        if (!_userEventSuccess && type != GA_Submit.CategoryType.GA_User)
        {
            _tempQueue.Add(item);
            return;
        }
                #endif

        if (_submittingData)
        {
            /*if (stack && type == GA_Submit.CategoryType.GA_Log)
             * {
             *      StackQueue(_tempQueue, item);
             * }
             * else
             * {*/
            _tempQueue.Add(item);
            //}
        }
        else
        {
            /*if (stack && type == GA_Submit.CategoryType.GA_Log)
             * {
             *      StackQueue(_queue, item);
             * }
             * else
             * {*/
            _queue.Add(item);
            //}
        }
    }
Exemple #3
0
    /// <summary>
    /// Add a new message to the submit queue. If we are in the middle of a queue submit we add the message to the temporary queue instead
    /// </summary>
    /// <param name="parameters">
    /// The message is a dictionary of parameters <see cref="Dictionary<System.String, System.Object>"/>
    /// </param>
    /// <param name="type">
    /// The GA service to send the message to (see GA_Submit) <see cref="GA_Submit.CategoryType"/>
    /// </param>
    /// <param name="stack">
    /// If true any identical messages in the queue will be merged/stacked as a single message, to save server load
    /// </param>
    public static void AddItem(Hashtable parameters, GA_Submit.CategoryType type, bool stack)
    {
        //No reason to add any more items if we have stopped submitting data or we are not supposed to submit in the first place
        if (_endsubmit || (Application.isEditor && !GA.SettingsGA.RunInEditorPlayMode))
        {
            return;
        }

        GA_Submit.Item item = new GA_Submit.Item
        {
            Type       = type,
            Parameters = parameters,
            AddTime    = Time.time
        };

        if (_submittingData)
        {
            if (stack && type == GA_Submit.CategoryType.GA_Log)
            {
                StackQueue(_tempQueue, item);
            }
            else
            {
                _tempQueue.Add(item);
            }
        }
        else
        {
            if (stack && type == GA_Submit.CategoryType.GA_Log)
            {
                StackQueue(_queue, item);
            }
            else
            {
                _queue.Add(item);
            }
        }
    }
    /// <summary>
    /// Gets data which has previously been archived due to lack of internet connectivity.
    /// The file containing the archived data is then deleted.
    /// </summary>
    /// <returns>
    /// The archived data as a list of items with parameters and category
    /// </returns>
    public List <GA_Submit.Item> GetArchivedData()
    {
                #if UNITY_WEBPLAYER || UNITY_NACL || UNITY_FLASH || UNITY_METRO
        return(null);
                #else
        List <GA_Submit.Item> items = new List <GA_Submit.Item>();

        StreamReader fileReader = null;
        string       fileName   = Application.persistentDataPath + "/" + FILE_NAME;

        if (File.Exists(fileName))
        {
            fileReader = File.OpenText(fileName);
        }

        if (fileReader != null)
        {
            string line = null;
            while ((line = fileReader.ReadLine()) != null)
            {
                string[] lineSplit = line.Split(' ');
                if (lineSplit.Length >= 2)
                {
                    string categoryString = lineSplit[0];
                    string json           = line.Substring(lineSplit[0].Length + 1);

                    bool saveData = false;
                    GA_Submit.CategoryType category = GA_Submit.CategoryType.GA_User;

                    foreach (KeyValuePair <GA_Submit.CategoryType, string> kvp in GA_Submit.Categories)
                    {
                        if (kvp.Key.ToString().Equals(categoryString))
                        {
                            category = kvp.Key;
                            saveData = true;
                        }
                    }

                    if (saveData)
                    {
                        ArrayList itemsParameters = (ArrayList)GA_MiniJSON.JsonDecode(json);                        //JsonMapper.ToObject<List<Dictionary<string, object>>>(json);

                        foreach (Hashtable parameters in itemsParameters)
                        {
                            GA_Submit.Item item = new GA_Submit.Item
                            {
                                Type       = category,
                                Parameters = parameters,
                                AddTime    = Time.time
                            };

                            items.Add(item);
                        }
                    }
                }
            }
            fileReader.Close();

            File.Delete(fileName);
        }

        return(items);
                #endif
    }
    /// <summary>
    /// Gets data which has previously been archived due to lack of internet connectivity.
    /// The file containing the archived data is then deleted.
    /// </summary>
    /// <returns>
    /// The archived data as a list of items with parameters and category
    /// </returns>
    public List<GA_Submit.Item> GetArchivedData()
    {
        #if UNITY_WEBPLAYER || UNITY_NACL || UNITY_FLASH

        return null;

        #else

        List<GA_Submit.Item> items = new List<GA_Submit.Item>();

        StreamReader fileReader = null;
        string fileName = Application.persistentDataPath + "/" + FILE_NAME;

        if (File.Exists(fileName))
        {
            fileReader = File.OpenText(fileName);
        }

        if (fileReader != null)
        {
            string line = null;
            while ((line = fileReader.ReadLine()) != null)
            {
                string[] lineSplit = line.Split(' ');
                if (lineSplit.Length >= 2)
                {
                    string categoryString = lineSplit[0];
                    string json = line.Substring(lineSplit[0].Length + 1);

                    bool saveData = false;
                    GA_Submit.CategoryType category = GA_Submit.CategoryType.GA_User;

                    foreach (KeyValuePair<GA_Submit.CategoryType, string> kvp in GA.API.Submit.Categories)
                    {
                        if (kvp.Key.ToString().Equals(categoryString))
                        {
                            category = kvp.Key;
                            saveData = true;
                        }
                    }

                    if (saveData)
                    {
                        List<object> itemsParameters = json.listFromJson();

                        foreach (var parameters in itemsParameters)
                        {
                            Dictionary<string, object> dict = parameters as Dictionary<string, object>;
                            GA_Submit.Item item = new GA_Submit.Item
                            {
                                Type = category,
                                Parameters = new Hashtable(dict),
                                AddTime = Time.time
                            };

                            items.Add(item);
                        }
                    }
                }
            }
            fileReader.Close();

            File.Delete(fileName);
        }

        return items;

        #endif
    }