Revision: 30
Author: duraid
Date: Thu Sep 17 13:51:29 2009
Log: more experimentation
http://code.google.com/p/sdmxdotnet/source/detail?r=30
Added:
/trunk/lib/xmldiffpatch.dll
/trunk/src/SDMX.Tests/ParserTests.cs
/trunk/src/SDMX.Tests/Requirements.txt
Modified:
/trunk/lib/CompactSample.xml
/trunk/src/SDMX.Tests/DataSet.cs
/trunk/src/SDMX.Tests/GenericDataTests.cs
/trunk/src/SDMX.Tests/Obs.cs
/trunk/src/SDMX.Tests/SDMX.Tests.csproj
/trunk/src/SDMX.Tests/Series.cs
/trunk/src/SDMX.Tests/Utility.cs
=======================================
--- /dev/null
+++ /trunk/lib/xmldiffpatch.dll Thu Sep 17 13:51:29 2009
Binary file, no diff available.
=======================================
--- /dev/null
+++ /trunk/src/SDMX.Tests/ParserTests.cs Thu Sep 17 13:51:29 2009
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.Xml.Linq;
+
+namespace SDMX.Tests.NewModel
+{
+ [TestFixture]
+ public class ParserTests
+ {
+ public void Can_parse_generic_format()
+ {
+
+
+
+ }
+
+ }
+}
=======================================
--- /dev/null
+++ /trunk/src/SDMX.Tests/Requirements.txt Thu Sep 17 13:51:29 2009
@@ -0,0 +1,20 @@
+1: produce generic data message from database
+
+1. load data from database as one table
+2. create new DataSet
+3. for each row
+ 1. build the serires and its attributes
+ 2. build the observation with its attributes
+ 3. add the observation to the series
+ 4. add the serires to the dataset
+ 5. build the group with its attributes
+ 6. add the group to dataset
+4. Create DataMessage
+5. Add header to data message
+6. Set the dataset to the data message
+7. Write the DataMessage to a file as GenericData sdmx message
+
+
+2:
+
+
=======================================
--- /trunk/lib/CompactSample.xml Wed Sep 16 13:27:46 2009
+++ /trunk/lib/CompactSample.xml Thu Sep 17 13:51:29 2009
@@ -52,8 +52,6 @@
<bisc:Series FREQ="A" COLLECTION="B" TIME_FORMAT="P1Y" VIS_CTY="MX"
JD_TYPE="P" JD_CATEGORY="A">
<bisc:Obs TIME_PERIOD="2000-01" OBS_VALUE="3.14" OBS_STATUS="A"/>
</bisc:Series>
-
-
<bisc:Series FREQ="M" COLLECTION="B" TIME_FORMAT="P1M" VIS_CTY="MX"
JD_TYPE="P" JD_CATEGORY="B">
<bisc:Obs TIME_PERIOD="2000-01" OBS_VALUE="5.14" OBS_STATUS="A"/>
<bisc:Obs TIME_PERIOD="2001-02" OBS_VALUE="3.29" OBS_STATUS="A"/>
=======================================
--- /trunk/src/SDMX.Tests/DataSet.cs Wed Sep 16 13:27:46 2009
+++ /trunk/src/SDMX.Tests/DataSet.cs Thu Sep 17 13:51:29 2009
@@ -4,6 +4,14 @@
{
public class DataSet
{
+ public IEnumerable<Series> Series
+ {
+ get
+ {
+ return series;
+ }
+ }
+
private List<Series> series = new List<Series>();
public KeyFamily KeyFamily { get; private set; }
=======================================
--- /trunk/src/SDMX.Tests/GenericDataTests.cs Wed Sep 16 13:27:46 2009
+++ /trunk/src/SDMX.Tests/GenericDataTests.cs Thu Sep 17 13:51:29 2009
@@ -8,6 +8,7 @@
using Generic = SDMX_ML.Framework.Generic;
using System.Xml.Linq;
using System.Linq;
+using System.Runtime.InteropServices;
namespace SDMX.Tests
{
@@ -46,6 +47,10 @@
string samplePath =
Utility.GetPathFromProjectBase("lib\\CompactSample.xml");
XDocument loadedXml = XDocument.Load(samplePath);
+ int bytes = Marshal.SizeOf(loadedXml);
+ int kbytes = bytes / 1024;
+ int Mbytes = kbytes / 1024;
+
var message = new Messages.CompactData(loadedXml.ToString());
XDocument generatedXml = XDocument.Parse(message.ToXml());
@@ -113,6 +118,8 @@
frequencyList.AddCode(new Code("D"));
var code = frequencyList["A"];
+
+
}
[Test]
@@ -152,18 +159,11 @@
series.SetKeyValue(value.Key, value.Value);
}
- object keyValue = series.GetKeyValue("FREQ");
-
- Observation obs = new Observation();
- obs.SetTimePeriod(timePeriod);
- obs.SetValue(obsValue);
+ Observation obs = Observation.Create(timePeriod, obsValue);
series.AddObservation(obs);
}
-
-
-
private static KeyFamily CreateKeyFamily()
{
=======================================
--- /trunk/src/SDMX.Tests/Obs.cs Wed Sep 16 13:27:46 2009
+++ /trunk/src/SDMX.Tests/Obs.cs Thu Sep 17 13:51:29 2009
@@ -5,21 +5,31 @@
namespace SDMX.Tests
{
- public class Observation
- {
-
- public DateTime TimePeriod { get; set; }
-
- public void SetValue(string valueString)
- {
- Value = decimal.Parse(valueString);
- }
-
- public void SetTimePeriod(string timePeriodString)
- {
- TimePeriod = DateTime.Parse(timePeriodString);
- }
-
- public object Value { get; set;}
+ public class TimePeriod
+ {
+ public DateTime Value { get; set; }
+
+ public static TimePeriod Parse(string timePeriod)
+ {
+ var period = new TimePeriod();
+ period.Value = DateTime.Parse(timePeriod);
+
+ return period;
+ }
+ }
+
+ public class Observation
+ {
+ public TimePeriod TimePeriod { get; set; }
+ public object Value { get; set;}
+
+ public static Observation Create(string timePeriod, string value)
+ {
+ var obs = new Observation();
+ obs.TimePeriod = TimePeriod.Parse(timePeriod);
+ obs.Value = decimal.Parse(value);
+
+ return obs;
+ }
}
}
=======================================
--- /trunk/src/SDMX.Tests/SDMX.Tests.csproj Wed Sep 16 13:27:46 2009
+++ /trunk/src/SDMX.Tests/SDMX.Tests.csproj Thu Sep 17 13:51:29 2009
@@ -45,6 +45,10 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
+ <Reference Include="xmldiffpatch, Version=1.0.8.28, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\xmldiffpatch.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Code.cs" />
@@ -56,6 +60,7 @@
<Compile Include="KeyFamily.cs" />
<Compile Include="DataSet.cs" />
<Compile Include="Obs.cs" />
+ <Compile Include="ParserTests.cs" />
<Compile Include="QueryMessageTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SDMXException.cs" />
=======================================
--- /trunk/src/SDMX.Tests/Series.cs Wed Sep 16 13:27:46 2009
+++ /trunk/src/SDMX.Tests/Series.cs Thu Sep 17 13:51:29 2009
@@ -9,8 +9,7 @@
{
//public SeriesKey Key { get; private set; }
private Dictionary<Dimension, object> key = new
Dictionary<Dimension,object>();
-
- public Observation Obs { get; set; }
+ private Dictionary<TimePeriod, Observation> observations = new
Dictionary<TimePeriod, Observation>();
private DataSet dataSet;
internal Series(DataSet dataSet)
@@ -49,9 +48,15 @@
return value;
}
- internal void AddObservation(Observation obs)
- {
- throw new NotImplementedException();
+ internal void AddObservation(Observation observation)
+ {
+ if (observations.Keys.Contains(observation.TimePeriod))
+ {
+ throw new SDMXException("observation with time period
already exsists '{0}'".F(observation.TimePeriod));
+ }
+
+ observations.Add(observation.TimePeriod, observation);
+
}
}
}
=======================================
--- /trunk/src/SDMX.Tests/Utility.cs Wed Sep 16 13:27:46 2009
+++ /trunk/src/SDMX.Tests/Utility.cs Thu Sep 17 13:51:29 2009
@@ -2,6 +2,8 @@
using System.IO;
using System.Xml.Linq;
using System.Xml.Schema;
+using Microsoft.XmlDiffPatch;
+using System.Xml;
namespace SDMX.Tests
{
@@ -46,7 +48,21 @@
internal static bool CompareXML(XDocument xmlDocument1, XDocument
xmlDocument2)
{
- return XNode.DeepEquals(xmlDocument1, xmlDocument1);
+ XmlDiff diff = new XmlDiff();
+ diff.IgnoreChildOrder = true;
+ diff.IgnoreXmlDecl = true;
+ diff.IgnoreWhitespace = true;
+ diff.IgnoreComments = true;
+ diff.IgnorePI = true;
+ diff.IgnoreDtd = true;
+ var doc1 = new XmlDocument();
+ doc1.LoadXml(xmlDocument1.ToString());
+ var doc2 = new XmlDocument();
+ doc2.LoadXml(xmlDocument2.ToString());
+
+ bool result = diff.Compare(doc1, doc2);
+
+ return result;
}
}
}