Exemple #1
0
        static void CreateEvent(string userTimeZone)
        {
            // Prompt user for info

            // Require a subject
            var subject = GetUserInput("subject", true,
                                       (input) => {
                return(GetUserYesNo($"Subject: {input} - is that right?"));
            });

            // Attendees are optional
            var attendeeList = new List <string>();

            if (GetUserYesNo("Do you want to invite attendees?"))
            {
                string attendee = null;

                do
                {
                    attendee = GetUserInput("attendee", false,
                                            (input) => {
                        return(GetUserYesNo($"{input} - add attendee?"));
                    });

                    if (!string.IsNullOrEmpty(attendee))
                    {
                        attendeeList.Add(attendee);
                    }
                }while (!string.IsNullOrEmpty(attendee));
            }

            var startString = GetUserInput("event start", true,
                                           (input) => {
                // Validate that input is a date
                return(DateTime.TryParse(input, out var result));
            });

            var start = DateTime.Parse(startString);

            var endString = GetUserInput("event end", true,
                                         (input) => {
                // Validate that input is a date
                // and is later than start
                return(DateTime.TryParse(input, out var result) &&
                       result.CompareTo(start) > 0);
            });

            var end = DateTime.Parse(endString);

            var body = GetUserInput("body", false,
                                    (input => { return(true); }));

            Console.WriteLine($"Subject: {subject}");
            Console.WriteLine($"Attendees: {string.Join(";", attendeeList)}");
            Console.WriteLine($"Start: {start.ToString()}");
            Console.WriteLine($"End: {end.ToString()}");
            Console.WriteLine($"Body: {body}");
            if (GetUserYesNo("Create event?"))
            {
                GraphHelper.CreateEvent(
                    userTimeZone,
                    subject,
                    start,
                    end,
                    attendeeList,
                    body).Wait();
            }
            else
            {
                Console.WriteLine("Canceled.");
            }
        }
        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. List calendar events");

                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
                    break;

                default:
                    Console.WriteLine("Invalid choice! Please try again.");
                    break;
                }
            }
        }
Exemple #3
0
        static async System.Threading.Tasks.Task 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 tenantId     = appConfig["tenantId"];
            var clientSecret = appConfig["clientSecret"];

            // Initialize the auth provider with values from appsettings.json
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                                                                           .Create(appId)
                                                                           .WithTenantId(tenantId)
                                                                           .WithClientSecret(clientSecret)
                                                                           .Build();


            //Install-Package Microsoft.Graph.Auth -PreRelease
            ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

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

            int choice = -1;

            while (choice != 0)
            {
                Console.WriteLine("Please choose one of the following options:");
                Console.WriteLine("0. Exit");
                Console.WriteLine("1. Get meeting's members");
                Console.WriteLine("2. Get call's attendance");

                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:
                    Console.WriteLine("Please input the meetingId");
                    string meetingId = Console.ReadLine();
                    var    members   = await GraphHelper.GetTeamMembers(meetingId);

                    foreach (User member in members.ToList())
                    {
                        Console.WriteLine("Found member: " + member.DisplayName);
                    }
                    //var meeting = await GraphHelper.GetMeeting("https://teams.microsoft.com/l/meetup-join/19%3ameeting_NTg3ZGQ5YjYtNjI1Ny00ZTQ4LTg0ZWMtMmI4ZjZkYjJkNGRj%40thread.v2/0?context=%7b%22Tid%22%3a%221aed5afa-c363-478e-ae14-b73b6949addb%22%2c%22Oid%22%3a%228b406a47-ed00-45cb-ad12-cd01d6143bbb%22%7d");
                    break;

                case 2:
                    Console.WriteLine("Please input the callId");
                    string callId = Console.ReadLine();
                    //var callRecord = await GraphHelper.GetCallRecord(callId != "" ? callId : "f4ea5721-a7b5-44ee-8ceb-9dfa7a6dd41e");
                    var callRecord = await GraphHelper.GetCallRecordSessions(callId != ""?callId : "f4ea5721-a7b5-44ee-8ceb-9dfa7a6dd41e");

                    var joinWebUrl = callRecord.JoinWebUrl;
                    if (joinWebUrl == null)
                    {
                        break;
                    }
                    foreach (Session session in callRecord.Sessions)
                    {
                        ParticipantEndpoint caller = (ParticipantEndpoint)session.Caller;
                        var user = await GraphHelper.GetUserAsync(caller.Identity.User.Id);

                        //TODO - Find the mapping between this userId and the university's student ID.
                        StudentEvent studentEvent = new StudentEvent
                        {
                            //TODO - Find course ID based on joinWebUrl.
                            CourseID     = "COMP0088", // Course ID Upper case.
                            Timestamp    = ((DateTimeOffset)session.StartDateTime).UtcDateTime,
                            EventType    = EventType.Attendance,
                            ActivityType = "Meeting",
                            ActivityName = "Weekly Lecture",
                            Student      = new Student
                            {
                                Email     = user.Mail,
                                FirstName = user.GivenName,
                                LastName  = user.Surname,
                                ID        = user.Id
                            }
                        };
                        Console.WriteLine(studentEvent.ToString());
                        //_eventAggregator.ProcessEvent(studentEvent);
                    }
                    break;

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