Exemplo n.º 1
0
        private static void WriteToFile(MixpanelEntity element)
        {
            Dictionary <string, object> values = new Dictionary <string, object>();

            element.CopyTo(values);
            string json = JsonConvert.SerializeObject(values);
            string b64  = Utilities.ToBase64(json);

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                if (!store.DirectoryExists(element.EndpointName))
                {
                    store.CreateDirectory(element.EndpointName);
                }

                string path = element.EndpointName + "\\" + element.FileName;
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(path, FileMode.Create, store))
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        writer.Write(b64);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves element locally. Event will be sent on next call of "TrySendLocalElements".
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public void SaveElement(MixpanelEntity element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            WriteToFile(element);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tracks the specified element (event or profile update).
        /// More info: https://mixpanel.com/help/reference/http#tracking-via-http
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">element</exception>
        public void Track(MixpanelEntity element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            WriteToFile(element);
            SendFile(element.EndpointName, element.FileName);
        }
Exemplo n.º 4
0
            /// <summary>
            /// Determines whether the store contains the specified entity.
            /// </summary>
            /// <param name="entity">The entity.</param>
            /// <returns></returns>
            /// <exception cref="System.ArgumentNullException">entity</exception>
            public bool Contains(MixpanelEntity entity)
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                ProfileUpdate profileUpdate = entity as ProfileUpdate;

                if (profileUpdate != null)
                {
                    return(Contains(profileUpdate));
                }

                TrackingEvent trackingEvent = entity as TrackingEvent;

                if (trackingEvent != null)
                {
                    return(Contains(trackingEvent));
                }

                return(false);
            }
Exemplo n.º 5
0
            /// <summary>
            /// Adds the specified entity to the local store.
            /// </summary>
            /// <param name="entity">The entity.</param>
            /// <exception cref="System.ArgumentNullException">entity</exception>
            public void Add(MixpanelEntity entity)
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                ProfileUpdate profileUpdate = entity as ProfileUpdate;

                if (profileUpdate != null)
                {
                    Add(profileUpdate);
                    return;
                }

                TrackingEvent trackingEvent = entity as TrackingEvent;

                if (trackingEvent != null)
                {
                    Add(trackingEvent);
                    return;
                }
            }