Пример #1
0
 public BoardGame Map(ICsvReaderRow row)
 {
     return(new BoardGame
     {
         Id = row.GetField <long>("id"),
         GameType = MapGameType(row.GetField <string>("type")),
         Name = row.GetField <string>("name"),
         YearPublished = row.GetField <int?>("yearpublished"),
         MinPlayers = row.GetField <int?>("minplayers"),
         MaxPlayers = row.GetField <int?>("maxplayers"),
         PlayingTime = row.GetField <int?>("playingtime"),
         MinAge = row.GetField <int?>("minage"),
         AverageRating = row.GetField <decimal?>("average_rating"),
         TotalOwners = row.GetField <int?>("total_owners")
     });
 }
Пример #2
0
        private static IngData.MededelingenData MededelingenParser(ICsvReaderRow row)
        {
            string mededelingen = row.GetField("Mededelingen");

            var options = new[] { "BIC", "Crediteur", "IBAN", "Kenmerk", "Mandaat", "Naam", "Omschrijving" };

            var results = options.Select(
                o => new { Option = o, Index = mededelingen.IndexOf(o, StringComparison.CurrentCultureIgnoreCase) })
                          .Where(obj => obj.Index > -1)
                          .OrderByDescending(obj => obj.Index).ToList();

            var data = new IngData.MededelingenData();

            foreach (var result in results)
            {
                string subStr = mededelingen.Substring(result.Index + result.Option.Length);

                if (subStr.StartsWith(":"))
                {
                    subStr = subStr.Remove(0, 1);
                }
                mededelingen = mededelingen.Remove(result.Index).Trim();

                data.SetOption(result.Option, subStr);
            }

            return(data);
        }
        int?ParseSafeIntegerValuesWithSuffix(ICsvReaderRow row, string fieldName, string suffix)
        {
            var stringValue = row.GetField <string>(fieldName).Trim();

            if (String.IsNullOrEmpty(stringValue))
            {
                return(null);
            }

            try
            {
                var startIndexOfSuffix = stringValue.ToLowerInvariant().IndexOf(suffix);
                if (startIndexOfSuffix > 0)
                {
                    stringValue = stringValue.Substring(0, startIndexOfSuffix).Trim();
                }
            }
            catch { }

            int integerValue;

            if (Int32.TryParse(stringValue, out integerValue))
            {
                return(integerValue);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// Get campaign id from header/jobid
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private int GetFeedbackCampaignRecipientId(ICsvReaderRow c)
        {
            string value = string.IsNullOrEmpty(c.GetField <string>("header_X-STCustomer")) ? string.Empty : c.GetField <string>("header_X-STCustomer");
            int    campaignRecipientId = 0;

            int.TryParse(value, out campaignRecipientId);
            return(campaignRecipientId);
        }
Пример #5
0
            private List <MetadataKeyword> GetKeywords(ICsvReaderRow row)
            {
                var keywords = new List <MetadataKeyword>();

                keywords.Add(new MetadataKeyword()
                {
                    Value = "Improve", Vocab = Vocabularies.MetadataAdmin.Id
                });

                keywords.AddRange(ParsePageKeywords(row.GetField("Keywords")));

                AddKeyword(keywords, nhbsVocab, row.GetField("NhbsNumber"));
                AddKeyword(keywords, isbnVocab, row.GetField("IsbnNumber"));
                AddKeyword(keywords, issnVocab, row.GetField("IssnNumber"));
                AddKeyword(keywords, reportSeriesNoVocab, row.GetField("JnccReportSeriesNumber"));

                if (row.GetField("Free") == "1")
                {
                    AddKeyword(keywords, publicationStatusVocab, "Free");
                }

                if (row.GetField("Discontinued") == "1")
                {
                    AddKeyword(keywords, publicationStatusVocab, "Discontinued");
                }

                keywords.AddRange(
                    GetDomain(keywords.Where(x => x.Vocab == publicationCategoryVocab).ToList()));
                AddKeyword(keywords, Vocabularies.JnccCategory.Id, "JNCC Publications");

                return(keywords);
            }
        private static int ParseHskLevel(ICsvReaderRow csv)
        {
            int hskLevel;

            if (!csv.TryGetField("HSK Level", out hskLevel))
            {
                hskLevel = int.Parse(csv.GetField <string>("HSK Level-Order").Split('-')[0]);
            }
            return(hskLevel);
        }
Пример #7
0
        private DateTime GetTimeLogged(ICsvReaderRow c)
        {
            DateTime field = DateTime.UtcNow;

            try
            {
                field = c.GetField <DateTime>("timeLogged");
            }
            catch { }
            return(field);
        }
        List <int> ParseIntList(ICsvReaderRow row, string fieldName)
        {
            var stringList = row.GetField <string>(fieldName).Trim();

            if (String.IsNullOrEmpty(stringList))
            {
                return(new List <int>());
            }

            return(stringList.Split(',')
                   .Select(sId => Int32.Parse(sId))
                   .ToList());
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                ? row.CurrentRecord.Length - 1
                                : propertyMapData.IndexEnd;

            var dictionary = new Dictionary <string, string>();

            for (var i = propertyMapData.Index; i <= indexEnd; i++)
            {
                dictionary.Add(row.FieldHeaders[i], row.GetField(i));
            }

            return(dictionary);
        }
Пример #10
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                ? row.CurrentRecord.Length - 1
                                : propertyMapData.IndexEnd;

            var list = new System.Collections.ArrayList();

            for (var i = propertyMapData.Index; i <= indexEnd; i++)
            {
                list.Add(row.GetField(i));
            }

            return(list);
        }
Пример #11
0
        private static DateTime DateTimeParser(ICsvReaderRow x)
        {
            string s = x.GetField("Datum");

            DateTime date;

            if (DateTime.TryParse(s, out date) ||
                DateTime.TryParseExact(s, DateTimeFormats, CultureInfo.CurrentCulture, DateTimeStyles.None, out date))
            {
                return(date);
            }

            Console.WriteLine(s + " is a invalid string format");

            throw new InvalidOperationException("Couldn't convert '" + s + "' to a DateTime");
        }
Пример #12
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            Array array;
            var   type = propertyMapData.Member.MemberType().GetElementType();

            if (propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet)
            {
                // Use the name.
                var list      = new List <object>();
                var nameIndex = 0;
                while (true)
                {
                    object field;
                    if (!row.TryGetField(type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field))
                    {
                        break;
                    }

                    list.Add(field);
                    nameIndex++;
                }

                array = (Array)ReflectionHelper.CreateInstance(propertyMapData.Member.MemberType(), list.Count);
                for (var i = 0; i < list.Count; i++)
                {
                    array.SetValue(list[i], i);
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                        ? row.CurrentRecord.Length - 1
                                        : propertyMapData.IndexEnd;

                var arraySize = indexEnd - propertyMapData.Index + 1;
                array = (Array)ReflectionHelper.CreateInstance(propertyMapData.Member.MemberType(), arraySize);
                var arrayIndex = 0;
                for (var i = propertyMapData.Index; i <= indexEnd; i++)
                {
                    array.SetValue(row.GetField(type, i), arrayIndex);
                    arrayIndex++;
                }
            }

            return(array);
        }
Пример #13
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            Array array;
            var type = propertyMapData.Member.MemberType().GetElementType();

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var list = new List<object>();
                var nameIndex = 0;
                while( true )
                {
                    object field;
                    if( !row.TryGetField( type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }

                array = (Array)ReflectionHelper.CreateInstance( propertyMapData.Member.MemberType(), list.Count );
                for( var i = 0; i < list.Count; i++ )
                {
                    array.SetValue( list[i], i );
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                var arraySize = indexEnd - propertyMapData.Index + 1;
                array = (Array)ReflectionHelper.CreateInstance( propertyMapData.Member.MemberType(), arraySize );
                var arrayIndex = 0;
                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    array.SetValue( row.GetField( type, i ), arrayIndex );
                    arrayIndex++;
                }
            }

            return array;
        }
Пример #14
0
            private static string GetCsvField(string name, ICsvReaderRow row, webModel.CsvImportConfiguration configuration)
            {
                var mapping = configuration.MappingItems.First(y => y.EntityColumnName == name);

                if (mapping == null)
                {
                    throw new NullReferenceException("mapping");
                }

                var retVal = mapping.CustomValue;

                if (mapping.CsvColumnName != null)
                {
                    retVal = row.GetField <string>(mapping.CsvColumnName);
                }
                return(retVal);
            }
Пример #15
0
        /// <summary>
        /// Get campaign id from header/jobid
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        private int GetCampaignId(ICsvReaderRow c)
        {
            string value      = string.IsNullOrEmpty(c.GetField <string>("jobID")) ? string.Empty : c.GetField <string>("jobID");
            int    campaignId = 0;

            if (value.Contains('/'))
            {
                try
                {
                    var length = value.Split('/').Length;
                    campaignId = Convert.ToInt32(value.Split('/')[length - 1]);
                }
                catch
                {
                    campaignId = 0;
                }
            }
            return(campaignId);
        }
Пример #16
0
            private decimal ConvertPrices(ICsvReaderRow row, int index)
            {
                var val = row.GetField <string>(index)
                          .Replace("$", string.Empty)
                          .Replace("-", string.Empty)
                          .Trim();

                if (string.IsNullOrWhiteSpace(val))
                {
                    return(0m);
                }

                if (val.Equals("included", StringComparison.OrdinalIgnoreCase))
                {
                    return(0m);
                }

                return(decimal.Parse(val));
            }
Пример #17
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                ? row.CurrentRecord.Length - 1
                                : propertyMapData.IndexEnd;

            // Since we're using the PropertyType here, this converter can be used for multiple types
            // as long as they implement IList.
            var list = (IList)ReflectionHelper.CreateInstance(propertyMapData.Property.PropertyType);

            var type = propertyMapData.Property.PropertyType.GetGenericArguments()[0];

            for (var i = propertyMapData.Index; i <= indexEnd; i++)
            {
                list.Add(row.GetField(type, i));
            }

            return(list);
        }
