private static LoginEvent ToLoginEvent(object[] row) { try { var evt = new LoginEvent { Id = Convert.ToInt32(row[0]), IP = Convert.ToString(row[1]), Login = Convert.ToString(row[2]), Browser = Convert.ToString(row[3]), Platform = Convert.ToString(row[4]), Date = TenantUtil.DateTimeFromUtc(Convert.ToDateTime(row[5])), TenantId = Convert.ToInt32(row[6]), UserId = Guid.Parse(Convert.ToString(row[7])), Page = Convert.ToString(row[8]), Action = Convert.ToInt32(row[9]) }; if (row[10] != null) { evt.Description = JsonConvert.DeserializeObject <IList <string> >( Convert.ToString(row[10]), new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); } evt.UserName = (row[11] != null && row[12] != null) ? UserFormatter.GetUserName(Convert.ToString(row[11]), Convert.ToString(row[12])) : !string.IsNullOrWhiteSpace(evt.Login) ? evt.Login : evt.UserId == Core.Configuration.Constants.Guest.ID ? AuditReportResource.GuestAccount : AuditReportResource.UnknownAccount; evt.ActionText = AuditActionMapper.GetActionText(evt); return(evt); } catch (Exception) { //log.Error("Error while forming event from db: " + ex); return(null); } }
private void SyncDbUsers(List <UserInfo> ldapUsers) { const double percents = 35; var step = percents / ldapUsers.Count; var percentage = (double)GetProgress(); if (!ldapUsers.Any()) { return; } var index = 0; var count = ldapUsers.Count; foreach (var userInfo in ldapUsers) { SetProgress(Convert.ToInt32(percentage), currentSource: string.Format("({0}/{1}): {2}", ++index, count, UserFormatter.GetUserName(userInfo, DisplayUserNameFormat.Default))); switch (OperationType) { case LdapOperationType.Save: case LdapOperationType.Sync: LDAPUserManager.SyncLDAPUser(userInfo, ldapUsers); break; case LdapOperationType.SaveTest: case LdapOperationType.SyncTest: LdapChangeCollection changes; LDAPUserManager.GetLDAPSyncUserChange(userInfo, ldapUsers, out changes); _ldapChanges.AddRange(changes); break; default: throw new ArgumentOutOfRangeException(); } percentage += step; } }
private static AuditEvent ToAuditEvent(object[] row) { try { var evt = new AuditEvent { Id = Convert.ToInt32(row[0]), IP = Convert.ToString(row[1]), Initiator = Convert.ToString(row[2]), Browser = Convert.ToString(row[3]), Platform = Convert.ToString(row[4]), Date = TenantUtil.DateTimeFromUtc(Convert.ToDateTime(row[5])), TenantId = Convert.ToInt32(row[6]), UserId = Guid.Parse(Convert.ToString(row[7])), Page = Convert.ToString(row[8]), Action = Convert.ToInt32(row[9]) }; if (row[10] != null) { evt.Description = JsonConvert.DeserializeObject <IList <string> >( Convert.ToString(row[10]), new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); } evt.UserName = (row[11] != null && row[12] != null) ? UserFormatter.GetUserName(Convert.ToString(row[11]), Convert.ToString(row[12])) : evt.UserId == Core.Configuration.Constants.CoreSystem.ID ? AuditReportResource.SystemAccount : evt.UserId == Core.Configuration.Constants.Guest.ID ? AuditReportResource.GuestAccount : evt.Initiator ?? AuditReportResource.UnknownAccount; evt.ActionText = AuditActionMapper.GetActionText(evt); evt.ActionTypeText = AuditActionMapper.GetActionTypeText(evt); evt.Product = AuditActionMapper.GetProductText(evt); evt.Module = AuditActionMapper.GetModuleText(evt); return(evt); } catch (Exception) { return(null); } }
public RemoveProgressItem(HttpContext context, int tenantId, UserInfo user, Guid currentUserId) { _context = context; _httpHeaders = QueueWorker.GetHttpHeaders(context.Request); _tenantId = tenantId; _userId = user.ID; _userName = UserFormatter.GetUserName(user, DisplayUserNameFormat.Default); _currentUserId = currentUserId; _docService = Web.Files.Classes.Global.FileStorageService; _mailEraser = new MailGarbageEraser(); Id = QueueWorker.GetProgressItemId(tenantId, _userId, typeof(RemoveProgressItem)); Status = ProgressStatus.Queued; Error = null; Percentage = 0; IsCompleted = false; }
public RemoveProgressItem(HttpContext context, MessageService messageService, QueueWorkerRemove queueWorkerRemove, StudioNotifyService studioNotifyService, int tenantId, UserInfo user, Guid currentUserId, bool notify) { _context = context; MessageService = messageService; StudioNotifyService = studioNotifyService; _httpHeaders = QueueWorker.GetHttpHeaders(context.Request); _tenantId = tenantId; User = user; FromUser = user.ID; _userName = UserFormatter.GetUserName(user, DisplayUserNameFormat.Default); _currentUserId = currentUserId; _notify = notify; //_docService = Web.Files.Classes.Global.FileStorageService; //_mailEraser = new MailGarbageEngine(); Id = queueWorkerRemove.GetProgressItemId(tenantId, FromUser); Status = ProgressStatus.Queued; Error = null; Percentage = 0; IsCompleted = false; }
private LoginEvent ToLoginEvent(Query query) { var evt = new LoginEvent { Id = query.LoginEvents.Id, IP = query.LoginEvents.Ip, Login = query.LoginEvents.Login, Browser = query.LoginEvents.Browser, Platform = query.LoginEvents.Platform, Date = query.LoginEvents.Date, TenantId = query.LoginEvents.TenantId, UserId = query.LoginEvents.UserId, Page = query.LoginEvents.Page, Action = query.LoginEvents.Action }; if (query.LoginEvents.Description != null) { evt.Description = JsonConvert.DeserializeObject <IList <string> >( query.LoginEvents.Description, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); } evt.UserName = (!string.IsNullOrEmpty(query.User?.FirstName) && !string.IsNullOrEmpty(query.User?.LastName)) ? UserFormatter.GetUserName(query.User.FirstName, query.User.LastName) : !string.IsNullOrWhiteSpace(evt.Login) ? evt.Login : evt.UserId == Core.Configuration.Constants.Guest.ID ? AuditReportResource.GuestAccount : AuditReportResource.UnknownAccount; evt.ActionText = AuditActionMapper.GetActionText(evt); return(evt); }
public override Vcard GetVCard(Jid jid, string id = "") { ASCContext.SetCurrentTenant(jid.Server); var tenant = ASCContext.GetCurrentTenant(); if (tenant == null) { return(new Vcard()); } jid = new Jid(jid.Bare.ToLowerInvariant()); var ui = ASCContext.UserManager.GetUserByUserName(jid.User); if (ui != null) { var vcard = cache.Get <Vcard>(jid.ToString()); if (vcard != null) { return(vcard); } vcard = new Vcard(); vcard.Name = new Name(ui.LastName, ui.FirstName, null); vcard.Fullname = UserFormatter.GetUserName(ui); vcard.Nickname = ui.UserName; vcard.Description = ui.Notes; if (ui.BirthDate != null) { vcard.Birthday = ui.BirthDate.Value; } vcard.JabberId = jid; if (ui.Sex.HasValue) { vcard.Gender = ui.Sex.Value ? Gender.MALE : Gender.FEMALE; } var index = ui.Contacts.FindIndex(c => string.Compare(c, "phone", true) == 0) + 1; if (0 < index && index < ui.Contacts.Count) { vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.Contacts[index])); } vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true)); var departments = string.Join(", ", CoreContext.UserManager.GetUserGroups(ui.ID).Select(d => HttpUtility.HtmlEncode(d.Name)).ToArray()); if (tenant != null) { vcard.Organization = new Organization(tenant.Name, departments); } vcard.Title = ui.Title; if (id == null || id.IndexOf("tmtalk", StringComparison.OrdinalIgnoreCase) < 0) { var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID)); if (image != null) { vcard.Photo = new Photo(image, ImageFormat.Png); image.Dispose(); } } cache.Insert(jid.ToString(), vcard, CACHE_TIMEOUT); return(vcard); } else { return(base.GetVCard(jid)); } }
/// <summary> /// Remove old LDAP users from db /// </summary> /// <param name="ldapUsers">list of actual LDAP users</param> /// <returns>New list of actual LDAP users</returns> private List <UserInfo> RemoveOldDbUsers(List <UserInfo> ldapUsers) { var dbLdapUsers = CoreContext.UserManager.GetUsers(EmployeeStatus.All).Where(u => u.Sid != null).ToList(); if (!dbLdapUsers.Any()) { return(ldapUsers); } var removedUsers = dbLdapUsers.Where(u => ldapUsers.FirstOrDefault(lu => u.Sid.Equals(lu.Sid)) == null).ToList(); if (!removedUsers.Any()) { return(ldapUsers); } const double percents = 8; var step = percents / removedUsers.Count; var percentage = (double)GetProgress(); var index = 0; var count = removedUsers.Count; foreach (var removedUser in removedUsers) { SetProgress(Convert.ToInt32(percentage), currentSource: string.Format("({0}/{1}): {2}", ++index, count, UserFormatter.GetUserName(removedUser, DisplayUserNameFormat.Default))); switch (OperationType) { case LdapOperationType.Save: case LdapOperationType.Sync: removedUser.Sid = null; if (!removedUser.IsOwner() && !(_currentUser != null && _currentUser.ID == removedUser.ID && removedUser.IsAdmin())) { removedUser.Status = EmployeeStatus.Terminated; // Disable user on portal } else { Warning = Resource.LdapSettingsErrorRemovedYourself; Logger.DebugFormat("RemoveOldDbUsers() Attempting to exclude yourself `{0}` from group or user filters, skipping.", removedUser.ID); } removedUser.ConvertExternalContactsToOrdinary(); Logger.DebugFormat("CoreContext.UserManager.SaveUserInfo({0})", removedUser.GetUserInfoString()); CoreContext.UserManager.SaveUserInfo(removedUser); break; case LdapOperationType.SaveTest: case LdapOperationType.SyncTest: _ldapChanges.SetSaveAsPortalUserChange(removedUser); break; default: throw new ArgumentOutOfRangeException(); } percentage += step; } dbLdapUsers.RemoveAll(removedUsers.Contains); var newLdapUsers = ldapUsers.Where(u => !removedUsers.Exists(ru => ru.ID.Equals(u.ID))).ToList(); return(newLdapUsers); }
private void UpdateDbGroup(GroupInfo dbLdapGroup, GroupInfo ldapGroup, List <UserInfo> ldapGroupUsers, int gIndex, int gCount) { SetProgress(currentSource: string.Format("({0}/{1}): {2}", gIndex, gCount, ldapGroup.Name)); var dbGroupMembers = CoreContext.UserManager.GetUsersByGroup(dbLdapGroup.ID, EmployeeStatus.All) .Where(u => u.Sid != null) .ToList(); var groupMembersToRemove = dbGroupMembers.Where( dbUser => ldapGroupUsers.FirstOrDefault(lu => dbUser.Sid.Equals(lu.Sid)) == null).ToList(); var groupMembersToAdd = (from ldapGroupUser in ldapGroupUsers let dbUser = dbGroupMembers.FirstOrDefault(u => u.Sid.Equals(ldapGroupUser.Sid)) where dbUser == null select SearchDbUserBySid(ldapGroupUser.Sid) into userBySid where !Equals(userBySid, Constants.LostUser) select userBySid) .ToList(); switch (OperationType) { case LdapOperationType.Save: case LdapOperationType.Sync: if (NeedUpdateGroup(dbLdapGroup, ldapGroup)) { dbLdapGroup.Name = ldapGroup.Name; dbLdapGroup.Sid = ldapGroup.Sid; dbLdapGroup = CoreContext.UserManager.SaveGroupInfo(dbLdapGroup); } var index = 0; var count = groupMembersToRemove.Count; foreach (var dbUser in groupMembersToRemove) { SetProgress( currentSource: string.Format("({0}/{1}): {2}, {3} ({4}/{5}): {6}", gIndex, gCount, dbLdapGroup.Name, Resource.LdapSettingsStatusRemovingGroupUser, ++index, count, UserFormatter.GetUserName(dbUser, DisplayUserNameFormat.Default))); CoreContext.UserManager.RemoveUserFromGroup(dbUser.ID, dbLdapGroup.ID); } index = 0; count = groupMembersToAdd.Count; foreach (var userInfo in groupMembersToAdd) { SetProgress( currentSource: string.Format("({0}/{1}): {2}, {3} ({4}/{5}): {6}", gIndex, gCount, ldapGroup.Name, Resource.LdapSettingsStatusAddingGroupUser, ++index, count, UserFormatter.GetUserName(userInfo, DisplayUserNameFormat.Default))); CoreContext.UserManager.AddUserIntoGroup(userInfo.ID, dbLdapGroup.ID); } if (dbGroupMembers.All(dbUser => groupMembersToRemove.Exists(u => u.ID.Equals(dbUser.ID))) && !groupMembersToAdd.Any()) { SetProgress(currentSource: string.Format("({0}/{1}): {2}", gIndex, gCount, dbLdapGroup.Name)); CoreContext.UserManager.DeleteGroup(dbLdapGroup.ID); } break; case LdapOperationType.SaveTest: case LdapOperationType.SyncTest: if (NeedUpdateGroup(dbLdapGroup, ldapGroup)) { _ldapChanges.SetUpdateGroupChange(ldapGroup); } if (groupMembersToRemove.Any()) { _ldapChanges.SetRemoveGroupMembersChange(dbLdapGroup, groupMembersToRemove); } if (groupMembersToAdd.Any()) { _ldapChanges.SetAddGroupMembersChange(dbLdapGroup, groupMembersToAdd); } if (dbGroupMembers.All(dbUser => groupMembersToRemove.Exists(u => u.ID.Equals(dbUser.ID))) && !groupMembersToAdd.Any()) { _ldapChanges.SetRemoveGroupChange(dbLdapGroup, Logger); } break; default: throw new ArgumentOutOfRangeException(); } }
private void AddNewGroup(GroupInfo ldapGroup, List <UserInfo> ldapGroupUsers, int gIndex, int gCount) { if (!ldapGroupUsers.Any()) // Skip empty groups { if (OperationType == LdapOperationType.SaveTest || OperationType == LdapOperationType.SyncTest) { _ldapChanges.SetSkipGroupChange(ldapGroup); } return; } var groupMembersToAdd = ldapGroupUsers.Select(ldapGroupUser => SearchDbUserBySid(ldapGroupUser.Sid)) .Where(userBySid => !Equals(userBySid, Constants.LostUser)) .ToList(); if (groupMembersToAdd.Any()) { switch (OperationType) { case LdapOperationType.Save: case LdapOperationType.Sync: ldapGroup = CoreContext.UserManager.SaveGroupInfo(ldapGroup); var index = 0; var count = groupMembersToAdd.Count; foreach (var userBySid in groupMembersToAdd) { SetProgress( currentSource: string.Format("({0}/{1}): {2}, {3} ({4}/{5}): {6}", gIndex, gCount, ldapGroup.Name, Resource.LdapSettingsStatusAddingGroupUser, ++index, count, UserFormatter.GetUserName(userBySid, DisplayUserNameFormat.Default))); CoreContext.UserManager.AddUserIntoGroup(userBySid.ID, ldapGroup.ID); } break; case LdapOperationType.SaveTest: case LdapOperationType.SyncTest: _ldapChanges.SetAddGroupChange(ldapGroup); _ldapChanges.SetAddGroupMembersChange(ldapGroup, groupMembersToAdd); break; default: throw new ArgumentOutOfRangeException(); } } else { if (OperationType == LdapOperationType.SaveTest || OperationType == LdapOperationType.SyncTest) { _ldapChanges.SetSkipGroupChange(ldapGroup); } } }
private void GiveUsersRights(Dictionary <LdapSettings.AccessRight, string> accessRightsSettings, List <LdapSettings.AccessRight> currentUserRights) { var current = LdapCurrentAcccessSettings.Load(); var currentAccessRights = new Dictionary <LdapSettings.AccessRight, List <string> >(); var usersWithRightsFlat = current.CurrentAccessRights == null ? new List <string>() : current.CurrentAccessRights.SelectMany(x => x.Value).Distinct().ToList(); var step = 3.0 / accessRightsSettings.Count(); var currentPercent = 95.0; foreach (var access in accessRightsSettings) { currentPercent += step; var ldapGroups = Importer.FindGroupsByAttribute(LDAPSettings.GroupNameAttribute, access.Value.Split(',').Select(x => x.Trim())); if (!ldapGroups.Any()) { Logger.DebugFormat("GiveUsersRights() No ldap groups found for ({0}) access rights, skipping", access.Key); continue; } foreach (var ldapGr in ldapGroups) { var gr = CoreContext.UserManager.GetGroupInfoBySid(ldapGr.Sid); if (gr == null) { Logger.DebugFormat("GiveUsersRights() Couldn't find portal group for '{0}'", ldapGr.Sid); continue; } var users = CoreContext.UserManager.GetUsersByGroup(gr.ID); Logger.DebugFormat("GiveUsersRights() Found '{0}' users for group '{1}' ({2})", users.Count(), gr.Name, gr.ID); foreach (var user in users) { if (!user.Equals(Constants.LostUser) && !user.IsVisitor()) { if (!usersWithRightsFlat.Contains(user.ID.ToString())) { usersWithRightsFlat.Add(user.ID.ToString()); var cleared = false; foreach (var r in Enum.GetValues(typeof(LdapSettings.AccessRight)).Cast <LdapSettings.AccessRight>()) { var prodId = LdapSettings.AccessRightsGuids[r]; if (Web.Core.WebItemSecurity.IsProductAdministrator(prodId, user.ID)) { cleared = true; Web.Core.WebItemSecurity.SetProductAdministrator(prodId, user.ID, false); } } if (cleared) { Logger.DebugFormat("GiveUsersRights() Cleared manually added user rights for '{0}'", user.DisplayUserName()); } } if (!currentAccessRights.ContainsKey(access.Key)) { currentAccessRights.Add(access.Key, new List <string>()); } currentAccessRights[access.Key].Add(user.ID.ToString()); SetProgress((int)currentPercent, string.Format(Resource.LdapSettingsStatusGivingRights, UserFormatter.GetUserName(user, DisplayUserNameFormat.Default), access.Key)); Web.Core.WebItemSecurity.SetProductAdministrator(LdapSettings.AccessRightsGuids[access.Key], user.ID, true); if (currentUserRights != null && currentUserRights.Contains(access.Key)) { currentUserRights.Remove(access.Key); } } } } } current.CurrentAccessRights = currentAccessRights; current.Save(); }
private void SyncLdapAvatar() { SetProgress(90, Resource.LdapSettingsStatusUpdatingUserPhotos); if (!LDAPSettings.LdapMapping.ContainsKey(LdapSettings.MappingFields.AvatarAttribute)) { var ph = LdapCurrentUserPhotos.Load(); if (ph.CurrentPhotos == null || !ph.CurrentPhotos.Any()) { return; } foreach (var guid in ph.CurrentPhotos.Keys) { Logger.InfoFormat("SyncLdapAvatar() Removing photo for '{0}'", guid); UserPhotoManager.RemovePhoto(guid); UserPhotoManager.ResetThumbnailSettings(guid); } ph.CurrentPhotos = null; ph.Save(); return; } var photoSettings = LdapCurrentUserPhotos.Load(); if (photoSettings.CurrentPhotos == null) { photoSettings.CurrentPhotos = new Dictionary <Guid, string>(); } var ldapUsers = Importer.AllDomainUsers.Where(x => !x.IsDisabled); var step = 5.0 / ldapUsers.Count(); var currentPercent = 90.0; foreach (var ldapUser in ldapUsers) { var image = ldapUser.GetValue(LDAPSettings.LdapMapping[LdapSettings.MappingFields.AvatarAttribute], true); if (image == null || image.GetType() != typeof(byte[])) { continue; } string hash; using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) { hash = Convert.ToBase64String(md5.ComputeHash((byte[])image)); } var user = CoreContext.UserManager.GetUserBySid(ldapUser.Sid); Logger.DebugFormat("SyncLdapAvatar() Found photo for '{0}'", ldapUser.Sid); if (photoSettings.CurrentPhotos.ContainsKey(user.ID) && photoSettings.CurrentPhotos[user.ID] == hash) { Logger.Debug("SyncLdapAvatar() Same hash, skipping."); continue; } try { SetProgress((int)(currentPercent += step), string.Format("{0}: {1}", Resource.LdapSettingsStatusSavingUserPhoto, UserFormatter.GetUserName(user, DisplayUserNameFormat.Default))); UserPhotoManager.ResetThumbnailSettings(user.ID); UserPhotoManager.SaveOrUpdatePhoto(user.ID, (byte[])image); if (photoSettings.CurrentPhotos.ContainsKey(user.ID)) { photoSettings.CurrentPhotos[user.ID] = hash; } else { photoSettings.CurrentPhotos.Add(user.ID, hash); } } catch { Logger.DebugFormat("SyncLdapAvatar() Couldn't save photo for '{0}'", user.ID); if (photoSettings.CurrentPhotos.ContainsKey(user.ID)) { photoSettings.CurrentPhotos.Remove(user.ID); } } } photoSettings.Save(); }
protected string GetContactsByPrefixJSON(EntityType targetEntityType, int targetEntityID, string prefix) { var allContacts = new List <Contact>(); var findedContacts = new List <Contact>(); switch (targetEntityType) { case EntityType.Opportunity: allContacts = Global.DaoFactory.GetContactDao().GetContacts(Global.DaoFactory.GetDealDao().GetMembers(targetEntityID)); break; case EntityType.Case: allContacts = Global.DaoFactory.GetContactDao().GetContacts(Global.DaoFactory.GetCasesDao().GetMembers(targetEntityID)); break; } foreach (var c in allContacts) { if (c is Person) { var people = (Person)c; if (UserFormatter.GetUserName(people.FirstName, people.LastName).IndexOf(prefix) != -1) { findedContacts.Add(c); } } else { var company = (Company)c; if (company.CompanyName.IndexOf(prefix) != -1) { findedContacts.Add(c); } } } return(JavaScriptSerializer.Serialize(findedContacts.ConvertAll(contact => { var displayTitle = String.Empty; var imgPath = String.Empty; if (contact is Person) { var people = (Person)contact; imgPath = ContactPhotoManager.GetSmallSizePhoto(people.ID, false);; displayTitle = UserFormatter.GetUserName(people.FirstName, people.LastName); } else { var company = (Company)contact; imgPath = ContactPhotoManager.GetSmallSizePhoto(company.ID, true); displayTitle = company.CompanyName; } return new { id = contact.ID, title = displayTitle, img = imgPath }; } ))); }
private string GetUserName(Guid id) { return(UserFormatter.GetUserName(CoreContext.UserManager.GetUsers(id))); }
private static AuditEvent ToAuditEvent(object[] row) { var evt = new AuditEvent { Id = Convert.ToInt32(row[0]), IP = Convert.ToString(row[1]), Initiator = Convert.ToString(row[2]), Browser = Convert.ToString(row[3]), Platform = Convert.ToString(row[4]), Date = TenantUtil.DateTimeFromUtc(Convert.ToDateTime(row[5])), TenantId = Convert.ToInt32(row[6]), UserId = Guid.Parse(Convert.ToString(row[7])), Page = Convert.ToString(row[8]), Action = Convert.ToInt32(row[9]) }; if (row[10] != null) { evt.Description = JsonConvert.DeserializeObject <IList <string> >( Convert.ToString(row[10]), new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); } evt.Target = MessageTarget.Parse(Convert.ToString(row[11])); var firstName = Convert.ToString(row[12]); var lastName = Convert.ToString(row[13]); if (evt.UserId == Core.Configuration.Constants.CoreSystem.ID) { evt.UserName = AuditReportResource.SystemAccount; } else if (evt.UserId == Core.Configuration.Constants.Guest.ID) { evt.UserName = AuditReportResource.GuestAccount; } else if (!(string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName))) { evt.UserName = UserFormatter.GetUserName(firstName, lastName); } else if (!string.IsNullOrEmpty(firstName)) { evt.UserName = firstName; } else if (!string.IsNullOrEmpty(lastName)) { evt.UserName = lastName; } else { evt.UserName = evt.Initiator ?? AuditReportResource.UnknownAccount; } var map = AuditActionMapper.GetMessageMaps(evt.Action); if (map != null) { evt.ActionText = map.GetActionText(evt); evt.ActionTypeText = map.GetActionTypeText(); evt.Product = map.GetProductText(); evt.Module = map.GetModuleText(); } return(evt); }
private AuditEvent ToAuditEvent(Query query) { try { var evt = new AuditEvent { Id = query.AuditEvent.Id, IP = query.AuditEvent.Ip, Initiator = query.AuditEvent.Initiator, Browser = query.AuditEvent.Browser, Platform = query.AuditEvent.Platform, Date = query.AuditEvent.Date, TenantId = query.AuditEvent.TenantId, UserId = query.AuditEvent.UserId, Page = query.AuditEvent.Page, Action = query.AuditEvent.Action }; if (query.AuditEvent.Description != null) { evt.Description = JsonConvert.DeserializeObject <IList <string> >( Convert.ToString(query.AuditEvent.Description), new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Utc }); } evt.Target = MessageTarget.Parse(query.AuditEvent.Target); evt.UserName = (query.User.FirstName != null && query.User.LastName != null) ? UserFormatter.GetUserName(query.User.FirstName, query.User.LastName) : evt.UserId == Core.Configuration.Constants.CoreSystem.ID ? AuditReportResource.SystemAccount : evt.UserId == Core.Configuration.Constants.Guest.ID ? AuditReportResource.GuestAccount : evt.Initiator ?? AuditReportResource.UnknownAccount; evt.ActionText = AuditActionMapper.GetActionText(evt); evt.ActionTypeText = AuditActionMapper.GetActionTypeText(evt); evt.Product = AuditActionMapper.GetProductText(evt); evt.Module = AuditActionMapper.GetModuleText(evt); return(evt); } catch (Exception) { } return(null); }