Exemple #1
0
        /// <summary>
        /// Executes the specified CSV writer.
        /// </summary>
        /// <param name="userdata">The user entry instance.</param>
        /// <param name="logger">The logger.</param>
        /// <exception cref="System.ArgumentNullException">If the userdata instance is null</exception>
        public void CSVWriteUser(CSVUserEntry userdata, LogHelper logger)
        {
            try
            {
                StringBuilder entry = new StringBuilder();

                bool FirstEntry = true;

                foreach (string cell in userdata)
                {
                    // Insert delimiter if not first column
                    if (!FirstEntry)
                    {
                        entry.Append(',');
                    }

                    // Insert value into builder
                    if (cell.IndexOfAny(new char[] { '"', ',' }) != -1)
                    {
                        entry.AppendFormat("\"{0}\"", cell.Replace("\"", "\"\""));
                    }
                    else
                    {
                        entry.Append(cell);
                    }

                    // Update first column flag
                    FirstEntry = false;
                }

                userdata.CellEntry = entry.ToString();

                //Replaces a line break ("\r\n") with a single space.  Line breaks are typically encountered in the streetAddress field in Active Directory.
                if (userdata.CellEntry.Contains("\r\n"))
                {
                    userdata.CellEntry = userdata.CellEntry.Replace("\r\n", " ");
                }

                // Output string to CSV file
                WriteLine(userdata.CellEntry);
            }
            catch (Exception ex)
            {
                logger.LogException(string.Empty, ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Executes the specified CSV writer.
        /// </summary>
        /// <param name="userdata">The user entry instance.</param>
        /// <param name="logger">The logger.</param>
        /// <exception cref="System.ArgumentNullException">If the userdata instance is null</exception>
        public void CSVWriteUser(CSVUserEntry userdata, LogHelper logger)
        {
            try
            {
                StringBuilder entry = new StringBuilder();

                bool FirstEntry = true;

                foreach (string cell in userdata)
                {
                    // Insert delimiter if not first column
                    if (!FirstEntry)
                    {
                        entry.Append(',');
                    }

                    // Insert value into builder
                    if (cell.IndexOfAny(new char[] { '"', ',' }) != -1)
                    {
                        entry.AppendFormat("\"{0}\"", cell.Replace("\"", "\"\""));
                    }
                    else
                    {
                        entry.Append(cell);
                    }

                    // Update first column flag
                    FirstEntry = false;
                }

                userdata.CellEntry = entry.ToString();

                // Output string to CSV file
                WriteLine(userdata.CellEntry);
            }
            catch (Exception ex)
            {
                logger.LogException(string.Empty, ex);
            }
        }