Пример #18
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                ? row.CurrentRecord.Length - 1
                                : propertyMapData.IndexEnd;

            var type     = propertyMapData.Property.PropertyType.GetGenericArguments()[0];
            var listType = typeof(List <>);

            listType = listType.MakeGenericType(type);
            var list = (IList)ReflectionHelper.CreateInstance(listType);

            for (var i = propertyMapData.Index; i <= indexEnd; i++)
            {
                list.Add(row.GetField(type, i));
            }

            return(list);
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                ? row.CurrentRecord.Length - 1
                                : propertyMapData.IndexEnd;

            var keyType        = propertyMapData.Property.PropertyType.GetGenericArguments()[0];
            var valueType      = propertyMapData.Property.PropertyType.GetGenericArguments()[1];
            var dictionaryType = typeof(Dictionary <,>);

            dictionaryType = dictionaryType.MakeGenericType(keyType, valueType);
            var dictionary = (IDictionary)ReflectionHelper.CreateInstance(dictionaryType);

            for (var i = propertyMapData.Index; i <= indexEnd; i++)
            {
                dictionary.Add(row.FieldHeaders[i], row.GetField(valueType, i));
            }

            return(dictionary);
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var type     = propertyMapData.Member.MemberType().GetGenericArguments()[0];
            var listType = typeof(List <>);

            listType = listType.MakeGenericType(type);
            var list = (IList)ReflectionHelper.CreateInstance(listType);

            if (propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet)
            {
                // Use the name.
                var nameIndex = 0;
                while (true)
                {
                    object field;
                    if (!row.TryGetField(type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field))
                    {
                        break;
                    }

                    list.Add(field);
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                        ? row.CurrentRecord.Length - 1
                                        : propertyMapData.IndexEnd;

                for (var i = propertyMapData.Index; i <= indexEnd; i++)
                {
                    var field = row.GetField(type, i);

                    list.Add(field);
                }
            }

            return(list);
        }
