public Principal GetPrincipalByLoginOrEmail( IAdobeConnectProxy provider, string login, string email, bool searchByEmail) { if (searchByEmail && string.IsNullOrWhiteSpace(email)) { return(null); } if (!searchByEmail && string.IsNullOrWhiteSpace(login)) { return(null); } PrincipalCollectionResult result = searchByEmail ? provider.GetAllByEmail(email) : provider.GetAllByLogin(login); if (!result.Success) { return(null); } return(result.Return(x => x.Values, Enumerable.Empty <Principal>()).FirstOrDefault()); }
public virtual OperationResultWithData <IEnumerable <PrincipalDto> > SearchExistingUser([FromBody] SearchRequestDto request) { try { var provider = GetAdminProvider(); var result = new List <Principal>(); PrincipalCollectionResult byLogin = provider.GetAllByFieldLike("login", request.SearchTerm); if (byLogin.Success) { result.AddRange(byLogin.Values); } else { // TODO: log error and return error!! } PrincipalCollectionResult byName = provider.GetAllByFieldLike("name", request.SearchTerm); if (byName.Success) { result.AddRange(byName.Values); } else { // TODO: log error and return error!! } var foundPrincipals = (from p in result group p by new { p.Login } into distinctLoginGroup select distinctLoginGroup.First()); if (!foundPrincipals.Any()) { return(new PrincipalDto[0].AsEnumerable().ToSuccessResult()); } return(foundPrincipals .GroupBy(p => p.PrincipalId) .Select(g => g.First()) .Return(x => x.Select(PrincipalDto.Build), Enumerable.Empty <PrincipalDto>()) .ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("AcUserController.SearchExistingUser", ex); return(OperationResultWithData <IEnumerable <PrincipalDto> > .Error(errorMessage)); } }
public IEnumerable <PrincipalReportDto> GetMeetingHostReport(IAdobeConnectProxy provider) { if (provider == null) { throw new ArgumentNullException(nameof(provider)); } var group = provider.GetGroupsByType(PrincipalType.live_admins); if (group.Status.Code != StatusCodes.ok) { throw new InvalidOperationException("AC.GetGroupsByType error"); } PrincipalCollectionResult usersResult = provider.GetGroupUsers(group.Values.First().PrincipalId); if (usersResult.Status.Code != StatusCodes.ok) { throw new InvalidOperationException("AC.GetGroupUsers error"); } var result = new List <PrincipalReportDto>(); foreach (Principal user in usersResult.Values) { var item = new PrincipalReportDto { Principal = PrincipalDto.Build(user), }; TransactionCollectionResult trxResult = provider.ReportMeetingTransactionsForPrincipal(user.PrincipalId, startIndex: 0, limit: 1); if (trxResult.Status.Code != StatusCodes.ok) { throw new InvalidOperationException("AC.ReportMeetingTransactionsForPrincipal error"); } TransactionInfo trx = trxResult.Values.FirstOrDefault(); if (trx != null) { item.LastTransaction = TransactionInfoDto.Build(trx); } result.Add(item); } return(result.AsReadOnly()); }
private PrincipalCollectionResult DoCallPrincipalList(string filter, int startIndex, int limit) { // act: "principal-list" StatusInfo status; var principals = this.requestProcessor.Process(Commands.Principal.List, filter.AppendPagingIfNeeded(startIndex, limit), out status); IEnumerable <Principal> data = PrincipalCollectionParser.Parse(principals); bool okResponse = ResponseIsOk(principals, status); if (!okResponse) { if (status.Code == StatusCodes.operation_size_error) { int?actualAcLimit = status.TryGetSubCodeAsInt32(); if (actualAcLimit.HasValue) { return(DoCallPrincipalList(filter + "&sort-principal-id=asc", startIndex, actualAcLimit.Value)); } } return(new PrincipalCollectionResult(status)); } if (data.Count() < limit) { return(new PrincipalCollectionResult(status, data)); } PrincipalCollectionResult nextPage = DoCallPrincipalList(filter, startIndex + limit, limit); if (!nextPage.Success) { return(nextPage); } return(new PrincipalCollectionResult(status, data.Concat(nextPage.Values))); }
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)); } }