/// <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)
     {
         MobileCenterLog.Error(MobileCenterLog.LogTag, $"MobileCenter accept only the two-letter ISO country code.");
         return;
     }
     DeviceInformationHelper.SetCountryCode(countryCode);
 }
Exemple #2
0
        private void SetInstanceCustomProperties(CustomProperties customProperties)
        {
            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.Enqueue(customPropertiesLog);
        }
Exemple #3
0
 public void StartInstanceAndConfigure(string appSecret, params Type[] services)
 {
     try
     {
         InstanceConfigure(appSecret);
         StartInstance(services);
     }
     catch (MobileCenterException ex)
     {
         var message = _instanceConfigured ? StartErrorMessage : ConfigurationErrorMessage;
         MobileCenterLog.Error(MobileCenterLog.LogTag, message, ex);
     }
 }
Exemple #4
0
 /// <summary>
 /// Start services.
 /// This may be called only once per service per application process lifetime.
 /// </summary>
 /// <param name="services">List of services to use.</param>
 public static void Start(params Type[] services)
 {
     lock (MobileCenterLock)
     {
         try
         {
             Instance.StartInstance(services);
         }
         catch (MobileCenterException ex)
         {
             MobileCenterLog.Error(MobileCenterLog.LogTag, StartErrorMessage, ex);
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Configure the SDK.
 /// This may be called only once per application process lifetime.
 /// </summary>
 /// <param name="appSecret">A unique and secret key used to identify the application.</param>
 public static void Configure(string appSecret)
 {
     lock (MobileCenterLock)
     {
         try
         {
             Instance.InstanceConfigure(appSecret);
         }
         catch (MobileCenterException ex)
         {
             MobileCenterLog.Error(MobileCenterLog.LogTag, ConfigurationErrorMessage, ex);
         }
     }
 }
Exemple #6
0
        internal void StartInstance(params Type[] services)
        {
            if (services == null)
            {
                throw new MobileCenterException("Services array is null.");
            }
            if (!_instanceConfigured)
            {
                throw new MobileCenterException("Mobile Center has not been configured.");
            }

            var startServiceLog = new StartServiceLog();

            foreach (var serviceType in services)
            {
                if (serviceType == null)
                {
                    MobileCenterLog.Warn(MobileCenterLog.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))
                    {
                        MobileCenterLog.Warn(MobileCenterLog.LogTag, "Distribute service is not yet supported on UWP.");
                    }
                    else
                    {
                        var serviceInstance = serviceType.GetRuntimeProperty("Instance")?.GetValue(null) as IMobileCenterService;
                        if (serviceInstance == null)
                        {
                            throw new MobileCenterException("Service type does not contain static 'Instance' property of type IMobileCenterService");
                        }
                        StartService(serviceInstance);
                        startServiceLog.Services.Add(serviceInstance.ServiceName);
                    }
                }
                catch (MobileCenterException e)
                {
                    MobileCenterLog.Error(MobileCenterLog.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);
            }
        }
Exemple #7
0
 private CustomProperties SetObject(string key, object value)
 {
     if (ValidateKey(key))
     {
         if (value == null)
         {
             MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom property \"" + key + "\" value cannot be null, did you mean to call clear?");
         }
         else
         {
             Properties[key] = value;
         }
     }
     return(this);
 }
Exemple #8
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 #9
0
 public CustomProperties PlatformSet(string key, string value)
 {
     if (ValidateKey(key))
     {
         if (value == null)
         {
             MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom property \"" + key + "\" value cannot be null, did you mean to call clear?");
         }
         else if (value.Length > MaxCustomPropertiesStringValueLength)
         {
             MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom property \"" + key + "\" value length cannot be longer than " + MaxCustomPropertiesStringValueLength + " characters.");
         }
         else
         {
             Properties[key] = value;
         }
     }
     return(this);
 }
Exemple #10
0
 private bool ValidateKey(string key)
 {
     if (key == null || !KeyPattern.IsMatch(key))
     {
         MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom property \"" + key + "\" must match \"" + KeyPattern + "\"");
         return(false);
     }
     if (key.Length > MaxCustomPropertiesKeyLength)
     {
         MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom property \"" + key + "\" key length cannot be longer than " + MaxCustomPropertiesKeyLength + " characters.");
         return(false);
     }
     if (Properties.ContainsKey(key))
     {
         MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom property \"" + key + "\" is already set or cleared and will be overridden.");
     }
     else if (Properties.Count >= MaxCustomPropertiesCount)
     {
         MobileCenterLog.Error(MobileCenterLog.LogTag, "Custom properties cannot contain more than " + MaxCustomPropertiesCount + " items.");
         return(false);
     }
     return(true);
 }