Пример #1
0
        /// <summary>
        /// Setup the service
        /// </summary>
        /// <param name="secrets">A list of services and their secrets that will be used in the app</param>
        public void Init(IEnumerable <ServiceSecret> secrets)
        {
            // A list of secrets must be provided
            var serviceSecrets = secrets as ServiceSecret[] ?? secrets.ToArray();

            if (!serviceSecrets.Any())
            {
                throw new Exception("No Keys Provided");
            }

            // Empty any other secrets
            ServiceSecrets.Clear();

            // Loop through all the keys and add them
            foreach (var secret in serviceSecrets)
            {
                // If there is already a service in the list, thow an exception, there
                // should only be one key for each service.
                if (ServiceSecrets.FirstOrDefault(x => x.Service == secret.Service) != null)
                {
                    throw new Exception("Only one key for each service!");
                }

                ServiceSecrets.Add(secret);
            }

            _isLoaded = true;
        }
Пример #2
0
        /// <summary>
        /// Setup the service
        /// </summary>
        /// <param name="secrets">A list of services and their secrets that will be used in the app</param>
        public void Init(List <ServiceSecret> secrets)
        {
            // A list of secrets must be provided
            if (!secrets.Any())
            {
                throw new Exception("No Keys Provided");
            }

            // Empty any other secrets
            ServiceSecrets.Clear();

            // Loop through all the keys and add them
            foreach (var secret in secrets)
            {
                // If there is already a service in the list, thow an exception, there
                // should only be one key for each service.
                if (ServiceSecrets.FirstOrDefault(x => x.Service == secret.Service) != null)
                {
                    throw new Exception("Only one key for each service!");
                }

                // If the user token is not null, we are logged in. This means we
                // have to grab the user for this service and save it. This logic
                // also serves as a way of making sure the user token is actually
                // correct. Methods for getting the current user object are different
                // for each platform, so we have to do a switch statement.
                if (secret.UserToken != null)
                {
                    try
                    {
                        switch (secret.Service)
                        {
                        case ServiceType.Fanburst:
                            secret.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <FanburstUser>(ServiceType.Fanburst, "/me")).ToBaseUser();
                            break;

                        case ServiceType.SoundCloud:
                        case ServiceType.SoundCloudV2:
                            secret.CurrentUser = AsyncHelper.RunSync(async() => await GetAsync <SoundCloudUser>(ServiceType.SoundCloud, "/me")).ToBaseUser();
                            break;

                        case ServiceType.YouTube:
                            // Do this later
                            break;
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }

                ServiceSecrets.Add(secret);
            }

            _isLoaded = true;
        }