示例#1
0
        private static void Test(LmsCompany entity, CompanyLmsDTO resultDto)
        {
            bool   isTransient = false;
            string lmsPassword = resultDto.lmsAdminPassword;

            if (!isTransient && string.IsNullOrWhiteSpace(resultDto.lmsAdminPassword))
            {
                if ((entity.LmsProviderId == (int)LmsProviderEnum.Moodle) ||
                    ((entity.LmsProviderId == (int)LmsProviderEnum.Blackboard) && !resultDto.enableProxyToolMode))
                {
                    lmsPassword = entity.AdminUser.Password;
                }
                else if ((entity.LmsProviderId == (int)LmsProviderEnum.Blackboard) && resultDto.enableProxyToolMode)
                {
                    lmsPassword = resultDto.proxyToolPassword;
                }
            }

            ConnectionInfoDTO lmsConnectionTest = TestConnectionService.TestConnection(new ConnectionTestDTO
            {
                domain = resultDto.lmsDomain,
                enableProxyToolMode = resultDto.enableProxyToolMode,
                login    = resultDto.lmsAdmin,
                password = lmsPassword,
                type     = resultDto.lmsProvider,
            });

            string acPassword = (isTransient || !string.IsNullOrWhiteSpace(resultDto.acPassword))
                ? resultDto.acPassword
                : entity.AcPassword;

            string acConnectionInfo;
            bool   loginSameAsEmail;
            bool   acConnectionTest = TestConnectionService.TestACConnection(new ConnectionTestDTO
            {
                domain = resultDto.acServer,
                enableProxyToolMode = resultDto.enableProxyToolMode,
                login    = resultDto.acUsername,
                password = acPassword,
                type     = "ac",
            }, out acConnectionInfo, out loginSameAsEmail);

            // NOTE: always use setting from AC not UI
            entity.ACUsesEmailAsLogin = loginSameAsEmail;
            entity.IsActive           = lmsConnectionTest.status == OkMessage && acConnectionTest;
        }
示例#2
0
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="resultDto">
        /// The result DTO.
        /// </param>
        /// <returns>
        /// The <see cref="CompanyLmsDTO"/>.
        /// </returns>
        public CompanyLmsOperationDTO Save(CompanyLmsDTO resultDto)
        {
            ValidationResult validationResult;

            if (!this.IsValid(resultDto, out validationResult))
            {
                var error = this.GenerateValidationError(validationResult);
                this.LogError("CompanyLMS.Save", error);
                throw new FaultException <Error>(error, error.errorMessage);
            }

            bool       isTransient = resultDto.id == 0;
            LmsCompany entity      = isTransient ? null : this.LmsCompanyModel.GetOneById(resultDto.id).Value;

            string lmsPassword = resultDto.lmsAdminPassword;

            if (!isTransient &&
                string.IsNullOrWhiteSpace(resultDto.lmsAdminPassword) &&
                ((entity.LmsProviderId == (int)LmsProviderEnum.Moodle &&
                  string.IsNullOrWhiteSpace(entity.GetSetting <string>(LmsLicenseSettingNames.MoodleCoreServiceToken))) ||
                 (entity.LmsProviderId == (int)LmsProviderEnum.Blackboard && !resultDto.enableProxyToolMode) ||
                 entity.LmsProviderId == (int)LmsProviderEnum.AgilixBuzz)
                )
            {
                lmsPassword = entity.AdminUser.Password;
            }

            if ((this.LmsProviderModel.GetByShortName(resultDto.lmsProvider).Id == (int)LmsProviderEnum.Blackboard) && resultDto.enableProxyToolMode)
            {
                lmsPassword = resultDto.proxyToolPassword;
            }

            if ((this.LmsProviderModel.GetByShortName(resultDto.lmsProvider).Id == (int)LmsProviderEnum.Schoology))
            {
                // TRICK: for test-connection only
                resultDto.lmsAdmin = resultDto.schoologyConsumerKey;
                lmsPassword        = resultDto.schoologyConsumerSecret;
            }

            ConnectionInfoDTO lmsConnectionTest;

            if (!string.IsNullOrWhiteSpace(resultDto.moodleCoreServiceToken))
            {
                lmsConnectionTest = new ConnectionInfoDTO {
                    status = OkMessage, info = "Test connection is not supported for Moodle Token mode"
                };
            }
            else
            {
                if (this.LmsProviderModel.GetByShortName(resultDto.lmsProvider).Id == (int)LmsProviderEnum.Haiku)
                {
                    lmsConnectionTest = TestConnection(new ConnectionTestDTO
                    {
                        domain = resultDto.lmsDomain,
                        enableProxyToolMode = resultDto.enableProxyToolMode,
                        login          = resultDto.lmsAdmin,
                        password       = lmsPassword,
                        type           = resultDto.lmsProvider,
                        consumerKey    = resultDto.haikuConsumerKey,
                        consumerSecret = resultDto.haikuConsumerSecret,
                        token          = resultDto.haikuToken,
                        tokenSecret    = resultDto.haikuTokenSecret
                    });
                }
                else
                {
                    lmsConnectionTest = TestConnection(new ConnectionTestDTO
                    {
                        domain = resultDto.lmsDomain,
                        enableProxyToolMode = resultDto.enableProxyToolMode,
                        login    = resultDto.lmsAdmin,
                        password = lmsPassword,
                        type     = resultDto.lmsProvider,
                    });
                }
            }

            string acPassword = (isTransient || !string.IsNullOrWhiteSpace(resultDto.acPassword))
                ? resultDto.acPassword
                : entity.AcPassword;

            string acConnectionInfo;
            bool   loginSameAsEmail;
            bool   acConnectionTest = TestConnectionService.TestACConnection(new ConnectionTestDTO
            {
                domain = resultDto.acServer,
                enableProxyToolMode = resultDto.enableProxyToolMode,
                login    = resultDto.acUsername,
                password = acPassword,
                type     = "ac",
            }, out acConnectionInfo, out loginSameAsEmail);

            string licenseTestResultMessage = null;

            if (lmsConnectionTest.status != OkMessage ||
                !acConnectionTest)
            {
                var message = new StringBuilder("LMS License is inactive due to following reasons: \r\n");
                if (lmsConnectionTest.status != OkMessage)
                {
                    message.AppendFormat("{0} connection failed. ({1}) \r\n",
                                         this.LmsProviderModel.GetByShortName(resultDto.lmsProvider).LmsProviderName,
                                         lmsConnectionTest.info);
                }

                if (!acConnectionTest)
                {
                    message.AppendFormat("Adobe Connect connection failed. ({0})",
                                         acConnectionInfo);
                }

                licenseTestResultMessage = message.ToString();
            }

            entity = ConvertDto(resultDto, entity);

            // NOTE: always use setting from AC not UI
            entity.ACUsesEmailAsLogin = loginSameAsEmail;
            entity.IsActive           = lmsConnectionTest.status == OkMessage && acConnectionTest;

            if (isTransient)
            {
                entity.ConsumerKey  = Guid.NewGuid().ToString();
                entity.SharedSecret = Guid.NewGuid().ToString();
            }

            this.LmsCompanyModel.RegisterSave(entity);
            this.LmsCompanyModel.ProcessLmsAdmin(entity, resultDto, LmsUserModel, LmsCompanyModel);

            LmsProvider lmsProvider = LmsProviderModel.GetById(entity.LmsProviderId);

            return(new CompanyLmsOperationDTO
            {
                companyLmsVO = new CompanyLmsDTO(entity, lmsProvider, Settings),
                message = licenseTestResultMessage,
            });
        }