static private GetClientContext ( string siteURl, string>.Dictionary |
||
siteURl | string | Site Url |
configVal | string>.Dictionary | Configuration values from excel |
return | ClientContext |
/// <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> /// Extract term store groups /// </summary> /// <param name="configVal">Configuration values from excel</param> /// <returns>Term sets</returns> internal static TermSets FetchGroupTerms(Dictionary <string, string> configVal) { TermStoreDetails termStoreDetails = new TermStoreDetails(); termStoreDetails.TermSetName = ConfigurationManager.AppSettings["PracticeGroupTermSetName"]; termStoreDetails.CustomPropertyName = ConfigurationManager.AppSettings["CustomPropertyName"]; termStoreDetails.TermGroup = ConfigurationManager.AppSettings["PracticeGroupName"]; TermSets practiceGroupTermSets = null; using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(configVal["TenantAdminURL"], configVal)) { TaxonomySession taxanomySession = TaxonomySession.GetTaxonomySession(clientContext); clientContext.Load(taxanomySession, items => items.TermStores.Include( item => item.Groups, item => item.Groups.Include( group => group.Name))); clientContext.ExecuteQuery(); TermGroup termGroup = taxanomySession.TermStores[0].Groups.GetByName(termStoreDetails.TermGroup); clientContext.Load(termGroup, group => group.Name, group => group.TermSets.Include( termSet => termSet.Name, termSet => termSet.Terms.Include( term => term.Name, term => term.Id, term => term.CustomProperties, term => term.Terms.Include( termArea => termArea.Name, termArea => termArea.Id, termArea => termArea.CustomProperties, termArea => termArea.Terms.Include( termSubArea => termSubArea.Name, termSubArea => termSubArea.Id, termSubArea => termSubArea.CustomProperties))))); clientContext.ExecuteQuery(); foreach (TermSet termSet in termGroup.TermSets) { if (termSet.Name.Equals(termStoreDetails.TermSetName, StringComparison.OrdinalIgnoreCase)) { if (termStoreDetails.TermSetName.Equals(termStoreDetails.TermSetName, StringComparison.OrdinalIgnoreCase)) { practiceGroupTermSets = TermStoreOperations.GetPracticeGroupTermSetHierarchy(termSet, termStoreDetails.CustomPropertyName); } } } return(practiceGroupTermSets); } }
/// <summary> /// Function to return client id and client url from term store /// </summary> /// <param name="configVal">Configuration from excel file</param> /// <returns>ClientId and ClientUrl</returns> internal static ClientTermSets GetClientDetails(Dictionary <string, string> configVal) { ClientTermSets clientDetails = new ClientTermSets(); clientDetails.ClientTerms = new List <Client>(); string groupName = ConfigurationManager.AppSettings["PracticeGroupName"]; string termSetName = ConfigurationManager.AppSettings["TermSetName"]; string clientIdProperty = ConfigurationManager.AppSettings["ClientIDProperty"]; string clientUrlProperty = ConfigurationManager.AppSettings["ClientUrlProperty"]; // 1. get client context using (ClientContext clientContext = MatterProvisionHelperUtility.GetClientContext(configVal["TenantAdminURL"], configVal)) { if (null != clientContext) { // 2. Create taxonomy session TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext); clientContext.Load(taxonomySession.TermStores); clientContext.ExecuteQuery(); // 3. Create term store object and load data TermStore termStore = taxonomySession.TermStores[0]; clientContext.Load( termStore, store => store.Name, store => store.Groups.Include( group => group.Name)); clientContext.ExecuteQuery(); // 4. create a term group object and load data TermGroup termGroup = GetTermGroup(groupName, clientContext, termStore); // 5. Get required term from term from extracted term set TermCollection fillteredTerms = termGroup.TermSets.Where(item => item.Name.Equals(termSetName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().Terms; GetClientTerms(clientDetails, clientIdProperty, clientUrlProperty, fillteredTerms); } else { clientDetails = null; } } return(clientDetails); }
/// <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); } }