コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void Prepend(QueueElement element)
        {
            List <QueueElement> list = this.Storage.Read();

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

            list.Add(element);
            this.Storage.Write(list);
            this.ElementCount++;
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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;
 }
コード例 #9
0
 internal void EventSendSucceeded(QueueElement element)
 {
     this.OmniataComponent.WaitTime = 1;
 }
コード例 #10
0
        private void SendToEventAPI(QueueElement element, NetworkResponseHandler networkResponseHandler)
        {
            string url = Utils.GetEventAPI(this.UseSSL, this.Debug) + "?" + element.WireFormat();

            this.Network.Send(url, networkResponseHandler);
        }
コード例 #11
0
 public EventAction AfterTrack(QueueElement queueElement)
 {
     return(EventAction.STORE);
 }
コード例 #12
0
 public EventAction AfterLoad(QueueElement queueElement)
 {
     return(EventAction.SEND);
 }
コード例 #13
0
 public EventAction AfterSendFail(QueueElement queueElement)
 {
     return(EventAction.DISCARD);
 }