Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine(".Net Core Tutorial for Graph API");

            var appConfig = LoadAppSettings();

            if (appConfig == null)
            {
                Console.WriteLine("Missing or invalid appsettings.json...exiting");
                return;
            }

            var appId  = appConfig["appId"];
            var scopes = appConfig.GetSection("scopes").Get <string[]>();

            // Initialize the auth provider with values from appsettings.json
            var authProvider = new DeviceCodeAuthProvider(appId, scopes);

            // Request a token to sign in the user
            var accessToken = authProvider.GetAccessToken().Result;
//***********************************************************************

            int choice = -1;

            while (choice != 0)
            {
                Console.WriteLine("0. To exit");
                Console.WriteLine("1. Display access token");
                Console.WriteLine("2. To exit");
                choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 0:
                    break;

                case 1:
                    //display access token
                    Console.WriteLine($"Access token: {accessToken}\n");

                    break;

                case 2:
                    // display calendar events
                    Console.WriteLine("The Calendar events are: ");
                    break;
                }
            }
        }
Пример #2
0
        public void RunExcelTask()
        {
            var appConfig = LoadAppSettings();

            if (appConfig == null)
            {
                Console.WriteLine("Missing or invalid appsettings.json...exiting");
                return;
            }

            var appId  = appConfig["appId"];
            var scopes = appConfig.GetSection("scopes").Get <string[]>();

            var authProvider = new DeviceCodeAuthProvider(appId, scopes);

            this.writer.Write("----------Task : Search for unique values in the excel file from the OneDrive.\n");
            var accessToken = authProvider.GetAccessToken().Result;

            GetUniqueValuesOneDrive();
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine(".NET Core Graph Tutorial\n");

            var appConfig = LoadAppSettings();

            if (appConfig == null)
            {
                Console.WriteLine("Missing or invalid appsettings.json...exiting");
                return;
            }

            var appId        = appConfig["appId"];
            var scopesString = appConfig["scopes"];
            var scopes       = scopesString.Split(';');

            // Initialize the auth provider with values from appsettings.json
            var authProvider = new DeviceCodeAuthProvider(appId, scopes);

            // Request a token to sign in the user
            var accessToken = authProvider.GetAccessToken().Result;

            // Initialize Graph client
            GraphHelper.Initialize(authProvider);

            // Get signed in user
            var user = GraphHelper.GetMeAsync().Result;

            Console.WriteLine($"Welcome {user.DisplayName}!\n");

            int choice = -1;

            while (choice != 0)
            {
                Console.WriteLine("Please choose one of the following options:");
                Console.WriteLine("0. Exit");
                Console.WriteLine("1. Display access token");
                Console.WriteLine("2. View this week's calendar");
                Console.WriteLine("3. Add an event");

                try
                {
                    choice = int.Parse(Console.ReadLine());
                }
                catch (System.FormatException)
                {
                    // Set to invalid value
                    choice = -1;
                }

                switch (choice)
                {
                case 0:
                    // Exit the program
                    Console.WriteLine("Goodbye...");
                    break;

                case 1:
                    // Display access token
                    Console.WriteLine($"Access token: {accessToken}\n");
                    break;

                case 2:
                    // List the calendar
                    ListCalendarEvents(
                        user.MailboxSettings.TimeZone,
                        $"{user.MailboxSettings.DateFormat} {user.MailboxSettings.TimeFormat}"
                        );
                    break;

                case 3:
                    // Create a new event
                    CreateEvent(user.MailboxSettings.TimeZone);
                    break;

                default:
                    Console.WriteLine("Invalid choice! Please try again.");
                    break;
                }
            }
        }