Пример #21
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                ? row.CurrentRecord.Length - 1
                                : propertyMapData.IndexEnd;

            var arraySize = indexEnd - propertyMapData.Index + 1;

            var array = (Array)ReflectionHelper.CreateInstance(propertyMapData.Property.PropertyType, arraySize);

            var type       = propertyMapData.Property.PropertyType.GetElementType();
            var arrayIndex = 0;

            for (var i = propertyMapData.Index; i <= indexEnd; i++)
            {
                array.SetValue(row.GetField(type, i), arrayIndex);
                arrayIndex++;
            }

            return(array);
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var keyType = propertyMapData.Member.MemberType().GetGenericArguments()[0];
            var valueType = propertyMapData.Member.MemberType().GetGenericArguments()[1];
            var dictionaryType = typeof( Dictionary<,> );
            dictionaryType = dictionaryType.MakeGenericType( keyType, valueType );
            var dictionary = (IDictionary)ReflectionHelper.CreateInstance( dictionaryType );

            var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                ? row.CurrentRecord.Length - 1
                : propertyMapData.IndexEnd;

            for( var i = propertyMapData.Index; i <= indexEnd; i++ )
            {
                var field = row.GetField( valueType, i );

                dictionary.Add( row.FieldHeaders[i], field );
            }

            return dictionary;
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            var type = propertyMapData.Member.MemberType().GetGenericArguments()[0];
            var listType = typeof( List<> );
            listType = listType.MakeGenericType( type );
            var list = (IList)ReflectionHelper.CreateInstance( listType );

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var nameIndex = 0;
                while( true )
                {
                    object field;
                    if( !row.TryGetField( type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    var field = row.GetField( type, i );

                    list.Add( field );
                }
            }

            return list;
        }
