DisplayErrorMessage() public static method

Function is used to display error message on console
public static DisplayErrorMessage ( string input ) : void
input string Message to display
return void
Exemplo n.º 1
0
        /// <summary>
        /// Function to return client id and client URL from term store
        /// </summary>
        /// <param name="clientContext">Tenant client context</param>
        /// <param name="groupName">TermStore Practice Group Name</param>
        /// <param name="termSetName">TermSet name</param>
        /// <param name="clientIdProperty">Name of Client ID property</param>
        /// <param name="clientPropertyName">Name of Client URL property</param>
        /// <returns>ClientId and ClientUrl</returns>
        public static ClientTermSets GetClientDetails(ClientContext clientContext, string groupName, string termSetName, string clientIdProperty, string clientPropertyName)
        {
            ClientTermSets clientDetails = new ClientTermSets();

            clientDetails.ClientTerms = new List <Client>();
            try
            {
                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 = termStore.Groups.Where(item => item.Name.Equals(groupName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    clientContext.Load(
                        termGroup,
                        group => group.Name,
                        group => group.TermSets.Include(
                            termSet => termSet.Name,
                            termSet => termSet.Terms.Include(
                                term => term.Name,
                                term => term.CustomProperties)));
                    clientContext.ExecuteQuery();

                    // 5. Get required term from term from extracted term set
                    TermCollection fillteredTerms = termGroup.TermSets.Where(item => item.Name.Equals(termSetName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().Terms;
                    clientDetails = GetClientTermSets(fillteredTerms, clientIdProperty, clientPropertyName);
                }
                else
                {
                    clientDetails = null;
                }
            }
            catch (Exception exception)
            {
                ErrorLogger.DisplayErrorMessage(string.Concat("Exception occurred during getting client details from TermStore.\n", exception.Message, exception.StackTrace));
            }
            return(clientDetails);
        }
Exemplo n.º 2
0
 /// <summary>
 /// This function reads Excel file and returns dictionary
 /// </summary>
 /// <param name="filePath">Full path to Excel file</param>
 /// <param name="sheetName">Sheet name containing configurations</param>
 /// <returns>Dictionary of configurations</returns>
 public static Dictionary <string, string> ReadFromExcel(string filePath, string sheetName)
 {
     if (!(string.IsNullOrWhiteSpace(filePath) || string.IsNullOrWhiteSpace(sheetName)))
     {
         Dictionary <string, string> myList = new Dictionary <string, string>();
         try
         {
             using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(filePath, false))
             {
                 WorkbookPart        workbookPart = myDoc.WorkbookPart;
                 IEnumerable <Sheet> sheets       = myDoc.WorkbookPart.Workbook.GetFirstChild <Sheets>().Elements <Sheet>().Where(s => s.Name == sheetName);
                 if (sheets.Count() == 0)
                 {
                     throw new ArgumentException("Message: Provided Sheet name is incorrect");
                 }
                 string        relationshipId = sheets.First().Id.Value;
                 WorksheetPart worksheetPart  = (WorksheetPart)myDoc.WorkbookPart.GetPartById(relationshipId);
                 SheetData     sheetData      = worksheetPart.Worksheet.GetFirstChild <SheetData>();
                 foreach (Row row in sheetData.Elements <Row>())
                 {
                     List <string> rowValue = new List <string>();
                     rowValue = ReadRow(row, workbookPart).ToList();
                     if (null != rowValue && 0 < rowValue.Count()) // Check count to avoid adding of blank row entry which having meta data
                     {
                         myList.Add(rowValue[0].Trim(), rowValue[1].Trim());
                     }
                 }
             }
         }
         catch (FileNotFoundException exception)
         {
             ErrorLogger.LogErrorToTextFile(errorFilePath, "Invalid file path, file not found" + exception.Message);
         }
         catch (Exception exception)
         {
             if (exception.Message.IndexOf("Invalid Hyperlink", 0, StringComparison.OrdinalIgnoreCase) != -1)
             {
                 ErrorLogger.DisplayErrorMessage("Unable to read Excel. Please remove all hyperlinks from configuration Excel");
             }
             ErrorLogger.LogErrorToTextFile(errorFilePath, "Exception Details: " + exception.Message);
         }
         return(myList);
     }
     else
     {
         throw new ArgumentException("Message: FilePath or Sheet name missing");
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Function is used to return all the values that are read from Sheet
        /// </summary>
        /// <param name="filePath">File path of the Excel</param>
        /// <param name="sheetName">Sheet to be read from Excel</param>
        /// <returns>Two-dimensional list with all values from Sheet</returns>
        public static Collection <Collection <string> > ReadSheet(string filePath, string sheetName)
        {
            Collection <Collection <string> > myList = new Collection <Collection <string> >();
            Collection <string> rowList = new Collection <string>();

            try
            {
                using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(filePath, false))
                {
                    WorkbookPart        workbookPart = myDoc.WorkbookPart;
                    IEnumerable <Sheet> sheets       = myDoc.WorkbookPart.Workbook.GetFirstChild <Sheets>().Elements <Sheet>().Where(s => s.Name == sheetName);
                    if (sheets.Count() == 0)
                    {
                        ErrorLogger.DisplayErrorMessage("Provided sheet name is invalid!");
                        return(myList);
                    }
                    string        relationshipId = sheets.First().Id.Value;
                    WorksheetPart worksheetPart  = (WorksheetPart)myDoc.WorkbookPart.GetPartById(relationshipId);
                    SheetData     sheetData      = worksheetPart.Worksheet.GetFirstChild <SheetData>();
                    foreach (Row row in sheetData.Elements <Row>())
                    {
                        rowList = ReadRow(row, workbookPart);
                        if (null != rowList && 0 < rowList.Count()) // Check count to avoid adding of blank row entry which having meta data
                        {
                            myList.Add(rowList);
                        }
                    }
                }
            }
            catch (FileNotFoundException exception)
            {
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Invalid file path, file not found" + exception.Message);
            }
            catch (Exception exception)
            {
                if (exception.Message.IndexOf("Invalid Hyperlink", 0, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    ErrorLogger.DisplayErrorMessage("Unable to read Excel. Please remove all hyperlinks from configuration Excel");
                }
                ErrorLogger.LogErrorToTextFile(errorFilePath, "Exception Details: " + exception.Message);
            }
            return(myList);
        }