Code Monkey home page Code Monkey logo

fixedwidthparserwriter's People

Contributors

borisdj avatar nemanjabodroza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fixedwidthparserwriter's Issues

Parsing a fixed-field-width string with repeating parts

If I have a string containing fixed-field-length fields that are repeating, how can I parse that string line?

For example

"00050003T3A1111        2999BOSH                          2100021        399APV                           2100022  "

This string represents fields like:

4  byte long message length      ("0005")
4  byte long message id          ("0003")
1  byte long message type        ("T")
1  byte long message sequence    ("3")
8  byte long car Id              ("A1111   ")  
9  byte long part-1 price        ("     2999")
30 byte long part-1 manufacturer ("BOSH                          ")
9  byte long part#               ("2100021  ")
9  byte long part-2 price        ("      399")
30 byte long part-2 manufacturer ("APV                           ")
9  byte long part#               ("2100022  ")

Above, fields [part price], [part manufacturer], and [part#] are repeating and could be only 1 tripple or multiple tripples of these.

Also, the part has no decimal.

How would you parse this?

Obviously, using data model like in your documentation wont work as this data model expects a field to always start at same location; however, repeating fields above start on different locations:

public class InvoiceItem
{
    [FixedWidthLineField(Start = 1, Length = 3)]
    public int Number { get; set; }

    [FixedWidthLineField(Start = 4, Length = 1)]
    public string NumberedBullet { get; set; } = ".";

    [FixedWidthLineField(Start = 5, Length = 30)]
    public string Description { get; set; }

    [FixedWidthLineField(Start = 35, Length = 6)]
    public int Quantity { get; set; }

    [FixedWidthLineField(Start = 41, Length = 13)]
    public decimal Price { get; set; }

    [FixedWidthLineField(Start = 54, Length = 13)]
    public decimal Amount => Quantity * Price;
}

Handling nullable fields in Parse method

If destination model has DateTime? field, the parse method fails for empty string.
As I can see neither of types, which have nullable property, are not handled in Parse method.

Dynamic FixedWidthLinesProvider class

Hi,

Is it possible to use variable class to FixedWidthLinesProvider?

Sample:


    public enum A3Type
    {
        [StringValue("C")] Account,
        [StringValue("0")] NotesWithoutVAT,
        [StringValue("1")] NotesWithVAT,
        [StringValue("9")] DetailWithVAT,
        [StringValue(" ")] Dummy,
    }

    List<A3Type.Account> items0 = new FixedWidthLinesProvider<A3Type.Account>().Parse(element.lineValues);

Unable to use in Full .NET Framework projects

Tried Install-Package FixedWidthParserWriter in a .NETFramework 4.6.1 project and got the below error.

Install-Package : Could not install package 'FixedWidthParserWriter 1.0.8'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the
package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

Exception on Overflow

When I have a property value longer than the lenght, there should be an option if what to get an exception on this.

Ex.:

Property

[FixedWidthLineField(Start=1,Length=14)]
public string CNPJ { get; set; }

Program

        static void Main(string[] args)
        {
            var p = new Pagamento(){CNPJ="123456789012345"};
            var ps = new List<Pagamento>();
            ps.Add(p);
            
            p = new Pagamento(){CNPJ="12345678901234"};
            ps.Add(p);

            var ls = new FixedWidthLinesProvider<Pagamento>().Write(ps);
            
            foreach (var l in ls)
            {
                Console.WriteLine(l);
            }
        }

Result

12345678901234
12345678901234

But there is a data truncation that I may be concerned in some use case.

DateTime parsing

Parsing DateTime with custom format "mm.dd.yyyy" adds 1 minute to resulting value.

Manually mapping the fields at runtime

What if I don't want to add FixedWidthLineField attributes to the class properties ? May be I can't modify the class or I need to define the Start and Length attributes at runtime. Is there any possibility to manually map the fields ?

Add Call for Single Line Parse

I found your code via Reddit and it appears to work for what I want. My problem is the file I'm working on tries to stuff relational data into a text file. One line is the header, next line is a transaction, next line is a child of transaction and so on. When I read in the lines I have to parse one line at a time going into a different object. Now it's not a big deal to add my line to a list and parse the list and return the first item from the return list but just feels like a hack.

It would be too hard to add a parse single line, not sure if it would go in the same class or a different one called FixedWidthLineProvider

It could just have a call like:
public T Parse(string line, int structureTypeId)
{
return ParseData(new List { line }, FieldType.LineField));
}

Or something like that, maybe the base call ParseData could even be changed to handle one line rather than a list as well.

Parsing on iOS fails with the message "Operation is not supported on this platform."

Using the below code works on Android but fails on iOS.

` FileData fileData = await CrossFilePicker.Current.PickFile();
if (fileData == null)
{
return; // user canceled file picking
}

            List<string> list = new List<string>();

            using (var reader = new StreamReader(fileData.GetStream()))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    list.Add(line);
                }
            }

            List<Animal> animals = new FixedWidthLinesProvider<Animal>().Parse(list);`

The stack trace is:
System.Exception: Operation is not supported on this platform.
at System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.pns.cs:129
at FastMember.TypeAccessor.CreateNew (System.Type type, System.Boolean allowNonPublicAccessors) [0x00276] in <9d6126e91d244195bc86e41f41f850df>:0
at FastMember.TypeAccessor.Create (System.Type type, System.Boolean allowNonPublicAccessors) [0x00057] in <9d6126e91d244195bc86e41f41f850df>:0
at FixedWidthParserWriter.FixedWidthBaseProvider.ParseData[T] (System.Collections.Generic.List1[T] lines, FixedWidthParserWriter.FieldType fieldType) [0x0000d] in <2014c71297f64b8a965d79b875d9e4dd>:0 at FixedWidthParserWriter.FixedWidthLinesProvider1[T].Parse (System.Collections.Generic.List`1[T] lines, System.Int32 structureTypeId) [0x0002c] in <2014c71297f64b8a965d79b875d9e4dd>:0
at BreedIQ.ImportViewModel.ImportPBB () [0x00135] in C:\inetpub\BreedIQ\BreedIQ\BreedIQ\ViewModels\ImportViewModel.cs:45

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.