示例#1
0
        // Gets the first instance of an app sceret and/or target token corresponding to the given platform name, or returns the string
        // as-is if no identifier can be found. Logs a message if no identifiers can be found.
        internal static string GetSecretAndTargetForPlatform(string secrets, string platformIdentifier)
        {
            var platformTargetIdentifier = platformIdentifier + TargetKeyNameUpper;

            if (string.IsNullOrEmpty(secrets))
            {
                throw new AppCenterException("App secrets string is null or empty");
            }

            // If there are no equals signs, then there are no named identifiers, but log a message in case the developer made
            // a typing error.
            if (!secrets.Contains(PlatformKeyValueDelimiter))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "No named identifier found in appSecret; using as-is");
                return(secrets);
            }

            // Iterate over matching patterns.
            var secretsDictionary = new Dictionary <string, string>();
            var matches           = _secretsRegex.Matches(secrets);

            foreach (Match match in matches)
            {
                secretsDictionary[match.Groups[1].Value] = match.Groups[2].Value;
            }

            // Extract the secrets for the current platform.
            if (secretsDictionary.ContainsKey(TargetKeyName))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "Found 'target=' identifier in the secret; using as-is.");
                return(secrets);
            }
            if (secretsDictionary.ContainsKey(AppSecretKeyName))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "Found 'appSecret=' identifier in the secret; using as-is.");
                return(secrets);
            }
            var platformSecret      = string.Empty;
            var platformTargetToken = string.Empty;

            if (secretsDictionary.ContainsKey(platformIdentifier))
            {
                secretsDictionary.TryGetValue(platformIdentifier, out platformSecret);
            }
            if (secretsDictionary.ContainsKey(platformTargetIdentifier))
            {
                secretsDictionary.TryGetValue(platformTargetIdentifier, out platformTargetToken);
            }
            if (string.IsNullOrEmpty(platformSecret) && string.IsNullOrEmpty(platformTargetToken))
            {
                throw new AppCenterException($"Error parsing key for '{platformIdentifier}'");
            }

            // Format the string as "appSecret={};target={}" or "target={}" if needed.
            if (!string.IsNullOrEmpty(platformTargetToken))
            {
                // If there is an app secret
                if (!string.IsNullOrEmpty(platformSecret))
                {
                    platformSecret = AppSecretKeyName + PlatformKeyValueDelimiter + platformSecret + SecretDelimiter;
                }
                platformSecret += TargetKeyName + PlatformKeyValueDelimiter + platformTargetToken;
            }
            return(platformSecret);
        }
 static void PlatformSetUserId(string userId)
 {
     AppCenterLog.Error(AppCenterLog.LogTag, "AppCenter.SetUserId is not supported on UWP.");
 }
示例#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 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
                {
                    // 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);
                        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);
                }
            }
        }
示例#4
0
        // Gets the first instance of an app sceret and/or target token corresponding to the given platform name, or returns the string
        // as-is if no identifier can be found. Logs a message if no identifiers can be found.
        internal static string GetSecretAndTargetForPlatform(string secrets, string platformIdentifier)
        {
            var platformTargetIdentifier = platformIdentifier + TargetKeyNameUpper;

            if (string.IsNullOrEmpty(secrets))
            {
                throw new AppCenterException("App secrets string is null or empty");
            }

            // If there are no equals signs, then there are no named identifiers, but log a message in case the developer made
            // a typing error.
            if (!secrets.Contains(PlatformKeyValueDelimiter))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "No named identifier found in appSecret; using as-is");
                return(secrets);
            }

            // Grouping by the name of the key.
            var secretsGroup = secrets.Split(SecretDelimiter.ToCharArray())
                               .Select(value => value.Split(PlatformKeyValueDelimiter.ToCharArray()))
                               .GroupBy(p => p[0] ?? "");

            // Create a dictionary choosing the last secret value for each key. If the key has more than one secret value then select the last of them.
            var secretsDictionary = secretsGroup.ToDictionary(pair => pair.Key, pair => pair.Last().Last());

            if (secretsDictionary.ContainsKey(TargetKeyName))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "Found 'target=' identifier in the secret; using as-is.");
                return(secrets);
            }
            if (secretsDictionary.ContainsKey(AppSecretKeyName))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "Found 'appSecret=' identifier in the secret; using as-is.");
                return(secrets);
            }
            var platformSecret      = string.Empty;
            var platformTargetToken = string.Empty;

            if (secretsDictionary.ContainsKey(platformIdentifier))
            {
                secretsDictionary.TryGetValue(platformIdentifier, out platformSecret);
            }
            if (secretsDictionary.ContainsKey(platformTargetIdentifier))
            {
                secretsDictionary.TryGetValue(platformTargetIdentifier, out platformTargetToken);
            }
            if (string.IsNullOrEmpty(platformSecret) && string.IsNullOrEmpty(platformTargetToken))
            {
                throw new AppCenterException($"Error parsing key for '{platformIdentifier}'");
            }

            // Format the string as "appSecret={};target={}" or "target={}" if needed.
            if (!string.IsNullOrEmpty(platformTargetToken))
            {
                // If there is an app secret
                if (!string.IsNullOrEmpty(platformSecret))
                {
                    platformSecret = AppSecretKeyName + PlatformKeyValueDelimiter + platformSecret + SecretDelimiter;
                }
                platformSecret += TargetKeyName + PlatformKeyValueDelimiter + platformTargetToken;
            }
            return(platformSecret);
        }