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);
        }
Beispiel #2
0
        public MoodleFromToCacheAdapter FillCategories()
        {
            var cursos = Service.GetCursosBySemestre(Configuration.SemestreAtual);

            if (cursos == null)
            {
                return(this);
            }


            var factory = new HttpClientFactory();

            using (var httpClient = factory.CreateMoodleHttpClient())
            {
                var getCategoryClient = new GetCategoryByNameClient();

                // Sharing the same HttpClient instance to improve performance
                getCategoryClient.AddHttpClient(httpClient);

                foreach (var modalidade in Modalidades)
                {
                    IEnumerable <CategoryResponse> moodleCategories = GetMoodleCategories(modalidade, httpClient);


                    if (moodleCategories?.Count() == 0)
                    {
                        continue;
                    }

                    getCategoryClient
                    .AddBaseUrl(modalidade.MoodleUrl)
                    .AddToken(modalidade.MoodleGetInfoServiceToken)
                    .AddServiceUrl(modalidade.MoodleServiceUrl);

                    var filtered = cursos.Where(x => x.IdModalidade == modalidade.IdModalidade).ToArray();

                    filtered.AsParallel()
                    .WithExecutionMode(ParallelExecutionMode.ForceParallelism)
                    .ForAll((item) =>
                    {
                        CategoryResponse moodleCategory = moodleCategories.Where(x => x.Name.ToLower() == item.CursoDescricao.ToLower())
                                                          .FirstOrDefault();

                        if (moodleCategory != null)
                        {
                            MoodleFromToCache.AddCategory(modalidade.IdModalidade, item.CursoDescricao, moodleCategory.Id);
                        }
                    });
                }
            }

            return(this);
        }
Beispiel #3
0
        public override ParallelSendResult <Disciplina, CourseResponse> SendAll()
        {
            Result = new ParallelSendResult <Disciplina, CourseResponse>();
            System.GC.Collect();

            IEnumerable <Disciplina> data = GetData("");

            if (data == null)
            {
                return(Result);
            }

            var factory = new HttpClientFactory();

            using (var httpClient = factory.CreateMoodleHttpClient())
            {
                GetCategoryByNameClient = new GetCategoryByNameClient();
                var createClient = new CreateCourseClient();
                var verifyClient = new GetCourseByNameClient();

                // Sharing the same HttpClient instance to improve performance
                verifyClient.AddHttpClient(httpClient);
                createClient.AddHttpClient(httpClient);
                GetCategoryByNameClient.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);
                    BuildMoodleClient(GetCategoryByNameClient, MoodleTokenType.LocalMoodleExternalApiGetInfoToken);

                    var filtered = data.Where(x => x.IdModalidade == modalidade.IdModalidade).ToArray();

                    if (UseParallelism)
                    {
                        ProcessWithParallelism(filtered, createClient, verifyClient);
                    }
                    else
                    {
                        ProcessWithRegularForeach(filtered, createClient, verifyClient);
                    }
                }
            }

            return(Result);
        }