private CustomProperties SetProperty(CustomProperty property)
        {
            try
            {
                property.Validate();
            }
            catch (ValidationException e)
            {
                AppCenterLog.Error(AppCenterLog.LogTag, e.Message);
                return(this);
            }
            if (Properties.Count >= MaxCustomPropertiesCount)
            {
                AppCenterLog.Error(AppCenterLog.LogTag, "Custom properties cannot contain more than " + MaxCustomPropertiesCount + " items.");
                return(this);
            }
            CustomProperty existingPropertyToRemove = null;

            foreach (var existingProperty in Properties)
            {
                if (existingProperty.Name == property.Name)
                {
                    existingPropertyToRemove = existingProperty;
                    break;
                }
            }
            if (existingPropertyToRemove != null)
            {
                AppCenterLog.Warn(AppCenterLog.LogTag, "Custom property \"" + property.Name + "\" is already set or cleared and will be overwritten.");
                Properties.Remove(existingPropertyToRemove);
            }
            Properties.Add(property);
            return(this);
        }
        internal void StartInstance(params Type[] services)
        {
            if (services == null)
            {
                throw new AppCenterException("Services array is null.");
            }
            if (!_instanceConfigured)
            {
                throw new AppCenterException("App Center has not been configured.");
            }

            var serviceNames = new List <string>();

            foreach (var serviceType in services)
            {
                if (serviceType == null)
                {
                    AppCenterLog.Warn(AppCenterLog.LogTag, "Skipping null service. Please check that you did not pass a null argument.");
                    continue;
                }
                try
                {
                    var serviceInstance = serviceType.GetRuntimeProperty("Instance")?.GetValue(null) as IAppCenterService;
                    if (serviceInstance == null)
                    {
                        throw new AppCenterException("Service type does not contain static 'Instance' property of type IAppCenterService. The service is either not an App Center service or it's unsupported on this platform or the SDK is used from a .NET standard library and the nuget was not also added to the UWP/WPF/WinForms project.");
                    }
                    StartService(serviceInstance);
                    serviceNames.Add(serviceInstance.ServiceName);
                }
                catch (AppCenterException e)
                {
                    AppCenterLog.Error(AppCenterLog.LogTag, $"Failed to start service '{serviceType.Name}'; skipping it.", e);
                }
            }

            // Enqueue a log indicating which services have been initialized
            if (serviceNames.Count > 0)
            {
                if (InstanceEnabled)
                {
                    _channel.EnqueueAsync(new StartServiceLog {
                        Services = serviceNames
                    });
                }
                else
                {
                    if (_startedServiceNames == null)
                    {
                        _startedServiceNames = new List <string>();
                    }
                    _startedServiceNames.AddRange(serviceNames);
                }
            }
        }
예제 #3
0
        internal void StartInstance(params Type[] services)
        {
            if (services == null)
            {
                throw new AppCenterException("Services array is null.");
            }
            if (!_instanceConfigured)
            {
                throw new AppCenterException("App Center has not been configured.");
            }

            var startServiceLog = new StartServiceLog();

            foreach (var serviceType in services)
            {
                if (serviceType == null)
                {
                    AppCenterLog.Warn(AppCenterLog.LogTag, "Skipping null service. Please check that you did not pass a null argument.");
                    continue;
                }
                try
                {
                    // We don't support distribute in UWP, not even a custom start.
                    if (IsDistributeService(serviceType))
                    {
                        AppCenterLog.Warn(AppCenterLog.LogTag, "Distribute service is not yet supported on UWP.");
                    }
                    else
                    {
                        var serviceInstance = serviceType.GetRuntimeProperty("Instance")?.GetValue(null) as IAppCenterService;
                        if (serviceInstance == null)
                        {
                            throw new AppCenterException("Service type does not contain static 'Instance' property of type IAppCenterService");
                        }
                        StartService(serviceInstance);
                        startServiceLog.Services.Add(serviceInstance.ServiceName);
                    }
                }
                catch (AppCenterException e)
                {
                    AppCenterLog.Error(AppCenterLog.LogTag, $"Failed to start service '{serviceType.Name}'; skipping it.", e);
                }
            }

            // Enqueue a log indicating which services have been initialized
            if (startServiceLog.Services.Count > 0)
            {
                _channel.EnqueueAsync(startServiceLog);
            }
        }
예제 #4
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.");
 }
예제 #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.");
        }