public override ParallelSendResult <Professor, UserResponse> SendAll() { Result = new ParallelSendResult <Professor, UserResponse>(); System.GC.Collect(); IEnumerable <Professor> data = GetData(""); if (data == null) { return(Result); } var factory = new HttpClientFactory(); using (var httpClient = factory.CreateMoodleHttpClient()) { CreateUserClient createClient = new CreateUserClient(); GetUserByUsernameClient verifyClient = new GetUserByUsernameClient(); // Sharing the same HttpClient instance to improve performance verifyClient.AddHttpClient(httpClient); createClient.AddHttpClient(httpClient); foreach (var modalidade in Modalidades) { ModalidadeAtual = modalidade; this.AddMoodleBaseUrl(modalidade.MoodleUrl) .AddMoodleToken(modalidade.MoodleToken) .AddMoodleGetInfoServiceToken(modalidade.MoodleGetInfoServiceToken) .AddMoodleServiceUrl(modalidade.MoodleServiceUrl); BuildMoodleClient(createClient, MoodleTokenType.OfficialMoodleApiFunctions); BuildMoodleClient(verifyClient, MoodleTokenType.LocalMoodleExternalApiGetInfoToken); var professores = data.Where ( x => ( x.Disciplinas .Where(d => d.IdModalidade == modalidade.IdModalidade) .Count() > 0 ) ) .ToArray(); if (UseParallelism) { ProcessWithParallelism(professores, createClient, verifyClient); } else { ProcessWithRegularForeach(professores, createClient, verifyClient); } } } return(Result); }
public override ParallelSendResult <AlunoDisciplinaViewModel, GetEnrolmentsByUserIdResponse> SendAll() { Result = new ParallelSendResult <AlunoDisciplinaViewModel, GetEnrolmentsByUserIdResponse>(); IEnumerable <AlunoDisciplinaViewModel> data = GetData(""); if (data == null) { return(Result); } var factory = new HttpClientFactory(); HttpClient = factory.CreateMoodleHttpClient(); CreateCourseClient = new CreateCourseClient(); CreateCategoryClient = new CreateCategoryClient(); CreateUserClient = new CreateUserClient(); GetCategoryByNameClient = new GetCategoryByNameClient(); GetCourseByNameClient = new GetCourseByNameClient(); GetUserByUsernameClient = new GetUserByUsernameClient(); EnrolmentClient = new EnrolmentClient(); GetEnrolementsrByUserIdClient = new GetEnrolementsrByUserIdClient(); CreateCourseClient.AddHttpClient(HttpClient); CreateCategoryClient.AddHttpClient(HttpClient); CreateUserClient.AddHttpClient(HttpClient); GetCategoryByNameClient.AddHttpClient(HttpClient); GetCourseByNameClient.AddHttpClient(HttpClient); GetUserByUsernameClient.AddHttpClient(HttpClient); EnrolmentClient.AddHttpClient(HttpClient); GetEnrolementsrByUserIdClient.AddHttpClient(HttpClient); foreach (var modalidade in Modalidades) { ModalidadeAtual = modalidade; this.AddMoodleBaseUrl(modalidade.MoodleUrl) .AddMoodleToken(modalidade.MoodleToken) .AddMoodleGetInfoServiceToken(modalidade.MoodleGetInfoServiceToken) .AddMoodleServiceUrl(modalidade.MoodleServiceUrl); this.AddMoodleCategoryParent(modalidade.MoodleCategoryParent) .AddMoodleDescriptionFormat(modalidade.MoodleDescriptionFormat); var alunos = data.Where(x => x.Aluno.IdModalidade == modalidade.IdModalidade).ToArray(); if (UseParallelism) { ProcessWithParallelism(alunos, null, null); } else { ProcessWithRegularForeach(alunos, null, null); } } return(Result); }
private UserResponse CriarUsuarioMoodle(Aluno item) { CreateUserClient client = CreateUserClient; BuildMoodleClient(client, MoodleTokenType.OfficialMoodleApiFunctions); var nome = item.AlunoNomeSocial ?? item.AlunoNome; var tuple = nome.SepararNomeSobrenome(); var matricula = item.AlunoMatricula.FormatarMatricula(); if (item.AlunoEmail == null) { item.AlunoEmail = ""; } UserRequest request = new UserRequest() { Email = item.AlunoEmail.TratarEmail(matricula), Username = item.AlunoCpf.DesformatarCpf(), Firstname = tuple.Item1, Lastname = tuple.Item2, Password = matricula }; request.Preferences.Add("auth_forcepasswordchange", "1"); Task <UserResponse> task = client.Post(request); task.Wait(); LastUrl = client.LastUrl; UserResponse response = task.Result; if (response != null) { response.Fullname = nome; response.Email = request.Email; } return(response); }
public override UserResponse SendItem(AbstractMoodleServiceClient client, Aluno item) { CreateUserClient createClient = (CreateUserClient)client; var nome = item.AlunoNomeSocial ?? item.AlunoNome; var tuple = nome.SepararNomeSobrenome(); var matricula = item.AlunoMatricula.FormatarMatricula(); if (item.AlunoEmail == null) { item.AlunoEmail = ""; } UserRequest request = new UserRequest() { Email = item.AlunoEmail.TratarEmail(matricula), Username = item.AlunoCpf.DesformatarCpf(), Firstname = tuple.Item1, Lastname = tuple.Item2, Password = matricula }; request.Preferences.Add("auth_forcepasswordchange", "1"); Task <UserResponse> task = createClient.Post(request); task.Wait(); UserResponse response = task.Result; LastUrl = createClient.LastUrl; if (response != null) { response.Fullname = item.AlunoNomeSocial; response.Email = item.AlunoEmail; } return(response); }