Beispiel #1
0
        public static async Task Main()
        {
            /* Configuration Values */
            MyConfig configuration = InitializeConfig();

            /* Do the auth stuff first */
            IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
                                                               .Create(configuration.ClientId).WithRedirectUri("http://localhost:1234")
                                                               .Build();
            InteractiveAuthenticationProvider authenticationProvider = new InteractiveAuthenticationProvider(publicClientApplication, configuration.Scopes);

            /* Get the client */
            GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);

            /* Get a valid token in cache */
            await AcquireTokenToCache(graphClient);

            /* Create a HttpQuery for use */
            HttpQuery query = new HttpQuery(graphClient);

            /* Run the four versions */
            await Run0(graphClient);
            await Run1(query, graphClient);
            await Run2(query, graphClient);

            Run3(graphClient);
        }
Beispiel #2
0
        /// <summary>
        /// Use the HttpQuery Class to populate a dynamic type to use.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="graphClient"></param>
        /// <returns></returns>
        private static async Task Run2(HttpQuery query, GraphServiceClient graphClient)
        {
            /* Request version 2 */
            /* Uses the dynamic type */
            _globalStopwatch = Stopwatch.StartNew();
            dynamic result = await query.PopulateAsync(new
            {
                Me       = graphClient.Me.Request(),
                Calendar = graphClient.Me.Calendar.Request(),
                Drive    = graphClient.Me.Drive.Request()
            });

            Console.WriteLine("Version 2 : PopulateAsync with dynamic type");
            Console.WriteLine("Display Name user: "******"Calendar Owner Address: " + result.Calendar.owner.address);
            Console.WriteLine("Display Drive Type: " + result.Drive.driveType);
            _globalStopwatch.Stop();
            var elapsedMs = _globalStopwatch.ElapsedMilliseconds;

            Console.WriteLine($"Elapsed Time {elapsedMs}");
            Console.WriteLine("\r\n\r\n");
        }
Beispiel #3
0
        /// <summary>
        /// Use the HttpQuery class to add requests and then execute them.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="graphClient"></param>
        /// <returns></returns>
        private static async Task Run1(HttpQuery query, GraphServiceClient graphClient)
        {
            /* Request version 1 */
            /* Uses a callback */
            ViewModel model = new ViewModel();

            _globalStopwatch = Stopwatch.StartNew();
            query.AddRequest <User>(graphClient.Me.Request(), u => model.Me = u);
            query.AddRequest <Calendar>(graphClient.Me.Calendar.Request(), cal => model.Calendar = cal);
            query.AddRequest <Drive>(graphClient.Me.Drive.Request(), dr => model.Drive           = dr);

            await query.ExecuteAsync();//run them at the same time :)

            Console.WriteLine("Version 1 : AddRequest in typed fashion");
            Console.WriteLine("Display Name user: "******"Display Owner Address: " + model.Calendar.Owner.Address);
            Console.WriteLine("Display Drive Type: " + model.Drive.DriveType);
            _globalStopwatch.Stop();
            var elapsedMs = _globalStopwatch.ElapsedMilliseconds;

            Console.WriteLine($"Elapsed Time {elapsedMs}");
            Console.WriteLine("\r\n\r\n");
        }