diff --git a/PCAxis.Core.Tests/EncodingUtilTests.cs b/PCAxis.Core.Tests/EncodingUtilTests.cs
new file mode 100644
index 0000000..53c4df7
--- /dev/null
+++ b/PCAxis.Core.Tests/EncodingUtilTests.cs
@@ -0,0 +1,24 @@
+using PCAxis.Paxiom;
+using System.Text;
+
+namespace PCAxis.Core.Tests;
+
+[TestClass]
+public class EncodingUtilTests
+{
+ [TestMethod]
+ public void ShouldGetEncoding()
+ {
+ // Arrange
+ //Get a UTF-32 encoding by codepage.
+ var encodingName = 12000;
+ var encoding1 = Encoding.GetEncoding(encodingName);
+
+
+ // Act
+ var encoding2 = EncodingUtil.GetEncoding("utf-32");
+
+ // Assert
+ Assert.AreEqual(encoding1, encoding2);
+ }
+}
diff --git a/PCAxis.Core.Tests/Fixtures/PxFileFixtures.cs b/PCAxis.Core.Tests/Fixtures/PxFileFixtures.cs
new file mode 100644
index 0000000..c5a25bc
--- /dev/null
+++ b/PCAxis.Core.Tests/Fixtures/PxFileFixtures.cs
@@ -0,0 +1,443 @@
+namespace PCAxis.Core.Tests.Fixtures
+{
+ internal static class PxFileFixtures
+ {
+ internal const string OkFile = @"
+CHARSET=""ANSI"";
+AXIS-VERSION=""2010"";
+CODEPAGE=""iso-8859-1"";
+LANGUAGE=""en"";
+LANGUAGES=""en"",""sv"";
+CREATION-DATE=""20230703 16:06"";
+DECIMALS=0;
+SHOWDECIMALS=0;
+MATRIX=""TAB003"";
+AGGREGALLOWED=NO;
+COPYRIGHT=NO;
+SUBJECT-CODE=""EN"";
+SUBJECT-AREA=""Environment"";
+TITLE=""Disposal facilities by treatment category, waste category, contents and year"";
+CONTENTS=""Disposal facilities"";
+STUB=""treatment category"",""waste category"";
+HEADING=""contents"",""year"";
+CONTVARIABLE=""contents"";
+VARIABLECODE(""treatment category"")=""TREATMENT_CAT"";
+VALUES(""treatment category"")=""RECYCLING"",""COMPOSTING AND ANAEROBIC DIGESTION"",""BACKFILLING"",""OTHER RECOVERY INCL. RECULTIVATION OF LANDFILLS AND CONSTRUCTION"",""INCINERATION WITH ENERGY RECOVERY"",""INCINERATION WITHOUT ENERGY RECOVERY"",""LANDFILLING"",
+""LAND TREATMENT OR RELEASE INTO WATER BODIES"",""PRE-TREATMENT AND SORTING"";
+VARIABLECODE(""waste category"")=""WASTE_CAT"";
+VALUES(""waste category"")=""spent solvents"",""acid, alkaline or saline wastes"",""used oils"",""chemical wastes"",""industrial effluent sludges"",""sludges and liquid wastes from w. treatm."",""health care and biological wastes"",""metallic wastes, ferrous"",""metallic wastes, non-ferrous"",
+""metallic wastes, mixed"",""glass wastes"",""paper and cardboard wastes"",""rubber wastes"",""plastic wastes"",""wood wastes"",""textile wastes"",""waste containing PCB"",""discarded equipment"",""discarded vehicles"",""batteries and accumulators wastes"",
+""animal and mixed waste"",""vegetal wastes"",""animal faeces, urine and manure"",""household and similar wastes"",""mixed and undifferentiated materials"",""sorting residues"",""common sludges"",""mineral waste from constr. and demol."",""other mineral wastes"",
+""combustion wastes"",""soils"",""dredging spoils (dry weight)"",""min. waste from w. treatm. and stabilised w."",""Total"";
+VARIABLECODE(""contents"")=""ContentsCode"";
+VALUES(""contents"")=""Treated waste, hazardous (tonnes)"",""Treated waste, non hazardous (tonnes)"";
+VARIABLECODE(""year"")=""TIME"";
+VALUES(""year"")=""2010"",""2012"",""2014"",""2016"";
+TIMEVAL(""year"")=TLIST(A1),""2010"",""2012"",""2014"",""2016"";
+CODES(""treatment category"")=""05"",""10"",""20"",""30"",""40"",""50"",""60"",""70"",""90"";
+CODES(""waste category"")=""01.1"",""01.2"",""01.3"",""01.4,02,03.1"",""03.2"",""03.3"",""05"",""06.1"",""06.2"",""06.3"",""07.1"",""07.2"",""07.3"",""07.4"",""07.5"",""07.6"",""07.7"",""08 ex 08.1,41"",""08.1"",""08.41"",""09.1"",""09.2"",""09.3"",""10.1"",""10.2"",""10.3"",""11"",""12.1"",""12.2,3,5"",""12.4"",""12.6"",""12.7"",""12.8,13"",
+""TOT"";
+CODES(""contents"")=""WasteHazard"",""WasteNonHazard"";
+CODES(""year"")=""2010"",""2012"",""2014"",""2016"";
+PRESTEXT(""year"")=0;
+UNITS=""tonnes"";
+BASEPERIOD(""Treated waste, hazardous (tonnes)"")=""Dummy baseperiod for waste sm"";
+LAST-UPDATED(""Treated waste, hazardous (tonnes)"")=""20230525 16:13"";
+CFPRICES(""Treated waste, hazardous (tonnes)"")=""C"";
+STOCKFA(""Treated waste, hazardous (tonnes)"")=""F"";
+DAYADJ(""Treated waste, hazardous (tonnes)"")=NO;
+SEASADJ(""Treated waste, hazardous (tonnes)"")=YES;
+UNITS(""Treated waste, hazardous (tonnes)"")=""tonnes"";
+BASEPERIOD(""Treated waste, non hazardous (tonnes)"")=""Dummy baseperiod for NON haz"";
+LAST-UPDATED(""Treated waste, non hazardous (tonnes)"")=""20230525 16:13"";
+CFPRICES(""Treated waste, non hazardous (tonnes)"")=""F"";
+STOCKFA(""Treated waste, non hazardous (tonnes)"")=""A"";
+DAYADJ(""Treated waste, non hazardous (tonnes)"")=YES;
+SEASADJ(""Treated waste, non hazardous (tonnes)"")=NO;
+UNITS(""Treated waste, non hazardous (tonnes)"")=""tonnes"";
+DATABASE=""Statistical database "";
+CONTACT(""Treated waste, hazardous (tonnes)"")=""Test Testsson, SCB#Tel: 08-111 222 33#Fax: 08-222 333 44#E-mail: test.testsson@sc""
+""b.se##Test2 Testsson2, SCB#Tel: 08-333 444 55#Fax: 08-444 555 66#E-mail: test2.testsson2""
+""@scb.se"";
+CONTACT(""Treated waste, non hazardous (tonnes)"")=""Test3 Testsson3, SCB#Tel: 08-111 222 33#Fax: 08-222 333 44#E-mail: test3.testsson3@sc""
+""b.se"";
+SOURCE=""Statistics Sweden"";
+INFOFILE=""ENVIRONMENT"";
+NEXT-UPDATE=""20240525 16:13"";
+LINK=""This is a link"";
+SURVEY=""This is a survey"";
+UPDATE-FREQUENCY=""This is a frequency"";
+NOTE="".. = Data not available"";
+DATASYMBOL1=""."";
+DATASYMBOL2="".."";
+DATASYMBOL3="".."";
+DATASYMBOLSUM=""*"";
+DATASYMBOLNIL=""-"";
+DATANOTESUM=""*"";
+TABLEID=""TAB003"";
+VARIABLE-TYPE(""treatment category"")=""V"";
+VARIABLE-TYPE(""waste category"")=""V"";
+VARIABLE-TYPE(""year"")=""T"";
+SUBJECT-AREA[sv]=""Miljö"";
+TITLE[sv]=""Disposal facilities efter behandlingstyp, avfallskategori, tabellinnehåll och år"";
+CONTENTS[sv]=""Disposal facilities"";
+STUB[sv]=""behandlingstyp"",""avfallskategori"";
+HEADING[sv]=""tabellinnehåll"",""år"";
+CONTVARIABLE[sv]=""tabellinnehåll"";
+VARIABLECODE[sv](""behandlingstyp"")=""TREATMENT_CAT"";
+VALUES[sv](""behandlingstyp"")=""MATERIALÅTERVINNING"",""RÖTNING OCH KOMPOSTERING"",""ÅTERFYLLNING"",""ANNAN ÅTERVINNING INKL. DEPONITÄCKNING OCH KONSTRUKTION"",""FÖRBRÄNNING MED ENERGIÅTERVINNING"",""FÖRBRÄNNING UTAN ENERGIÅTERVINNING"",""DEPONERING"",""UTSLÄPP I VATTEN ELLER MARKBEHANDLING"",
+""FÖRBEHANDLING OCH SORTERING"";
+VARIABLECODE[sv](""avfallskategori"")=""WASTE_CAT"";
+VALUES[sv](""avfallskategori"")=""lösningsmedelavfall"",""surt, alkaliskt eller salthaltigt avfall"",""oljeavfall"",""kemiska rester"",""avloppsslam från industrier (torrvikt)"",""slam och vätskor från avfallshantering (torrvikt)"",""sjukvårdsavfall och biologiskt avfall"",
+""metallavfall, ferromagnetiskt"",""metallavfall, icke ferromagnetiskt"",""blandade metaller"",""glasavfall"",""pappers- och pappavfall"",""gummiavfall"",""plastavfall"",""träavfall"",""textilavfall"",""avfall innehållande PCB"",
+""kasserad utrustning (exkl. kasserade fordon, batterier och ackumulatorer)"",""uttjänta fordon"",""batterier och ackumulatorer"",""animaliskt och blandat avfall"",""vegetabiliskt avfall"",""animalisk faeces, animalisk urin och gödsel"",
+""hushållsavfall och liknande avfall"",""blandade och ej differentierade material"",""sorteringsrester"",""vanligt slam (torrvikt)"",""mineralavfall från bygg och rivning"",""annat mineralavfall"",""avfall från förbränning"",""jord"",""muddermassor (torrvikt)"",
+""mineralavfall från avfallshantering"",""Totalt"";
+VARIABLECODE[sv](""tabellinnehåll"")=""ContentsCode"";
+VALUES[sv](""tabellinnehåll"")=""Hanterat avfall (farligt)"",""Hanterat avfall (ofarligt)"";
+VARIABLECODE[sv](""Ã¥r"")=""TIME"";
+VALUES[sv](""Ã¥r"")=""2010"",""2012"",""2014"",""2016"";
+TIMEVAL[sv](""Ã¥r"")=TLIST(A1),""2010"",""2012"",""2014"",""2016"";
+CODES[sv](""behandlingstyp"")=""05"",""10"",""20"",""30"",""40"",""50"",""60"",""70"",""90"";
+CODES[sv](""avfallskategori"")=""01.1"",""01.2"",""01.3"",""01.4,02,03.1"",""03.2"",""03.3"",""05"",""06.1"",""06.2"",""06.3"",""07.1"",""07.2"",""07.3"",""07.4"",""07.5"",""07.6"",""07.7"",""08 ex 08.1,41"",""08.1"",""08.41"",""09.1"",""09.2"",""09.3"",""10.1"",""10.2"",""10.3"",""11"",""12.1"",""12.2,3,5"",""12.4"",""12.6"",""12.7"",""12.8,13"",
+""TOT"";
+CODES[sv](""tabellinnehåll"")=""WasteHazard"",""WasteNonHazard"";
+PRESTEXT[sv](""Ã¥r"")=0;
+DOMAIN[sv](""behandlingstyp"")=""Behandlingstyp"";
+DOMAIN[sv](""avfallskategori"")=""Avfallskategori"";
+UNITS[sv]=""ton"";
+LAST-UPDATED[sv](""Hanterat avfall (farligt)"")=""20230525 16:13"";
+CFPRICES[sv](""Hanterat avfall (farligt)"")=""C"";
+STOCKFA[sv](""Hanterat avfall (farligt)"")=""F"";
+DAYADJ[sv](""Hanterat avfall (farligt)"")=NO;
+SEASADJ[sv](""Hanterat avfall (farligt)"")=YES;
+UNITS[sv](""Hanterat avfall (farligt)"")=""ton"";
+LAST-UPDATED[sv](""Hanterat avfall (ofarligt)"")=""20230525 16:13"";
+CFPRICES[sv](""Hanterat avfall (ofarligt)"")=""F"";
+STOCKFA[sv](""Hanterat avfall (ofarligt)"")=""A"";
+DAYADJ[sv](""Hanterat avfall (ofarligt)"")=YES;
+SEASADJ[sv](""Hanterat avfall (ofarligt)"")=NO;
+UNITS[sv](""Hanterat avfall (ofarligt)"")=""ton"";
+DATABASE[sv]=""Statistikdatabasen "";
+SOURCE[sv]=""Statistikmyndigheten"";
+CONTACT[sv](""Hanterat avfall (farligt)"")=""Test Testsson, SCB#Tel: 08-111 222 33#Fax: 08-222 333 44#E-mail: test.testsson@sc""
+""b.se##Test2 Testsson2, SCB#Tel: 08-333 444 55#Fax: 08-444 555 66#E-mail: test2.testsson2""
+""@scb.se"";
+CONTACT[sv](""Hanterat avfall (ofarligt)"")=""Test3 Testsson3, SCB#Tel: 08-111 222 33#Fax: 08-222 333 44#E-mail: test3.testsson3@sc""
+""b.se"";
+NOTE[sv]="".. = Data not available"";
+DATANOTESUM[sv]=""*"";
+VARIABLE-TYPE[sv](""behandlingstyp"")=""V"";
+VARIABLE-TYPE[sv](""avfallskategori"")=""V"";
+VARIABLE-TYPE[sv](""Ã¥r"")=""T"";
+DATA=
+30 500 10 0 0 0 0 0
+0 0 0 22400 0 0 49800 91300
+0 0 0 0 0 0 0 0
+0 3270 200 5820 0 0 0 20
+0 0 0 910 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 1725000 1638000 1316000 2066000
+0 0 0 0 76000 144000 108000 209000
+0 0 0 0 0 22800 214000 44900
+0 0 0 0 145000 0 149000 247000
+0 0 0 0 1889000 1497000 1318000 1111000
+0 0 0 0 0 0 0 39700
+0 0 0 0 45300 96700 81100 83600
+0 0 0 0 0 0 0 870
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+40000 "".."" 120000 120000 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+70800 69700 73800 77300 0 0 0 0
+0 0 0 0 0 0 0 11900
+0 0 0 0 0 0 0 27300
+0 0 0 0 0 0 0 10300
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 60
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 21600
+0 0 20 0 0 0 42600 131000
+0 0 0 0 0 0 7700 30000
+0 0 0 0 0 0 910 153000
+0 0 0 0 0 0 0 220
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 30 7270
+111000 158000 194000 226000 3880000 3399000 3287000 4287000
+2420 20 0 0 0 0 0 0
+0 0 0 0 0 20 0 0
+0 0 0 0 0 0 0 0
+0 20 0 0 0 0 0 480
+20 0 0 0 48600 17700 20100 36000
+0 0 0 0 5050 1080 0 1280
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 9720 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 30 0 0
+0 0 0 0 65700 49900 25600 20000
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 "".."" 0 0 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 477000 560000 834000 918000
+0 0 0 0 288000 516000 406000 467000
+0 0 0 0 110000 421000 603000 717000
+0 0 0 0 82200 3540 0 0
+0 0 0 0 30400 39600 5530 560
+0 0 0 0 250 4500 790 870
+0 0 0 0 56100 57300 47400 47100
+0 0 0 0 0 20 0 0
+0 0 0 0 410 1010 0 1950
+0 0 0 0 800 4950 0 0
+0 20 0 0 0 600 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+2430 60 0 0 1175000 1677000 1943000 2210000
+0 0 0 0 0 0 0 0
+0 0 0 0 0 27200 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 17900 0 14200
+0 0 0 0 0 4970 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 680 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 1360 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 "".."" 0 0 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 3100 0 0
+0 0 0 0 0 0 30 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 1200 46900
+0 0 0 0 791000 557000 2448000 6128000
+0 0 0 0 0 38300 16500 15800
+0 0 0 0 0 103000 66500 156000
+0 0 0 0 0 0 0 356000
+0 22500 0 0 0 0 0 0
+0 22500 0 0 792000 752000 2532000 6717000
+0 0 0 0 0 0 0 0
+0 340 0 0 158000 34100 17400 11600
+18300 19200 7620 0 0 0 0 0
+0 0 0 0 133000 123000 74800 7400
+2730 2790 0 0 35800 14900 22800 2630
+80 0 0 0 1040 890 380 800
+38800 0 0 0 0 0 0 0
+0 0 0 0 0 0 80 90
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 118000 2240 590
+0 0 0 0 0 0 0 0
+0 0 0 0 34300 28800 52600 50
+0 0 0 0 0 0 10 0
+0 0 0 0 26300 8350 4390 1380
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 "".."" 0 0 2040 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 40500 68500 9650 5540
+0 0 0 0 1010 580 11900 135000
+0 0 0 0 4320 3270 10000 6680
+0 0 0 0 420 10 3780 410
+0 0 0 0 231000 232000 25300 28900
+0 60 790 0 89400 297000 173000 125000
+0 0 0 0 60700 29300 171000 125000
+9840 68500 79400 25400 609000 428000 463000 683000
+40 0 8720 0 6007000 8733000 3658000 4851000
+300 63800 5770 6340 455000 626000 1062000 538000
+53800 129000 112000 111000 2198000 2123000 3241000 2400000
+0 0 0 620 15800 15600 32500 357000
+8150 12400 2290 15700 394000 316000 501000 311000
+132000 297000 217000 159000 10495000 13202000 9538000 9590000
+430 1390 5380 1940 0 0 0 0
+0 0 0 0 0 0 0 6200
+100 4720 29600 21600 0 0 0 0
+19500 48600 10300 2250 27000 0 0 300
+0 120 0 0 112000 111000 39300 35500
+6910 2600 1970 6800 0 0 0 0
+3520 5620 3440 0 1610 550 660 250
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 12200 5960 2230 1160
+0 0 0 0 62700 38400 28900 40900
+0 0 0 0 84700 105000 71400 152000
+52400 47000 97700 77300 1320000 1144000 1556000 1955000
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 "".."" 270 0 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 364000 11700 0 42700
+0 0 0 0 13400 13900 68100 63700
+0 0 0 0 0 0 0 0
+0 0 0 0 2268000 2296000 2165000 2456000
+0 30 0 0 1383000 2354000 2587000 2909000
+0 1200 20 0 486000 441000 877000 1047000
+0 0 0 0 42700 28900 53000 22700
+0 26200 4310 0 0 11900 2250 220000
+0 0 0 0 160 0 0 0
+0 0 0 0 0 12600 13200 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+82800 137000 153000 110000 6178000 6574000 7464000 8952000
+3880 5000 7900 10700 0 0 0 0
+0 0 0 230 0 0 0 0
+4320 2500 3940 5860 0 0 0 0
+67900 24300 82200 117000 0 0 0 0
+0 3150 980 4560 0 0 3200 0
+0 0 0 0 0 0 0 0
+110 30 360 4550 910 820 430 1040
+0 0 0 0 0 0 0 10
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 1520
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 230 0
+1600 2500 0 40000 0 0 0 5550
+0 0 0 0 0 0 0 0
+0 0 0 520 0 0 0 0
+3000 "".."" 3130 3160 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 520 540
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+5000 2750 2810 2260 0 0 390 0
+0 100 1100 520 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 19500 0 0 0 300
+0 0 0 0 0 0 0 540
+0 0 50 150 0 0 0 0
+0 0 30 1140 0 0 0 700
+0 0 0 0 0 0 0 0
+0 0 200 290 0 0 0 60
+85800 42300 103000 210000 910 820 4760 10200
+0 0 0 400 0 0 0 0
+2050 2920 18200 9980 11100 23900 15400 14500
+70 10 20 0 0 0 0 0
+4370 43000 23100 20000 85300 93600 126000 158000
+7000 10400 9590 7780 1280 7780 19100 5600
+0 2070 350 510 90 200 20 580
+0 0 0 0 0 0 0 0
+0 0 0 0 190 1580 1040 210
+0 0 0 0 0 560 330 340
+0 0 0 0 0 0 0 330
+0 0 0 0 390 320 810 12800
+0 0 0 0 560 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 410 50 20 60
+0 0 50 0 60 6460 4390 0
+0 0 0 0 0 0 580 40
+2810 0 0 0 0 0 0 0
+550 "".."" 0 0 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 1180 400 250 60
+0 0 0 0 2300 240 70 0
+0 0 0 0 0 0 0 0
+0 0 0 0 17000 26800 21900 26700
+0 10100 5680 5550 262000 289000 116000 206000
+0 8160 130 2320 280000 247000 286000 244000
+0 0 0 0 26200 5310 1560 1870
+7130 5040 11700 16900 176000 87500 413000 338000
+19600 20100 28100 23900 43980000 75270000 81865000 48978000
+6270 13000 32100 8580 415000 434000 550000 406000
+205000 307000 221000 362000 1543000 1104000 1611000 2538000
+0 0 0 10 5880 4370 0 226000
+101000 44300 76100 169000 50500 38900 34200 12800
+356000 466000 426000 627000 46858000 77642000 85067000 53170000
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 260 0
+0 0 0 0 3610 1640 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 "".."" 0 0 0 "".."" 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 1640 1300 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 250 1220 0 0
+0 0 0 0 0 0 0 0
+0 0 0 0 36751000 44842000 51185000 50333000
+0 0 0 0 28200 14300 2830 2490
+0 0 0 0 1500 0 0 0
+0 0 0 0 3540000 1995000 1170000 417000
+0 0 0 0 0 0 0 0
+0 0 0 0 40327000 46856000 52358000 50752000
+0 0 0 0 0 0 0 0
+2320 7210 21100 6650 0 1340 340 360
+107000 136000 140000 157000 0 0 0 0
+341000 297000 526000 244000 290 0 6420 1260
+2670 2180 6550 2360 130 2740 5230 2490
+10 2110 0 0 0 0 1800 120
+0 0 42000 0 0 0 0 0
+0 0 0 0 9590 3580 188000 124000
+0 0 0 0 0 0 640 2450
+0 0 0 0 242000 1437000 500000 1408000
+0 0 0 0 170 2450 195000 370
+0 0 0 0 13100 60300 13300 79800
+0 0 0 0 19300 26900 2420 31200
+0 0 0 0 28500 23500 71100 18900
+20 0 174000 129000 480 12300 128000 301000
+0 0 0 0 0 0 10 0
+4510 5230 0 1270 0 0 0 0
+76400 "".."" 194000 251000 10500 "".."" 3430 450
+172000 119000 218000 252000 464000 528000 0 0
+0 0 1050 1280 0 1050 0 0
+0 0 0 0 980 90300 27100 54600
+0 0 0 0 1930 3910 69800 79700
+0 0 0 0 460 1560 6070 2450
+0 0 0 0 115000 183000 227000 107000
+110 10 40 830 600000 917000 832000 1839000
+0 0 0 0 1800 7300 13800 2640
+0 0 0 0 0 910 114000 14100
+6860 4430 260 13500 114000 187000 479000 1046000
+270 0 280 0 0 8770 11600 24500
+0 15000 57200 0 151000 153000 119000 84700
+269000 285000 259000 322000 17100 118000 168000 301000
+0 0 0 0 0 0 0 0
+15000 8380 1430 4960 4000 44400 89400 51900
+997000 1069000 1641000 1386000 1794000 3815000 3273000 5578000;";
+
+
+ }
+}
diff --git a/PCAxis.Core.Tests/MSTestSettings.cs b/PCAxis.Core.Tests/MSTestSettings.cs
new file mode 100644
index 0000000..aaf278c
--- /dev/null
+++ b/PCAxis.Core.Tests/MSTestSettings.cs
@@ -0,0 +1 @@
+[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
diff --git a/PCAxis.Core.Tests/PCAxis.Core.Tests.csproj b/PCAxis.Core.Tests/PCAxis.Core.Tests.csproj
new file mode 100644
index 0000000..0f79210
--- /dev/null
+++ b/PCAxis.Core.Tests/PCAxis.Core.Tests.csproj
@@ -0,0 +1,34 @@
+
+
+
+ net8.0
+ latest
+ enable
+ enable
+ true
+ Exe
+ true
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PCAxis.Core.Tests/PXFileBuilderTests.cs b/PCAxis.Core.Tests/PXFileBuilderTests.cs
new file mode 100644
index 0000000..54afdb3
--- /dev/null
+++ b/PCAxis.Core.Tests/PXFileBuilderTests.cs
@@ -0,0 +1,32 @@
+using Moq;
+using PCAxis.Core.Tests.Fixtures;
+using PCAxis.Paxiom;
+using PCAxis.Paxiom.Parsers;
+
+namespace PCAxis.Core.Tests;
+
+[TestClass]
+public class PXFileBuilderTests
+{
+ [TestMethod]
+ public void Reading_a_valid_px_file_should_not_throw_exception()
+ {
+ // Arrange
+ var parser = new Utils.PxFileParserProxy(PxFileFixtures.OkFile);
+ var parserFactory = new Mock();
+ parserFactory.Setup(f => f.Create()).Returns(parser);
+
+
+ try
+ {
+ var builder = new PXFileBuilder(parserFactory.Object);
+ builder.SetPath("Dummy path");
+ builder.BuildForSelection();
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail($"An exception was thrown while reading a valid PX file: {ex.Message}");
+ }
+
+ }
+}
diff --git a/PCAxis.Core.Tests/PXFileParserTests.cs b/PCAxis.Core.Tests/PXFileParserTests.cs
new file mode 100644
index 0000000..0ef453e
--- /dev/null
+++ b/PCAxis.Core.Tests/PXFileParserTests.cs
@@ -0,0 +1,22 @@
+using PCAxis.Paxiom.Parsers;
+
+namespace PCAxis.Core.Tests;
+
+[TestClass]
+public class PXFileParserTests
+{
+ [TestMethod]
+ public void ShouldReturnDescription()
+ {
+ // Arrange
+ var parser = new PXFileParser();
+
+ // Act
+
+ var description = parser.Description.ToLower();
+
+ // Assert
+ Assert.AreEqual("this is the default plugin which reads a classical pc-axis file", description);
+
+ }
+}
diff --git a/PCAxis.Core.Tests/PxFileSerializerTests.cs b/PCAxis.Core.Tests/PxFileSerializerTests.cs
new file mode 100644
index 0000000..3d5c1c9
--- /dev/null
+++ b/PCAxis.Core.Tests/PxFileSerializerTests.cs
@@ -0,0 +1,63 @@
+using PCAxis.Paxiom;
+
+namespace PCAxis.Core.Tests;
+
+[TestClass]
+public class PxFileSerializerTests
+{
+ [TestMethod]
+ public void ShouldBeAbleToSerialize()
+ {
+ // Arrange
+ var model = new PXModel();
+
+ var timeVar = new Variable("Period", PlacementType.Heading);
+ timeVar.IsTime = true;
+ timeVar.Values.Add(new Value("2018M01"));
+
+ model.Meta.AddVariable(timeVar);
+
+ var regionVar = new Variable("Region", PlacementType.Stub);
+ regionVar.IsTime = false;
+ regionVar.Values.Add(new Value("A"));
+ regionVar.Values.Add(new Value("B"));
+
+ model.Meta.AddVariable(regionVar);
+
+ model.Meta.AxisVersion = "2018";
+ model.Meta.Language = "en";
+ model.Meta.SubjectArea = "TST";
+ model.Meta.SubjectCode = "TST";
+ model.Meta.Matrix = "TST01";
+ model.Meta.Title = "Test data";
+ model.Meta.Source = "PxTools";
+ model.Meta.Contents = "Test data";
+ model.Meta.Decimals = 0;
+ model.Meta.Description = "Test file";
+ model.Meta.DescriptionDefault = false;
+
+ var contentInfo = new ContInfo();
+ contentInfo.Units = "Amount";
+ model.Meta.ContentInfo = contentInfo;
+ model.IsComplete = true;
+
+ model.Data.SetMatrixSize(1, 1);
+
+ model.Data.WriteElement(0, 100);
+
+ // Act
+ // Get a UTF-32 encoding by name.
+ var serializer = new PXFileSerializer();
+
+ //Assert
+ try
+ {
+ serializer.Serialize(model, Stream.Null);
+ }
+ catch (Exception ex)
+ {
+ //If an exception is thrown, the test fails.
+ Assert.Fail("Serialization threw an exception: " + ex.Message);
+ }
+ }
+}
diff --git a/PCAxis.Core.Tests/Utils/PxFileParserProxy.cs b/PCAxis.Core.Tests/Utils/PxFileParserProxy.cs
new file mode 100644
index 0000000..9e01dbd
--- /dev/null
+++ b/PCAxis.Core.Tests/Utils/PxFileParserProxy.cs
@@ -0,0 +1,15 @@
+using PCAxis.Paxiom.Parsers;
+using System.Text;
+
+namespace PCAxis.Core.Tests.Utils
+{
+ internal sealed class PxFileParserProxy(string fileData) : PXFileParser
+ {
+ protected override Stream GetStream()
+ {
+ var bytes = Encoding.UTF8.GetBytes(fileData);
+ return new MemoryStream(bytes, writable: false);
+ }
+
+ }
+}
diff --git a/PCAxis.Core.Tests/VariableTests.cs b/PCAxis.Core.Tests/VariableTests.cs
new file mode 100644
index 0000000..d65e708
--- /dev/null
+++ b/PCAxis.Core.Tests/VariableTests.cs
@@ -0,0 +1,21 @@
+using PCAxis.Paxiom;
+
+namespace PCAxis.Core.Tests;
+
+[TestClass]
+public class VariableTests
+{
+ [TestMethod]
+ public void ShouldAddValue()
+ {
+ // Arrange
+ var variable = new Variable();
+ var value = new Value("TestValue");
+
+ // Act
+ variable.Values.Add(value);
+
+ // Assert
+ Assert.AreEqual(1, variable.Values.Count);
+ }
+}
diff --git a/PCAxis.Core.UnitTest/EncodingUtilTest.vb b/PCAxis.Core.UnitTest/EncodingUtilTest.vb
deleted file mode 100644
index b57e2d1..0000000
--- a/PCAxis.Core.UnitTest/EncodingUtilTest.vb
+++ /dev/null
@@ -1,29 +0,0 @@
-Imports System.Text
-Imports Microsoft.VisualStudio.TestTools.UnitTesting
-Imports PCAxis.Paxiom
-
-Namespace PCAxis.Common.UnitTest
-
- Public Class EncodingUtilTest
-
- Sub ShouldGetEncoding()
-
- 'Arrange
- 'Get a UTF-32 encoding by codepage.
- Dim e1 As System.Text.Encoding
- e1 = Encoding.GetEncoding(12000)
-
- 'Act
- 'Get a UTF-32 encoding by name.
- Dim e2 As System.Text.Encoding
- e2 = EncodingUtil.GetEncoding("utf-32")
-
- 'Assert
- 'Check their equality.
- Assert.AreEqual(e1, e2)
-
- End Sub
- End Class
-
-End Namespace
-
diff --git a/PCAxis.Core.UnitTest/PCAxis.Core.UnitTest.vbproj b/PCAxis.Core.UnitTest/PCAxis.Core.UnitTest.vbproj
deleted file mode 100644
index 76a9bf0..0000000
--- a/PCAxis.Core.UnitTest/PCAxis.Core.UnitTest.vbproj
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
- PCAxis.Core.UnitTest
- net8.0
-
- false
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
-
-
diff --git a/PCAxis.Core.UnitTest/PXFileParserTest.vb b/PCAxis.Core.UnitTest/PXFileParserTest.vb
deleted file mode 100644
index 93701c7..0000000
--- a/PCAxis.Core.UnitTest/PXFileParserTest.vb
+++ /dev/null
@@ -1,21 +0,0 @@
-Imports Microsoft.VisualStudio.TestTools.UnitTesting
-Imports PCAxis.Paxiom.Parsers
-
-Namespace PCAxis.PX.Core.UnitTest
-
- Public Class PXFileBuilderTest
-
- Sub ShouldReturnDescription()
- 'Arrange
- Dim e As New PXFileParser()
-
- 'Act
- Dim testDesc As String = e.Description
-
- 'Assert
- Assert.AreEqual(testDesc.ToLower(), "this is the default plugin which reads a classical pc-axis file")
-
- End Sub
- End Class
-End Namespace
-
diff --git a/PCAxis.Core.UnitTest/PxFileSerializerTest.vb b/PCAxis.Core.UnitTest/PxFileSerializerTest.vb
deleted file mode 100644
index 34ef6b7..0000000
--- a/PCAxis.Core.UnitTest/PxFileSerializerTest.vb
+++ /dev/null
@@ -1,67 +0,0 @@
-Imports System.IO
-Imports System.Text
-Imports Microsoft.VisualStudio.TestTools.UnitTesting
-Imports PCAxis.Paxiom
-
-
-
-Public Class PxFileSerializerTest
-
- Sub ShouldBeAbleToSerialize()
-
- 'Arrange
- Dim pxModel As New PXModel()
-
- Dim timeVar As New Variable("Period", PlacementType.Heading)
- timeVar.IsTime = True
- timeVar.Values.Add(New Value("2018M01"))
-
- pxModel.Meta.AddVariable(timeVar)
-
- Dim regionVar As New Variable("Region", PlacementType.Stub)
- regionVar.IsTime = False
- regionVar.Values.Add(New Value("A"))
- regionVar.Values.Add(New Value("B"))
-
- pxModel.Meta.AddVariable(regionVar)
-
- pxModel.Meta.AxisVersion = "2018"
- pxModel.Meta.Language = "en"
- pxModel.Meta.SubjectArea = "TST"
- pxModel.Meta.SubjectCode = "TST"
- pxModel.Meta.Matrix = "TST01"
- pxModel.Meta.Title = "Test data"
- pxModel.Meta.Source = "PxTools"
- pxModel.Meta.Contents = "Test data"
- pxModel.Meta.Decimals = 0
- pxModel.Meta.Description = "Test file"
- pxModel.Meta.DescriptionDefault = False
-
- Dim contentInfo As New ContInfo()
- contentInfo.Units = "Amount"
- pxModel.Meta.ContentInfo = contentInfo
- pxModel.IsComplete = True
-
- pxModel.Data.SetMatrixSize(1, 1)
-
- pxModel.Data.WriteElement(0, 100)
-
- 'Act
- 'Get a UTF-32 encoding by name.
- Dim serializer As PXFileSerializer = New PXFileSerializer()
-
- serializer.Serialize(pxModel, Stream.Null)
-
- 'Assert
- Try
- serializer.Serialize(pxModel, Stream.Null)
- 'Assert
- 'If no exception is thrown, the test passes.
- Assert.IsTrue(True)
- Catch ex As Exception
- 'If an exception is thrown, the test fails.
- Assert.Fail("Serialization threw an exception: " & ex.Message)
- End Try
-
- End Sub
-End Class
diff --git a/PCAxis.Core.UnitTest/VariableTest.vb b/PCAxis.Core.UnitTest/VariableTest.vb
deleted file mode 100644
index d86703b..0000000
--- a/PCAxis.Core.UnitTest/VariableTest.vb
+++ /dev/null
@@ -1,21 +0,0 @@
-Imports Microsoft.VisualStudio.TestTools.UnitTesting
-Imports PCAxis.Paxiom
-
-Namespace PCAxis.Core.UnitTest
-
- Public Class VariableTest
-
- Sub ShouldAddValue()
- 'Arrange
- Dim variable As New Variable
-
- 'Act
- Dim value As Value = New Value("TestValue")
- variable.Values.Add(value)
-
- 'Assert
- Assert.AreEqual(variable.Values.Count, 1)
- End Sub
- End Class
-End Namespace
-
diff --git a/PCAxis.Core.sln b/PCAxis.Core.sln
index 4e47361..1d1c2c5 100644
--- a/PCAxis.Core.sln
+++ b/PCAxis.Core.sln
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29709.97
+# Visual Studio Version 17
+VisualStudioVersion = 17.14.37411.7 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "PCAxis.Core", "PCAxis.Core\PCAxis.Core.vbproj", "{662D22ED-BE31-4A42-8AE8-0E196A18EF17}"
EndProject
-Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "PCAxis.Core.UnitTest", "PCAxis.Core.UnitTest\PCAxis.Core.UnitTest.vbproj", "{CD6FB271-11BC-47BF-883D-14891D501F3F}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCAxis.Core.Tests", "PCAxis.Core.Tests\PCAxis.Core.Tests.csproj", "{150AEB1B-F74E-4DA5-85CE-C947A13EAE7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,10 +17,10 @@ Global
{662D22ED-BE31-4A42-8AE8-0E196A18EF17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{662D22ED-BE31-4A42-8AE8-0E196A18EF17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{662D22ED-BE31-4A42-8AE8-0E196A18EF17}.Release|Any CPU.Build.0 = Release|Any CPU
- {CD6FB271-11BC-47BF-883D-14891D501F3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {CD6FB271-11BC-47BF-883D-14891D501F3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {CD6FB271-11BC-47BF-883D-14891D501F3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {CD6FB271-11BC-47BF-883D-14891D501F3F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {150AEB1B-F74E-4DA5-85CE-C947A13EAE7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {150AEB1B-F74E-4DA5-85CE-C947A13EAE7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {150AEB1B-F74E-4DA5-85CE-C947A13EAE7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {150AEB1B-F74E-4DA5-85CE-C947A13EAE7F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/PCAxis.Core/Builders/PXFileBuilder.vb b/PCAxis.Core/Builders/PXFileBuilder.vb
index 5f5d051..0b32a4c 100644
--- a/PCAxis.Core/Builders/PXFileBuilder.vb
+++ b/PCAxis.Core/Builders/PXFileBuilder.vb
@@ -1,3 +1,5 @@
+Imports PCAxis.Paxiom.Parsers
+
Namespace PCAxis.Paxiom
Public Class PXFileBuilder
@@ -10,6 +12,17 @@ Namespace PCAxis.Paxiom
Private _host As PCAxis.PlugIn.IPlugInHost
Private _originalGroupedVariables As Dictionary(Of String, Variable)
Private _groupingIncludes As Dictionary(Of String, GroupingIncludesType)
+ Private m_parserFactory As IPXFileParserFactory
+
+ Public Sub New()
+ m_parserFactory = New PXFileParserFactory()
+ End Sub
+
+ Public Sub New(ByVal parserFactory As IPXFileParserFactory)
+ m_parserFactory = parserFactory
+ End Sub
+
+
'Private _groupingInclude As GroupingIncludesType
#End Region
@@ -25,11 +38,11 @@ Namespace PCAxis.Paxiom
m_path = path
- Dim plugin As PCAxis.PlugIn.IPlugIn
- plugin = New PCAxis.Paxiom.Parsers.PXFileParser
+ Dim parser As PXFileParser
+ parser = m_parserFactory.Create()
- DirectCast(plugin, PCAxis.Paxiom.Parsers.PXFileParser).SetPath(path.ToString())
- m_parser = DirectCast(plugin, PCAxis.Paxiom.Parsers.PXFileParser)
+ parser.SetPath(path.ToString())
+ m_parser = parser
End Sub
@@ -85,7 +98,7 @@ Namespace PCAxis.Paxiom
Me.Errors.Add(New BuilderMessage(ex.Message))
Return False
End Try
-
+
Me.m_model.Meta.MainTable = m_path
@@ -464,15 +477,15 @@ Namespace PCAxis.Paxiom
End Function
- '''
+ '''
''' Substitutes variables in variables collection
'''
''' The variable collection
''' The old variable in the collection that will be replaced
''' The new variable
'''
- Private Sub SubstituteVariables(ByVal variables As Variables, _
- ByVal oldVar As Variable, _
+ Private Sub SubstituteVariables(ByVal variables As Variables,
+ ByVal oldVar As Variable,
ByVal newVar As Variable)
Dim index As Integer
@@ -516,29 +529,29 @@ Namespace PCAxis.Paxiom
#Region "Plugin implementation"
- Public ReadOnly Property Description() As String Implements plugin.IPlugIn.Description
+ Public ReadOnly Property Description() As String Implements PlugIn.IPlugIn.Description
Get
Return "Model builder from the PX-file format"
End Get
End Property
- Public ReadOnly Property Id() As System.Guid Implements plugin.IPlugIn.Id
+ Public ReadOnly Property Id() As System.Guid Implements PlugIn.IPlugIn.Id
Get
Return New Guid("B8ACBF13-4512-48a0-981B-B55A25A46E80")
End Get
End Property
- Public Sub Initialize(ByVal host As PlugIn.IPlugInHost, ByVal configuration As System.Collections.Generic.Dictionary(Of String, String)) Implements plugin.IPlugIn.Initialize
+ Public Sub Initialize(ByVal host As PlugIn.IPlugInHost, ByVal configuration As System.Collections.Generic.Dictionary(Of String, String)) Implements PlugIn.IPlugIn.Initialize
_host = host
End Sub
- Public ReadOnly Property Name() As String Implements plugin.IPlugIn.Name
+ Public ReadOnly Property Name() As String Implements PlugIn.IPlugIn.Name
Get
Return "PXFileBuilder"
End Get
End Property
- Public Sub Terminate() Implements plugin.IPlugIn.Terminate
+ Public Sub Terminate() Implements PlugIn.IPlugIn.Terminate
End Sub
diff --git a/PCAxis.Core/Parsers/IPXFileParserFactory.vb b/PCAxis.Core/Parsers/IPXFileParserFactory.vb
new file mode 100644
index 0000000..348c959
--- /dev/null
+++ b/PCAxis.Core/Parsers/IPXFileParserFactory.vb
@@ -0,0 +1,20 @@
+Namespace PCAxis.Paxiom.Parsers
+ Public Interface IPXFileParserFactory
+
+ Function Create() As PXFileParser
+
+
+ End Interface
+
+ Public Class PXFileParserFactory
+ Implements IPXFileParserFactory
+
+ Public Sub New()
+ End Sub
+
+ Public Function Create() As PXFileParser Implements IPXFileParserFactory.Create
+ Return New PXFileParser()
+ End Function
+ End Class
+
+End Namespace
\ No newline at end of file
diff --git a/PCAxis.Core/Parsers/PXFileParser.vb b/PCAxis.Core/Parsers/PXFileParser.vb
index 894cf82..58891ca 100644
--- a/PCAxis.Core/Parsers/PXFileParser.vb
+++ b/PCAxis.Core/Parsers/PXFileParser.vb
@@ -1,5 +1,6 @@
'TODO Move to plugin.core
-Imports PCAxis.Paxiom
+
+Imports System.IO
Namespace PCAxis.Paxiom.Parsers
@@ -43,7 +44,7 @@ Namespace PCAxis.Paxiom.Parsers
End Try
End If
Try
- Me._encoding = GetEncoding(path)
+ Me._encoding = Me.GetEncoding()
Catch ex As Exception
Me._encoding = System.Text.Encoding.Default
End Try
@@ -53,36 +54,58 @@ Namespace PCAxis.Paxiom.Parsers
Me.state = ParserState.ReadKeyword
End Sub
- Public Shared Function GetEncoding(ByVal path As String) As System.Text.Encoding
+ Public Function GetEncoding() As System.Text.Encoding
+ Dim encoding As System.Text.Encoding = GetEncodingFromCodePage(GetStream())
- If System.IO.Path.GetExtension(path).ToLower.Equals(".px") Then
- Using tr As System.IO.TextReader = New System.IO.StreamReader(path)
- Dim lineCount = 1
- Dim nextLine As String = tr.ReadLine()
+ If encoding Is Nothing Then
+ GetEncodingFromUde(GetStream, 16000)
+ End If
- While lineCount <= 100 And nextLine IsNot Nothing And Not nextLine.ToUpper().StartsWith("DATA=")
- If nextLine.ToUpper().StartsWith("CODEPAGE=") Then
- nextLine = nextLine.Substring(nextLine.IndexOf("""") + 1)
- nextLine = nextLine.Substring(0, nextLine.LastIndexOf(""""))
- Return System.Text.Encoding.GetEncoding(nextLine)
- End If
+ Return encoding
+ End Function
+
+ Public Shared Function GetEncoding(ByVal path As String) As System.Text.Encoding
+ Dim encoding As System.Text.Encoding = GetEncodingFromCodePage(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
- lineCount += 1
- nextLine = tr.ReadLine()
- End While
- End Using
+ If encoding Is Nothing Then
+ GetEncodingFromUde(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read), Convert.ToInt32(New System.IO.FileInfo(path).Length))
End If
+ Return encoding
+ End Function
+
+
+ Private Shared Function GetEncodingFromCodePage(stream As System.IO.Stream) As System.Text.Encoding
+
+ Using tr As System.IO.TextReader = New System.IO.StreamReader(stream)
+ Dim lineCount = 1
+ Dim nextLine As String = tr.ReadLine()
+
+ While lineCount <= 100 And nextLine IsNot Nothing And Not nextLine.ToUpper().StartsWith("DATA=")
+ If nextLine.ToUpper().StartsWith("CODEPAGE=") Then
+ nextLine = nextLine.Substring(nextLine.IndexOf("""") + 1)
+ nextLine = nextLine.Substring(0, nextLine.LastIndexOf(""""))
+ Return System.Text.Encoding.GetEncoding(nextLine)
+ End If
+
+ lineCount += 1
+ nextLine = tr.ReadLine()
+ End While
+ End Using
+
+ Return Nothing
+ End Function
+
+ Private Shared Function GetEncodingFromUde(stream As System.IO.Stream, length As Integer) As System.Text.Encoding
Dim cs As String
Dim BUFFER_SIZE As Integer = 1024
Dim buffer(BUFFER_SIZE - 1) As Byte
Dim size As Integer
- Using fs As System.IO.FileStream = System.IO.File.OpenRead(path)
+ Using fs As System.IO.FileStream = stream
Dim det As Ude.ICharsetDetector
det = New Ude.CharsetDetector
- Dim fi As New System.IO.FileInfo(path)
- size = Math.Min(BUFFER_SIZE, Convert.ToInt32(fi.Length))
+ size = Math.Min(BUFFER_SIZE, length)
size = fs.Read(buffer, 0, size)
det.Feed(buffer, 0, size)
det.DataEnd()
@@ -110,368 +133,373 @@ Namespace PCAxis.Paxiom.Parsers
#Region "Constants"
- 'The default value of the data buffer size
- Private Const DEFAULT_DATA_BUFFER_SIZE As Integer = 256
- Private Const START_SUBKEY As Char = "("c
- Private Const END_SUBKEY As Char = ")"c
- Private Const START_VALUES As Char = "="c
- Private Const END_VALUES As Char = ";"c
- Private Const FNUTT As Char = """"c
- Private Const COMMA As Char = ","c
- Private Const COLON As Char = ":"c
- Private Const START_LANGUAGE As Char = "["c
- Private Const END_LANGUAGE As Char = "]"c
- Private Const MINUS As Char = "-"c
-
- Public Const FILENAME As String = "Filename"
+ 'The default value of the data buffer size
+ Private Const DEFAULT_DATA_BUFFER_SIZE As Integer = 256
+ Private Const START_SUBKEY As Char = "("c
+ Private Const END_SUBKEY As Char = ")"c
+ Private Const START_VALUES As Char = "="c
+ Private Const END_VALUES As Char = ";"c
+ Private Const FNUTT As Char = """"c
+ Private Const COMMA As Char = ","c
+ Private Const COLON As Char = ":"c
+ Private Const START_LANGUAGE As Char = "["c
+ Private Const END_LANGUAGE As Char = "]"c
+ Private Const MINUS As Char = "-"c
+
+ Public Const FILENAME As String = "Filename"
#End Region
#Region "Enum(s)"
- Private Enum ParserState
- ReadKeyword
- ReadLanguage
- ReadSubkeys
- ReadValues
- End Enum
-
- Private Enum KeysStates
- TrimWhiteSpaceBeforeKey
- ReadKey
- TrimWhiteSpaceAfterKey
- TrimWiteSpaceSurroundValue
- ReadValue
- End Enum
-
- Private Enum ValueType
- NotSet
- FnuttValue
- NoFnuttValue
- ErrorValue
- End Enum
+ Private Enum ParserState
+ ReadKeyword
+ ReadLanguage
+ ReadSubkeys
+ ReadValues
+ End Enum
+
+ Private Enum KeysStates
+ TrimWhiteSpaceBeforeKey
+ ReadKey
+ TrimWhiteSpaceAfterKey
+ TrimWiteSpaceSurroundValue
+ ReadValue
+ End Enum
+
+ Private Enum ValueType
+ NotSet
+ FnuttValue
+ NoFnuttValue
+ ErrorValue
+ End Enum
#End Region
#Region "ParseMeta"
- Public Sub ParseMeta(ByVal handler As Paxiom.IPXModelParser.MetaHandler, ByVal preferredLanguage As String) Implements Paxiom.IPXModelParser.ParseMeta
- 'Om man kontroll om man readan har lästin all metadata
- If mHasParsedMeta Then
- Exit Sub
- End If
-
- 'Checks that the object is still alive
- If Me.disposed Then
- Throw New ObjectDisposedException(Me.GetType().ToString, _
- "This object has been disposed.")
- End If
-
- Me.theStream = New IO.StreamReader(New System.IO.FileStream(_path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048), _encoding)
-
- Dim keyword As String = Nothing
- Dim language As String = Nothing
- Dim subkey As String = Nothing
- Dim values As System.Collections.Specialized.StringCollection = Nothing
- Dim hasLanguage As Boolean = False
- Dim hasSubkeys As Boolean = False
- 'Dim keepRunning As Boolean = True
- Dim sb As System.Text.StringBuilder
- 'Dim ws As Boolean
- Dim n As Integer
- Dim ch As Char
- Dim currentRow As Integer = 0
- InFnutt = False
+ Public Sub ParseMeta(ByVal handler As Paxiom.IPXModelParser.MetaHandler, ByVal preferredLanguage As String) Implements Paxiom.IPXModelParser.ParseMeta
+ 'Om man kontroll om man readan har lästin all metadata
+ If mHasParsedMeta Then
+ Exit Sub
+ End If
+
+ 'Checks that the object is still alive
+ If Me.disposed Then
+ Throw New ObjectDisposedException(Me.GetType().ToString,
+ "This object has been disposed.")
+ End If
+
+ Me.theStream = New IO.StreamReader(GetStream(), _encoding)
+
+ Dim keyword As String = Nothing
+ Dim language As String = Nothing
+ Dim subkey As String = Nothing
+ Dim values As System.Collections.Specialized.StringCollection = Nothing
+ Dim hasLanguage As Boolean = False
+ Dim hasSubkeys As Boolean = False
+ 'Dim keepRunning As Boolean = True
+ Dim sb As System.Text.StringBuilder
+ 'Dim ws As Boolean
+ Dim n As Integer
+ Dim ch As Char
+ Dim currentRow As Integer = 0
+ InFnutt = False
Dim valueType As ValueType
Dim charCount = 0
- _keepRunning = True
+ _keepRunning = True
- If _encoding IsNot Nothing Then
- values = New System.Collections.Specialized.StringCollection()
- values.Add(_encoding.WebName)
- handler(PXKeywords.CODEPAGE, Nothing, Nothing, values)
- values = Nothing
- End If
+ If _encoding IsNot Nothing Then
+ values = New System.Collections.Specialized.StringCollection()
+ values.Add(_encoding.WebName)
+ handler(PXKeywords.CODEPAGE, Nothing, Nothing, values)
+ values = Nothing
+ End If
n = theStream.Read()
charCount += 1
- sb = New System.Text.StringBuilder
- While n > -1 And _keepRunning
+ sb = New System.Text.StringBuilder
+ While n > -1 And _keepRunning
ch = Convert.ToChar(n)
- 'Testar om man är inom dubellfnuttar
- If ch = FNUTT Then
- InFnutt = Not InFnutt
- End If
- 'Går igenom en sektion
- Select Case state
- Case ParserState.ReadKeyword
- Select Case ch
- Case FNUTT
- Exit Select
- Case START_LANGUAGE
- 'Om vi redan har läst in subkeys så kastar vi ett fel
- If hasSubkeys Then
- Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
- End If
- keyword = sb.ToString()
- sb = New System.Text.StringBuilder
- state = ParserState.ReadLanguage
- hasLanguage = True
- Case START_SUBKEY
- If Not hasLanguage Then
- keyword = sb.ToString()
- End If
- sb = New System.Text.StringBuilder
- state = ParserState.ReadSubkeys
- hasSubkeys = True
- Case START_VALUES
- If Not (hasSubkeys Or hasLanguage) Then
- keyword = sb.ToString()
- End If
- values = New System.Collections.Specialized.StringCollection
- sb = New System.Text.StringBuilder
- state = ParserState.ReadValues
- If keyword = "DATA" Then
+ 'Testar om man är inom dubellfnuttar
+ If ch = FNUTT Then
+ InFnutt = Not InFnutt
+ End If
+ 'Går igenom en sektion
+ Select Case state
+ Case ParserState.ReadKeyword
+ Select Case ch
+ Case FNUTT
+ Exit Select
+ Case START_LANGUAGE
+ 'Om vi redan har läst in subkeys så kastar vi ett fel
+ If hasSubkeys Then
+ Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
+ End If
+ keyword = sb.ToString()
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadLanguage
+ hasLanguage = True
+ Case START_SUBKEY
+ If Not hasLanguage Then
+ keyword = sb.ToString()
+ End If
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadSubkeys
+ hasSubkeys = True
+ Case START_VALUES
+ If Not (hasSubkeys Or hasLanguage) Then
+ keyword = sb.ToString()
+ End If
+ values = New System.Collections.Specialized.StringCollection
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadValues
+ If keyword = "DATA" Then
_keepRunning = False
Exit While
- End If
- valueType = PXFileParser.ValueType.NotSet
- Case END_VALUES, END_LANGUAGE, END_SUBKEY
- Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
- Case Else
- If InFnutt Then
- sb.Append(ch)
- Else
- If Not Char.IsWhiteSpace(ch) Then
- sb.Append(ch)
- End If
- End If
- End Select
- Case ParserState.ReadLanguage
- If Char.IsWhiteSpace(ch) Then
- Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
- End If
- Select Case ch
- Case START_VALUES, START_SUBKEY, START_LANGUAGE, END_VALUES, END_SUBKEY, FNUTT
- Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
- Case END_LANGUAGE
- language = sb.ToString()
- sb = New System.Text.StringBuilder
- state = ParserState.ReadKeyword
- Case Else
- sb.Append(ch)
- End Select
- Case ParserState.ReadSubkeys
- Select Case ch
- 'Case START_VALUES, START_SUBKEY, START_LANGUAGE, END_VALUES, END_LANGUAGE
- 'Throw New FileParserException("Invalid PX file")
- Case FNUTT
- ' Include these characters to subkey stringbuilder
- ' we will remove these before calling the handler further down
- sb.Append(ch)
- 'Exit Select
- Case END_SUBKEY
- If InFnutt Then
- sb.Append(ch)
- Else
- subkey = sb.ToString()
- sb = New System.Text.StringBuilder
- state = ParserState.ReadKeyword
- End If
- Case Else
- If InFnutt Then
- sb.Append(ch)
- Else
- If Not Char.IsWhiteSpace(ch) Then
- sb.Append(ch)
- End If
- End If
- End Select
- Case ParserState.ReadValues
- If valueType = PXFileParser.ValueType.ErrorValue Then
- 'There are errors in values -> Read to ; and send error
- If ch = END_VALUES Then
- values = New System.Collections.Specialized.StringCollection
- values.Add(keyword)
- values.Add(language)
- values.Add(subkey)
-
- _keepRunning = handler("KEYWORD_ERROR", Nothing, Nothing, values)
-
- keyword = Nothing
- language = Nothing
- subkey = Nothing
- values = Nothing
- hasLanguage = False
- hasSubkeys = False
- sb = New System.Text.StringBuilder
- state = ParserState.ReadKeyword
- InFnutt = False
- End If
- Else
- If InFnutt Then
- Select Case valueType
- Case PXFileParser.ValueType.NotSet
- valueType = PXFileParser.ValueType.FnuttValue
- If Not ch = FNUTT Then
- sb.Append(ch)
- End If
- Case PXFileParser.ValueType.FnuttValue
- If Not ch = FNUTT Then
- sb.Append(ch)
- End If
- Case PXFileParser.ValueType.NoFnuttValue
- 'No fnutts allowed in NoFnuttValues!
- valueType = PXFileParser.ValueType.ErrorValue
- End Select
- Else
- If Char.IsWhiteSpace(ch) Or ch = FNUTT Then
- Exit Select
- End If
- Select Case ch
- Case START_LANGUAGE, START_VALUES, END_LANGUAGE
- Throw New Exception("Invalid PX file")
- Case COMMA
- values.Add(sb.ToString())
- sb = New System.Text.StringBuilder
- 'Some keywords (e.g. TIMEVAL) may have values of both type
- 'FnuttValue and NoFnuttValue. Reset ValueType between values
- 'to handle this
- valueType = PXFileParser.ValueType.NotSet
- Case COLON
- 'Hiearchyvalue - Add colon...
- sb.Append(ch)
- Case MINUS
- Select Case keyword
- Case "TIMEVAL"
- 'Timeval in interval format
- sb.Append(ch)
- 'Read past the next "-character
+ End If
+ valueType = PXFileParser.ValueType.NotSet
+ Case END_VALUES, END_LANGUAGE, END_SUBKEY
+ Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
+ Case Else
+ If InFnutt Then
+ sb.Append(ch)
+ Else
+ If Not Char.IsWhiteSpace(ch) Then
+ sb.Append(ch)
+ End If
+ End If
+ End Select
+ Case ParserState.ReadLanguage
+ If Char.IsWhiteSpace(ch) Then
+ Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
+ End If
+ Select Case ch
+ Case START_VALUES, START_SUBKEY, START_LANGUAGE, END_VALUES, END_SUBKEY, FNUTT
+ Throw New PlugIn.PCAxisPlugInException("Invalid PX file")
+ Case END_LANGUAGE
+ language = sb.ToString()
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadKeyword
+ Case Else
+ sb.Append(ch)
+ End Select
+ Case ParserState.ReadSubkeys
+ Select Case ch
+ 'Case START_VALUES, START_SUBKEY, START_LANGUAGE, END_VALUES, END_LANGUAGE
+ 'Throw New FileParserException("Invalid PX file")
+ Case FNUTT
+ ' Include these characters to subkey stringbuilder
+ ' we will remove these before calling the handler further down
+ sb.Append(ch)
+ 'Exit Select
+ Case END_SUBKEY
+ If InFnutt Then
+ sb.Append(ch)
+ Else
+ subkey = sb.ToString()
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadKeyword
+ End If
+ Case Else
+ If InFnutt Then
+ sb.Append(ch)
+ Else
+ If Not Char.IsWhiteSpace(ch) Then
+ sb.Append(ch)
+ End If
+ End If
+ End Select
+ Case ParserState.ReadValues
+ If valueType = PXFileParser.ValueType.ErrorValue Then
+ 'There are errors in values -> Read to ; and send error
+ If ch = END_VALUES Then
+ values = New System.Collections.Specialized.StringCollection
+ values.Add(keyword)
+ values.Add(language)
+ values.Add(subkey)
+
+ _keepRunning = handler("KEYWORD_ERROR", Nothing, Nothing, values)
+
+ keyword = Nothing
+ language = Nothing
+ subkey = Nothing
+ values = Nothing
+ hasLanguage = False
+ hasSubkeys = False
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadKeyword
+ InFnutt = False
+ End If
+ Else
+ If InFnutt Then
+ Select Case valueType
+ Case PXFileParser.ValueType.NotSet
+ valueType = PXFileParser.ValueType.FnuttValue
+ If Not ch = FNUTT Then
+ sb.Append(ch)
+ End If
+ Case PXFileParser.ValueType.FnuttValue
+ If Not ch = FNUTT Then
+ sb.Append(ch)
+ End If
+ Case PXFileParser.ValueType.NoFnuttValue
+ 'No fnutts allowed in NoFnuttValues!
+ valueType = PXFileParser.ValueType.ErrorValue
+ End Select
+ Else
+ If Char.IsWhiteSpace(ch) Or ch = FNUTT Then
+ Exit Select
+ End If
+ Select Case ch
+ Case START_LANGUAGE, START_VALUES, END_LANGUAGE
+ Throw New Exception("Invalid PX file")
+ Case COMMA
+ values.Add(sb.ToString())
+ sb = New System.Text.StringBuilder
+ 'Some keywords (e.g. TIMEVAL) may have values of both type
+ 'FnuttValue and NoFnuttValue. Reset ValueType between values
+ 'to handle this
+ valueType = PXFileParser.ValueType.NotSet
+ Case COLON
+ 'Hiearchyvalue - Add colon...
+ sb.Append(ch)
+ Case MINUS
+ Select Case keyword
+ Case "TIMEVAL"
+ 'Timeval in interval format
+ sb.Append(ch)
+ 'Read past the next "-character
n = theStream.Read()
charCount += 1
- If n <> 34 Then '34 = "
- valueType = PXFileParser.ValueType.ErrorValue
- End If
- InFnutt = True
- Case Else
- valueType = PXFileParser.ValueType.ErrorValue
- End Select
- Case END_SUBKEY
- Select Case keyword
- Case "TIMEVAL"
- 'Timeval in interval format
- sb.Append(ch)
- Case Else
- valueType = PXFileParser.ValueType.ErrorValue
- End Select
- Case END_VALUES
-
- values.Add(sb.ToString())
-
- ' Remove start/ending FNUTT
- If subkey IsNot Nothing AndAlso subkey.Length > 0 Then
- If subkey.Substring(0, 1) = FNUTT Then subkey = subkey.Substring(1)
- If subkey.Length > 0 AndAlso subkey.Substring(subkey.Length - 1, 1) = FNUTT Then subkey = subkey.Substring(0, subkey.Length - 1)
- End If
-
- 'Storing information if the data is in KEYS format
- If String.IsNullOrEmpty(language) Then
- Select Case keyword
- Case PXKeywords.STUB 'Adding info about the value
- For Each variable As String In values
- _stubVariables.Add(variable, New ValueCodeContainer())
- _stubVariableList.Add(variable)
- Next
- Case PXKeywords.VALUES 'Storing info about the values for a variable in the stub
- If _stubVariables.ContainsKey(subkey) Then
- _stubVariables(subkey).Values = values
- End If
- Case PXKeywords.CODES 'Storing info about the codes for a variable in the stub
- If _stubVariables.ContainsKey(subkey) Then
- _stubVariables(subkey).Codes = values
- End If
- Case PXKeywords.KEYS 'Checks if the data is in KEYS format
- _inKeysFormat = True
- If _stubVariables.ContainsKey(subkey) Then
- _stubVariables(subkey).Key = values(0)
- End If
- End Select
- End If
-
- _keepRunning = handler(keyword, language, subkey, values)
- keyword = Nothing
- language = Nothing
- subkey = Nothing
- values = Nothing
- hasLanguage = False
- hasSubkeys = False
- sb = New System.Text.StringBuilder
- state = ParserState.ReadKeyword
- Case Else 'TODO 20050810 För att få med sånt som står utan fnuttar i values
- ''Enbart bett värde utan fnuttar är tillåtet annars är det ett fel i nyckelordet.
- 'If values.Count = 0 Then
- ' sb.Append(ch)
- 'Else
- ' 'TODO FIXA bugg
- ' 'Signalera att det är ett fel i keywordet
- ' 'Läs till EOL eller semikolon
- 'End If
-
- Select Case valueType
- Case PXFileParser.ValueType.NotSet
- valueType = PXFileParser.ValueType.NoFnuttValue
- If values.Count = 0 Then
- sb.Append(ch)
- End If
- Case PXFileParser.ValueType.NoFnuttValue
- If values.Count = 0 Then
- sb.Append(ch)
- End If
- Case PXFileParser.ValueType.FnuttValue
- 'This is wrong...
- valueType = PXFileParser.ValueType.ErrorValue
- End Select
- End Select
- End If
- End If
- End Select
+ If n <> 34 Then '34 = "
+ valueType = PXFileParser.ValueType.ErrorValue
+ End If
+ InFnutt = True
+ Case Else
+ valueType = PXFileParser.ValueType.ErrorValue
+ End Select
+ Case END_SUBKEY
+ Select Case keyword
+ Case "TIMEVAL"
+ 'Timeval in interval format
+ sb.Append(ch)
+ Case Else
+ valueType = PXFileParser.ValueType.ErrorValue
+ End Select
+ Case END_VALUES
+
+ values.Add(sb.ToString())
+
+ ' Remove start/ending FNUTT
+ If subkey IsNot Nothing AndAlso subkey.Length > 0 Then
+ If subkey.Substring(0, 1) = FNUTT Then subkey = subkey.Substring(1)
+ If subkey.Length > 0 AndAlso subkey.Substring(subkey.Length - 1, 1) = FNUTT Then subkey = subkey.Substring(0, subkey.Length - 1)
+ End If
+
+ 'Storing information if the data is in KEYS format
+ If String.IsNullOrEmpty(language) Then
+ Select Case keyword
+ Case PXKeywords.STUB 'Adding info about the value
+ For Each variable As String In values
+ _stubVariables.Add(variable, New ValueCodeContainer())
+ _stubVariableList.Add(variable)
+ Next
+ Case PXKeywords.VALUES 'Storing info about the values for a variable in the stub
+ If _stubVariables.ContainsKey(subkey) Then
+ _stubVariables(subkey).Values = values
+ End If
+ Case PXKeywords.CODES 'Storing info about the codes for a variable in the stub
+ If _stubVariables.ContainsKey(subkey) Then
+ _stubVariables(subkey).Codes = values
+ End If
+ Case PXKeywords.KEYS 'Checks if the data is in KEYS format
+ _inKeysFormat = True
+ If _stubVariables.ContainsKey(subkey) Then
+ _stubVariables(subkey).Key = values(0)
+ End If
+ End Select
+ End If
+
+ _keepRunning = handler(keyword, language, subkey, values)
+ keyword = Nothing
+ language = Nothing
+ subkey = Nothing
+ values = Nothing
+ hasLanguage = False
+ hasSubkeys = False
+ sb = New System.Text.StringBuilder
+ state = ParserState.ReadKeyword
+ Case Else 'TODO 20050810 För att få med sånt som står utan fnuttar i values
+ ''Enbart bett värde utan fnuttar är tillåtet annars är det ett fel i nyckelordet.
+ 'If values.Count = 0 Then
+ ' sb.Append(ch)
+ 'Else
+ ' 'TODO FIXA bugg
+ ' 'Signalera att det är ett fel i keywordet
+ ' 'Läs till EOL eller semikolon
+ 'End If
+
+ Select Case valueType
+ Case PXFileParser.ValueType.NotSet
+ valueType = PXFileParser.ValueType.NoFnuttValue
+ If values.Count = 0 Then
+ sb.Append(ch)
+ End If
+ Case PXFileParser.ValueType.NoFnuttValue
+ If values.Count = 0 Then
+ sb.Append(ch)
+ End If
+ Case PXFileParser.ValueType.FnuttValue
+ 'This is wrong...
+ valueType = PXFileParser.ValueType.ErrorValue
+ End Select
+ End Select
+ End If
+ End If
+ End Select
n = theStream.Read()
charCount += 1
- End While
+ End While
- If n = -1 Then
+ If n = -1 Then
'Throw New PXModelParserException(Localization.PxResourceManager.GetResourceManager.GetString(ErrorCodes.DATA_MISSING))
Throw New PXModelParserException(ErrorCodes.DATA_MISSING)
Else
mHasParsedMeta = True
- End If
+ End If
_position = charCount 'GetPosition(theStream)
theStream.Close()
- End Sub
-
- '''
- ''' Stop parsing
- '''
- '''
- Public Sub StopParsing()
- _keepRunning = False
- End Sub
+ End Sub
+
+ '''
+ ''' Stop parsing
+ '''
+ '''
+ Public Sub StopParsing()
+ _keepRunning = False
+ End Sub
#End Region
#Region "Helper functions"
- Private Function CheckWhiteSpace(ByVal ch As Char) As Boolean
- If Char.IsWhiteSpace(ch) Then
- Return True
- End If
- Return False
- End Function
+ Private Function CheckWhiteSpace(ByVal ch As Char) As Boolean
+ If Char.IsWhiteSpace(ch) Then
+ Return True
+ End If
+ Return False
+ End Function
#End Region
+
+ Protected Overridable Function GetStream() As Stream
+ Return New System.IO.FileStream(_path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048)
+ End Function
+
Private Sub FastForward(ByVal s As System.IO.StreamReader, ByVal charCount As Long)
For index As Long = 1 To charCount
@@ -482,263 +510,263 @@ Namespace PCAxis.Paxiom.Parsers
#Region "ParseData"
- Public Sub ParseData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer) Implements Paxiom.IPXModelParser.ParseData
+ Public Sub ParseData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer) Implements Paxiom.IPXModelParser.ParseData
- 'Checks that the object is still alive
- If Me.disposed Then
- Throw New ObjectDisposedException(Me.GetType().ToString, _
- "This object has been disposed.")
- End If
+ 'Checks that the object is still alive
+ If Me.disposed Then
+ Throw New ObjectDisposedException(Me.GetType().ToString,
+ "This object has been disposed.")
+ End If
- 'Check that the metadata has been read
- If Not mHasParsedMeta Then
- Exit Sub
- End If
- If mHasParsedData Then
- Exit Sub 'Data has aready been read.
- End If
+ 'Check that the metadata has been read
+ If Not mHasParsedMeta Then
+ Exit Sub
+ End If
+ If mHasParsedData Then
+ Exit Sub 'Data has aready been read.
+ End If
- Me.theStream = New IO.StreamReader(New System.IO.FileStream(_path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048), _encoding)
+ Me.theStream = New IO.StreamReader(GetStream(), _encoding)
'theStream.BaseStream.Seek(_position, IO.SeekOrigin.Begin)
'theStream.DiscardBufferedData()
FastForward(theStream, _position)
- If _inKeysFormat Then
- ParseKeysData(handler, preferredBufferSize)
- Else
- ParseMatrixData(handler, preferredBufferSize)
- End If
+ If _inKeysFormat Then
+ ParseKeysData(handler, preferredBufferSize)
+ Else
+ ParseMatrixData(handler, preferredBufferSize)
+ End If
mHasParsedData = True
theStream.Close()
- End Sub
-
- Private Sub ParseKeysData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer)
- Dim DBG As Boolean = Logger.IsDebugEnabled
-
- 'Contains a empty row
- Dim clearBuffer(preferredBufferSize - 1) As Double
- 'The buffer that will be used for the parsed values
- Dim buffer(preferredBufferSize - 1) As Double
-
- 'Number of variables in the stub
- Dim noOfVariables As Integer = _stubVariables.Keys.Count
- 'The number of rows in the entire matrix
- Dim rowSize As Integer = 1
- 'Matrix containing weights for variables in the stub
- Dim sMatrix(noOfVariables - 1) As Integer
- For i As Integer = 0 To noOfVariables - 1
- sMatrix(i) = 1
- rowSize *= _stubVariables(_stubVariableList(i)).Values.Count
- For j As Integer = i + 1 To noOfVariables - 1
- sMatrix(i) *= _stubVariables(_stubVariableList(j)).Values.Count
- Next
- Next
- 'The current row index
- Dim currentRow As Integer = 0
-
- Dim keyCount As Integer = 0
- Dim valueCount As Integer = 0
- Dim columnSize As Integer = preferredBufferSize
- Dim columnCount As Integer = 0
-
- Dim keyRowIndex As Integer = 0
-
- For i As Integer = 0 To preferredBufferSize - 1
- clearBuffer(i) = 0.0
- Next
-
- Dim ch As Char
- Dim n As Integer
- Dim sb As New System.Text.StringBuilder()
- Dim data As String
- Dim done As Boolean = False
- Dim currentIndex As Integer = 0
- Dim stopReading As Boolean = False
- Dim state As KeysStates = KeysStates.TrimWhiteSpaceBeforeKey
- Dim reEval As Boolean = False
- n = theStream.Read()
- While n > -1 And Not done
- ch = Convert.ToChar(n)
- reEval = True
-
- While reEval
- reEval = False
-
- Select Case state
- Case KeysStates.TrimWhiteSpaceBeforeKey
- If keyCount = noOfVariables Then
- state = KeysStates.TrimWiteSpaceSurroundValue
- columnCount = 0
- reEval = True
- ElseIf ch = FNUTT Then
- state = KeysStates.ReadKey
- sb = New System.Text.StringBuilder
- ElseIf Char.IsWhiteSpace(ch) Then
- 'Continue remove white space
- Else
- 'TODO ERROR
- End If
- Case KeysStates.ReadKey
- If ch = FNUTT Then
- state = KeysStates.TrimWhiteSpaceAfterKey
-
- data = sb.ToString()
-
- 'Calculates the index of the roow in the entire matrix
- Dim list As System.Collections.Specialized.StringCollection
- If _stubVariables.ContainsKey(_stubVariableList(keyCount)) Then
- Dim vcc As ValueCodeContainer = _stubVariables(_stubVariableList(keyCount))
- If String.Compare(vcc.Key, "CODES", True) = 0 Then
- list = vcc.Codes
- Else
- list = vcc.Values
- End If
-
- Dim vIndex As Integer
- vIndex = list.IndexOf(data)
- If vIndex > -1 Then
- keyRowIndex += sMatrix(keyCount) * vIndex
- keyCount += 1
-
- If DBG Then
- Logger.Debug(data)
- End If
-
- Else
- Throw New PXModelParserException(String.Format("Value {0} dose not exist for variable {1}", data, _stubVariableList(keyCount)))
- End If
- End If
- Else
- sb.Append(ch)
- End If
- Case KeysStates.TrimWhiteSpaceAfterKey
- If ch = COMMA Then
- state = KeysStates.TrimWhiteSpaceBeforeKey
- '---TODO reset
- 'reEval = True
- ElseIf Char.IsWhiteSpace(ch) Then
- 'Continue reading white spaces
- Else
- 'TODO ERROR
- End If
- Case KeysStates.TrimWiteSpaceSurroundValue
- If Char.IsWhiteSpace(ch) Then
- 'Keep reading white spaces
- Else
- sb = New System.Text.StringBuilder()
- reEval = True
- state = KeysStates.ReadValue
- End If
- Case KeysStates.ReadValue
- If Char.IsWhiteSpace(ch) Then
- data = sb.ToString()
- 'Create a new empty buffer to store the next value
- sb = New System.Text.StringBuilder()
- buffer(columnCount) = StringToDouble(data)
- columnCount += 1
- If columnCount = columnSize Then
- 'The hole line of data is read
- SignalNewData(handler, preferredBufferSize, clearBuffer, buffer, currentRow, keyCount, keyRowIndex, done, stopReading, state)
- End If
-
- ElseIf ch = END_VALUES Then
- data = sb.ToString()
- buffer(columnCount) = StringToDouble(data)
- columnCount += 1
- If columnCount = columnSize Then
- 'Last line of data has been read
- SignalNewData(handler, preferredBufferSize, clearBuffer, buffer, currentRow, keyCount, keyRowIndex, done, stopReading, state)
- End If
- 'writes the rest of the zeros
- If Not done Then
- Dim zeroCount As Integer
- zeroCount = rowSize - currentRow
- For i As Integer = 0 To zeroCount - 1
- handler(clearBuffer, 0, preferredBufferSize - 1, stopReading)
- If stopReading Then
- done = True
- Exit For
- End If
- currentRow += 1
- Next
- End If
- done = True
- Else
- sb.Append(ch)
- End If
- End Select
- End While
-
- n = theStream.Read()
- End While
- End Sub
-
- Private Shared Sub SignalNewData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer, ByVal clearBuffer As Double(), ByVal buffer As Double(), ByRef currentRow As Integer, ByRef keyCount As Integer, ByRef keyRowIndex As Integer, ByRef done As Boolean, ByVal stopReading As Boolean, ByRef state As KeysStates)
- 'Fills up with zeros
- Dim zeroCount As Integer
- zeroCount = keyRowIndex - currentRow
- For i As Integer = 0 To zeroCount - 1
- handler(clearBuffer, 0, preferredBufferSize - 1, stopReading)
- If stopReading Then
- done = True
- Exit For
- End If
- currentRow += 1
- Next
- 'writes the data row
- handler(buffer, 0, preferredBufferSize - 1, stopReading)
- If stopReading Then
- done = True
- End If
- currentRow += 1
-
- state = KeysStates.TrimWhiteSpaceBeforeKey
- keyCount = 0
- keyRowIndex = 0
- End Sub
-
- Private Sub ParseMatrixData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer)
- Dim DBG As Boolean = Logger.IsDebugEnabled
- Dim ch As Char
- Dim n As Integer
- Dim sb As System.Text.StringBuilder
- Dim data As String
- Dim buffer As Double()
- Dim done As Boolean = False
- Dim bufferSize As Integer
- Dim currentIndex As Integer = 0
- Dim stopReading As Boolean = False
- 'Dim dc As String = PCAxis.AxiOM.PXModel.DecimalSeparator
-
-
- 'Sets the databuffer size
- If preferredBufferSize > 0 Then
- bufferSize = preferredBufferSize
- Else
- bufferSize = PXFileParser.DEFAULT_DATA_BUFFER_SIZE
- End If
- 'Creates the databuffer
- ReDim buffer(bufferSize - 1)
-
- sb = New System.Text.StringBuilder
- n = theStream.Read()
- While n > -1 And Not done
- ch = Convert.ToChar(n)
-
- 'If we are at
- If ch = END_VALUES Then
- done = True
- data = sb.ToString()
- sb = New System.Text.StringBuilder
- If data Is Nothing Or data = String.Empty Then
- Throw New PXModelParserException("Data in KEYS format is missing or corrupt", ErrorCodes.DATA_MISSING.ToString())
- Else
- 'handler(Double.Parse(data))
- buffer(currentIndex) = StringToDouble(data)
- currentIndex += 1
- End If
+ End Sub
+
+ Private Sub ParseKeysData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer)
+ Dim DBG As Boolean = Logger.IsDebugEnabled
+
+ 'Contains a empty row
+ Dim clearBuffer(preferredBufferSize - 1) As Double
+ 'The buffer that will be used for the parsed values
+ Dim buffer(preferredBufferSize - 1) As Double
+
+ 'Number of variables in the stub
+ Dim noOfVariables As Integer = _stubVariables.Keys.Count
+ 'The number of rows in the entire matrix
+ Dim rowSize As Integer = 1
+ 'Matrix containing weights for variables in the stub
+ Dim sMatrix(noOfVariables - 1) As Integer
+ For i As Integer = 0 To noOfVariables - 1
+ sMatrix(i) = 1
+ rowSize *= _stubVariables(_stubVariableList(i)).Values.Count
+ For j As Integer = i + 1 To noOfVariables - 1
+ sMatrix(i) *= _stubVariables(_stubVariableList(j)).Values.Count
+ Next
+ Next
+ 'The current row index
+ Dim currentRow As Integer = 0
+
+ Dim keyCount As Integer = 0
+ Dim valueCount As Integer = 0
+ Dim columnSize As Integer = preferredBufferSize
+ Dim columnCount As Integer = 0
+
+ Dim keyRowIndex As Integer = 0
+
+ For i As Integer = 0 To preferredBufferSize - 1
+ clearBuffer(i) = 0.0
+ Next
+
+ Dim ch As Char
+ Dim n As Integer
+ Dim sb As New System.Text.StringBuilder()
+ Dim data As String
+ Dim done As Boolean = False
+ Dim currentIndex As Integer = 0
+ Dim stopReading As Boolean = False
+ Dim state As KeysStates = KeysStates.TrimWhiteSpaceBeforeKey
+ Dim reEval As Boolean = False
+ n = theStream.Read()
+ While n > -1 And Not done
+ ch = Convert.ToChar(n)
+ reEval = True
+
+ While reEval
+ reEval = False
+
+ Select Case state
+ Case KeysStates.TrimWhiteSpaceBeforeKey
+ If keyCount = noOfVariables Then
+ state = KeysStates.TrimWiteSpaceSurroundValue
+ columnCount = 0
+ reEval = True
+ ElseIf ch = FNUTT Then
+ state = KeysStates.ReadKey
+ sb = New System.Text.StringBuilder
+ ElseIf Char.IsWhiteSpace(ch) Then
+ 'Continue remove white space
+ Else
+ 'TODO ERROR
+ End If
+ Case KeysStates.ReadKey
+ If ch = FNUTT Then
+ state = KeysStates.TrimWhiteSpaceAfterKey
+
+ data = sb.ToString()
+
+ 'Calculates the index of the roow in the entire matrix
+ Dim list As System.Collections.Specialized.StringCollection
+ If _stubVariables.ContainsKey(_stubVariableList(keyCount)) Then
+ Dim vcc As ValueCodeContainer = _stubVariables(_stubVariableList(keyCount))
+ If String.Compare(vcc.Key, "CODES", True) = 0 Then
+ list = vcc.Codes
+ Else
+ list = vcc.Values
+ End If
+
+ Dim vIndex As Integer
+ vIndex = list.IndexOf(data)
+ If vIndex > -1 Then
+ keyRowIndex += sMatrix(keyCount) * vIndex
+ keyCount += 1
+
+ If DBG Then
+ Logger.Debug(data)
+ End If
+
+ Else
+ Throw New PXModelParserException(String.Format("Value {0} dose not exist for variable {1}", data, _stubVariableList(keyCount)))
+ End If
+ End If
+ Else
+ sb.Append(ch)
+ End If
+ Case KeysStates.TrimWhiteSpaceAfterKey
+ If ch = COMMA Then
+ state = KeysStates.TrimWhiteSpaceBeforeKey
+ '---TODO reset
+ 'reEval = True
+ ElseIf Char.IsWhiteSpace(ch) Then
+ 'Continue reading white spaces
+ Else
+ 'TODO ERROR
+ End If
+ Case KeysStates.TrimWiteSpaceSurroundValue
+ If Char.IsWhiteSpace(ch) Then
+ 'Keep reading white spaces
+ Else
+ sb = New System.Text.StringBuilder()
+ reEval = True
+ state = KeysStates.ReadValue
+ End If
+ Case KeysStates.ReadValue
+ If Char.IsWhiteSpace(ch) Then
+ data = sb.ToString()
+ 'Create a new empty buffer to store the next value
+ sb = New System.Text.StringBuilder()
+ buffer(columnCount) = StringToDouble(data)
+ columnCount += 1
+ If columnCount = columnSize Then
+ 'The hole line of data is read
+ SignalNewData(handler, preferredBufferSize, clearBuffer, buffer, currentRow, keyCount, keyRowIndex, done, stopReading, state)
+ End If
+
+ ElseIf ch = END_VALUES Then
+ data = sb.ToString()
+ buffer(columnCount) = StringToDouble(data)
+ columnCount += 1
+ If columnCount = columnSize Then
+ 'Last line of data has been read
+ SignalNewData(handler, preferredBufferSize, clearBuffer, buffer, currentRow, keyCount, keyRowIndex, done, stopReading, state)
+ End If
+ 'writes the rest of the zeros
+ If Not done Then
+ Dim zeroCount As Integer
+ zeroCount = rowSize - currentRow
+ For i As Integer = 0 To zeroCount - 1
+ handler(clearBuffer, 0, preferredBufferSize - 1, stopReading)
+ If stopReading Then
+ done = True
+ Exit For
+ End If
+ currentRow += 1
+ Next
+ End If
+ done = True
+ Else
+ sb.Append(ch)
+ End If
+ End Select
+ End While
+
+ n = theStream.Read()
+ End While
+ End Sub
+
+ Private Shared Sub SignalNewData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer, ByVal clearBuffer As Double(), ByVal buffer As Double(), ByRef currentRow As Integer, ByRef keyCount As Integer, ByRef keyRowIndex As Integer, ByRef done As Boolean, ByVal stopReading As Boolean, ByRef state As KeysStates)
+ 'Fills up with zeros
+ Dim zeroCount As Integer
+ zeroCount = keyRowIndex - currentRow
+ For i As Integer = 0 To zeroCount - 1
+ handler(clearBuffer, 0, preferredBufferSize - 1, stopReading)
+ If stopReading Then
+ done = True
+ Exit For
+ End If
+ currentRow += 1
+ Next
+ 'writes the data row
+ handler(buffer, 0, preferredBufferSize - 1, stopReading)
+ If stopReading Then
+ done = True
+ End If
+ currentRow += 1
+
+ state = KeysStates.TrimWhiteSpaceBeforeKey
+ keyCount = 0
+ keyRowIndex = 0
+ End Sub
+
+ Private Sub ParseMatrixData(ByVal handler As PCAxis.Paxiom.IPXModelParser.DataHandler, ByVal preferredBufferSize As Integer)
+ Dim DBG As Boolean = Logger.IsDebugEnabled
+ Dim ch As Char
+ Dim n As Integer
+ Dim sb As System.Text.StringBuilder
+ Dim data As String
+ Dim buffer As Double()
+ Dim done As Boolean = False
+ Dim bufferSize As Integer
+ Dim currentIndex As Integer = 0
+ Dim stopReading As Boolean = False
+ 'Dim dc As String = PCAxis.AxiOM.PXModel.DecimalSeparator
+
+
+ 'Sets the databuffer size
+ If preferredBufferSize > 0 Then
+ bufferSize = preferredBufferSize
+ Else
+ bufferSize = PXFileParser.DEFAULT_DATA_BUFFER_SIZE
+ End If
+ 'Creates the databuffer
+ ReDim buffer(bufferSize - 1)
+
+ sb = New System.Text.StringBuilder
+ n = theStream.Read()
+ While n > -1 And Not done
+ ch = Convert.ToChar(n)
+
+ 'If we are at
+ If ch = END_VALUES Then
+ done = True
+ data = sb.ToString()
+ sb = New System.Text.StringBuilder
+ If data Is Nothing Or data = String.Empty Then
+ Throw New PXModelParserException("Data in KEYS format is missing or corrupt", ErrorCodes.DATA_MISSING.ToString())
+ Else
+ 'handler(Double.Parse(data))
+ buffer(currentIndex) = StringToDouble(data)
+ currentIndex += 1
+ End If
ElseIf Char.IsWhiteSpace(ch) Then
data = sb.ToString()
sb = New System.Text.StringBuilder
@@ -753,188 +781,188 @@ Namespace PCAxis.Paxiom.Parsers
currentIndex += 1
End If
- Else
- sb.Append(ch)
- End If
-
- 'Check if buffer is full
- If currentIndex >= bufferSize Or done Then
- handler(buffer, 0, currentIndex - 1, stopReading)
- If stopReading Then
- Exit While
- End If
- 'IF we are done we do not reallocate any space
- If Not done Then
- ReDim buffer(bufferSize)
- currentIndex = 0
- End If
- End If
-
- n = theStream.Read()
- End While
- End Sub
+ Else
+ sb.Append(ch)
+ End If
+
+ 'Check if buffer is full
+ If currentIndex >= bufferSize Or done Then
+ handler(buffer, 0, currentIndex - 1, stopReading)
+ If stopReading Then
+ Exit While
+ End If
+ 'IF we are done we do not reallocate any space
+ If Not done Then
+ ReDim buffer(bufferSize)
+ currentIndex = 0
+ End If
+ End If
+
+ n = theStream.Read()
+ End While
+ End Sub
#End Region
#Region "CovertFunctions"
- Private Shared _NumberFormat As System.Globalization.NumberFormatInfo
-
- Shared Sub New()
- Try
- _NumberFormat = CType(System.Globalization.CultureInfo.InstalledUICulture.NumberFormat.Clone(), System.Globalization.NumberFormatInfo)
- _NumberFormat.NumberDecimalSeparator = "."
- Catch ex As Exception
- Logger.Error("Could not create NumberFormat", ex)
- End Try
-
- End Sub
-
-
- Private Function StringToDouble(ByVal data As String) As Double
- Dim d As Double
- Dim dd As String '= data.Trim()
- If Not Double.TryParse(data, Globalization.NumberStyles.Number, _NumberFormat, d) Then
- dd = data.Trim()
- If dd.StartsWith("""") Then
- dd = dd.Substring(1)
- End If
- If dd.EndsWith("""") Then
- dd = dd.Substring(0, dd.Length - 1)
- End If
- Select Case dd
- Case PXConstant.DATASYMBOL_1_STRING
- d = PXConstant.DATASYMBOL_1
- Case PXConstant.DATASYMBOL_2_STRING
- d = PXConstant.DATASYMBOL_2
- Case PXConstant.DATASYMBOL_3_STRING
- d = PXConstant.DATASYMBOL_3
- Case PXConstant.DATASYMBOL_4_STRING
- d = PXConstant.DATASYMBOL_4
- Case PXConstant.DATASYMBOL_5_STRING
- d = PXConstant.DATASYMBOL_5
- Case PXConstant.DATASYMBOL_6_STRING
- d = PXConstant.DATASYMBOL_6
- Case PXConstant.DATASYMBOL_7_STRING
- d = PXConstant.DATASYMBOL_7
- Case PXConstant.DATASYMBOL_NIL_STRING
- d = PXConstant.DATASYMBOL_NIL
- Case Else
- 'TODO change to TryParse
- 'If DecimalSeparator <> DefaultDecimalSeparator Then
- ' d = Double.Parse(data.Replace(".", DecimalSeparator))
- 'Else
- ' d = Double.Parse(data)
- 'End If
- d = Double.Parse(data, _NumberFormat)
-
- End Select
-
- End If
-
- Return d
- End Function
+ Private Shared _NumberFormat As System.Globalization.NumberFormatInfo
+
+ Shared Sub New()
+ Try
+ _NumberFormat = CType(System.Globalization.CultureInfo.InstalledUICulture.NumberFormat.Clone(), System.Globalization.NumberFormatInfo)
+ _NumberFormat.NumberDecimalSeparator = "."
+ Catch ex As Exception
+ Logger.Error("Could not create NumberFormat", ex)
+ End Try
+
+ End Sub
+
+
+ Private Function StringToDouble(ByVal data As String) As Double
+ Dim d As Double
+ Dim dd As String '= data.Trim()
+ If Not Double.TryParse(data, Globalization.NumberStyles.Number, _NumberFormat, d) Then
+ dd = data.Trim()
+ If dd.StartsWith("""") Then
+ dd = dd.Substring(1)
+ End If
+ If dd.EndsWith("""") Then
+ dd = dd.Substring(0, dd.Length - 1)
+ End If
+ Select Case dd
+ Case PXConstant.DATASYMBOL_1_STRING
+ d = PXConstant.DATASYMBOL_1
+ Case PXConstant.DATASYMBOL_2_STRING
+ d = PXConstant.DATASYMBOL_2
+ Case PXConstant.DATASYMBOL_3_STRING
+ d = PXConstant.DATASYMBOL_3
+ Case PXConstant.DATASYMBOL_4_STRING
+ d = PXConstant.DATASYMBOL_4
+ Case PXConstant.DATASYMBOL_5_STRING
+ d = PXConstant.DATASYMBOL_5
+ Case PXConstant.DATASYMBOL_6_STRING
+ d = PXConstant.DATASYMBOL_6
+ Case PXConstant.DATASYMBOL_7_STRING
+ d = PXConstant.DATASYMBOL_7
+ Case PXConstant.DATASYMBOL_NIL_STRING
+ d = PXConstant.DATASYMBOL_NIL
+ Case Else
+ 'TODO change to TryParse
+ 'If DecimalSeparator <> DefaultDecimalSeparator Then
+ ' d = Double.Parse(data.Replace(".", DecimalSeparator))
+ 'Else
+ ' d = Double.Parse(data)
+ 'End If
+ d = Double.Parse(data, _NumberFormat)
+
+ End Select
+
+ End If
+
+ Return d
+ End Function
#End Region
#Region "Constructor(s)"
- Public Sub New()
+ Public Sub New()
- End Sub
+ End Sub
- Public Sub New(ByVal path As String)
- _encoding = GetEncoding(path)
- Me.theStream = New IO.StreamReader(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048), _encoding)
- Me.state = ParserState.ReadKeyword
- End Sub
+ Public Sub New(ByVal path As String)
+ _encoding = GetEncoding(path)
+ Me.theStream = New IO.StreamReader(New System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048), _encoding)
+ Me.state = ParserState.ReadKeyword
+ End Sub
#End Region
#Region "IPlugIn implementation"
- Public ReadOnly Property Id() As System.Guid Implements PCAxis.PlugIn.IPlugIn.Id
- Get
- Return New Guid("c6fd3c04-c14d-42ce-8271-e151a0bfdc8d")
- End Get
- End Property
-
- Public ReadOnly Property Name() As String Implements PCAxis.PlugIn.IPlugIn.Name
- Get
- Return "PX-file parser"
- End Get
- End Property
-
- Public ReadOnly Property Description() As String Implements PCAxis.PlugIn.IPlugIn.Description
- Get
- Return "This is the default plugin which reads a classical PC-Axis file"
- End Get
- End Property
-
- Public Sub Initialize(ByVal host As PCAxis.PlugIn.IPlugInHost, ByVal configuration As Dictionary(Of String, String)) Implements PCAxis.PlugIn.IPlugIn.Initialize
- Dim filename As String
- 'Checks that there is a filename
- If Not configuration.ContainsKey(PXFileParser.FILENAME) Then
- Throw New PCAxis.Paxiom.PXModelParserException("No file was given")
- End If
- filename = configuration(PXFileParser.FILENAME)
-
- 'Dispose the previous stream if there was one
- If Not theStream Is Nothing Then
- theStream.Dispose()
- End If
-
- 'Opens a stream to the file
- _encoding = GetEncoding(filename)
- Me.theStream = New System.IO.StreamReader(New System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048), _encoding)
- Me.state = ParserState.ReadKeyword
- End Sub
-
- Public Sub Terminate() Implements PCAxis.PlugIn.IPlugIn.Terminate
- Me.Dispose()
- End Sub
+ Public ReadOnly Property Id() As System.Guid Implements PCAxis.PlugIn.IPlugIn.Id
+ Get
+ Return New Guid("c6fd3c04-c14d-42ce-8271-e151a0bfdc8d")
+ End Get
+ End Property
+
+ Public ReadOnly Property Name() As String Implements PCAxis.PlugIn.IPlugIn.Name
+ Get
+ Return "PX-file parser"
+ End Get
+ End Property
+
+ Public ReadOnly Property Description() As String Implements PCAxis.PlugIn.IPlugIn.Description
+ Get
+ Return "This is the default plugin which reads a classical PC-Axis file"
+ End Get
+ End Property
+
+ Public Sub Initialize(ByVal host As PCAxis.PlugIn.IPlugInHost, ByVal configuration As Dictionary(Of String, String)) Implements PCAxis.PlugIn.IPlugIn.Initialize
+ Dim filename As String
+ 'Checks that there is a filename
+ If Not configuration.ContainsKey(PXFileParser.FILENAME) Then
+ Throw New PCAxis.Paxiom.PXModelParserException("No file was given")
+ End If
+ filename = configuration(PXFileParser.FILENAME)
+
+ 'Dispose the previous stream if there was one
+ If Not theStream Is Nothing Then
+ theStream.Dispose()
+ End If
+
+ 'Opens a stream to the file
+ _encoding = GetEncoding(filename)
+ Me.theStream = New System.IO.StreamReader(New System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, 2048), _encoding)
+ Me.state = ParserState.ReadKeyword
+ End Sub
+
+ Public Sub Terminate() Implements PCAxis.PlugIn.IPlugIn.Terminate
+ Me.Dispose()
+ End Sub
#End Region
#Region "IDisposable implementation"
- Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
- If Not Me.disposed Then
- If disposing Then
- If Not theStream Is Nothing Then
- theStream.Dispose()
- End If
- End If
- ' Add code here to release the unmanaged resource.
- theStream = Nothing
- ' Note that this is not thread safe.
- End If
- Me.disposed = True
- End Sub
-
-
- ' Do not change or add Overridable to these methods.
- ' Put cleanup code in Dispose(ByVal disposing As Boolean).
- Public Overloads Sub Dispose() Implements IDisposable.Dispose
- Dispose(True)
- GC.SuppressFinalize(Me)
- End Sub
-
- Protected Overrides Sub Finalize()
- Dispose(False)
- MyBase.Finalize()
- End Sub
+ Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
+ If Not Me.disposed Then
+ If disposing Then
+ If Not theStream Is Nothing Then
+ theStream.Dispose()
+ End If
+ End If
+ ' Add code here to release the unmanaged resource.
+ theStream = Nothing
+ ' Note that this is not thread safe.
+ End If
+ Me.disposed = True
+ End Sub
+
+
+ ' Do not change or add Overridable to these methods.
+ ' Put cleanup code in Dispose(ByVal disposing As Boolean).
+ Public Overloads Sub Dispose() Implements IDisposable.Dispose
+ Dispose(True)
+ GC.SuppressFinalize(Me)
+ End Sub
+
+ Protected Overrides Sub Finalize()
+ Dispose(False)
+ MyBase.Finalize()
+ End Sub
#End Region
#Region "Helper classes"
- Private Class ValueCodeContainer
- Public Values As System.Collections.Specialized.StringCollection
- Public Codes As System.Collections.Specialized.StringCollection
- Public Key As String
- End Class
+ Private Class ValueCodeContainer
+ Public Values As System.Collections.Specialized.StringCollection
+ Public Codes As System.Collections.Specialized.StringCollection
+ Public Key As String
+ End Class
#End Region
- End Class
+ End Class
End Namespace