コード例 #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);
        }
コード例 #3
0
        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
ファイル: MailStat.cs プロジェクト: rtbhosale/SmartTouch
        /// <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
ファイル: PubCatMapping.cs プロジェクト: SoniaKhela/topcat
            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);
            }
コード例 #6
0
        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
ファイル: MailStat.cs プロジェクト: rtbhosale/SmartTouch
        private DateTime GetTimeLogged(ICsvReaderRow c)
        {
            DateTime field = DateTime.UtcNow;

            try
            {
                field = c.GetField <DateTime>("timeLogged");
            }
            catch { }
            return(field);
        }
コード例 #8
0
        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());
        }
コード例 #9
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 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
ファイル: ArrayConverter.cs プロジェクト: young1048/CsvHelper
        /// <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
ファイル: ArrayConverter.cs プロジェクト: ravensorb/CsvHelper
        /// <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
ファイル: MailStat.cs プロジェクト: rtbhosale/SmartTouch
        /// <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);
        }
コード例 #19
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 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);
        }
コード例 #20
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)
        {
            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);
        }
コード例 #22
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 )
        {
            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;
        }
コード例 #23
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 )
        {
            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);
        }
コード例 #25
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;
        }
コード例 #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
ファイル: DoajImportRecordMap.cs プロジェクト: spapaseit/qoam
 private static bool MapHasSeal(ICsvReaderRow r)
 {
     return(HasSealTrueValues.Contains(r.GetField("DOAJ Seal") ?? string.Empty));
 }
コード例 #29
0
ファイル: MailStat.cs プロジェクト: rtbhosale/SmartTouch
        /// <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
ファイル: DoajImportRecordMap.cs プロジェクト: spapaseit/qoam
        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());
 }