Пример #1
0
        public void Dispose()
        {
            // Arrange
            var connectionInfo = new JwtConnectionInfo(API_KEY, API_SECRET);
            var client         = new ZoomClient(connectionInfo, (IWebProxy)null);

            // Act
            client.Dispose();

            // Assert
            // Nothing to assert. We just want to confirm that 'Dispose' did not throw any exception
        }
Пример #2
0
        public JwtTokenHandler(JwtConnectionInfo connectionInfo, TimeSpan?tokenLifeSpan = null, TimeSpan?clockSkew = null)
        {
            if (string.IsNullOrEmpty(connectionInfo.ApiKey))
            {
                throw new ArgumentNullException(nameof(connectionInfo.ApiKey));
            }
            if (string.IsNullOrEmpty(connectionInfo.ApiSecret))
            {
                throw new ArgumentNullException(nameof(connectionInfo.ApiSecret));
            }

            _connectionInfo  = connectionInfo;
            _tokenLifeSpan   = tokenLifeSpan.GetValueOrDefault(TimeSpan.FromMinutes(30));
            _clockSkew       = clockSkew.GetValueOrDefault(TimeSpan.FromMinutes(5));
            _tokenExpiration = DateTime.MinValue;
        }
        public static List <User> GetZoomUsers(string apikey, string apisecret)
        {
            var connectionInfo = new JwtConnectionInfo(apikey, apisecret);
            var zoomClient     = new ZoomClient(connectionInfo);

            List <User> userlist   = new List <User>();
            int         pagenumber = 1;

            // Iterate through all pages and load all users in the account. As Zoom provide maximum 300 users to be loaded in one api call.
            while (true)
            {
                PaginatedResponse <User> paginateduserlist = zoomClient.Users.GetAllAsync(UserStatus.Active, null, 300, pagenumber).Result;
                userlist.AddRange(paginateduserlist.Records);

                if (paginateduserlist.PageCount == pagenumber)
                {
                    break;
                }
                pagenumber++;
            }


            return(userlist);
        }
