Example #1
0
        /// <summary>
        /// Get a list of ADConnectors.User created since a give date
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="earliest"></param>
        /// <returns></returns>
        private static (List <User>, List <Dictionary <string, string> >) CheckNewAccount(IConfiguration configuration, DateTime earliest)
        {
            List <User> users = new List <User>();
            List <Dictionary <string, string> > incompletedUsers = new List <Dictionary <string, string> >();

            using (IADSearcher ad = Creater.GetADConnector(configuration.GetSection("AD")))
            {
                List <Dictionary <string, string> > results = ad.Search(earliest);
                Log.Information($"Total user found: {results.Count}");

                int i = 0;
                foreach (var user in results)
                {
                    i++;
                    Console.WriteLine("User {0}: {1} ({2} {3})", i, user["samaccountname"], user["givenname"], user["sn"]);
                    Log.Debug("User {0}: {1} ({2} {3})", i, user["samaccountname"], user["givenname"], user["sn"]);
                    try
                    {
                        users.Add(new User(user));
                    }
                    catch (KeyNotFoundException)
                    {
                        incompletedUsers.Add(user);
                    }
                }
            };
            return(users, incompletedUsers);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            eRSA = Creater.GetADConnector(Configuration.GetSection("AD"));
            services.AddSingleton <IADSearcher>(eRSA);
            try
            {
                CRMClient crmClient = new CRMClient(Configuration["Dynamics:Authority"], Configuration["Dynamics:Resource"],
                                                    Configuration["Dynamics:ClientId"], Configuration["Dynamics:ClientSecret"], Configuration["Dynamics:Version"]);
                services.AddSingleton <ITokenConsumer>(crmClient);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.ToString());
                throw new ApplicationException("Cannot continue because saved token file is not found.");
            }

            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .CreateLogger();
            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));
            Log.Logger.Debug("All services have been set up.");
        }