public override void OnChannelGroupReady(IChannelGroup channelGroup, string appSecret)
 {
     lock (_serviceLock)
     {
         base.OnChannelGroupReady(channelGroup, appSecret);
         if (ApplicationLifecycleHelper == null)
         {
             // If it isn't null, that likely means that a test provided its own lifecycle helper
             ApplicationLifecycleHelper = new ApplicationLifecycleHelper();
         }
         ApplyEnabledState(InstanceEnabled);
         if (ApplicationLifecycleHelper.HasShownWindow && !ApplicationLifecycleHelper.IsSuspended)
         {
             SessionTracker?.Resume();
             _hasStarted = true;
         }
         else
         {
             ApplicationLifecycleHelper.ApplicationStarted += (sender, e) =>
             {
                 SessionTracker?.Resume();
                 _hasStarted = true;
             };
         }
         ApplicationLifecycleHelper.ApplicationResuming  += (sender, e) => SessionTracker?.Resume();
         ApplicationLifecycleHelper.ApplicationSuspended += (sender, e) => SessionTracker?.Pause();
     }
 }
Пример #2
0
        // Internal for testing
        internal void InstanceConfigure(string appSecretOrSecrets)
        {
            if (_instanceConfigured)
            {
                throw new MobileCenterException("Multiple attempts to configure Mobile Center");
            }
            _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 = new ApplicationLifecycleHelper();

            _applicationLifecycleHelper.UnhandledExceptionOccurred += (sender, e) => _channelGroup.Shutdown();
            _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.");
        }
 internal Analytics(ISessionTrackerFactory sessionTrackerFactory, IApplicationLifecycleHelper lifecycleHelper) : this()
 {
     _sessionTrackerFactory     = sessionTrackerFactory;
     ApplicationLifecycleHelper = lifecycleHelper;
 }