コード例 #1
0
        public static async Task <CacheExecutorResults> ExecuteAsync(
            ILanguageExecutor languageExecutor,
            string clientId,
            string authority,
            string scope,
            string username,
            string userPassword,
            string msalV3CacheFilePath,
            CancellationToken cancellationToken)
        {
            try
            {
                var processRunResults = await languageExecutor.ExecuteAsync(
                    clientId,
                    authority,
                    scope,
                    username,
                    userPassword,
                    msalV3CacheFilePath,
                    CancellationToken.None).ConfigureAwait(false);

                string stdout = processRunResults.StandardOut;

                Console.WriteLine();
                Console.WriteLine("PYTHON STDOUT");
                Console.WriteLine(stdout);
                Console.WriteLine();
                Console.WriteLine("PYTHON STDERR");
                Console.WriteLine(processRunResults.StandardError);
                Console.WriteLine();

                if (stdout.Contains("**TOKEN RECEIVED FROM CACHE**"))
                {
                    return(new CacheExecutorResults(username, true));
                }
                else if (stdout.Contains("**TOKEN RECEIVED, BUT _NOT_ FROM CACHE**"))
                {
                    return(new CacheExecutorResults(username, false));
                }
                else
                {
                    Console.WriteLine("NO TOKEN REPORTED AS RECEIVED!");
                    return(new CacheExecutorResults(username, false));
                }
            }
            catch (ProcessRunException prex)
            {
                Console.WriteLine(prex.ProcessStandardOutput);
                Console.WriteLine(prex.ProcessStandardError);
                Console.WriteLine(prex.Message);
                return(new CacheExecutorResults(string.Empty, false));
            }
        }
コード例 #2
0
        public static async Task ExecuteAsync(
            ILanguageExecutor languageExecutor,
            TestInputData testInputData,
            CancellationToken cancellationToken)
        {
            try
            {
                var    v1App    = PreRegisteredApps.CommonCacheTestV1;
                string resource = PreRegisteredApps.MsGraph;
                string scope    = resource + "/user.read";

                var languageTestInputData = new LanguageTestInputData(testInputData)
                {
                    Authority     = v1App.Authority,
                    ClientId      = v1App.ClientId,
                    Scope         = scope,
                    CacheFilePath = CommonCacheTestUtils.MsalV3CacheFilePath
                };

                var    inputDataJson = JsonConvert.SerializeObject(languageTestInputData);
                string inputFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
                File.WriteAllText(inputFilePath, inputDataJson);

                var sb = new StringBuilder();
                sb.Append($"--inputPath {inputFilePath.EncloseQuotes()} ");
                string arguments = sb.ToString();

                var processRunResults = await languageExecutor.ExecuteAsync(arguments, cancellationToken).ConfigureAwait(false);

                string stdout = processRunResults.StandardOut;

                Console.WriteLine();
                Console.WriteLine("STDOUT");
                Console.WriteLine(stdout);
                Console.WriteLine();
                Console.WriteLine("STDERR");
                Console.WriteLine(processRunResults.StandardError);
                Console.WriteLine();
            }
            catch (ProcessRunException prex)
            {
                Console.WriteLine(prex.ProcessStandardOutput);
                Console.WriteLine(prex.ProcessStandardError);
                Console.WriteLine(prex.Message);
            }
        }