コード例 #1
0
        public override CourseResponse SendItem(AbstractMoodleServiceClient client, Disciplina item)
        {
            CreateCourseClient createClient = (CreateCourseClient)client;
            long?categoryId = item.GetMoodleCursoId(ModalidadeAtual, GetCategoryByNameClient, client.GetUnderlyingHttpClient());

            if (!categoryId.HasValue)
            {
                throw new MoodleDataNotExistsException($"O curso [{item.CursoDescricao}]´nõa está adicionado ao MOODLE.");
            }

            CourseRequest request = new CourseRequest()
            {
                CategoryId = categoryId.Value,
                Fullname   = item.DisciplinaNome,
                Shortname  = item.ShortName,
                Visible    = 1
            };

            Task <CourseResponse> task = createClient.Post(request);

            task.Wait();

            CourseResponse response = task.Result;

            LastUrl = createClient.LastUrl;

            return(response);
        }
コード例 #2
0
        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);
        }
コード例 #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);
        }
        private CourseResponse CriarDisciplinaMoodle(Disciplina item, long moodleCategoryId)
        {
            CreateCourseClient client = CreateCourseClient;

            BuildMoodleClient(client, MoodleTokenType.OfficialMoodleApiFunctions);

            CourseRequest request = new CourseRequest()
            {
                CategoryId = moodleCategoryId,
                Fullname   = item.DisciplinaNome,
                Shortname  = item.ShortName,
                Visible    = 1
            };

            Task <CourseResponse> task = client.Post(request);

            task.Wait();

            LastUrl = client.LastUrl;
            CourseResponse response = task.Result;

            return(response);
        }