Пример #4
0
        public async Task <int> RunAsync()
        {
            // -----------------------------------------------------------------------------
            // Do you want to proxy requests through Fiddler? Can be useful for debugging.
            var useFiddler  = true;
            var fiddlerPort = 8866;             // By default Fiddler4 uses port 8888 and Fiddler Everywhere uses port 8866

            // Do you want to use JWT or OAuth?
            var connectionMethod = ConnectionMethods.OAuth;
            // -----------------------------------;------------------------------------------

            // Configure ZoomNet client
            IConnectionInfo connectionInfo;

            if (connectionMethod == ConnectionMethods.Jwt)
            {
                var apiKey    = Environment.GetEnvironmentVariable("ZOOM_JWT_APIKEY", EnvironmentVariableTarget.User);
                var apiSecret = Environment.GetEnvironmentVariable("ZOOM_JWT_APISECRET", EnvironmentVariableTarget.User);
                connectionInfo = new JwtConnectionInfo(apiKey, apiSecret);
            }
            else
            {
                var clientId     = Environment.GetEnvironmentVariable("ZOOM_OAUTH_CLIENTID", EnvironmentVariableTarget.User);
                var clientSecret = Environment.GetEnvironmentVariable("ZOOM_OAUTH_CLIENTSECRET", EnvironmentVariableTarget.User);
                var refreshToken = Environment.GetEnvironmentVariable("ZOOM_OAUTH_REFRESHTOKEN", EnvironmentVariableTarget.User);
                var accessToken  = Environment.GetEnvironmentVariable("ZOOM_OAUTH_ACCESSTOKEN", EnvironmentVariableTarget.User);
                connectionInfo = new OAuthConnectionInfo(clientId, clientSecret, refreshToken, accessToken,
                                                         (newRefreshToken, newAccessToken) =>
                {
                    Environment.SetEnvironmentVariable("ZOOM_OAUTH_REFRESHTOKEN", newRefreshToken, EnvironmentVariableTarget.User);
                    Environment.SetEnvironmentVariable("ZOOM_OAUTH_ACCESSTOKEN", newAccessToken, EnvironmentVariableTarget.User);
                });

                //var authorizationCode = "<-- the code generated by Zoom when the app is authorized by the user -->";
                //connectionInfo = new OAuthConnectionInfo(clientId, clientSecret, authorizationCode,
                //	(newRefreshToken, newAccessToken) =>
                //	{
                //		Environment.SetEnvironmentVariable("ZOOM_OAUTH_REFRESHTOKEN", newRefreshToken, EnvironmentVariableTarget.User);
                //		Environment.SetEnvironmentVariable("ZOOM_OAUTH_ACCESSTOKEN", newAccessToken, EnvironmentVariableTarget.User);
                //	});
            }

            var userId = Environment.GetEnvironmentVariable("ZOOM_USERID");
            var proxy  = useFiddler ? new WebProxy($"http://localhost:{fiddlerPort}") : null;
            var client = new ZoomClient(connectionInfo, proxy, null, _loggerFactory.CreateLogger <ZoomClient>());

            // Configure Console
            var source = new CancellationTokenSource();

            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                source.Cancel();
            };

            // Ensure the Console is tall enough and centered on the screen
            Console.WindowHeight = Math.Min(60, Console.LargestWindowHeight);
            Utils.CenterConsole();

            // These are the integration tests that we will execute
            var integrationTests = new Type[]
            {
                typeof(Meetings),
                typeof(Users),
                typeof(Webinars),
            };

            // Execute the async tests in parallel (with max degree of parallelism)
            var results = await integrationTests.ForEachAsync(
                async testType =>
            {
                var log = new StringWriter();

                try
                {
                    var integrationTest = (IIntegrationTest)Activator.CreateInstance(testType);
                    await integrationTest.RunAsync(userId, client, log, source.Token).ConfigureAwait(false);
                    return(TestName : testType.Name, ResultCode : ResultCodes.Success, Message : SUCCESSFUL_TEST_MESSAGE);
                }
                catch (OperationCanceledException)
                {
                    await log.WriteLineAsync($"-----> TASK CANCELLED").ConfigureAwait(false);
                    return(TestName : testType.Name, ResultCode : ResultCodes.Cancelled, Message : "Task cancelled");
                }
                catch (Exception e)
                {
                    var exceptionMessage = e.GetBaseException().Message;
                    await log.WriteLineAsync($"-----> AN EXCEPTION OCCURRED: {exceptionMessage}").ConfigureAwait(false);
                    return(TestName : testType.Name, ResultCode : ResultCodes.Exception, Message : exceptionMessage);
                }
                finally
                {
                    lock (Console.Out)
                    {
                        Console.Out.WriteLine(log.ToString());
                    }
                }
            }, MAX_ZOOM_API_CONCURRENCY)
                          .ConfigureAwait(false);

            // Display summary
            var summary = new StringWriter();
            await summary.WriteLineAsync("\n\n**************************************************").ConfigureAwait(false);

            await summary.WriteLineAsync("******************** SUMMARY *********************").ConfigureAwait(false);

            await summary.WriteLineAsync("**************************************************").ConfigureAwait(false);

            foreach (var(TestName, ResultCode, Message) in results.OrderBy(r => r.TestName).ToArray())
            {
                var name = TestName.Length <= TEST_NAME_MAX_LENGTH ? TestName : TestName.Substring(0, TEST_NAME_MAX_LENGTH - 3) + "...";
                await summary.WriteLineAsync($"{name.PadRight(TEST_NAME_MAX_LENGTH, ' ')} : {Message}").ConfigureAwait(false);
            }

            await summary.WriteLineAsync("**************************************************").ConfigureAwait(false);

            await Console.Out.WriteLineAsync(summary.ToString()).ConfigureAwait(false);

            // Prompt user to press a key in order to allow reading the log in the console
            var promptLog = new StringWriter();
            await promptLog.WriteLineAsync("\n\n**************************************************").ConfigureAwait(false);

            await promptLog.WriteLineAsync("Press any key to exit").ConfigureAwait(false);

            Utils.Prompt(promptLog.ToString());

            // Return code indicating success/failure
            var resultCode = (int)ResultCodes.Success;

            if (results.Any(result => result.ResultCode != ResultCodes.Success))
            {
                if (results.Any(result => result.ResultCode == ResultCodes.Exception))
                {
                    resultCode = (int)ResultCodes.Exception;
                }
                else if (results.Any(result => result.ResultCode == ResultCodes.Cancelled))
                {
                    resultCode = (int)ResultCodes.Cancelled;
                }
                else
                {
                    resultCode = (int)results.First(result => result.ResultCode != ResultCodes.Success).ResultCode;
                }
            }

            return(await Task.FromResult(resultCode));
        }