public SessionTracker(IChannelGroup channelGroup, IChannelUnit channel, IApplicationSettings applicationSettings)
        {
            // Need to lock in constructor because of the event handler being set for channelGroup.
            lock (_lockObject)
            {
                _channel                   = channel;
                _applicationSettings       = applicationSettings;
                channelGroup.EnqueuingLog += HandleEnqueuingLog;
                var sessionsString = _applicationSettings.GetValue <string>(StorageKey, null);
                if (sessionsString == null)
                {
                    return;
                }
                _sessions = SessionsFromString(sessionsString);

                // Re-write sessions in storage in case of any invalid strings
                _applicationSettings.SetValue(StorageKey, SessionsAsString());
                if (_sessions.Count == 0)
                {
                    return;
                }
                var loadedSessionsString = _sessions.Values.Aggregate("Loaded stored sessions:\n", (current, session) => current + ("\t" + session + "\n"));
                MobileCenterLog.Debug(Analytics.Instance.LogTag, loadedSessionsString);
            }
        }
Esempio n. 2
0
 public SessionTracker(IChannel channelGroup, IChannelUnit channel)
 {
     // Need to lock in constructor because of the event handler being set for channelGroup.
     lock (_lockObject)
     {
         _channel = channel;
         channelGroup.EnqueuingLog += HandleEnqueuingLog;
     }
 }
 public SessionTracker(IChannelGroup channelGroup, IChannelUnit channel, IApplicationSettings applicationSettings)
 {
     // Need to lock in constructor because of the event handler being set for channelGroup.
     lock (_lockObject)
     {
         _channel                   = channel;
         _applicationSettings       = applicationSettings;
         channelGroup.EnqueuingLog += HandleEnqueuingLog;
     }
 }
 /// <exception cref="AppCenterException">Attempted to add duplicate channel to group</exception>
 public void AddChannel(IChannelUnit channel)
 {
     ThrowIfDisposed();
     lock (_channelGroupLock)
     {
         if (channel == null)
         {
             throw new AppCenterException("Attempted to add null channel to group");
         }
         var added = _channels.Add(channel);
         if (!added)
         {
             // The benefit of throwing an exception in this case is debatable. Might make sense to allow this.
             throw new AppCenterException("Attempted to add duplicate channel to group");
         }
         channel.EnqueuingLog    += AnyChannelEnqueuingLog;
         channel.SendingLog      += AnyChannelSendingLog;
         channel.SentLog         += AnyChannelSentLog;
         channel.FailedToSendLog += AnyChannelFailedToSendLog;
     }
 }
Esempio n. 5
0
        // Internal for testing
        internal void InstanceConfigure(string appSecretOrSecrets)
        {
            if (_instanceConfigured)
            {
                AppCenterLog.Warn(AppCenterLog.LogTag, "App Center may only be configured once.");
                return;
            }
            _appSecret = GetSecretForPlatform(appSecretOrSecrets, PlatformIdentifier);

            // If a factory has been supplied, use it to construct the channel group - this is designed for testing.
            _networkStateAdapter = new NetworkStateAdapter();
            _channelGroup        = _channelGroupFactory?.CreateChannelGroup(_appSecret) ?? new ChannelGroup(_appSecret, null, _networkStateAdapter);
            _channel             = _channelGroup.AddChannel(ChannelName, Constants.DefaultTriggerCount, Constants.DefaultTriggerInterval,
                                                            Constants.DefaultTriggerMaxParallelRequests);
            if (_logUrl != null)
            {
                _channelGroup.SetLogUrl(_logUrl);
            }
            _instanceConfigured = true;
            AppCenterLog.Assert(AppCenterLog.LogTag, "App Center SDK configured successfully.");
        }
Esempio n. 6
0
        public SessionTracker(IChannelGroup channelGroup, IChannelUnit channel)
        {
            _channel = channel;
            channelGroup.EnqueuingLog += HandleEnqueuingLog;
            var sessionsString = _applicationSettings.GetValue <string>(StorageKey, null);

            if (sessionsString == null)
            {
                return;
            }
            _sessions = SessionsFromString(sessionsString);
            // Re-write sessions in storage in case of any invalid strings
            _applicationSettings[StorageKey] = SessionsAsString();
            if (_sessions.Count == 0)
            {
                return;
            }
            var loadedSessionsString = _sessions.Values.Aggregate("Loaded stored sessions:\n", (current, session) => current + ("\t" + session + "\n"));

            MobileCenterLog.Debug(Analytics.Instance.LogTag, loadedSessionsString);
        }
Esempio n. 7
0
        // Internal for testing
        internal void InstanceConfigure(string appSecretOrSecrets)
        {
            if (_instanceConfigured)
            {
                MobileCenterLog.Warn(MobileCenterLog.LogTag, "Mobile Center may only be configured once.");
                return;
            }
            _appSecret = GetSecretForPlatform(appSecretOrSecrets, PlatformIdentifier);

            // If a factory has been supplied, use it to construct the channel group - this is designed for testing.
            // Normal scenarios will use new ChannelGroup(string).
            _channelGroup = _channelGroupFactory?.CreateChannelGroup(_appSecret) ?? new ChannelGroup(_appSecret);
            ApplicationLifecycleHelper.Instance.UnhandledExceptionOccurred += (sender, e) => _channelGroup.ShutdownAsync();
            _channel = _channelGroup.AddChannel(ChannelName, Constants.DefaultTriggerCount, Constants.DefaultTriggerInterval,
                                                Constants.DefaultTriggerMaxParallelRequests);
            if (_logUrl != null)
            {
                _channelGroup.SetLogUrl(_logUrl);
            }
            _instanceConfigured = true;
            MobileCenterLog.Assert(MobileCenterLog.LogTag, "Mobile Center SDK configured successfully.");
        }
 private ISessionTracker CreateSessionTracker(IChannelGroup channelGroup, IChannelUnit channel, IApplicationSettings applicationSettings)
 {
     return(_sessionTrackerFactory?.CreateSessionTracker(channelGroup, channel, applicationSettings) ?? new SessionTracker(channelGroup, channel, applicationSettings));
 }
 private ISessionTracker CreateSessionTracker(IChannelGroup channelGroup, IChannelUnit channel)
 {
     return(_sessionTrackerFactory?.CreateSessionTracker(channelGroup, channel) ?? new SessionTracker(channelGroup, channel));
 }