Пример #24
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            // Since we're using the PropertyType here, this converter can be used for multiple types
            // as long as they implement IList.
            var list = (IList)ReflectionHelper.CreateInstance(propertyMapData.Member.MemberType());
            var type = propertyMapData.Member.MemberType().GetGenericArguments()[0];

            if (propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet)
            {
                // Use the name.
                var nameIndex = 0;
                while (true)
                {
                    object field;
                    if (!row.TryGetField(type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field))
                    {
                        break;
                    }

                    list.Add(field);
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                        ? row.CurrentRecord.Length - 1
                                        : propertyMapData.IndexEnd;

                for (var i = propertyMapData.Index; i <= indexEnd; i++)
                {
                    var field = row.GetField(type, i);

                    list.Add(field);
                }
            }

            return(list);
        }
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property/field being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString( string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData )
        {
            // Since we're using the PropertyType here, this converter can be used for multiple types
            // as long as they implement IList.
            var list = (IList)ReflectionHelper.CreateInstance( propertyMapData.Member.MemberType() );
            var type = propertyMapData.Member.MemberType().GetGenericArguments()[0];

            if( propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet )
            {
                // Use the name.
                var nameIndex = 0;
                while( true )
                {
                    object field;
                    if( !row.TryGetField( type, propertyMapData.Names.FirstOrDefault(), nameIndex, out field ) )
                    {
                        break;
                    }

                    list.Add( field );
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                    ? row.CurrentRecord.Length - 1
                    : propertyMapData.IndexEnd;

                for( var i = propertyMapData.Index; i <= indexEnd; i++ )
                {
                    var field = row.GetField( type, i );

                    list.Add( field );
                }
            }

            return list;
        }
Пример #26
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var dictionary = new Dictionary <string, string>();

            if (propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet)
            {
                // Use the name.
                var nameIndex = 0;
                while (true)
                {
                    string field;
                    var    name = propertyMapData.Names.FirstOrDefault() ?? string.Empty;
                    row.TryGetField(name, nameIndex, out field);
                    if (field == null)
                    {
                        break;
                    }

                    dictionary.Add(name, field);
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                        ? row.CurrentRecord.Length - 1
                                        : propertyMapData.IndexEnd;

                for (var i = propertyMapData.Index; i <= indexEnd; i++)
                {
                    dictionary.Add(row.FieldHeaders[i], row.GetField(i));
                }
            }

            return(dictionary);
        }
Пример #27
0
        /// <summary>
        /// Converts the string to an object.
        /// </summary>
        /// <param name="text">The string to convert to an object.</param>
        /// <param name="row">The <see cref="ICsvReaderRow"/> for the current record.</param>
        /// <param name="propertyMapData">The <see cref="CsvPropertyMapData"/> for the property being created.</param>
        /// <returns>The object created from the string.</returns>
        public override object ConvertFromString(string text, ICsvReaderRow row, CsvPropertyMapData propertyMapData)
        {
            var list = new List <string>();

            if (propertyMapData.IsNameSet || row.Configuration.HasHeaderRecord && !propertyMapData.IsIndexSet)
            {
                // Use the name.
                var nameIndex = 0;
                while (true)
                {
                    string field;
                    row.TryGetField(propertyMapData.Names.FirstOrDefault(), nameIndex, out field);
                    if (field == null)
                    {
                        break;
                    }

                    list.Add(field);
                    nameIndex++;
                }
            }
            else
            {
                // Use the index.
                var indexEnd = propertyMapData.IndexEnd < propertyMapData.Index
                                        ? row.CurrentRecord.Length - 1
                                        : propertyMapData.IndexEnd;

                for (var i = propertyMapData.Index; i <= indexEnd; i++)
                {
                    list.Add(row.GetField(i));
                }
            }

            return(list);
        }
Пример #28
0
 private static bool MapHasSeal(ICsvReaderRow r)
 {
     return(HasSealTrueValues.Contains(r.GetField("DOAJ Seal") ?? string.Empty));
 }
Пример #29
0
        /// <summary>
        /// Get bounce category
        /// </summary>
        /// <param name="b"></param>
        /// <returns></returns>
        private BounceCat GetBounceCategory(ICsvReaderRow b)
        {
            var       value = b.GetField <string>("bounceCat");
            BounceCat bc    = BounceCat.Other;

            switch (value)
            {
            case "other": bc = BounceCat.Other;
                break;

            case "bad-mailbox": bc = BounceCat.BadMailbox;
                break;

            case "bad-domain": bc = BounceCat.BadDomain;
                break;

            case "inactive-mailbox": bc = BounceCat.InactiveMailbox;
                break;

            case "bad-configuration": bc = BounceCat.BadConfiguration;
                break;

            case "bad-connection": bc = BounceCat.BadConnection;
                break;

            case "content-related": bc = BounceCat.ContentRelated;
                break;

            case "invalid-sender": bc = BounceCat.InvalidSender;
                break;

            case "message-expired": bc = BounceCat.MessageExpired;
                break;

            case "no-answer-from-host": bc = BounceCat.NoAnswerFromHost;
                break;

            case "policy-related": bc = BounceCat.PolicyRelated;
                break;

            case "protocol-errors": bc = BounceCat.ProtocolErrors;
                break;

            case "quota-issues": bc = BounceCat.QuotaIssues;
                break;

            case "relaying-issues": bc = BounceCat.RelayingIssues;
                break;

            case "routing-errors": bc = BounceCat.RoutingErrors;
                break;

            case "spam-related": bc = BounceCat.SpamRelated;
                break;

            case "virus-related": bc = BounceCat.VirusRelated;
                break;

            default:
                break;
            }
            return(bc);
        }
Пример #30
0
        private static string MapISSN(ICsvReaderRow r)
        {
            var eissn = r.GetField("Journal EISSN (online version)");

            return(string.IsNullOrWhiteSpace(eissn) ? r.GetField("Journal ISSN (print version)") : eissn);
        }
Пример #31
0
 private static string GetColumn(ICsvReaderRow csv, string columnName)
 {
     return(csv.GetField <string>(columnName).Trim());
 }