public void Store(IEnumerable <DataSource> sources) { var sheet = new DataSourcesSheet(); sheet.SetSources(sources); var file = Path.Combine(myProjectHost.Project.StorageRoot, "DataSources.xdb"); using (var stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { var serializer = new ImportSpecSerializer(); serializer.Write(stream, sheet); } }
public static void Dump <T>(T obj, TextWriter writer) { Contract.RequiresNotNull(obj, "obj"); var settings = new XmlWriterSettings { Indent = true }; using (var xmlWriter = XmlWriter.Create(writer, settings)) { var serializer = new ImportSpecSerializer { EnableValidation = false }; serializer.Write(xmlWriter, obj); } }
// TODO: add some caching here to avoid Disk/IO public IEnumerable <DataSource> Load() { var file = Path.Combine(myProjectHost.Project.StorageRoot, "DataSources.xdb"); if (!File.Exists(file)) { return(Enumerable.Empty <DataSource>()); } DataSourcesSheet sheet; using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { var serializer = new ImportSpecSerializer(); sheet = serializer.ReadCompatible(stream); } if (sheet.WasMigratedToNewerVersion) { Store(sheet.GetSources <DataSource>()); } return(sheet.GetSources <DataSource>()); }
public void Load_ImportSpecVersion2_AllDataDeserialized() { using (var stream = new FileStream(Path.Combine(TestDataRoot, "DataSources", "Version2.xdb"), FileMode.Open, FileAccess.Read)) { var serializer = new ImportSpecSerializer(); var sheet = serializer.Read <DataSourcesSheet>(stream); Assert.That(sheet.WasMigratedToNewerVersion, Is.False); { var dataSource = sheet.GetSources <DataSource>().Single(ds => ds.Name == "Fundamentals"); Assert.That(dataSource.Vendor, Is.EqualTo("Ariva")); Assert.That(dataSource.DocumentType, Is.EqualTo(DocumentType.Html)); Assert.That(dataSource.Location.Fragments[0], Is.InstanceOf <Request>()); Assert.That(dataSource.Location.Fragments[0].UrlString, Is.EqualTo("http://www.ariva.de/search/search.m?searchname=${Isin}")); Assert.That(dataSource.Location.Fragments[1], Is.InstanceOf <Response>()); Assert.That(dataSource.Location.Fragments[1].UrlString, Is.EqualTo("http://www.ariva.de/{(.*)}?")); Assert.That(dataSource.Location.Fragments[2], Is.InstanceOf <Request>()); Assert.That(dataSource.Location.Fragments[2].UrlString, Is.EqualTo("http://www.ariva.de/{0}/bilanz-guv")); Assert.That(dataSource.Figures.Single(), Is.InstanceOf <PathSeriesDescriptor>()); var descriptor = ( PathSeriesDescriptor )dataSource.Figures.Single(); Assert.That(descriptor.Excludes, Is.EquivalentTo(new int[] { 6 })); Assert.That(descriptor.Figure, Is.EqualTo("Dividend")); Assert.That(descriptor.Orientation, Is.EqualTo(SeriesOrientation.Row)); Assert.That(descriptor.Path, Is.EqualTo("/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/TABLE[3]/TBODY[0]/TR[9]/TD[1]")); Assert.That(descriptor.TimeFormat.Type, Is.EqualTo(typeof(int))); Assert.That(descriptor.TimeFormat.Format, Is.EqualTo("0000")); Assert.That((( AbsolutePositionLocator )descriptor.TimesLocator).SeriesPosition, Is.EqualTo(0)); Assert.That(descriptor.ValueFormat.Type, Is.EqualTo(typeof(double))); Assert.That(descriptor.ValueFormat.Format, Is.EqualTo("000.000,0000")); Assert.That(descriptor.ValueFormat.InMillions, Is.False); Assert.That((( StringContainsLocator )descriptor.ValuesLocator).Pattern, Is.EqualTo("Dividendenaussch")); } { var dataSource = sheet.GetSources <DataSource>().Single(ds => ds.Name == "Prices"); Assert.That(dataSource.Vendor, Is.EqualTo("Ariva")); Assert.That(dataSource.DocumentType, Is.EqualTo(DocumentType.Html)); Assert.That(dataSource.Location.Fragments[0], Is.InstanceOf <Request>()); Assert.That(dataSource.Location.Fragments[0].UrlString, Is.EqualTo("http://www.ariva.de/search/search.m?searchname=${Isin}")); Assert.That(dataSource.Location.Fragments[1], Is.InstanceOf <Response>()); Assert.That(dataSource.Location.Fragments[1].UrlString, Is.EqualTo("http://www.ariva.de/{(.*)}?")); Assert.That(dataSource.Location.Fragments[2], Is.InstanceOf <Request>()); Assert.That(dataSource.Location.Fragments[2].UrlString, Is.EqualTo("http://www.ariva.de/{0}/kurs")); Assert.That(dataSource.Figures.Single(), Is.InstanceOf <PathCellDescriptor>()); var descriptor = ( PathCellDescriptor )dataSource.Figures.Single(); Assert.That((( StringContainsLocator )descriptor.Column).HeaderSeriesPosition, Is.EqualTo(0)); Assert.That((( StringContainsLocator )descriptor.Column).Pattern, Is.EqualTo("Letzter")); Assert.That(descriptor.Currency, Is.EquivalentTo("EUR")); Assert.That(descriptor.Figure, Is.EqualTo("Price")); Assert.That(descriptor.Path, Is.EqualTo("/BODY[0]/DIV[0]/DIV[1]/DIV[6]/DIV[1]/DIV[0]/DIV[0]/TABLE[0]/TBODY[0]")); Assert.That((( StringContainsLocator )descriptor.Row).HeaderSeriesPosition, Is.EqualTo(0)); Assert.That((( StringContainsLocator )descriptor.Row).Pattern, Is.EqualTo("Frankfurt")); Assert.That(descriptor.ValueFormat.Type, Is.EqualTo(typeof(double))); Assert.That(descriptor.ValueFormat.Format, Is.EqualTo("000.000,0000")); Assert.That(descriptor.ValueFormat.InMillions, Is.False); } } }