/// <summary> /// Reverts the changes for sample data based on the information provided /// </summary> /// <param name="matterDetailsCollection">Matter details collection</param> /// <param name="clientCollection">Client details collection</param> /// <param name="configVal">Configuration values from Excel</param> internal static void RevertData(List <DataStorage> matterDetailsCollection, ClientTermSets clientCollection, Dictionary <string, string> configVal) { try { if (null != matterDetailsCollection && null != clientCollection && null != configVal && 0 < matterDetailsCollection.Count) { foreach (DataStorage matterDetails in matterDetailsCollection) { Client clientObject = clientCollection.ClientTerms.Where(item => item.ClientName.Equals(matterDetails.ClientName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (null != clientObject) { using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(clientObject.ClientUrl, configVal)) { PropertyValues properties = clientContext.Web.Lists.GetByTitle(matterDetails.MatterPrefix).RootFolder.Properties; clientContext.Load(properties); clientContext.ExecuteQuery(); Matter matter = new Matter(matterDetails); matter.MatterGuid = properties.FieldValues.ContainsKey("MatterGUID") ? System.Web.HttpUtility.HtmlDecode(Convert.ToString(properties.FieldValues["MatterGUID"], CultureInfo.InvariantCulture)) : matterDetails.MatterPrefix; MatterProvisionHelper.DeleteMatter(clientContext, matter); } } else { Console.WriteLine("Failed to get Client Url for client: {0}", matterDetails.ClientName); Console.WriteLine("-------------------------------------------------------------------------------"); continue; } } } } catch (Exception exception) { Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Add Calendar Web Part to client site /// </summary> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="matter">Matter object containing Matter data</param> internal static void AddCalendarList(ClientContext clientContext, Matter matter) { string calendarName = string.Concat(matter.MatterName, ConfigurationManager.AppSettings["CalendarNameSuffix"]); try { Web web = clientContext.Web; clientContext.Load(web, item => item.ListTemplates); clientContext.ExecuteQuery(); ListTemplate listTemplate = null; foreach (var calendar in web.ListTemplates) { if (calendar.Name == Constants.CalendarName) { listTemplate = calendar; } } ListCreationInformation listCreationInformation = new ListCreationInformation(); listCreationInformation.TemplateType = listTemplate.ListTemplateTypeKind; listCreationInformation.Title = calendarName; // Added URL property for URL consolidation changes listCreationInformation.Url = Constants.TitleListPath + matter.MatterGuid + ConfigurationManager.AppSettings["CalendarNameSuffix"]; web.Lists.Add(listCreationInformation); web.Update(); clientContext.ExecuteQuery(); MatterProvisionHelperFunction.BreakPermission(clientContext, matter.MatterName, matter.CopyPermissionsFromParent, calendarName); } catch (Exception exception) { //// Generic Exception MatterProvisionHelperFunction.DeleteMatter(clientContext, matter); MatterProvisionHelperFunction.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Creates the OneNote. /// </summary> /// <param name="clientContext">The client context.</param> /// <param name="clientUrl">The client URL.</param> /// <param name="matter">Matter object containing Matter data</param> /// <returns>Returns the URL of the OneNote</returns> internal static string CreateOneNote(ClientContext clientContext, Uri clientUrl, Matter matter) { string returnValue = string.Empty; try { byte[] oneNoteFile = System.IO.File.ReadAllBytes("./Open Notebook.onetoc2"); Microsoft.SharePoint.Client.Web web = clientContext.Web; Microsoft.SharePoint.Client.File file = web.GetFolderByServerRelativeUrl(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", clientUrl.AbsolutePath, Constants.Backslash, matter.MatterGuid + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"], Constants.Backslash, matter.MatterGuid)).Files.Add(new FileCreationInformation() { Url = string.Format(CultureInfo.InvariantCulture, "{0}{1}", matter.MatterGuid, ConfigurationManager.AppSettings["ExtensionOneNoteTableOfContent"]), Overwrite = true, ContentStream = new MemoryStream(oneNoteFile) }); web.Update(); clientContext.Load(file); clientContext.ExecuteQuery(); ListItem oneNote = file.ListItemAllFields; oneNote["Title"] = matter.MatterName; oneNote.Update(); returnValue = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}{5}{6}", clientUrl.Scheme, Constants.COLON, Constants.Backslash, Constants.Backslash, clientUrl.Authority, file.ServerRelativeUrl, "?Web=1"); } catch (Exception exception) { Utility.DisplayAndLogError(Utility.ErrorFilePath, "Message: " + "Matter name: " + matter.MatterName + "\n" + exception.Message + "\nStacktrace: " + exception.StackTrace); throw; } return returnValue; }
/// <summary> /// Add Calendar Web Part to client site /// </summary> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="matter">Matter object containing Matter data</param> internal static void AddCalendarList(ClientContext clientContext, Matter matter) { string calendarName = string.Concat(matter.MatterName, ConfigurationManager.AppSettings["CalendarNameSuffix"]); try { Web web = clientContext.Web; clientContext.Load(web, item => item.ListTemplates); clientContext.ExecuteQuery(); ListTemplate listTemplate = null; foreach (var calendar in web.ListTemplates) { if (calendar.Name == Constants.CalendarName) { listTemplate = calendar; } } ListCreationInformation listCreationInformation = new ListCreationInformation(); listCreationInformation.TemplateType = listTemplate.ListTemplateTypeKind; listCreationInformation.Title = calendarName; // Added URL property for URL consolidation changes listCreationInformation.Url = Constants.TitleListPath + matter.MatterGuid + ConfigurationManager.AppSettings["CalendarNameSuffix"]; web.Lists.Add(listCreationInformation); web.Update(); clientContext.ExecuteQuery(); MatterProvisionHelperUtility.BreakPermission(clientContext, matter.MatterName, matter.CopyPermissionsFromParent, calendarName); } catch (Exception exception) { //// Generic Exception MatterProvisionHelper.DeleteMatter(clientContext, matter); DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Function is used to Configure XML of web parts /// </summary> /// <param name="client">Client object containing Client data</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="uri">To get URL segments</param> /// <param name="web">Web object of the current context</param> /// <returns>List of Web Parts</returns> internal static string[] ConfigureXMLCodeOfWebParts(Client client, Matter matter, ClientContext clientContext, List sitePageLib, FileCreationInformation objFileInfo, Uri uri, Web web) { string[] result = null; try { sitePageLib = web.Lists.GetByTitle(matter.MatterName); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); ////Configure list View Web Part XML string listViewWebPart = ConfigureListViewWebPart(sitePageLib, clientContext, objFileInfo, client, matter, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, Constants.Backslash, matter.MatterName, Constants.Backslash, objFileInfo.Url)); string[] contentEditorSectionIds = ConfigurationManager.AppSettings["MatterLandingPageSections"].Split(','); ////Configure content Editor Web Part of user information XML string contentEditorWebPartTasks = string.Empty; if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { contentEditorWebPartTasks = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.TaskPanel, CultureInfo.InvariantCulture)])); } string calendarWebpart = string.Empty, rssFeedWebPart = string.Empty, rssTitleWebPart = string.Empty; if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { rssFeedWebPart = string.Format(CultureInfo.InvariantCulture, Constants.RssFeedWebpart, HttpUtility.UrlEncode(matter.MatterName)); rssTitleWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.RSSTitlePanel, CultureInfo.InvariantCulture)])); } ////Configure calendar Web Part XML if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { ////If create calendar is enabled configure calendar Web Part XML; else don't configure calendarWebpart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.CalendarPanel, CultureInfo.InvariantCulture)])); } string matterInformationSection = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.InformationPanel, CultureInfo.InvariantCulture)])); string cssLink = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["MatterLandingCSSFileName"], ConfigurationManager.AppSettings["MatterLandingFolderName"]); string cssLinkCommon = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["CommonCSSFileName"], ConfigurationManager.AppSettings["CommonFolderName"]); string jsLinkMatterLandingPage = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["MatterLandingJSFileName"], ConfigurationManager.AppSettings["MatterLandingFolderName"]); string jsLinkJQuery = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["JQueryFileName"], ConfigurationManager.AppSettings["CommonFolderName"]); string jsCommonLink = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["CommonJSFileName"], ConfigurationManager.AppSettings["CommonFolderName"]); string headerWebPartSection = string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.HeaderPanel, CultureInfo.InvariantCulture)]); string footerWebPartSection = string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.FooterPanel, CultureInfo.InvariantCulture)]); headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.StyleTag, cssLink), headerWebPartSection); headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.StyleTag, cssLinkCommon), headerWebPartSection); headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTagWithContents, string.Format(CultureInfo.InvariantCulture, Constants.matterLandingStampProperties, matter.MatterName, matter.MatterGuid)), headerWebPartSection); footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTag, jsLinkMatterLandingPage), footerWebPartSection); footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTag, jsCommonLink), footerWebPartSection); footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTag, jsLinkJQuery), footerWebPartSection); string headerWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, headerWebPartSection); string footerWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, footerWebPartSection); string oneNoteWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.OneNotePanel, CultureInfo.InvariantCulture)])); string[] webParts = { headerWebPart, matterInformationSection, oneNoteWebPart, listViewWebPart, rssFeedWebPart, rssTitleWebPart, footerWebPart, calendarWebpart, contentEditorWebPartTasks }; result = webParts; } catch (Exception exception) { MatterProvisionHelperFunction.DeleteMatter(clientContext, matter); MatterProvisionHelperFunction.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } return(result); }
/// <summary> /// Creates matter /// </summary> internal static string CreateMatter(ClientContext clientContext, string url, Matter matterData, string folders) { string result = string.Empty; string oneNoteLibraryName = matterData.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"]; try { Microsoft.SharePoint.Client.Web web = clientContext.Web; clientContext.Load(web.Lists); clientContext.ExecuteQuery(); List matterLibrary = (from list in web.Lists where list.Title.ToString().ToUpper() == matterData.MatterName.ToUpper() select list).FirstOrDefault(); List oneNoteLibrary = (from list in web.Lists where list.Title.ToString().ToUpper() == oneNoteLibraryName.ToUpper() select list).FirstOrDefault(); Uri clientUri = new Uri(url); string requestedUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}{5}", clientUri.AbsolutePath, Constants.Backslash, ConfigurationManager.AppSettings["MatterLandingPageRepository"].Replace(Constants.SPACE, string.Empty), Constants.Backslash, matterData.MatterName, Constants.AspxExtension); bool isMatterLandingPageExists = PageExists(requestedUrl, clientContext); // Matter exists if (null != matterLibrary || null != oneNoteLibrary || isMatterLandingPageExists) { if (null != matterLibrary) { result = Constants.MatterLibraryExists; // return if matter library exists } else if (null != oneNoteLibrary) { result = Constants.OneNoteLibraryExists; // return if OneNote library exists } else if (isMatterLandingPageExists) { result = Constants.MatterLandingPageExists; // return if matter landing page exists } } else { //Create Document library CreateDocumentLibrary(matterData.MatterName, clientContext, folders, false, matterData); //Create OneNote library CreateDocumentLibrary(oneNoteLibraryName, clientContext, folders, true, matterData); if (Convert.ToBoolean(ConfigurationManager.AppSettings["CalendarCreationEnabled"], CultureInfo.InvariantCulture)) { MatterLandingHelperFunction.AddCalendarList(clientContext, matterData); } CreateOneNote(clientContext, new Uri(url), matterData); if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { CreateTaskList(clientContext, matterData); } result = Constants.MatterProvisionPrerequisitesSuccess; } } catch (Exception exception) { DeleteMatter(clientContext, matterData); DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "Matter name: " + matterData.MatterName + "\nStacktrace: " + exception.StackTrace); } return result; }
/// <summary> /// Creates Matter Landing Page on matter creation /// </summary> /// <param name="clientContext">Client Context</param> /// <param name="client">Client object containing Client data</param> /// <param name="matter">Matter object containing Matter data</param> /// <returns>true if success else false</returns> internal static string CreateMatterLandingPage(ClientContext clientContext, Client client, Matter matter) { string response = string.Empty; if (null != clientContext && null != client && null != matter) { try { using (clientContext) { Uri uri = new Uri(client.ClientUrl); Web web = clientContext.Web; FileCreationInformation objFileInfo = new FileCreationInformation(); List sitePageLib = null; //// Create Matter Landing Web Part Page objFileInfo.Url = string.Format(CultureInfo.InvariantCulture, "{0}{1}", matter.MatterGuid, Constants.AspxExtension); response = CreateWebPartPage(sitePageLib, clientContext, objFileInfo, matter, web); if (Constants.TRUE == response) { //// Configure All Web Parts string[] webParts = ConfigureXMLCodeOfWebParts(client, matter, clientContext, sitePageLib, objFileInfo, uri, web); Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, Constants.Backslash, ConfigurationManager.AppSettings["MatterLandingPageRepository"].Replace(Constants.SPACE, string.Empty), Constants.Backslash, objFileInfo.Url)); clientContext.Load(file); clientContext.ExecuteQuery(); LimitedWebPartManager limitedWebPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared); WebPartDefinition webPartDefinition = null; string[] zones = { Constants.HeaderZone, Constants.TopZone, Constants.RightZone, Constants.TopZone, Constants.RightZone, Constants.RightZone, Constants.FooterZone, Constants.RightZone, Constants.RightZone }; AddWebPart(clientContext, limitedWebPartManager, webPartDefinition, webParts, zones); } else { response = Constants.FALSE; } } } catch (Exception ex) { ////Generic Exception MatterProvisionHelperFunction.DisplayAndLogError(errorFilePath, string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["ErrorMessage"], "creating Matter Landing page")); MatterProvisionHelperFunction.DisplayAndLogError(errorFilePath, "Message: " + ex.Message + "\nStacktrace: " + ex.StackTrace); throw; } return response; } else { return string.Format(CultureInfo.InvariantCulture, Constants.ServiceResponse, string.Empty, Constants.MessageNoInputs); } }
/// <summary> /// Deletes Matter if exception occur post creation /// </summary> /// <param name="clientContext">Client context object for SharePoint</param> /// <param name="matter">Matter object containing Matter data</param> internal static void DeleteMatter(ClientContext clientContext, Matter matter) { //Delete matter library DeleteMatterObject(clientContext, matter.MatterName, true); //Delete Task List DeleteMatterObject(clientContext, matter.MatterName + ConfigurationManager.AppSettings["TaskListSuffix"], true); //Delete OneNote library DeleteMatterObject(clientContext, matter.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"], true); //Delete Calendar list DeleteMatterObject(clientContext, matter.MatterName + ConfigurationManager.AppSettings["CalendarNameSuffix"], true); //Delete Matter landing page DeleteMatterObject(clientContext, matter.MatterGuid, false); Console.WriteLine(ConfigurationManager.AppSettings["dashedLine"]); }
/// <summary> /// Creates task list while provisioning matter /// </summary> /// <param name="clientContext">Client context object</param> /// <param name="matter">Matter object containing Matter data</param> internal static void CreateTaskList(ClientContext clientContext, Matter matter) { try { Microsoft.SharePoint.Client.Web web = clientContext.Web; ListCreationInformation creationInfo = new ListCreationInformation(); string listName = matter.MatterName + ConfigurationManager.AppSettings["TaskListSuffix"]; creationInfo.Title = listName; creationInfo.Description = matter.MatterDescription; // Added list property for URL consolidation changes creationInfo.Url = Constants.TitleListPath + matter.MatterGuid + ConfigurationManager.AppSettings["TaskListSuffix"]; creationInfo.TemplateType = (int)ListTemplateType.Tasks; List list = web.Lists.Add(creationInfo); list.ContentTypesEnabled = false; list.Update(); clientContext.ExecuteQuery(); MatterProvisionHelperUtility.BreakPermission(clientContext, listName, matter.CopyPermissionsFromParent); } catch (Exception exception) { Utility.DisplayAndLogError(Utility.ErrorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Function is used to Configure XML of web parts /// </summary> /// <param name="client">Client object containing Client data</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="uri">To get URL segments</param> /// <param name="web">Web object of the current context</param> /// <returns>List of Web Parts</returns> internal static string[] ConfigureXMLCodeOfWebParts(Client client, Matter matter, ClientContext clientContext, List sitePageLib, FileCreationInformation objFileInfo, Uri uri, Web web) { string[] result = null; try { sitePageLib = web.Lists.GetByTitle(matter.MatterName); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); ////Configure list View Web Part XML string listViewWebPart = ConfigureListViewWebPart(sitePageLib, clientContext, objFileInfo, client, matter, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, Constants.Backslash, matter.MatterName, Constants.Backslash, objFileInfo.Url)); string[] contentEditorSectionIds = ConfigurationManager.AppSettings["MatterLandingPageSections"].Split(','); ////Configure content Editor Web Part of user information XML string contentEditorWebPartTasks = string.Empty; if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { contentEditorWebPartTasks = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.TaskPanel, CultureInfo.InvariantCulture)])); } string calendarWebpart = string.Empty, rssFeedWebPart = string.Empty, rssTitleWebPart = string.Empty; if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { rssFeedWebPart = string.Format(CultureInfo.InvariantCulture, Constants.RssFeedWebpart, HttpUtility.UrlEncode(matter.MatterName)); rssTitleWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.RSSTitlePanel, CultureInfo.InvariantCulture)])); } ////Configure calendar Web Part XML if (Convert.ToBoolean(ConfigurationManager.AppSettings["TaskListCreationEnabled"], CultureInfo.InvariantCulture)) { ////If create calendar is enabled configure calendar Web Part XML; else don't configure calendarWebpart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.CalendarPanel, CultureInfo.InvariantCulture)])); } string matterInformationSection = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.InformationPanel, CultureInfo.InvariantCulture)])); string cssLink = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["MatterLandingCSSFileName"], ConfigurationManager.AppSettings["MatterLandingFolderName"]); string cssLinkCommon = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["CommonCSSFileName"], ConfigurationManager.AppSettings["CommonFolderName"]); string jsLinkMatterLandingPage = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["MatterLandingJSFileName"], ConfigurationManager.AppSettings["MatterLandingFolderName"]); string jsLinkJQuery = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["JQueryFileName"], ConfigurationManager.AppSettings["CommonFolderName"]); string jsCommonLink = string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["CommonJSFileName"], ConfigurationManager.AppSettings["CommonFolderName"]); string headerWebPartSection = string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.HeaderPanel, CultureInfo.InvariantCulture)]); string footerWebPartSection = string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.FooterPanel, CultureInfo.InvariantCulture)]); headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.StyleTag, cssLink), headerWebPartSection); headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.StyleTag, cssLinkCommon), headerWebPartSection); headerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTagWithContents, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingStampProperties, matter.MatterName, matter.MatterGuid)), headerWebPartSection); footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTag, jsLinkMatterLandingPage), footerWebPartSection); footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTag, jsCommonLink), footerWebPartSection); footerWebPartSection = string.Concat(string.Format(CultureInfo.InvariantCulture, Constants.ScriptTag, jsLinkJQuery), footerWebPartSection); string headerWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, headerWebPartSection); string footerWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, footerWebPartSection); string oneNoteWebPart = string.Format(CultureInfo.InvariantCulture, Constants.ContentEditorWebPart, string.Format(CultureInfo.InvariantCulture, Constants.MatterLandingSectionContent, contentEditorSectionIds[Convert.ToInt32(Constants.MatterLandingSection.OneNotePanel, CultureInfo.InvariantCulture)])); string[] webParts = { headerWebPart, matterInformationSection, oneNoteWebPart, listViewWebPart, rssFeedWebPart, rssTitleWebPart, footerWebPart, calendarWebpart, contentEditorWebPartTasks }; result = webParts; } catch (Exception exception) { MatterProvisionHelper.DeleteMatter(clientContext, matter); Utility.DisplayAndLogError(Utility.ErrorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } return result; }
/// <summary> /// Configure XML Code of List View Web Part /// </summary> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="client">Client object containing Client data</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="titleUrl">Segment of URL</param> /// <returns>Configured ListView Web Part</returns> internal static string ConfigureListViewWebPart(List sitePageLib, ClientContext clientContext, FileCreationInformation objFileInfo, Client client, Matter matter, string titleUrl) { string listViewWebPart = Constants.ListviewWebpart; Uri uri = new Uri(client.ClientUrl); ViewCollection viewColl = sitePageLib.Views; clientContext.Load( viewColl, views => views.Include( view => view.Title, view => view.Id)); clientContext.ExecuteQuery(); string viewName = string.Empty; foreach (View view in viewColl) { viewName = view.Id.ToString(); break; } viewName = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Constants.OpeningCurlyBrace, viewName, Constants.ClosingCurlyBrace); listViewWebPart = string.Format(CultureInfo.InvariantCulture, listViewWebPart, sitePageLib.Id.ToString(), titleUrl, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Constants.OpeningCurlyBrace, sitePageLib.Id.ToString(), Constants.ClosingCurlyBrace), viewName, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, Constants.Backslash, matter.MatterName, Constants.Backslash, objFileInfo.Url)); return listViewWebPart; }
/// <summary> /// Creates sample data based on the information provided /// </summary> /// <param name="listval">Matter details collection</param> /// <param name="clientDetails">Client details collection</param> /// <param name="configVal">Config values from Excel</param> internal static void CreateData(List<DataStorage> listval, ClientTermSets clientDetails, Dictionary<string, string> configVal) { try { int successMatterNameCount = 0, alreadyExistsMatterCount = 0; Regex validateMatterId = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterId"]), validateMatterTitle = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterTitle"]), validateMatterDesc = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterDescription"]); //Read data from term store TermSets terms = TermStoreOperations.FetchGroupTerms(configVal); if (null == terms) { Utility.DisplayAndLogError(errorFilePath, "Failed to get Group Terms, skipping matter creation."); return; } else { MatterMetadata matterMetadata = new MatterMetadata(); //retrieve data from the list for (int count = 0; count < listval.Count; count++) { string clientName = listval[count].ClientName; /* Read from Term store */ Client client = clientDetails.ClientTerms.Where(item => item.ClientName.Equals(clientName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (null == client) { Console.WriteLine("Failed to get client Id and/or client Url from term store for '{0}' client.", clientName); Console.WriteLine("-------------------------------------------------------------------------------"); continue; } List<string> practiceGroupsList = Utility.ProcessString(listval[count].PracticeGroup).Split(';').ToList(); List<string> areaOfLawsList = Utility.ProcessString(listval[count].AreaOfLaw).Split(';').ToList(); List<string> subAreaOfLawsList = Utility.ProcessString(listval[count].SubAreaOfLaw).Split(';').ToList(); string folders = string.Empty; string documentTemplate = string.Empty; bool flag = false; AssociateTermStoreProperties(listval, terms, matterMetadata, count, practiceGroupsList, areaOfLawsList, subAreaOfLawsList, ref folders, ref documentTemplate, ref flag); if (string.IsNullOrWhiteSpace(documentTemplate) || string.IsNullOrWhiteSpace(listval[count].DefaultContentType)) { Console.WriteLine("Skipping matter creation as no matching document templates exists in term store corresponding to entry for '{0}' in the configuration Excel", client.ClientName); Console.WriteLine("-------------------------------------------------------------------------------"); continue; } string[] contentTypes = documentTemplate.Split(';'); Matter matterObj = new Matter(listval[count]); Console.WriteLine("Client details fetched"); Console.WriteLine("Client name: {0}", clientName); using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(client.ClientUrl, configVal)) { CheckMatterCreationStatus(configVal, ref successMatterNameCount, ref alreadyExistsMatterCount, validateMatterId, validateMatterTitle, validateMatterDesc, matterMetadata, clientName, client, folders, contentTypes, matterObj, clientContext); } } // end of for Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(ConfigurationManager.AppSettings["MatterSuccess"], successMatterNameCount, listval.Count); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ConfigurationManager.AppSettings["MatterFound"], alreadyExistsMatterCount); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ConfigurationManager.AppSettings["MatterFailure"], Convert.ToString((listval.Count - (successMatterNameCount + alreadyExistsMatterCount)), CultureInfo.InvariantCulture), listval.Count); Console.ForegroundColor = ConsoleColor.White; } } catch (Exception exception) { Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Reverts the changes for sample data based on the information provided /// </summary> /// <param name="matterDetailsCollection">Matter details collection</param> /// <param name="clientCollection">Client details collection</param> /// <param name="configVal">Configuration values from Excel</param> internal static void RevertData(List<DataStorage> matterDetailsCollection, ClientTermSets clientCollection, Dictionary<string, string> configVal) { try { if (null != matterDetailsCollection && null != clientCollection && null != configVal && 0 < matterDetailsCollection.Count) { foreach (DataStorage matterDetails in matterDetailsCollection) { Client clientObject = clientCollection.ClientTerms.Where(item => item.ClientName.Equals(matterDetails.ClientName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (null != clientObject) { using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(clientObject.ClientUrl, configVal)) { PropertyValues properties = clientContext.Web.Lists.GetByTitle(matterDetails.MatterPrefix).RootFolder.Properties; clientContext.Load(properties); clientContext.ExecuteQuery(); Matter matter = new Matter(matterDetails); matter.MatterGuid = properties.FieldValues.ContainsKey("MatterGUID") ? System.Web.HttpUtility.HtmlDecode(Convert.ToString(properties.FieldValues["MatterGUID"], CultureInfo.InvariantCulture)) : matterDetails.MatterPrefix; MatterProvisionHelper.DeleteMatter(clientContext, matter); } } else { Console.WriteLine("Failed to get Client Url for client: {0}", matterDetails.ClientName); Console.WriteLine("-------------------------------------------------------------------------------"); continue; } } } } catch (Exception exception) { Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Creates task list while provisioning matter /// </summary> /// <param name="clientContext">Client context object</param> /// <param name="matter">Matter object containing Matter data</param> internal static void CreateTaskList(ClientContext clientContext, Matter matter) { try { Microsoft.SharePoint.Client.Web web = clientContext.Web; ListCreationInformation creationInfo = new ListCreationInformation(); string listName = matter.MatterName + ConfigurationManager.AppSettings["TaskListSuffix"]; creationInfo.Title = listName; creationInfo.Description = matter.MatterDescription; // Added list property for URL consolidation changes creationInfo.Url = Constants.TitleListPath + matter.MatterGuid + ConfigurationManager.AppSettings["TaskListSuffix"]; creationInfo.TemplateType = (int)ListTemplateType.Tasks; List list = web.Lists.Add(creationInfo); list.ContentTypesEnabled = false; list.Update(); clientContext.ExecuteQuery(); BreakPermission(clientContext, listName, matter.CopyPermissionsFromParent); } catch (Exception exception) { DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }
/// <summary> /// Inserts details into LegalDMSMatters list /// </summary> /// <param name="configVal">Dictionary object</param> /// <param name="title">Title of matter</param> /// <param name="matter">Matter object</param> /// <param name="client">client object</param> /// <returns>Boolen value</returns> internal static string InsertIntoMatterCenterMatters(Dictionary<string, string> configVal, string title, Matter matter, Client client) { try { using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(configVal["CatalogSiteURL"], configVal)) { bool isConflict = Convert.ToBoolean(matter.Conflict.ConflictIdentified, CultureInfo.InvariantCulture); List<FieldUserValue> conflictByUsers = MatterProvisionHelperUtility.ResolveUserNames(configVal, matter.Conflict.ConflictCheckBy).ToList<FieldUserValue>(), blockedUsers = !string.IsNullOrEmpty(matter.TeamInfo.BlockedUsers.Trim()) ? MatterProvisionHelperUtility.ResolveUserNames(configVal, matter.TeamInfo.BlockedUsers).ToList<FieldUserValue>() : null, managingUsers = MatterProvisionHelperUtility.ResolveUserNames(configVal, matter.TeamInfo.ResponsibleAttorneys).ToList<FieldUserValue>(), supportUsers = !string.IsNullOrEmpty(matter.TeamInfo.Attorneys.Trim()) ? MatterProvisionHelperUtility.ResolveUserNames(configVal, matter.TeamInfo.Attorneys).ToList<FieldUserValue>() : null; List list = clientContext.Web.Lists.GetByTitle(ConfigurationManager.AppSettings["MatterCenterList"]); ListItemCreationInformation listCreationInformation = new ListItemCreationInformation(); ListItem listItem = list.AddItem(listCreationInformation); listItem["Title"] = title; // "MyTitle"; listItem["ClientName"] = client.ClientName; listItem["ClientID"] = client.ClientId; // "MyID"; listItem["MatterName"] = matter.MatterName; listItem["MatterID"] = matter.MatterId; listItem["ConflictCheckBy"] = conflictByUsers; listItem["ConflictCheckOn"] = matter.Conflict.ConflictCheckOn; listItem["ConflictIdentified"] = isConflict; if (isConflict) { listItem["BlockUsers"] = blockedUsers; } listItem["ManagingAttorney"] = managingUsers; listItem["Support"] = supportUsers; listItem.Update(); clientContext.ExecuteQuery(); } return "true"; } 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; } }
/// <summary> /// Create a Web Part page of matter in its document library /// </summary> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="web">Web object containing Web data</param> /// <returns>true if success else false</returns> internal static string CreateWebPartPage(List sitePageLib, ClientContext clientContext, FileCreationInformation objFileInfo, Matter matter, Web web) { string response = string.Empty; //// Find Default Layout from Master Page Gallery to create Web Part Page sitePageLib = web.Lists.GetByTitle(Constants.MasterPageGallery); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = Constants.DMSRoleQuery; ListItemCollection collection = sitePageLib.GetItems(camlQuery); clientContext.Load( collection, items => items.Include( item => item.DisplayName, item => item.Id)); clientContext.ExecuteQuery(); response = WebPartsCreation(sitePageLib, clientContext, objFileInfo, matter, web, collection); return response; }
/// <summary> /// Configure XML Code of List View Web Part /// </summary> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="client">Client object containing Client data</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="titleUrl">Segment of URL</param> /// <returns>Configured ListView Web Part</returns> internal static string ConfigureListViewWebPart(List sitePageLib, ClientContext clientContext, FileCreationInformation objFileInfo, Client client, Matter matter, string titleUrl) { string listViewWebPart = Constants.ListviewWebpart; Uri uri = new Uri(client.ClientUrl); ViewCollection viewColl = sitePageLib.Views; clientContext.Load( viewColl, views => views.Include( view => view.Title, view => view.Id)); clientContext.ExecuteQuery(); string viewName = string.Empty; foreach (View view in viewColl) { viewName = view.Id.ToString(); break; } viewName = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Constants.OpeningCurlyBrace, viewName, Constants.ClosingCurlyBrace); listViewWebPart = string.Format(CultureInfo.InvariantCulture, listViewWebPart, sitePageLib.Id.ToString(), titleUrl, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", Constants.OpeningCurlyBrace, sitePageLib.Id.ToString(), Constants.ClosingCurlyBrace), viewName, string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, Constants.Backslash, matter.MatterName, Constants.Backslash, objFileInfo.Url)); return(listViewWebPart); }
/// <summary> /// Method to check matter creation status /// </summary> /// <param name="configVal">dictionary object</param> /// <param name="successMatterNameCount">success matter name</param> /// <param name="alreadyExistsMatterCount">count of existing matter</param> /// <param name="validateMatterId">validate matter id</param> /// <param name="validateMatterTitle">validate title</param> /// <param name="validateMatterDesc"> validate description</param> /// <param name="matterMetadata">matter metadata</param> /// <param name="clientName">client name</param> /// <param name="client">client object</param> /// <param name="folders">folder name</param> /// <param name="contentTypes">array of content type</param> /// <param name="matterObj">matter object</param> /// <param name="clientContext">client context</param> private static void CheckMatterCreationStatus(Dictionary <string, string> configVal, ref int successMatterNameCount, ref int alreadyExistsMatterCount, Regex validateMatterId, Regex validateMatterTitle, Regex validateMatterDesc, MatterMetadata matterMetadata, string clientName, Client client, string folders, string[] contentTypes, Matter matterObj, ClientContext clientContext) { string matterCreatedSuccessfully; if (Convert.ToInt32(ConfigurationManager.AppSettings["MatterIdMaxLength"], CultureInfo.InvariantCulture) < matterObj.MatterId.Length || (!validateMatterId.IsMatch(matterObj.MatterId))) { matterCreatedSuccessfully = Constants.InvalidMatterID; } else if (Convert.ToInt32(ConfigurationManager.AppSettings["MatterTitleMaxLength"], CultureInfo.InvariantCulture) < matterObj.MatterName.Length || (!validateMatterTitle.IsMatch(matterObj.MatterName))) { matterCreatedSuccessfully = Constants.InvalidMatterTitle; } else if (!validateMatterDesc.IsMatch(matterObj.MatterDescription)) { matterCreatedSuccessfully = Constants.InvalidMatterDescription; } else if (Constants.InvalidConflictDate.Equals(matterObj.Conflict.ConflictCheckOn)) { matterCreatedSuccessfully = Constants.InvalidConflictDate; } else { // Call to create matter matterCreatedSuccessfully = MatterProvisionHelper.CreateMatter(clientContext, client.ClientUrl, matterObj, folders); } if (Constants.MatterProvisionPrerequisitesSuccess == matterCreatedSuccessfully) { try { successMatterNameCount = OnMatterCreationSuccess(configVal, successMatterNameCount, matterMetadata, clientName, client, contentTypes, matterObj, clientContext); } catch (Exception exception) { Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); MatterProvisionHelper.DeleteMatter(clientContext, matterObj); } } else { switch (matterCreatedSuccessfully) { case "1": // matter is already present Console.WriteLine("Matter: {0} is already present", matterObj.MatterName); alreadyExistsMatterCount++; break; case "2": // OneNote library is already present Console.WriteLine("OneNote Library: {0} is already present", matterObj.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"]); alreadyExistsMatterCount++; break; case "3": // matter landing page is already present Console.WriteLine("Matter Landing Page: {0} is already present", matterObj.MatterName); alreadyExistsMatterCount++; break; case "4": // Validation fail for matter ID Console.WriteLine("Matter Id validation fail for Matter {0}", matterObj.MatterName); break; case "5": // Validation fail for matter Name Console.WriteLine("Matter Name validation fail for Matter {0}", matterObj.MatterName); break; case "6": // Validation fail for matter description Console.WriteLine("Matter Description validation fail for Matter {0}", matterObj.MatterName); break; case "7": // Validation fail for conflict date Console.WriteLine("Conflict date validation fail for Matter {0}", matterObj.MatterName); break; } Console.WriteLine("-------------------------------------------------------------------------------"); } }
/// <summary> /// Breaks, assigns user permission and create Web Parts layout in Matter Landing Page /// </summary> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="web">Web object containing Web data</param> /// <param name="collection">ListItemCollection object consist of items in Master Page Library</param> /// <returns>true or exception value</returns> internal static string WebPartsCreation(List sitePageLib, ClientContext clientContext, FileCreationInformation objFileInfo, Matter matter, Web web, ListItemCollection collection) { ListItem fileName = null; foreach (ListItem findLayout in collection) { if (findLayout.DisplayName.Equals(Constants.DefaultLayout, StringComparison.OrdinalIgnoreCase)) { fileName = findLayout; break; } } Microsoft.SharePoint.Client.File fileLayout = fileName.File; clientContext.Load(fileLayout); clientContext.ExecuteQuery(); ClientResult <Stream> filedata = fileLayout.OpenBinaryStream(); sitePageLib = web.Lists.GetByTitle(ConfigurationManager.AppSettings["MatterLandingPageRepository"]); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); StreamReader reader = new StreamReader(filedata.Value); objFileInfo.Content = System.Text.Encoding.ASCII.GetBytes(reader.ReadToEnd()); int matterLandingPageId = AddMatterLandingPageFile(sitePageLib, clientContext, objFileInfo, matter.MatterName); BreakItemPermission(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], matter.CopyPermissionsFromParent, matterLandingPageId); List <string> responsibleAttorneyList = matter.TeamInfo.ResponsibleAttorneys.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>(); List <string> attorneyList = matter.TeamInfo.Attorneys.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>(); List <string> blockedUserList = matter.TeamInfo.BlockedUploadUsers.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList <string>(); if (0 < responsibleAttorneyList.Count) { AssignUserPermissionsToItem(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], responsibleAttorneyList, ConfigurationManager.AppSettings["FullControl"], matterLandingPageId); } if (0 < attorneyList.Count) { AssignUserPermissionsToItem(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], attorneyList, ConfigurationManager.AppSettings["Contribute"], matterLandingPageId); } if (0 < blockedUserList.Count) { AssignUserPermissionsToItem(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], blockedUserList, ConfigurationManager.AppSettings["Read"], matterLandingPageId); } return(Constants.TRUE); }
/// <summary> /// Create a Web Part page of matter in its document library /// </summary> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="web">Web object containing Web data</param> /// <returns>true if success else false</returns> internal static string CreateWebPartPage(List sitePageLib, ClientContext clientContext, FileCreationInformation objFileInfo, Matter matter, Web web) { string response = string.Empty; //// Find Default Layout from Master Page Gallery to create Web Part Page sitePageLib = web.Lists.GetByTitle(Constants.MasterPageGallery); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = Constants.DMSRoleQuery; ListItemCollection collection = sitePageLib.GetItems(camlQuery); clientContext.Load( collection, items => items.Include( item => item.DisplayName, item => item.Id)); clientContext.ExecuteQuery(); response = WebPartsCreation(sitePageLib, clientContext, objFileInfo, matter, web, collection); return(response); }
/// <summary> /// Updates meta data for list /// </summary> 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(GetEncodedValueForSearchIndexProperty(keys))); clientContext.Load(props); clientContext.ExecuteQuery(); SetPropertyValueForList(clientContext, props, matter.MatterName, propertyList); properties = GetPropertyValueForList(clientContext, matter.MatterName, propertyList); } catch (Exception exception) { DisplayAndLogError(errorFilePath, string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["ErrorMessage"], "while updating Metadata")); DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "Matter name: " + matter.MatterName + "\nStacktrace: " + exception.StackTrace); throw; } return properties; }
/// <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> /// Breaks, assigns user permission and create Web Parts layout in Matter Landing Page /// </summary> /// <param name="sitePageLib">SharePoint List of matter library</param> /// <param name="clientContext">SharePoint Client Context</param> /// <param name="objFileInfo">Object of FileCreationInformation</param> /// <param name="matter">Matter object containing Matter data</param> /// <param name="web">Web object containing Web data</param> /// <param name="collection">ListItemCollection object consist of items in Master Page Library</param> /// <returns>true or exception value</returns> internal static string WebPartsCreation(List sitePageLib, ClientContext clientContext, FileCreationInformation objFileInfo, Matter matter, Web web, ListItemCollection collection) { ListItem fileName = null; foreach (ListItem findLayout in collection) { if (findLayout.DisplayName.Equals(Constants.DefaultLayout, StringComparison.OrdinalIgnoreCase)) { fileName = findLayout; break; } } Microsoft.SharePoint.Client.File fileLayout = fileName.File; clientContext.Load(fileLayout); clientContext.ExecuteQuery(); ClientResult<Stream> filedata = fileLayout.OpenBinaryStream(); sitePageLib = web.Lists.GetByTitle(ConfigurationManager.AppSettings["MatterLandingPageRepository"]); clientContext.Load(sitePageLib); clientContext.ExecuteQuery(); StreamReader reader = new StreamReader(filedata.Value); objFileInfo.Content = System.Text.Encoding.ASCII.GetBytes(reader.ReadToEnd()); int matterLandingPageId = AddMatterLandingPageFile(sitePageLib, clientContext, objFileInfo, matter.MatterName); BreakItemPermission(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], matter.CopyPermissionsFromParent, matterLandingPageId); List<string> responsibleAttorneyList = matter.TeamInfo.ResponsibleAttorneys.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); List<string> attorneyList = matter.TeamInfo.Attorneys.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); List<string> blockedUserList = matter.TeamInfo.BlockedUploadUsers.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); if (0 < responsibleAttorneyList.Count) { AssignUserPermissionsToItem(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], responsibleAttorneyList, ConfigurationManager.AppSettings["FullControl"], matterLandingPageId); } if (0 < attorneyList.Count) { AssignUserPermissionsToItem(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], attorneyList, ConfigurationManager.AppSettings["Contribute"], matterLandingPageId); } if (0 < blockedUserList.Count) { AssignUserPermissionsToItem(clientContext, ConfigurationManager.AppSettings["MatterLandingPageRepository"], blockedUserList, ConfigurationManager.AppSettings["Read"], matterLandingPageId); } return Constants.TRUE; }
/// <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); }
/// <summary> /// Creates Matter Landing Page on matter creation /// </summary> /// <param name="clientContext">Client Context</param> /// <param name="client">Client object containing Client data</param> /// <param name="matter">Matter object containing Matter data</param> /// <returns>true if success else false</returns> internal static string CreateMatterLandingPage(ClientContext clientContext, Client client, Matter matter) { string response = string.Empty; if (null != clientContext && null != client && null != matter) { try { using (clientContext) { Uri uri = new Uri(client.ClientUrl); Web web = clientContext.Web; FileCreationInformation objFileInfo = new FileCreationInformation(); List sitePageLib = null; //// Create Matter Landing Web Part Page objFileInfo.Url = string.Format(CultureInfo.InvariantCulture, "{0}{1}", matter.MatterGuid, Constants.AspxExtension); response = CreateWebPartPage(sitePageLib, clientContext, objFileInfo, matter, web); if (Constants.TRUE == response) { //// Configure All Web Parts string[] webParts = ConfigureXMLCodeOfWebParts(client, matter, clientContext, sitePageLib, objFileInfo, uri, web); Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}{4}", uri.AbsolutePath, Constants.Backslash, ConfigurationManager.AppSettings["MatterLandingPageRepository"].Replace(Constants.SPACE, string.Empty), Constants.Backslash, objFileInfo.Url)); clientContext.Load(file); clientContext.ExecuteQuery(); LimitedWebPartManager limitedWebPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared); WebPartDefinition webPartDefinition = null; string[] zones = { Constants.HeaderZone, Constants.TopZone, Constants.RightZone, Constants.TopZone, Constants.RightZone, Constants.RightZone, Constants.FooterZone, Constants.RightZone, Constants.RightZone }; AddWebPart(clientContext, limitedWebPartManager, webPartDefinition, webParts, zones); } else { response = Constants.FALSE; } } } catch (Exception ex) { ////Generic Exception MatterProvisionHelperFunction.DisplayAndLogError(errorFilePath, string.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["ErrorMessage"], "creating Matter Landing page")); MatterProvisionHelperFunction.DisplayAndLogError(errorFilePath, "Message: " + ex.Message + "\nStacktrace: " + ex.StackTrace); throw; } return(response); } else { return(string.Format(CultureInfo.InvariantCulture, Constants.ServiceResponse, string.Empty, Constants.MessageNoInputs)); } }
/// <summary> /// Function to create document library for Matter and OneNote /// </summary> /// <param name="libraryName">Matter library name</param> /// <param name="clientContext">client context information</param> /// <param name="folders">folders to create in document library</param> /// <param name="isOneNoteLibrary">Flag to determine OneNote library or Matter Library</param> /// <param name="matter">Matter object containing Matter data</param> internal static void CreateDocumentLibrary(string libraryName, ClientContext clientContext, string folders, bool isOneNoteLibrary, Matter matter) { IList<string> folderNames = new List<string>(); Microsoft.SharePoint.Client.Web web = clientContext.Web; ListCreationInformation creationInfo = new ListCreationInformation(); creationInfo.Title = libraryName; creationInfo.Description = matter.MatterDescription; creationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary; // Added library GUID for URL consolidation changes creationInfo.Url = matter.MatterGuid + (isOneNoteLibrary ? ConfigurationManager.AppSettings["OneNoteLibrarySuffix"] : string.Empty); List list = web.Lists.Add(creationInfo); list.ContentTypesEnabled = true; // Version setting for OneNote document library if (isOneNoteLibrary) { list.EnableVersioning = false; string oneNoteFolderName = string.Empty; oneNoteFolderName = matter.MatterGuid; // create folder folderNames = new List<string>() { oneNoteFolderName }; } else { list.EnableVersioning = true; list.EnableMinorVersions = false; list.ForceCheckout = false; //Addition of Email folder folderNames = folders.Split(';').Where(folder => !string.IsNullOrWhiteSpace(folder.Trim())).ToList(); } list.Update(); clientContext.ExecuteQuery(); Utility.AddFolders(clientContext, list, folderNames); MatterProvisionHelperUtility.BreakPermission(clientContext, libraryName, matter.CopyPermissionsFromParent); }
/// <summary> /// Method to check matter creation status /// </summary> /// <param name="configVal">dictionary object</param> /// <param name="successMatterNameCount">success matter name</param> /// <param name="alreadyExistsMatterCount">count of existing matter</param> /// <param name="validateMatterId">validate matter id</param> /// <param name="validateMatterTitle">validate title</param> /// <param name="validateMatterDesc"> validate description</param> /// <param name="matterMetadata">matter metadata</param> /// <param name="clientName">client name</param> /// <param name="client">client object</param> /// <param name="folders">folder name</param> /// <param name="contentTypes">array of content type</param> /// <param name="matterObj">matter object</param> /// <param name="clientContext">client context</param> private static void CheckMatterCreationStatus(Dictionary<string, string> configVal, ref int successMatterNameCount, ref int alreadyExistsMatterCount, Regex validateMatterId, Regex validateMatterTitle, Regex validateMatterDesc, MatterMetadata matterMetadata, string clientName, Client client, string folders, string[] contentTypes, Matter matterObj, ClientContext clientContext) { string matterCreatedSuccessfully; if (Convert.ToInt32(ConfigurationManager.AppSettings["MatterIdMaxLength"], CultureInfo.InvariantCulture) < matterObj.MatterId.Length || (!validateMatterId.IsMatch(matterObj.MatterId))) { matterCreatedSuccessfully = Constants.InvalidMatterID; } else if (Convert.ToInt32(ConfigurationManager.AppSettings["MatterTitleMaxLength"], CultureInfo.InvariantCulture) < matterObj.MatterName.Length || (!validateMatterTitle.IsMatch(matterObj.MatterName))) { matterCreatedSuccessfully = Constants.InvalidMatterTitle; } else if (!validateMatterDesc.IsMatch(matterObj.MatterDescription)) { matterCreatedSuccessfully = Constants.InvalidMatterDescription; } else if (Constants.InvalidConflictDate.Equals(matterObj.Conflict.ConflictCheckOn)) { matterCreatedSuccessfully = Constants.InvalidConflictDate; } else { // Call to create matter matterCreatedSuccessfully = MatterProvisionHelper.CreateMatter(clientContext, client.ClientUrl, matterObj, folders); } if (Constants.MatterProvisionPrerequisitesSuccess == matterCreatedSuccessfully) { try { successMatterNameCount = OnMatterCreationSuccess(configVal, successMatterNameCount, matterMetadata, clientName, client, contentTypes, matterObj, clientContext); } catch (Exception exception) { Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); MatterProvisionHelper.DeleteMatter(clientContext, matterObj); } } else { switch (matterCreatedSuccessfully) { case "1": // matter is already present Console.WriteLine("Matter: {0} is already present", matterObj.MatterName); alreadyExistsMatterCount++; break; case "2": // OneNote library is already present Console.WriteLine("OneNote Library: {0} is already present", matterObj.MatterName + ConfigurationManager.AppSettings["OneNoteLibrarySuffix"]); alreadyExistsMatterCount++; break; case "3": // matter landing page is already present Console.WriteLine("Matter Landing Page: {0} is already present", matterObj.MatterName); alreadyExistsMatterCount++; break; case "4": // Validation fail for matter ID Console.WriteLine("Matter Id validation fail for Matter {0}", matterObj.MatterName); break; case "5": // Validation fail for matter Name Console.WriteLine("Matter Name validation fail for Matter {0}", matterObj.MatterName); break; case "6": // Validation fail for matter description Console.WriteLine("Matter Description validation fail for Matter {0}", matterObj.MatterName); break; case "7": // Validation fail for conflict date Console.WriteLine("Conflict date validation fail for Matter {0}", matterObj.MatterName); break; } Console.WriteLine("-------------------------------------------------------------------------------"); } }
/// <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> /// Creates sample data based on the information provided /// </summary> /// <param name="listval">Matter details collection</param> /// <param name="clientDetails">Client details collection</param> /// <param name="configVal">Config values from Excel</param> internal static void CreateData(List <DataStorage> listval, ClientTermSets clientDetails, Dictionary <string, string> configVal) { try { int successMatterNameCount = 0, alreadyExistsMatterCount = 0; Regex validateMatterId = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterId"]), validateMatterTitle = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterTitle"]), validateMatterDesc = new Regex(ConfigurationManager.AppSettings["SpecialCharacterExpressionMatterDescription"]); //Read data from term store TermSets terms = TermStoreOperations.FetchGroupTerms(configVal); if (null == terms) { Utility.DisplayAndLogError(errorFilePath, "Failed to get Group Terms, skipping matter creation."); return; } else { MatterMetadata matterMetadata = new MatterMetadata(); //retrieve data from the list for (int count = 0; count < listval.Count; count++) { string clientName = listval[count].ClientName; /* Read from Term store */ Client client = clientDetails.ClientTerms.Where(item => item.ClientName.Equals(clientName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (null == client) { Console.WriteLine("Failed to get client Id and/or client Url from term store for '{0}' client.", clientName); Console.WriteLine("-------------------------------------------------------------------------------"); continue; } List <string> practiceGroupsList = Utility.ProcessString(listval[count].PracticeGroup).Split(';').ToList(); List <string> areaOfLawsList = Utility.ProcessString(listval[count].AreaOfLaw).Split(';').ToList(); List <string> subAreaOfLawsList = Utility.ProcessString(listval[count].SubAreaOfLaw).Split(';').ToList(); string folders = string.Empty; string documentTemplate = string.Empty; bool flag = false; AssociateTermStoreProperties(listval, terms, matterMetadata, count, practiceGroupsList, areaOfLawsList, subAreaOfLawsList, ref folders, ref documentTemplate, ref flag); if (string.IsNullOrWhiteSpace(documentTemplate) || string.IsNullOrWhiteSpace(listval[count].DefaultContentType)) { Console.WriteLine("Skipping matter creation as no matching document templates exists in term store corresponding to entry for '{0}' in the configuration Excel", client.ClientName); Console.WriteLine("-------------------------------------------------------------------------------"); continue; } string[] contentTypes = documentTemplate.Split(';'); Matter matterObj = new Matter(listval[count]); Console.WriteLine("Client details fetched"); Console.WriteLine("Client name: {0}", clientName); using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(client.ClientUrl, configVal)) { CheckMatterCreationStatus(configVal, ref successMatterNameCount, ref alreadyExistsMatterCount, validateMatterId, validateMatterTitle, validateMatterDesc, matterMetadata, clientName, client, folders, contentTypes, matterObj, clientContext); } } // end of for Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(ConfigurationManager.AppSettings["MatterSuccess"], successMatterNameCount, listval.Count); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ConfigurationManager.AppSettings["MatterFound"], alreadyExistsMatterCount); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ConfigurationManager.AppSettings["MatterFailure"], Convert.ToString((listval.Count - (successMatterNameCount + alreadyExistsMatterCount)), CultureInfo.InvariantCulture), listval.Count); Console.ForegroundColor = ConsoleColor.White; } } catch (Exception exception) { Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace); } }