// That method isn't async itself but can return async task from the channel for awaiting log enqueue.
        private Task SetInstanceEnabled(bool value)
        {
            var enabledTerm = value ? "enabled" : "disabled";

            if (InstanceEnabled == value)
            {
                AppCenterLog.Info(AppCenterLog.LogTag, $"App Center has already been {enabledTerm}.");
                return(Task.FromResult(default(object)));
            }

            // Update channels state.
            _channelGroup?.SetEnabled(value);

            // Store state in the application settings.
            _applicationSettings.SetValue(EnabledKey, value);

            // Apply change to services.
            foreach (var service in _services)
            {
                service.InstanceEnabled = value;
            }
            AppCenterLog.Info(AppCenterLog.LogTag, $"App Center has been {enabledTerm}.");

            // Send started services.
            if (_startedServiceNames != null && value)
            {
                var startServiceLog = new StartServiceLog {
                    Services = _startedServiceNames
                };
                _startedServiceNames = null;
                return(_channel.EnqueueAsync(startServiceLog));
            }
            return(Task.FromResult(default(object)));
        }
예제 #2
0
 private void StartService(IAppCenterService service)
 {
     if (service == null)
     {
         throw new AppCenterException("Attempted to start an invalid App Center service.");
     }
     if (_channelGroup == null)
     {
         throw new AppCenterException("Attempted to start a service after App Center has been shut down.");
     }
     if (_services.Contains(service))
     {
         AppCenterLog.Warn(AppCenterLog.LogTag, $"App Center has already started the service with class name '{service.GetType().Name}'");
         return;
     }
     service.OnChannelGroupReady(_channelGroup, _appSecret);
     _services.Add(service);
     AppCenterLog.Info(AppCenterLog.LogTag, $"'{service.GetType().Name}' service started.");
 }
        // 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 useful for wrapper SDKs and testing.
            _networkStateAdapter = new NetworkStateAdapter();
            _channelGroup        = _channelGroupFactory?.CreateChannelGroup(_appSecret, _networkStateAdapter) ?? new ChannelGroup(_appSecret, null, _networkStateAdapter);
            _channel             = _channelGroup.AddChannel(ChannelName, Constants.DefaultTriggerCount, Constants.DefaultTriggerInterval,
                                                            Constants.DefaultTriggerMaxParallelRequests);
            _channel.SetEnabled(InstanceEnabled);
            if (_logUrl != null)
            {
                _channelGroup.SetLogUrl(_logUrl);
            }
            _instanceConfigured = true;
            AppCenterLog.Info(AppCenterLog.LogTag, "App Center SDK configured successfully.");
        }