Esempio n. 1
0
        public static void CheckForNameChange(List <User> users, GraphServiceClient graphClient)
        {
            Queue <User> work = new Queue <User>();

            foreach (var user in users)
            {
                work.Enqueue(user);
            }

            int wait = 0;

            while (work.Count > 0)
            {
                wait++;
                Thread.Sleep(25);

                var temp = work.Dequeue();

                /*
                 * User teneoUser;
                 * try
                 * {
                 *  teneoUser = graphClient.Users[temp.Id].Request().GetAsync().Result;
                 * }
                 * catch { teneoUser = null; }*/
                if (temp.Mail != null)
                {
                    if (temp.Mail.Contains("teneo.com"))
                    {
                        Console.WriteLine(temp.DisplayName + " has been updated, sending mail.");
                        String html = System.IO.File.ReadAllText("C:/Rebrand/Misc/Notification.html");
                        html = html.Replace("TENEOAZUREFIRSTNAME", temp.GivenName);
                        // Send mail of MySite reflecting UPN change
                        Message notification = MailHelper.ComposeMail("Your Teneo Email Has Been Updated",
                                                                      html,
                                                                      new List <string>()
                        {
                            temp.Mail
                        });
                        graphClient.Me.SendMail(notification, false).Request().PostAsync();

                        // Changing OneDrive Permissions
                        //var result = UpdatePermissions("C:/Rebrand/Teneo_PEM.txt", graphClient, temp.Id);

                        //if (result != null) { OneDrive.Enqueue(result); }

                        // Send asynchronous call to permission rewrite for this user.
                    }
                    else
                    {
                        Console.WriteLine("\t" + temp.DisplayName + " has not changed yet. . . ");
                        // update user object
                        temp = graphClient.Users[temp.Id].Request().GetAsync().Result;
                        Console.WriteLine("\tupdated user object and re-queueing.");
                        work.Enqueue(temp);
                    }
                }

                /* List<String> moreToDo = new List<String>();
                 * if (wait == 25)
                 * {
                 *   for(int x = 0; x < OneDrive.Count;x++)
                 *   {
                 *       var moreWork = OneDrive.Dequeue();
                 *       var stillMore = UpdatePermissions("C:/Rebrand/Teneo_PEM.txt", graphClient, moreWork);
                 *
                 *       if (stillMore != null) { moreToDo.Add(stillMore); }
                 *   }
                 * }
                 *
                 * OneDrive = new Queue<string>(moreToDo);*/
            }
        }