Пример #1
0
        /// <summary>
        /// Function to create document library for Matter and OneNote
        /// </summary>
        /// <param name="clientContext">Client Context</param>
        /// <param name="listInfo">List information</param>
        /// <returns>Success flag</returns>

        public static bool Create(ClientContext clientContext, ListInformation listInfo)
        {
            bool result = true;

            if (null != clientContext && null != listInfo && !string.IsNullOrWhiteSpace(listInfo.name))
            {
                Web web = clientContext.Web;
                ListTemplateCollection  listTemplates = web.ListTemplates;
                ListCreationInformation creationInfo  = new ListCreationInformation();
                creationInfo.Title       = listInfo.name;
                creationInfo.Description = listInfo.description;
                // To determine changes in URL we specified below condition as this function is common
                if (!string.IsNullOrWhiteSpace(listInfo.Path))
                {
                    creationInfo.Url = listInfo.Path;
                }
                if (!string.IsNullOrWhiteSpace(listInfo.templateType))
                {
                    string templateType = listInfo.templateType;
                    clientContext.Load(listTemplates, item => item.Include(currentTemplate => currentTemplate.Name, currentTemplate => currentTemplate.ListTemplateTypeKind).Where(selectedTemplate => selectedTemplate.Name == templateType));
                    clientContext.ExecuteQuery();
                    if (null != listTemplates && 0 < listTemplates.Count)
                    {
                        creationInfo.TemplateType = listTemplates.FirstOrDefault().ListTemplateTypeKind;
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    creationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary;
                }
                if (result)
                {
                    List list = web.Lists.Add(creationInfo);
                    list.ContentTypesEnabled = listInfo.isContentTypeEnable;
                    if (null != listInfo.folderNames && listInfo.folderNames.Count > 0)
                    {
                        list = Lists.AddFolders(clientContext, list, listInfo.folderNames);
                    }
                    if (null != listInfo.versioning)
                    {
                        list.EnableVersioning    = listInfo.versioning.EnableVersioning;
                        list.EnableMinorVersions = listInfo.versioning.EnableMinorVersions;
                        list.ForceCheckout       = listInfo.versioning.ForceCheckout;
                    }
                    list.Update();
                    clientContext.Load(list, l => l.DefaultViewUrl);
                    clientContext.ExecuteQuery();
                    result = true;
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Function to create document library for Matter and OneNote
        /// </summary>
        /// <param name="clientContext">Client Context</param>
        /// <param name="listInfo">List information</param>
        /// <returns>Success flag</returns>

        public static bool Create(ClientContext clientContext, ListInformation listInfo)
        {
            bool result = true;
            if (null != clientContext && null != listInfo && !string.IsNullOrWhiteSpace(listInfo.name))
            {
                Web web = clientContext.Web;
                ListTemplateCollection listTemplates = web.ListTemplates;
                ListCreationInformation creationInfo = new ListCreationInformation();
                creationInfo.Title = listInfo.name;
                creationInfo.Description = listInfo.description;
                // To determine changes in URL we specified below condition as this function is common
                if (!string.IsNullOrWhiteSpace(listInfo.Path))
                {
                    creationInfo.Url = listInfo.Path;
                }
                if (!string.IsNullOrWhiteSpace(listInfo.templateType))
                {
                    string templateType = listInfo.templateType;
                    clientContext.Load(listTemplates, item => item.Include(currentTemplate => currentTemplate.Name, currentTemplate => currentTemplate.ListTemplateTypeKind).Where(selectedTemplate => selectedTemplate.Name == templateType));
                    clientContext.ExecuteQuery();
                    if (null != listTemplates && 0 < listTemplates.Count)
                    {
                        creationInfo.TemplateType = listTemplates.FirstOrDefault().ListTemplateTypeKind;
                    }
                    else
                    {
                        result = false;
                    }
                }
                else
                {
                    creationInfo.TemplateType = (int)ListTemplateType.DocumentLibrary;
                }
                if (result)
                {
                    List list = web.Lists.Add(creationInfo);
                    list.ContentTypesEnabled = listInfo.isContentTypeEnable;
                    if (null != listInfo.folderNames && listInfo.folderNames.Count > 0)
                    {
                        list = Lists.AddFolders(clientContext, list, listInfo.folderNames);
                    }
                    if (null != listInfo.versioning)
                    {
                        list.EnableVersioning = listInfo.versioning.EnableVersioning;
                        list.EnableMinorVersions = listInfo.versioning.EnableMinorVersions;
                        list.ForceCheckout = listInfo.versioning.ForceCheckout;
                    }
                    list.Update();
                    clientContext.Load(list, l => l.DefaultViewUrl);
                    clientContext.ExecuteQuery();
                    result = true;
                }
            }
            return result;
        }
        /// <summary>
        /// Utility function to create matter.
        /// </summary>
        /// <param name="requestObject">object of type request object</param>
        /// <param name="client">object of client</param>
        /// <param name="matter">object of matter type</param>
        /// <param name="clientContext">client context information</param>
        /// <param name="matterURL">URL of matter</param>
        /// <returns>Matter URL</returns>
        internal static string CreateMatterUtility(RequestObject requestObject, Client client, Matter matter, ClientContext clientContext, string matterURL, MatterConfigurations matterConfigurations)
        {
            try
            {
                Uri centralListURL = new Uri(string.Concat(ServiceConstantStrings.CentralRepositoryUrl, ConstantStrings.ForwardSlash, ConstantStrings.Lists, ConstantStrings.ForwardSlash, ServiceConstantStrings.DMSMatterListName)); // Central Repository List URL
                IList<string> documentLibraryFolders = new List<string>();
                Dictionary<string, bool> documentLibraryVersioning = new Dictionary<string, bool>();
                Uri clientUrl = new Uri(client.Url);

                ListInformation listInformation = new ListInformation();
                listInformation.name = matter.Name;
                listInformation.description = matter.Description;
                listInformation.folderNames = matter.FolderNames;
                listInformation.isContentTypeEnable = true;
                listInformation.versioning = new VersioningInfo();
                listInformation.versioning.EnableVersioning = ServiceConstantStrings.IsMajorVersionEnable;
                listInformation.versioning.EnableMinorVersions = ServiceConstantStrings.IsMinorVersionEnable;
                listInformation.versioning.ForceCheckout = ServiceConstantStrings.IsForceCheckOut;
                listInformation.Path = matter.MatterGuid;

                Lists.Create(clientContext, listInformation);

                documentLibraryVersioning.Add("EnableVersioning", false);
                documentLibraryFolders.Add(matter.MatterGuid);
                listInformation.name = matter.Name + ServiceConstantStrings.OneNoteLibrarySuffix;
                listInformation.folderNames = documentLibraryFolders;
                listInformation.versioning.EnableVersioning = false;
                listInformation.versioning.EnableMinorVersions = false;
                listInformation.versioning.ForceCheckout = false;
                listInformation.Path = matter.MatterGuid + ServiceConstantStrings.OneNoteLibrarySuffix;
                Lists.Create(clientContext, listInformation);

                bool isCopyRoleAssignment = CopyRoleAssignment(matter.Conflict.Identified, matter.Conflict.SecureMatter);
                //create calendar list if create calendar flag is enabled and break its permissions
                string calendarName = string.Concat(matter.Name, ServiceConstantStrings.CalendarNameSuffix);
                string taskListName = string.Concat(matter.Name, ServiceConstantStrings.TaskNameSuffix);
                if (ServiceConstantStrings.IsCreateCalendarEnabled && matterConfigurations.IsCalendarSelected)
                {
                    ListInformation calendarInformation = new ListInformation();
                    calendarInformation.name = calendarName;
                    calendarInformation.isContentTypeEnable = false;
                    calendarInformation.templateType = ConstantStrings.CalendarName;
                    calendarInformation.Path = ServiceConstantStrings.TitleListsPath + matter.MatterGuid + ServiceConstantStrings.CalendarNameSuffix;

                    if (Lists.Create(clientContext, calendarInformation))
                    {
                        Lists.BreakPermission(clientContext, calendarName, isCopyRoleAssignment);
                    }
                    else
                    {
                        MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeAddCalendarList, TextConstants.ErrorMessageAddCalendarList);
                        throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function
                    }
                }
                if (matterConfigurations.IsTaskSelected)
                {
                    ListInformation taskListInformation = new ListInformation();
                    taskListInformation.name = taskListName;
                    taskListInformation.isContentTypeEnable = false;
                    taskListInformation.templateType = ConstantStrings.TaskListTemplateType;
                    taskListInformation.Path = ServiceConstantStrings.TitleListsPath + matter.MatterGuid + ServiceConstantStrings.TaskNameSuffix;
                    if (Lists.Create(clientContext, taskListInformation))
                    {
                        Lists.BreakPermission(clientContext, taskListName, isCopyRoleAssignment);
                    }
                    else
                    {
                        MatterCenterException customException = new MatterCenterException(TextConstants.ErrorCodeAddTaskList, TextConstants.ErrorMessageAddTaskList);
                        throw customException; // Throw will direct to current function's catch block (if present). If not present then it will direct to parent catch block. Parent will be the calling function
                    }
                }
                string oneNoteUrl = string.Concat(clientUrl.AbsolutePath, ConstantStrings.ForwardSlash, matter.MatterGuid, ServiceConstantStrings.OneNoteLibrarySuffix, ConstantStrings.ForwardSlash, matter.MatterGuid);
                matterURL = Lists.AddOneNote(clientContext, client.Url, oneNoteUrl, matter.MatterGuid, matter.Name);
                matterURL = string.Format(CultureInfo.InvariantCulture, ConstantStrings.ServiceResponse, string.Empty, client.Url);
                if (null != matter.Conflict)
                {
                    //Break permission for Matter library
                    Lists.BreakPermission(clientContext, matter.Name, isCopyRoleAssignment);

                    //Break permission for OneNote document library
                    string oneNoteLibraryName = string.Concat(matter.Name, ServiceConstantStrings.OneNoteLibrarySuffix);
                    Lists.BreakPermission(clientContext, oneNoteLibraryName, isCopyRoleAssignment);
                }
                string roleCheck = ValidationHelperFunctions.RoleCheck(requestObject, matter, client);
                if (string.IsNullOrEmpty(roleCheck))
                {
                    string centralList = Convert.ToString(centralListURL, CultureInfo.InvariantCulture);
                    string matterSiteURL = centralList.Substring(0, centralList.LastIndexOf(string.Concat(ConstantStrings.ForwardSlash, ConstantStrings.Lists, ConstantStrings.ForwardSlash), StringComparison.OrdinalIgnoreCase));
                    string matterListName = centralList.Substring(centralList.LastIndexOf(ConstantStrings.ForwardSlash, StringComparison.OrdinalIgnoreCase) + 1);
                    ClientContext listClientContext = ServiceUtility.GetClientContext(requestObject.SPAppToken, new Uri(matterSiteURL), requestObject.RefreshToken);
                    ProvisionHelperFunctions.SaveMatterDetails(requestObject, client, matter, matterListName, matterConfigurations, listClientContext);
                }
                else
                {
                    matterURL = roleCheck;
                }
            }
            catch (Exception exception)
            {
                ProvisionHelperFunctions.DeleteMatter(requestObject, client, matter);
                matterURL = Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
            return matterURL;
        }