public static void UpdateGroupStub( int stubId , string abbreviation , string toolTip , string url , bool openInBrowser , int width , int height , byte[] icon , ArrayList groups , bool deleteIcon) { // Groups ArrayList newGroups = new ArrayList(groups); ArrayList deletedGroups = new ArrayList(); using (IDataReader reader = DBWebStubs.GetListGroupsByStub(stubId)) { while (reader.Read()) { int groupId = (int)reader["GroupId"]; if (newGroups.Contains(groupId)) { newGroups.Remove(groupId); } else { deletedGroups.Add(groupId); } } } // Users ArrayList users = new ArrayList(); foreach (int groupId in groups) { using (IDataReader reader = SecureGroup.GetListAllUsersInGroup(groupId)) { while (reader.Read()) { if (reader["OriginalId"] != DBNull.Value) { int userId = (int)reader["OriginalId"]; if (!users.Contains(userId)) { users.Add(userId); } } } } } foreach (int groupId in deletedGroups) { using (IDataReader reader = SecureGroup.GetListAllUsersInGroup(groupId)) { while (reader.Read()) { if (reader["OriginalId"] != DBNull.Value) { int userId = (int)reader["OriginalId"]; if (!users.Contains(userId)) { users.Add(userId); } } } } } using (DbTransaction tran = DbTransaction.Begin()) { DBWebStubs.Update(stubId, abbreviation, toolTip, url, openInBrowser, width, height); if (deleteIcon) { DBWebStubs.UpdateStubIcon(stubId, null); } else if (icon != null) { DBWebStubs.UpdateStubIcon(stubId, icon); } // Remove Group foreach (int groupId in deletedGroups) { DBWebStubs.DeleteStubGroup(stubId, groupId); } // Add Group foreach (int groupId in newGroups) { DBWebStubs.AddStubGroup(stubId, groupId); } // Stubs Version foreach (int userId in users) { User.IncreaseStubsVersion(userId); } try { foreach (int userId in users) { IMManager.UpdateUserWebStub(userId); } } catch (Exception) { } tran.Commit(); } }
public static void AddSystemEvents(SystemEventTypes eventType, int?objectId, Guid?objectUid, int relObjectId, string emailTo, string emailFrom, ArrayList excludeUsers, Dictionary <string, string> additionalValues) { // User can be unregistered int CurrentUserId = -1; if (Security.CurrentUser != null) { CurrentUserId = Security.CurrentUser.UserID; } ObjectTypes objectType, relObjectType; string ObjectTitle = string.Empty; string RelObjectTitle = string.Empty; string XMLData = Alerts2.GetXmlData(eventType, objectId, objectUid, relObjectId, out objectType, out relObjectType, ref ObjectTitle, ref RelObjectTitle, additionalValues); // Здесь будем хранить обработанных пользователей и пользователей, которых не надо обрабатывать ArrayList processedUsers = new ArrayList(); if (CurrentUserId > 0 && !Alerts2.SendToCurrentUser) { processedUsers.Add(CurrentUserId); } // Получатели info-сообщений ArrayList infoRecipients = new ArrayList(); using (DbTransaction tran = DbTransaction.Begin()) { int eventId = DBSystemEvents.AddSystemEvents((int)eventType, objectId, objectUid, ObjectTitle, relObjectId, RelObjectTitle, CurrentUserId, XMLData, DbContext.Current.TransactionId); #region Персональные сообщения if ( eventType == SystemEventTypes.CalendarEntry_Updated_Manager_ManagerAdded || eventType == SystemEventTypes.CalendarEntry_Updated_Manager_ManagerDeleted || eventType == SystemEventTypes.CalendarEntry_Updated_ResourceList_AssignmentAdded || eventType == SystemEventTypes.CalendarEntry_Updated_ResourceList_AssignmentDeleted || eventType == SystemEventTypes.CalendarEntry_Updated_ResourceList_RequestAdded || eventType == SystemEventTypes.Document_Updated_ResourceList_AssignmentAdded || eventType == SystemEventTypes.Document_Updated_ResourceList_AssignmentDeleted || eventType == SystemEventTypes.Document_Updated_ResourceList_RequestAdded || eventType == SystemEventTypes.Issue_Created || eventType == SystemEventTypes.Issue_Updated_Forum_MessageAdded || eventType == SystemEventTypes.Issue_Updated_Manager_ManagerAdded || eventType == SystemEventTypes.Issue_Updated_Manager_ManagerDeleted || eventType == SystemEventTypes.Issue_Updated_ResourceList_AssignmentAdded || eventType == SystemEventTypes.Issue_Updated_ResourceList_AssignmentDeleted || eventType == SystemEventTypes.Issue_Updated_ResourceList_RequestAdded || eventType == SystemEventTypes.Issue_Updated_Responsible_Requested || eventType == SystemEventTypes.Issue_Updated_Responsible_Assigned || eventType == SystemEventTypes.Issue_Updated_Responsible_Resigned || eventType == SystemEventTypes.Issue_Updated_Controller_Assigned || eventType == SystemEventTypes.Issue_Updated_Controller_Resigned || eventType == SystemEventTypes.Project_Updated_ExecutiveManager_ExecutiveManagerAdded || eventType == SystemEventTypes.Project_Updated_ExecutiveManager_ExecutiveManagerDeleted || eventType == SystemEventTypes.Project_Updated_Manager_ManagerAdded || eventType == SystemEventTypes.Project_Updated_Manager_ManagerDeleted || eventType == SystemEventTypes.Project_Updated_SponsorList_SponsorAdded || eventType == SystemEventTypes.Project_Updated_SponsorList_SponsorDeleted || eventType == SystemEventTypes.Project_Updated_StakeholderList_StakeholderAdded || eventType == SystemEventTypes.Project_Updated_StakeholderList_StakeholderDeleted || eventType == SystemEventTypes.Project_Updated_TeamMemberList_TeamMemberAdded || eventType == SystemEventTypes.Project_Updated_TeamMemberList_TeamMemberDeleted || eventType == SystemEventTypes.Todo_Updated_Manager_ManagerAdded || eventType == SystemEventTypes.Todo_Updated_Manager_ManagerDeleted || eventType == SystemEventTypes.Todo_Updated_ResourceList_AssignmentAdded || eventType == SystemEventTypes.Todo_Updated_ResourceList_AssignmentDeleted || eventType == SystemEventTypes.Todo_Updated_ResourceList_RequestAdded || eventType == SystemEventTypes.Task_Updated_ResourceList_AssignmentAdded || eventType == SystemEventTypes.Task_Updated_ResourceList_AssignmentDeleted || eventType == SystemEventTypes.Task_Updated_ResourceList_RequestAdded || eventType == SystemEventTypes.User_Activated || eventType == SystemEventTypes.User_Created || eventType == SystemEventTypes.User_Created_External || eventType == SystemEventTypes.User_Created_Partner || eventType == SystemEventTypes.User_Deleted || eventType == SystemEventTypes.User_Deactivated || eventType == SystemEventTypes.Assignment_Updated_Participant_Assigned || eventType == SystemEventTypes.Assignment_Updated_Participant_Resigned ) { ArrayList users = new ArrayList(); if (objectType == ObjectTypes.User) { users.Add(objectId); } if (relObjectType == ObjectTypes.User) { if (User.IsGroup(relObjectId)) { // this method doesn't return inactive users using (IDataReader reader = SecureGroup.GetListAllUsersInGroup(relObjectId, false)) { while (reader.Read()) { users.Add((int)reader["UserId"]); } } } else { if (User.GetUserActivity(relObjectId) == User.UserActivity.Active) { users.Add(relObjectId); } } } foreach (int userId in users) { if (!processedUsers.Contains(userId)) { AddSystemEventRecipient(eventId, userId, MessageTypes.Resource); processedUsers.Add(userId); } } if (emailTo != null) { AddSystemEventRecipient(eventId, MessageTypes.Resource, emailTo, emailFrom); } } #endregion CollectAllObjectSubscribers(eventType, objectType, objectId, objectUid, processedUsers, infoRecipients); foreach (int userId in infoRecipients) { if ((excludeUsers == null || !excludeUsers.Contains(userId)) && CheckRights(eventType, objectType, relObjectType, objectId, relObjectId, objectUid, userId)) { AddSystemEventRecipient(eventId, userId, MessageTypes.Info); } } _hasNewEvent = true; tran.Commit(); } }