This class provides meta data related information for matter provision.
Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
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);
            }
        }