/// <summary> /// Created to refactor CreateData method /// </summary> /// <param name="configVal">Dictionary object</param> /// <param name="successMatterNameCount">Success matter name</param> /// <param name="matterMetadata">Matter metadata</param> /// <param name="clientName">Client name</param> /// <param name="client">Client object</param> /// <param name="contentTypes">Array of content type</param> /// <param name="matterObj">Matter object</param> /// <param name="clientContext">Client context</param> /// <returns>integer value</returns> private static int OnMatterCreationSuccess(Dictionary <string, string> configVal, int successMatterNameCount, MatterMetadata matterMetadata, string clientName, Client client, string[] contentTypes, Matter matterObj, ClientContext clientContext) { Console.WriteLine("Created Matter, OneNote library, calendar list and Task List"); List <string> listResponsibleAttorneys = matterObj.TeamInfo.ResponsibleAttorneys.Trim().Split(';').ToList(); List <string> listAttorneys = matterObj.TeamInfo.Attorneys.Trim().Split(';').ToList(); List <string> listBlockedUploadUsers = matterObj.TeamInfo.BlockedUploadUsers.Trim().Split(';').ToList(); IList <IList <string> > assignUserNames = new List <IList <string> >(); assignUserNames.Add(listResponsibleAttorneys); assignUserNames.Add(listAttorneys); assignUserNames.Add(listBlockedUploadUsers); matterObj.AssignUserNames = assignUserNames; matterMetadata.Matter = matterObj; matterMetadata.Client = client; // Create Matter Landing page MatterProvisionHelper.CreateMatterLandingPage(clientContext, client, matterObj); Console.WriteLine("Created matter landing Page"); // Step 4 Assign Content Types matterMetadata.ContentTypes = contentTypes.Distinct().ToList(); MatterProvisionHelperUtility.AssignContentType(clientContext, matterMetadata); Console.WriteLine("Assigned content type"); // Step 5 Assign Permissions bool isCalendarEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["CalendarCreationEnabled"], CultureInfo.InvariantCulture); bool isTaskEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture); string calendarName = string.Empty, taskListName = string.Empty; if (isCalendarEnabled) { calendarName = string.Concat(matterObj.MatterName, ConfigurationManager.AppSettings["CalendarNameSuffix"]); } if (isTaskEnabled) { taskListName = string.Concat(matterObj.MatterName, ConfigurationManager.AppSettings["TaskListSuffix"]); } List <string> responsibleAttorneysList = matterObj.TeamInfo.ResponsibleAttorneys.Split(';').Where(responsibleAttorney => !string.IsNullOrWhiteSpace(responsibleAttorney.Trim())).Select(responsibleAttorney => responsibleAttorney.Trim()).ToList(); MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName, responsibleAttorneysList, ConfigurationManager.AppSettings["FullControl"]); MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"], responsibleAttorneysList, ConfigurationManager.AppSettings["FullControl"]); if (isCalendarEnabled) { // If isCreateCalendar flag is enabled; assign FULL CONTROL permissions to calendar list MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName, responsibleAttorneysList, ConfigurationManager.AppSettings["FullControl"], calendarName); } if (isTaskEnabled) { // If isTaskEnabled flag is enabled; assign FULL CONTROL permissions to task list MatterProvisionHelperUtility.AssignUserPermissions(clientContext, taskListName, responsibleAttorneysList, ConfigurationManager.AppSettings["FullControl"]); } List <string> attorneysList = new List <string>(); string[] attorneys = matterObj.TeamInfo.Attorneys.Split(';'); if (!string.IsNullOrWhiteSpace(attorneys[0].Trim())) { int attorneyCount = matterObj.TeamInfo.Attorneys.Split(';').Length; for (int iLength = 0; iLength < attorneyCount; iLength++) { attorneysList.Add(attorneys[iLength].Trim()); } MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName, attorneysList, ConfigurationManager.AppSettings["Contribute"]); MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"], attorneysList, ConfigurationManager.AppSettings["Contribute"]); if (isCalendarEnabled) { //If isCreateCalendar flag is enabled; assign CONTRIBUTE permissions to calendar list MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName, attorneysList, ConfigurationManager.AppSettings["Contribute"], calendarName); } if (isTaskEnabled) { //If isTaskEnabled flag is enabled; assign CONTRIBUTE permissions to task list MatterProvisionHelperUtility.AssignUserPermissions(clientContext, taskListName, attorneysList, ConfigurationManager.AppSettings["Contribute"]); } } List <string> blockedUploadUserList = new List <string>(); string[] blockedUploadUsers = matterObj.TeamInfo.BlockedUploadUsers.Split(';'); if (!string.IsNullOrWhiteSpace(blockedUploadUsers[0].Trim())) { int blockUploadUsersCount = blockedUploadUsers.Length; for (int iLength = 0; iLength < blockUploadUsersCount; iLength++) { blockedUploadUserList.Add(blockedUploadUsers[iLength].Trim()); } MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName, blockedUploadUserList, ConfigurationManager.AppSettings["Read"]); MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"], blockedUploadUserList, ConfigurationManager.AppSettings["Read"]); if (isCalendarEnabled) { //If isCreateCalendar flag is enabled; assign READ permissions to calendar list MatterProvisionHelperUtility.AssignUserPermissions(clientContext, matterObj.MatterName, blockedUploadUserList, ConfigurationManager.AppSettings["Read"], calendarName); } if (isTaskEnabled) { //If isTaskEnabled flag is enabled; assign READ permissions to task list MatterProvisionHelperUtility.AssignUserPermissions(clientContext, taskListName, blockedUploadUserList, ConfigurationManager.AppSettings["Read"]); } } Console.WriteLine("Assigned permission"); // Step 6 Stamp properties ListOperations.UpdateMetadataForList(clientContext, matterObj, client); Console.WriteLine("Updated matter properties"); // Step 7 Add entry to list MatterProvisionHelper.InsertIntoMatterCenterMatters(configVal, clientName + "_" + matterObj.MatterName, matterObj, client); Console.WriteLine("{0} created successfully", matterObj.MatterName); Console.WriteLine("-------------------------------------------------------------------------------"); successMatterNameCount++; return(successMatterNameCount); }
/// <summary> /// Updates metadata for list /// </summary> /// <param name="clientContext">CLient context</param> /// <param name="matter">Matter object</param> /// <param name="client">Client object</param> /// <returns>String value</returns> internal static string UpdateMetadataForList(ClientContext clientContext, Matter matter, Client client) { string properties = string.Empty; try { var props = clientContext.Web.Lists.GetByTitle(matter.MatterName).RootFolder.Properties; List <string> keys = new List <string>(); keys.Add("PracticeGroup"); keys.Add("AreaOfLaw"); keys.Add("SubAreaOfLaw"); keys.Add("MatterName"); keys.Add("MatterID"); keys.Add("ClientName"); keys.Add("ClientID"); keys.Add("ResponsibleAttorney"); keys.Add("TeamMembers"); keys.Add("IsMatter"); keys.Add("OpenDate"); keys.Add("SecureMatter"); keys.Add("BlockedUploadUsers"); keys.Add("Success"); keys.Add("IsConflictIdentified"); keys.Add("MatterConflictCheckBy"); keys.Add("MatterConflictCheckDate"); keys.Add("MatterCenterPermissions"); keys.Add("MatterCenterRoles"); keys.Add("MatterCenterUsers"); keys.Add("DocumentTemplateCount"); keys.Add("MatterCenterDefaultContentType"); keys.Add("MatterDescription"); keys.Add("BlockedUsers"); keys.Add("MatterGUID"); Dictionary <string, string> propertyList = new Dictionary <string, string>(); propertyList.Add("PracticeGroup", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterType.PracticeGroup)); propertyList.Add("AreaOfLaw", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterType.AreaofLaw)); propertyList.Add("SubAreaOfLaw", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterType.SubAreaofLaw)); propertyList.Add("MatterName", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterName)); propertyList.Add("MatterID", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterId)); propertyList.Add("ClientName", Microsoft.Security.Application.Encoder.HtmlEncode(client.ClientName)); propertyList.Add("ClientID", Microsoft.Security.Application.Encoder.HtmlEncode(client.ClientId)); propertyList.Add("ResponsibleAttorney", Microsoft.Security.Application.Encoder.HtmlEncode(matter.TeamInfo.ResponsibleAttorneys)); propertyList.Add("TeamMembers", Microsoft.Security.Application.Encoder.HtmlEncode(matter.TeamInfo.Attorneys)); propertyList.Add("IsMatter", Microsoft.Security.Application.Encoder.HtmlEncode("true")); propertyList.Add("OpenDate", Microsoft.Security.Application.Encoder.HtmlEncode(matter.OpenDate)); propertyList.Add("SecureMatter", Microsoft.Security.Application.Encoder.HtmlEncode(matter.Conflict.SecureMatter)); propertyList.Add("Success", Microsoft.Security.Application.Encoder.HtmlEncode("true")); propertyList.Add("BlockedUsers", Microsoft.Security.Application.Encoder.HtmlEncode(matter.TeamInfo.BlockedUsers)); propertyList.Add("IsConflictIdentified", Microsoft.Security.Application.Encoder.HtmlEncode("true")); propertyList.Add("MatterConflictCheckBy", Microsoft.Security.Application.Encoder.HtmlEncode(matter.Conflict.ConflictCheckBy.TrimEnd(';'))); propertyList.Add("MatterConflictCheckDate", Microsoft.Security.Application.Encoder.HtmlEncode(matter.Conflict.ConflictCheckOn)); propertyList.Add("MatterCenterRoles", Microsoft.Security.Application.Encoder.HtmlEncode(ConfigurationManager.AppSettings["Roles"])); propertyList.Add("MatterCenterUsers", Microsoft.Security.Application.Encoder.HtmlEncode(matter.TeamInfo.ResponsibleAttorneys + Constants.SEPARATOR + matter.TeamInfo.Attorneys + Constants.SEPARATOR + matter.TeamInfo.BlockedUploadUsers).TrimEnd(';')); propertyList.Add("MatterCenterPermissions", Microsoft.Security.Application.Encoder.HtmlEncode(ConfigurationManager.AppSettings["FullControl"] + Constants.SEPARATOR + ConfigurationManager.AppSettings["Contribute"] + Constants.SEPARATOR + ConfigurationManager.AppSettings["Read"])); propertyList.Add("DocumentTemplateCount", Microsoft.Security.Application.Encoder.HtmlEncode(matter.DocumentCount)); propertyList.Add("MatterCenterDefaultContentType", Microsoft.Security.Application.Encoder.HtmlEncode(matter.DefaultContentType)); propertyList.Add("MatterDescription", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterDescription)); propertyList.Add("BlockedUploadUsers", Microsoft.Security.Application.Encoder.HtmlEncode(matter.TeamInfo.BlockedUploadUsers.TrimEnd(';'))); propertyList.Add("MatterGUID", Microsoft.Security.Application.Encoder.HtmlEncode(matter.MatterGuid)); propertyList.Add("vti_indexedpropertykeys", Microsoft.Security.Application.Encoder.HtmlEncode(MatterProvisionHelperUtility.GetEncodedValueForSearchIndexProperty(keys))); clientContext.Load(props); clientContext.ExecuteQuery(); SetPropertyValueForList(clientContext, props, matter.MatterName, propertyList); properties = ListOperations.GetPropertyValueForList(clientContext, matter.MatterName, propertyList); } catch (Exception exception) { Utility.DisplayAndLogError(Utility.ErrorFilePath, string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["ErrorMessage"], "while updating Metadata")); Utility.DisplayAndLogError(Utility.ErrorFilePath, "Message: " + exception.Message + "Matter name: " + matter.MatterName + "\nStacktrace: " + exception.StackTrace); throw; } return(properties); }