static async Task MainMT(string[] args) { var authProvider = new DeviceCodeAuthProvider(); //graphClient = new GraphServiceClient(authProvider); using HttpClient client = new HttpClient(new HttpClientHandler() { MaxConnectionsPerServer = 1440 }); graphClient = new GraphServiceClient(client); graphClient.AuthenticationProvider = authProvider; await DbOperations.ClearResourcesAsync(); Console.WriteLine("Clear DB .."); Console.WriteLine("Start Watching.."); perf.StartOn = DateTime.UtcNow; perf.TeamsCount = noTeams; //await RunBatchAsync(); await BatchRequestExample(graphClient, 20); //await WatchTeamsAsync(noTeams); perf.ActivitiesCalls = activitiesCalls; perf.DeltaCalls = libraryDeltaCalls; perf.Duration = (int)DateTime.UtcNow.Subtract(perf.StartOn).TotalSeconds; perf.CompletedOn = DateTime.UtcNow; perf.AverageSyncDuration = DbOperations.GetAverageSync(); perf.TotalDuration = totalDuration; perf.NoOfRuns = noOfRuns; perf.AvgDuration = totalDuration / noOfRuns; await DbOperations.UpdatePerformanceAsync(perf); Console.WriteLine($"Teams={perf.TeamsCount} - DeltaCalls={perf.DeltaCalls} - ActivitiesCalls={perf.ActivitiesCalls} - AverageSyncDuration={perf.AverageSyncDuration}"); }
private static DeviceCodeAuthProvider CreateDeviceCodeAuthProvider(CalendarInformationRequest.Types.Client client) { var authority = string.Join('/', BaseAuthorityUrl, client.TenantId); var authProvider = new DeviceCodeAuthProvider(client.ClientId, client.ClientSecret, authority); return(authProvider); }
public IGraphServiceClient InitializeAccount() { var authProvider = new DeviceCodeAuthProvider( _configuration.ClientId, _configuration.Scopes.Split(';')); return(new GraphServiceClient(authProvider)); }
static async Task Main(string[] args) { var appConfig = LoadAppSettings(); var authProvider = new DeviceCodeAuthProvider( appConfig["AzureAppId"], _scopes); _graphClient = new GraphServiceClient(authProvider); await WatchMailFolders(_pollIntervalInSecs); }
//Start the program private static async Task start() { // Initialize the auth provider with values from appsettings.json var authProvider = new DeviceCodeAuthProvider(appID, scopes); // Initialize Graph client TaskHelper.Initialize(authProvider); //Create new folder for storing data if not already created System.IO.Directory.CreateDirectory( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\todo\\"); // Get signed in user var user = TaskHelper.GetMeAsync().Result; Console.WriteLine($"Welcome {user.DisplayName}!"); //make new task because it doesnt work unless i do this or smth var newTask = new TodoTask { ODataType = null, Title = getTitle() }; //Get title //ID for the list to add the task to var listID = getLists().Result; //Setup the date and time for the task/reminder Console.WriteLine("Date: Format: YYYY-MM-DD (Empty for today)"); var dateString = getDate(); Console.Write("Time: "); var newTime = getTime(); //Set all the juicy task info var reminderTime = new DateTimeTimeZone { ODataType = null,//Required for whatever reason TimeZone = TimeZoneInfo.Local.StandardName, DateTime = dateString + "T" + newTime.TimeOfDay + ".0000000" }; newTask.ReminderDateTime = reminderTime; //No set time if (newTime.TimeOfDay.ToString() != "") { newTask.ReminderDateTime = reminderTime; } newTask.DueDateTime = reminderTime; //Set the due date for the reminder await CreateTask(newTask, listID); }
static async Task MainST(string[] args) { await DbOperations.ClearResourcesAsync(); Console.WriteLine("Clear DB .."); Console.WriteLine("Start Watching.."); var authProvider = new DeviceCodeAuthProvider(); graphClient = new GraphServiceClient(authProvider); await WatchTeamsAsync(); endTime = DateTime.UtcNow; }
public IGraphServiceClient InitializeMail(IMicrosoftGraphService graphService, string email) { try { var authProvider = new DeviceCodeAuthProvider( _configuration.ClientId, _configuration.Scopes.Split(';'), graphService, email); return(new GraphServiceClient(authProvider)); } catch { // logger return(null); } }
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; } } }
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(); }
public GraphService(AppConfig config) { var authProvider = new DeviceCodeAuthProvider(config.Azure.AppId, config.Azure.TenantId, config.Azure.AllScopes); _graphClient = new GraphServiceClient(authProvider); }
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; } } }