private void OnUnhandledExceptionOccurred(object sender, UnhandledExceptionOccurredEventArgs args)
 {
     lock (AppCenterLock)
     {
         if (_channelGroup != null)
         {
             AppCenterLog.Debug(AppCenterLog.LogTag, "Shutting down channel group due to unhandled exception.");
             _channelGroup.ShutdownAsync();
             _channelGroup = null;
         }
     }
 }
예제 #2
0
        // Gets the first instance of an app secret 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 GetSecretForPlatform(string secrets, string platformIdentifier)
        {
            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("="))
            {
                AppCenterLog.Debug(AppCenterLog.LogTag, "No named identifier found in appSecret; using as-is");
                return(secrets);
            }

            var parseErrorMessage = $"Error parsing key for '{platformIdentifier}'";

            var platformIndicator = platformIdentifier + "=";
            var secretIdx         = secrets.IndexOf(platformIndicator, StringComparison.Ordinal);

            if (secretIdx == -1)
            {
                throw new AppCenterException(parseErrorMessage);
            }
            secretIdx += platformIndicator.Length;
            var platformSecret = string.Empty;

            while (secretIdx < secrets.Length)
            {
                var nextChar = secrets[secretIdx++];
                if (nextChar == ';')
                {
                    break;
                }

                platformSecret += nextChar;
            }

            if (platformSecret == string.Empty)
            {
                throw new AppCenterException(parseErrorMessage);
            }

            return(platformSecret);
        }
예제 #3
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);
        }
예제 #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);
        }