This class contains client term set members
Example #1
0
 /// <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);
     }
 }
Example #2
0
        /// <summary>
        /// Main Method to initiate the execution
        /// </summary>
        /// <param name="args">Command line argument</param>
        public static void Main(string[] args)
        {
            try
            {
                if (null != args && 2 <= args.Length)
                {
                    bool createData = Convert.ToBoolean(args[0], CultureInfo.InvariantCulture);
                    if (!ExcelOperations.IsNullOrEmptyCredential(args[1], args[2]))
                    {
                        //// Read Configuration sheet and Sample data sheet from Excel
                        string filePath        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\" + ConfigurationManager.AppSettings["filename"];
                        string sheetName       = ConfigurationManager.AppSettings["sheetname"];
                        string configSheetName = ConfigurationManager.AppSettings["configsheetname"];
                        Dictionary <string, string> configVal = ExcelOperations.ReadFromExcel(filePath, configSheetName);
                        configVal.Add("Username", args[1].Trim());
                        configVal.Add("Password", args[2].Trim());
                        Collection <Collection <string> > dataValue = ExcelOperations.ReadSheet(filePath, sheetName);
                        List <DataStorage> matterDetails            = MatterProvisionHelper.FetchMatterData(dataValue);
                        ClientTermSets     clientDetails            = TermStoreOperations.GetClientDetails(configVal);

                        if (createData)
                        {
                            CreateData(matterDetails, clientDetails, configVal);
                        }
                        else
                        {
                            RevertData(matterDetails, clientDetails, configVal);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Username and Password");
                    }
                }
                else
                {
                    Console.WriteLine("Incorrect command line argument was supplied. Kindly provide correct command line argument.");
                }
                Console.WriteLine("\n\n---Execution completed---");
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
            catch (Exception exception)
            {
                Utility.DisplayAndLogError(errorFilePath, "Message: " + exception.Message + "\nStacktrace: " + exception.StackTrace);
                Console.WriteLine("Error log will found at {0}", errorFilePath);
                Console.WriteLine("\n\n---Execution completed---");
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
Example #3
0
        /// <summary>
        /// Method to get client terms
        /// </summary>
        /// <param name="clientDetails">client term sets</param>
        /// <param name="clientIdProperty">client id property</param>
        /// <param name="clientUrlProperty">client url property</param>
        /// <param name="fillteredTerms">term collection</param>
        private static void GetClientTerms(ClientTermSets clientDetails, string clientIdProperty, string clientUrlProperty, TermCollection fillteredTerms)
        {
            Client client;

            foreach (Term term in fillteredTerms)
            {
                if (term.CustomProperties.ContainsKey(clientIdProperty) && term.CustomProperties.ContainsKey(clientUrlProperty))
                {
                    client            = new Client();
                    client.ClientName = term.Name;
                    client.ClientId   = term.CustomProperties[clientIdProperty];
                    client.ClientUrl  = term.CustomProperties[clientUrlProperty];
                    clientDetails.ClientTerms.Add(client);
                }
            }
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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);
            }
        }