aocakli / mikrotik4net

Automatically exported from code.google.com/p/mikrotik4net
Other
0 stars 0 forks source link

Error parsing response #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. List<ITikEntityRow> SriptsList = 
apiConnector.ApiExecuteReader("/system/script/print");

What is the expected output? 
True array.
What do you see instead?
Error: "Some value in dataRow does not start with '='".

What version of the product are you using?
tik4net 0.9.1.

Please provide any additional information below.

Some value in dataRow really does not start with '=' because response body 
contains code of scripts. Trouble occurs at parsing of value '=source={'.

Original issue reported on code.google.com by soroki...@gmail.com on 26 May 2011 at 10:40

GoogleCodeExporter commented 9 years ago
I've fixed procedure ApiEntityRow in a file ApiEntityRow.cs

public ApiEntityRow(string dataRow)
        {
            //!re=.id=*100004B=name=TOP=parent=global-out=packet-mark==limit-at=10000000=queue=wireless-default=priority=3=max-limit=15000000=burst-limit=0=burst-threshold=0=burst-time=00:00:00=bytes=0=packets=0=dropped=0=rate=0=packet-rate=0=queued-packets=0=queued-bytes=0=lends=0=borrows=0=pcq-queues=0=disabled=true=invalid=true

            DataRow = dataRow;             
            if (!dataRow.StartsWith("!re", StringComparison.OrdinalIgnoreCase))
                throw new TikResponseParseException("Invalid response row: {0}", dataRow);
            string[] items = dataRow.Split('\n');
            string[] parts =new string[1];
            for (int i = 1; i < (items.Length); i++)
            {
                if (!items[i].StartsWith(SEPARATOR, StringComparison.OrdinalIgnoreCase))
                {
                    //throw new TikResponseParseException("Some value in dataRow does not start with '{0}'. Row: {1}", SEPARATOR, dataRow);
                    parts[1]+=items[i];
                }
                else
                {
                    parts = items[i].Substring(1).Split(new char[] { '=' }, 2);
                    if (parts.Length != 2)
                        throw new TikResponseParseException("Invalid response format in datarow '{0}'. Expected '{1}attrName{1}attrValue'", items[i], SEPARATOR);
                }

                if (i == items.Length-1)
                    this.items.Add(parts[0], parts[1]);
                else 
                    if(items[i+1].StartsWith(SEPARATOR, StringComparison.OrdinalIgnoreCase))
                        this.items.Add(parts[0], parts[1]);
            }
        }

It works for me. Sorry for my coding. i'm using C# second day =)

Original comment by soroki...@gmail.com on 26 May 2011 at 8:38

GoogleCodeExporter commented 9 years ago
Thanx for report. It will be fixed in next release.

Danik
PS: I have to addopt somehow idea that some system characters could be part of 
content - thanks again for betatesting.

Original comment by daniel.f...@gmail.com on 4 Jun 2011 at 6:49