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);
        }
 /// <summary>
 /// Sets the two-letter ISO country code to send to the backend.
 /// </summary>
 /// <param name="countryCode">The two-letter ISO country code. See <see href="https://www.iso.org/obp/ui/#search"/> for more information.</param>
 public static void SetCountryCode(string countryCode)
 {
     if (countryCode != null && countryCode.Length != 2)
     {
         AppCenterLog.Error(AppCenterLog.LogTag, "App Center accepts only the two-letter ISO country code.");
         return;
     }
     DeviceInformationHelper.SetCountryCode(countryCode);
 }
        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);
                }
            }
        }
 static void PlatformStart(params Type[] services)
 {
     lock (AppCenterLock)
     {
         try
         {
             Instance.StartInstance(services);
         }
         catch (AppCenterException ex)
         {
             AppCenterLog.Error(AppCenterLog.LogTag, StartErrorMessage, ex);
         }
     }
 }
 static void PlatformConfigure(string appSecret)
 {
     lock (AppCenterLock)
     {
         try
         {
             Instance.InstanceConfigure(appSecret);
         }
         catch (AppCenterException ex)
         {
             AppCenterLog.Error(AppCenterLog.LogTag, ConfigurationErrorMessage, ex);
         }
     }
 }
예제 #6
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);
            }
        }
 private void SetInstanceCustomProperties(CustomProperties customProperties)
 {
     if (!Configured)
     {
         AppCenterLog.Error(AppCenterLog.LogTag, NotConfiguredMessage);
         return;
     }
     if (customProperties == null || customProperties.Properties.Count == 0)
     {
         AppCenterLog.Error(AppCenterLog.LogTag, "Custom properties may not be null or empty");
         return;
     }
     _channel.EnqueueAsync(new CustomPropertyLog {
         Properties = customProperties.Properties
     });
 }
예제 #8
0
        private void SetInstanceCustomProperties(CustomProperties customProperties)
        {
            if (!Configured)
            {
                AppCenterLog.Error(AppCenterLog.LogTag, "App Center hasn't been configured. " +
                                   "You need to call AppCenter.Start with appSecret or AppCenter.Configure first.");
                return;
            }
            if (customProperties == null || customProperties.Properties.Count == 0)
            {
                AppCenterLog.Error(AppCenterLog.LogTag, "Custom properties may not be null or empty");
                return;
            }
            var customPropertiesLog = new CustomPropertyLog();

            customPropertiesLog.Properties = customProperties.Properties;
            _channel.EnqueueAsync(customPropertiesLog);
        }
 static void PlatformStart(string appSecret, params Type[] services)
 {
     lock (AppCenterLock)
     {
         try
         {
             Instance.InstanceConfigure(appSecret);
         }
         catch (AppCenterException ex)
         {
             AppCenterLog.Error(AppCenterLog.LogTag, ConfigurationErrorMessage, ex);
         }
         try
         {
             Instance.StartInstance(services);
         }
         catch (AppCenterException ex)
         {
             AppCenterLog.Error(AppCenterLog.LogTag, StartErrorMessage, ex);
         }
     }
 }
예제 #10
0
 static void PlatformSetUserId(string userId)
 {
     AppCenterLog.Error(AppCenterLog.LogTag, "AppCenter.SetUserId is not supported on UWP.");
 }