Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Record FileRecord "1" {
	Record LotRecord "abcd" {
		Field a 1{"NONE"}
		Field b 2 {2, 3}
		Field C 3 {"None", "a", "b"}
		Field d 1 {0}
		List ClassLookupList {
			Columns 3 { int32 CLASSNUMBER, string CLASSNAME, string CLASSCODE }
			Data 5{
				0 "aa" "";
				1 "bb" "";
				2 "cc" "";
				3 "dd" "";
				4 "ee" "";
			}
		}
		Record DataRecord "377" {
			Field a 2 {0, 0}
			Field b 1 {""}
			Field C 7 {"None", "", "", "", "", "", ""}
			List DefectList {
				Columns 14 { int32 DEFECTID, int32 XREL, int32 YREL, int32 XINDEX, int32 YINDEX, int32 XSIZE, int32 YSIZE, float DEFECTAREA, int32 DSIZE, int32 CLASSNUMBER, int32 TEST, int32 ROUGHBINNUMBER, int32 FINEBINNUMBER, int32 REVIEWSAMPLE }
				Data 3{
					1 134312000 133394000 0 0 0 0 0.0 758 0 6 0 0 0;
					2 150981000 115346000 0 0 0 0 0.0 299 0 6 0 0 0;
					3 194310000 137293000 0 0 0 0 0.0 300 0 6 0 0 1;				}
			}
			
	}
	Field FileTimestamp 2 {"09-10-2018", "09:28:46"}
}
EndOfFile;


What I have tried:

using (var reader = new StreamReader(fileName))
				{
					string line = null;//await reader.ReadToEndAsync();
					while ((line = await reader.ReadLineAsync()) != null)
					{
						if (!string.IsNullOrWhiteSpace(line) || !string.IsNullOrWhiteSpace(line.Split(',')[0]))
						{
							if (line.Contains("1.8"))
								await GetData(reader.ReadLine());
							else
								return null;
						}
					}



				}


This approach will take lot of coding. Could someone please help me with better approach?
Posted
Updated 17-Sep-18 12:59pm
Comments
Richard MacCutchan 17-Sep-18 5:58am    
Why are you using asynchronous file IO? It does not help with your project.

Looking at the data you have no real option but a lot of scanning and keyword searching. It looks like a cross between JSON and some form of database, but I have never seen anything like it before.
Manoj_Baddi 17-Sep-18 6:49am    
My method is async. That's the reason I was using async file IO(I will change the same to ReadAllLines or ReadToEnd ). I'm not sure what kind of file this is.

Damn! scanning the whole file and searching will take loads of time. Anyways, thanks for the help, Richard!

1 solution

Know your data.

You can parse "thousands" of lines of text in memory in no time at all.

Once loaded, you can do multiple scans to get at want you want; including "removing" stuff that "gets in the way".

List<string> is preferred over "sting arrays" for performance and flexibility.

Use File.ReadAllText or RealAllLines depending on the situation.

Use Debug or Trace output to monitor your parsing.
 
Share this answer
 
Comments
Manoj_Baddi 18-Sep-18 2:06am    
I'm aware of the fact that we can parse thousands of lines within a second. But, searching each line and use necessary stuff will take time. I've been told that the file content may vary(Eg: Sometimes DataRecord section may be missing). So, I'll have to write something generic.

Thanks for the help though!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900