public void Track(string eventType, Dictionary <string, string> parameters)
        {
            if (!this.Initialized)
            {
                throw new InvalidOperationException("Uninitialized");
            }
            Dictionary <string, string> dictionary = new Dictionary <string, string>(parameters);

            dictionary.Add("om_event_type", eventType);
            dictionary.Add("api_key", this.ApiKey);
            dictionary.Add("uid", this.UserID);
            QueueElement queueElement = new QueueElement(eventType, Utils.SecondsSinceEpoch(), 0, dictionary);
            EventAction  eventAction  = this.EventPolicy.AfterTrack(queueElement);

            if (eventAction == EventAction.SEND)
            {
                this.SendToEventAPI(queueElement, new EventAPINetworkResponseHandler(this, queueElement));
            }
            else if (eventAction != EventAction.DISCARD)
            {
                if (eventAction == EventAction.STORE)
                {
                    this.EventQueue.Put(queueElement);
                }
                else
                {
                    Log.Error("Omniata", "Unkown eventAction: " + eventAction);
                }
            }
        }
        public void ProcessEvents()
        {
            if (this.EventQueue.Count() == 0)
            {
                return;
            }
            if (!this.Reachability.Reachable())
            {
                return;
            }
            QueueElement queueElement = this.EventQueue.Peek();
            EventAction  eventAction  = this.EventPolicy.AfterLoad(queueElement);

            if (eventAction == EventAction.SEND)
            {
                this.EventQueue.Take();
                this.SendToEventAPI(queueElement, new EventAPINetworkResponseHandler(this, queueElement));
            }
            else if (eventAction == EventAction.DISCARD)
            {
                this.EventQueue.Take();
            }
            else if (eventAction != EventAction.STORE)
            {
                Log.Error("Omniata", "Unkown eventAction: " + eventAction);
            }
        }
        public List <QueueElement> Read()
        {
            if (!this.Exist())
            {
                Log.Debug("Storage", "queue file missing");
                return(new List <QueueElement>());
            }
            List <QueueElement> list = new List <QueueElement>();
            string text = this.ReadFromFile();

            if (text.Length > 0)
            {
                string[] array = text.Split(new char[]
                {
                    '&'
                });
                string[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    string       s            = array2[i];
                    string       text2        = WWW.UnEscapeURL(s);
                    QueueElement queueElement = QueueElement.Deserialize(text2);
                    if (queueElement == null)
                    {
                        Log.Error("Storage", "Invalid event found, skipping: " + text2);
                    }
                    else
                    {
                        list.Add(queueElement);
                    }
                }
            }
            return(list);
        }
        public void Prepend(QueueElement element)
        {
            List <QueueElement> list = this.Storage.Read();

            list.Insert(0, element);
            this.Storage.Write(list);
            this.ElementCount++;
        }
        public void Put(QueueElement element)
        {
            List <QueueElement> list = this.Storage.Read();

            list.Add(element);
            this.Storage.Write(list);
            this.ElementCount++;
        }
        public QueueElement Take()
        {
            if (this.ElementCount == 0)
            {
                throw new InvalidOperationException("Queue is empty");
            }
            List <QueueElement> list   = this.Storage.Read();
            QueueElement        result = list[0];

            list.RemoveAt(0);
            this.Storage.Write(list);
            this.ElementCount--;
            return(result);
        }
        internal void EventSendFailed(QueueElement element)
        {
            element.Retries++;
            int waitTime = Math.Min(64, this.OmniataComponent.WaitTime * 2);

            this.OmniataComponent.WaitTime = waitTime;
            EventAction eventAction = this.EventPolicy.AfterSendFail(element);

            if (eventAction == EventAction.SEND)
            {
                this.SendToEventAPI(element, new EventAPINetworkResponseHandler(this, element));
            }
            else if (eventAction != EventAction.DISCARD)
            {
                if (eventAction == EventAction.STORE)
                {
                    this.EventQueue.Prepend(element);
                }
                else
                {
                    Log.Error("Omniata", "Unkown eventAction: " + eventAction);
                }
            }
        }
 public EventAPINetworkResponseHandler(Omniata omniata, QueueElement queueElement)
 {
     this.Omniata      = omniata;
     this.QueueElement = queueElement;
 }
 internal void EventSendSucceeded(QueueElement element)
 {
     this.OmniataComponent.WaitTime = 1;
 }
        private void SendToEventAPI(QueueElement element, NetworkResponseHandler networkResponseHandler)
        {
            string url = Utils.GetEventAPI(this.UseSSL, this.Debug) + "?" + element.WireFormat();

            this.Network.Send(url, networkResponseHandler);
        }
Esempio n. 11
0
 public EventAction AfterTrack(QueueElement queueElement)
 {
     return(EventAction.STORE);
 }
Esempio n. 12
0
 public EventAction AfterLoad(QueueElement queueElement)
 {
     return(EventAction.SEND);
 }
Esempio n. 13
0
 public EventAction AfterSendFail(QueueElement queueElement)
 {
     return(EventAction.DISCARD);
 }