Ejemplo n.º 1
0
        private Principal CreatePrincipal(
            IAdobeConnectProxy provider,
            string login,
            string email,
            string firstName,
            string lastName,
            bool acUsesEmailAsLogin)
        {
            if (string.IsNullOrWhiteSpace(firstName))
            {
                throw new Core.WarningMessageException("Adobe Connect User's First Name can't be empty.");
            }
            if (string.IsNullOrWhiteSpace(lastName))
            {
                throw new Core.WarningMessageException("Adobe Connect User's Last Name can't be empty.");
            }

            var setup = new PrincipalSetup
            {
                Email     = string.IsNullOrWhiteSpace(email) ? null : email,
                FirstName = firstName,
                LastName  = lastName,
                Name      = login,
                Login     = login,
                Type      = PrincipalType.user,
            };

            PrincipalResult pu = provider.PrincipalUpdate(setup, false, false);

            if (!pu.Success)
            {
                if (pu.Status.InvalidField == "login" && pu.Status.SubCode == StatusSubCodes.duplicate)
                {
                    if (acUsesEmailAsLogin)
                    {
                        UserCollectionResult guestsByEmail = provider.ReportGuestsByEmail(HttpUtilsInternal.UrlEncode(email));
                        if (guestsByEmail.Success && guestsByEmail.Values.Any())
                        {
                            throw new Core.WarningMessageException(string.Format(Messages.PrincipalEmailUsedForGuest, email));
                        }
                    }
                    else
                    {
                        UserCollectionResult guestsByLogin = provider.ReportGuestsByLogin(login);
                        if (guestsByLogin.Success && guestsByLogin.Values.Any())
                        {
                            throw new Core.WarningMessageException(string.Format(Messages.PrincipalLoginUsedForGuest, login));
                        }
                    }
                }
            }

            if (pu.Principal != null)
            {
                return(pu.Principal);
            }
            return(null);
        }
Ejemplo n.º 2
0
        private static Principal CreatePrincipal(PrincipalInputDto user, ILmsLicense credentials, IAdobeConnectProxy provider)
        {
            string login = (credentials.ACUsesEmailAsLogin ?? false) ? null : user.Login;

            var setup = new PrincipalSetup
            {
                Email       = user.Email,
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                Login       = login,
                SendEmail   = user.SendEmail,
                HasChildren = false,
                Type        = PrincipalType.user,
                Password    = user.Password,
                //Name = NOTE: name is used for groups ONLY!!
            };

            PrincipalResult pu = provider.PrincipalUpdate(setup, false, false);

            if (!pu.Success)
            {
                if (pu.Status.InvalidField == "login" && pu.Status.SubCode == StatusSubCodes.duplicate)
                {
                    throw new WarningMessageException(string.Format(Messages.PrincipalValidateAlreadyInAc, login ?? user.Email));
                }

                if (pu.Status.InvalidField == "name" && pu.Status.SubCode == StatusSubCodes.range)
                {
                    throw new WarningMessageException(Messages.PrincipalValidateNameLength);
                }

                if (pu.Status.InvalidField == "email" && pu.Status.SubCode == StatusSubCodes.range)
                {
                    throw new WarningMessageException(Messages.PrincipalValidateEmailLength);
                }

                if (pu.Status.InvalidField == "email" && pu.Status.SubCode == StatusSubCodes.format)
                {
                    throw new WarningMessageException(Messages.PrincipalValidateEmailFormat);
                }

                if (pu.Status.InvalidField == "login" && pu.Status.SubCode == StatusSubCodes.range)
                {
                    throw new WarningMessageException(Messages.PrincipalValidateLoginLength);
                }

                string additionalData = string.Format("firstName: {0}, lastName: {1}, login: {2}, email: {3}", user.FirstName, user.LastName, user.Login, user.Email);
                if (pu.Status.UnderlyingExceptionInfo != null)
                {
                    throw new InvalidOperationException(string.Format("AC.PrincipalUpdate error. Additional Data: {0}", additionalData), pu.Status.UnderlyingExceptionInfo);
                }

                if (!string.IsNullOrEmpty(pu.Status.InvalidField))
                {
                    throw new InvalidOperationException(string.Format("AC.PrincipalUpdate error. Invalid Field: {0}. Status.SubCode: {1}. Additional Data: {2}", pu.Status.InvalidField, pu.Status.SubCode, additionalData));
                }

                throw new InvalidOperationException(string.Format("AC.PrincipalUpdate error. Status.Code: {0}. Status.SubCode: {1}. Additional Data: {2}", pu.Status.Code, pu.Status.SubCode, additionalData));
            }

            Principal createdPrincipal = pu.Principal;

            return(createdPrincipal);
        }
