// 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)));
        }
Exemple #2
0
        private void SetInstanceCustomProperties(CustomProperties customProperties)
        {
            if (!Configured)
            {
                MobileCenterLog.Error(MobileCenterLog.LogTag, "Mobile Center hasn't been configured. You need to call MobileCenter.Start with appSecret or MobileCenter.Configure first.");
                return;
            }
            if (customProperties == null || customProperties.Properties.Count == 0)
            {
                MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom properties may not be null or empty");
                return;
            }
            var customPropertiesLog = new CustomPropertiesLog();

            customPropertiesLog.Properties = customProperties.Properties;
            _channel.EnqueueAsync(customPropertiesLog);
        }
Exemple #3
0
        private void SendStartSessionIfNeeded()
        {
            var now = TimeHelper.CurrentTimeInMilliseconds();

            if (SessionContext.SessionId != null && !HasSessionTimedOut(now))
            {
                return;
            }

            SessionContext.SessionId = Guid.NewGuid();
            _lastQueuedLogTime       = TimeHelper.CurrentTimeInMilliseconds();
            var startSessionLog = new StartSessionLog {
                Sid = SessionContext.SessionId
            };

            _channel.EnqueueAsync(startSessionLog).ConfigureAwait(false);
        }
        private void SendStartSessionIfNeeded()
        {
            var now = TimeHelper.CurrentTimeInMilliseconds();

            if (_sid != Guid.Empty && !HasSessionTimedOut(now))
            {
                return;
            }
            _sid = Guid.NewGuid();
#pragma warning disable CS0612 // Type or member is obsolete
            AppCenter.TestAndSetCorrelationId(Guid.Empty, ref _sid);
#pragma warning restore CS0612 // Type or member is obsolete
            _lastQueuedLogTime = TimeHelper.CurrentTimeInMilliseconds();
            var startSessionLog = new StartSessionLog {
                Sid = _sid
            };
            _channel.EnqueueAsync(startSessionLog);
        }
        private void SendStartSessionIfNeeded()
        {
            var now = TimeHelper.CurrentTimeInMilliseconds();

            if (_sid != Guid.Empty && !HasSessionTimedOut(now))
            {
                return;
            }
            if (_sessions.Count == StorageMaxSessions)
            {
                _sessions.Remove(_sessions.Keys.Min());
            }
            _sid = Guid.NewGuid();
#pragma warning disable CS0612 // Type or member is obsolete
            MobileCenter.TestAndSetCorrelationId(Guid.Empty, ref _sid);
#pragma warning restore CS0612 // Type or member is obsolete
            _sessions.Add(now, _sid);
            _applicationSettings.SetValue(StorageKey, SessionsAsString());
            _lastQueuedLogTime = TimeHelper.CurrentTimeInMilliseconds();
            var startSessionLog = new StartSessionLog {
                Sid = _sid
            };
            _channel.EnqueueAsync(startSessionLog);
        }