Exemple #1
0
        /// <summary>
        /// Iterates the row from the CSV file
        /// </summary>
        /// <param name="context">The ClientContext instance.</param>
        /// <param name="entries">The collection values per row.</param>
        /// <param name="logger">The logger.</param>
        public override void IterateCollection(ClientContext context, Collection<string> entries, LogHelper logger)
        {
            List<PropertyData> data = new List<PropertyData>();         

            foreach (PropertyBase item in this.Properties)
            {
                if (item.Index < entries.Count)
                {
                    try
                    {
                        string account = entries[this.UserNameIndex];
                        PropertyData property = new PropertyData();
                        property.Name = item.Name;
                        property = item.Process(property, entries[item.Index], this) as PropertyData;
                        data.Add(property);
                    }
                    catch (Exception ex)
                    {
                        logger.LogException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Error occured whilst processing account '{0}', Property '{1}'. Stack {2}", entries[this.UserNameIndex], item.Name, ex.ToString()), ex);
                    }
                }
            }

            logger.LogVerbose(string.Format("Attempting to update profile for account '{0}'", entries[this.UserNameIndex]));
            
            try
            {
                this.profileService.ModifyUserPropertyByAccountName(entries[this.UserNameIndex], data.ToArray());
                logger.LogOutcome(entries[this.UserNameIndex], "SUCCESS");
            }
            catch(Exception ex)
            {
                logger.LogException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Error occured whilst processing account '{0}' - the account does not exist", entries[this.UserNameIndex]), ex);
                logger.LogOutcome(entries[this.UserNameIndex], "FAILURE");
            }

        }
Exemple #2
0
        /// <summary>
        /// Executes the specified reader.
        /// </summary>
        /// <param name="reader">The reader instance.</param>
        /// <param name="action">The logic to execute.</param>
        /// <param name="logger">The logger.</param>
        /// <exception cref="System.ArgumentNullException">If the reader instance is null</exception>
        public void Execute(TextReader reader, Action<Collection<string>, LogHelper> action, LogHelper logger)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            int lineNum = -1;

            try
            {
                string line = null;

                while ((line = reader.ReadLine()) != null)
                {
                    lineNum++;

                    if (lineNum == 0)
                    {
                        string[] separator = new string[] { this.DelimiterAsString };
                        string[] commaSeperator = new string[] { "," };

                        int length = line.Split(separator, StringSplitOptions.None).Length;

                        if (line.Split(commaSeperator, StringSplitOptions.None).Length > length)
                        {
                            this.DelimiterAsString = commaSeperator[0];
                        }
                    }
                    else if ((lineNum <= 1) || !string.IsNullOrEmpty(line.Trim()))
                    {
                        try
                        {
                            Collection<string> entries = this.ParseLineIntoEntries(line);
                            action.Invoke(entries, logger);
                        }
                        catch (Exception ex)
                        {
                            logger.LogException(string.Empty, ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(string.Empty, ex);
            }
        }