Ejemplo n.º 1
0
        /// <summary>
        /// Starts Countly tracking session.
        /// Call from your App.xaml.cs Application_Launching and Application_Activated events.
        /// Must be called before other SDK methods can be used.
        /// </summary>
        /// <param name="serverUrl">URL of the Countly server to submit data to; use "https://cloud.count.ly" for Countly Cloud</param>
        /// <param name="appKey">app key for the application being tracked; find in the Countly Dashboard under Management > Applications</param>
        public static async Task StartSession(string serverUrl, string appKey)
        {
            if (String.IsNullOrWhiteSpace(serverUrl))
            {
                throw new ArgumentException("invalid server url");
            }

            if (String.IsNullOrWhiteSpace(appKey))
            {
                throw new ArgumentException("invalid application key");
            }

            ServerUrl = serverUrl;
            AppKey    = appKey;

            Events.Clear();

            startTime    =
                lastTime = DateTime.UtcNow;

            var interval = TimeSpan.FromSeconds(updateInterval);

            Timer = new Timer(UpdateSession, null, interval, interval);

            var view = lastView;

            if (view != null)
            {
                view.Time = DateTime.UtcNow;
                AddEvent(new CountlyEvent(ViewEvent, 1, null, null, view.Segmentation));
            }

            await Upload(CountlyRequest.CreateBeginSession());
        }