Ejemplo n.º 3
0
        public OperationResultDto DeletePrincipals(int lmsCompanyId, string login, string password, string[] principalIds)
        {
            //http://dev.connectextensions.com/api/xml?action=principal-list&filter-principal-id=313091&filter-principal-id=256215&filter-principal-id=257331
            try
            {
                if (principalIds == null)
                {
                    throw new ArgumentNullException("principalIds");
                }

                LmsCompany         currentLicense         = this.LmsCompanyModel.GetOneById(lmsCompanyId).Value;
                IAdobeConnectProxy currentLicenseProvider = null;
                try
                {
                    currentLicenseProvider = AdobeConnectAccountService.GetProvider(currentLicense.AcServer, new UserCredentials(login, password), true);
                }
                catch (InvalidOperationException)
                {
                    return(OperationResultDto.Error("Login to Adobe Connect failed."));
                }
                PrincipalCollectionResult principalsToDelete = currentLicenseProvider.GetAllByPrincipalIds(principalIds);

                IEnumerable <LmsCompany> companyLicenses = this.LmsCompanyModel.GetAllByCompanyId(currentLicense.CompanyId);
                var lmsLicensePrincipals = new List <string>();
                foreach (LmsCompany lms in companyLicenses)
                {
                    if (lms.AcServer.TrimEnd(new char[] { '/' }) == currentLicense.AcServer.TrimEnd(new char[] { '/' }))
                    {
                        bool tryToDeleteAcUserFromLicense = principalsToDelete.Values.Select(x => x.Login).Contains(lms.AcUsername);
                        if (tryToDeleteAcUserFromLicense)
                        {
                            lmsLicensePrincipals.Add(string.Format("Adobe Connect account '{0}' is used within your LMS license '{1}'. ", lms.AcUsername, lms.Title));
                        }
                    }
                }

                if (lmsLicensePrincipals.Count > 0)
                {
                    string msg = (lmsLicensePrincipals.Count == 1)
                        ? "You should not delete account. "
                        : "You should not delete some accounts. ";
                    return(OperationResultDto.Error(msg + string.Join("", lmsLicensePrincipals)));
                }

                bool allOK            = true;
                var  failedPrincipals = new List <string>();

                foreach (string principalId in principalIds)
                {
                    PrincipalResult deleteResult = currentLicenseProvider.PrincipalDelete(new PrincipalDelete {
                        PrincipalId = principalId
                    });
                    if (deleteResult.Status.Code != StatusCodes.ok)
                    {
                        Logger.ErrorFormat("AC.PrincipalDelete error. {0} PrincipalId: {1}.",
                                           deleteResult.Status.GetErrorInfo(),
                                           principalId);
                        allOK = false;
                        failedPrincipals.Add(principalId);
                    }
                }

                if (allOK)
                {
                    return(OperationResultDto.Success());
                }
                else
                {
                    return(OperationResultDto.Error(string.Format("Failed to delete {0} principal(s) from Adobe Connect", failedPrincipals.Count.ToString())));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("LmsService.DeletePrincipals", ex);
                return(OperationResultDto.Error(ErrorsTexts.UnexpectedError));
            }
        }